Various additional tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {beforeAll, expect, test} from 'bun:test'
|
||||
import {PwdBox} from '..'
|
||||
import {misc, PwdBox} from '..'
|
||||
|
||||
let k1!: string
|
||||
let k2!: string
|
||||
@@ -8,7 +8,7 @@ let message!: Uint8Array
|
||||
beforeAll(async () => {
|
||||
k1 = 'abc'
|
||||
k2 = 'def'
|
||||
message = new TextEncoder().encode('Salut ! ça va ?')
|
||||
message = misc.payload_fromString('Salut ! ça va ?')
|
||||
})
|
||||
|
||||
test('base case', async () => {
|
||||
@@ -23,12 +23,15 @@ test("Different key can't decrypt", async () => {
|
||||
})
|
||||
|
||||
test('serialization', async () => {
|
||||
const message = new Uint8Array(8)
|
||||
const box = await PwdBox.encrypt(message, k1)
|
||||
|
||||
const ser = box.toString()
|
||||
const de = PwdBox.fromString(ser)
|
||||
expect(de).not.toBeNull()
|
||||
|
||||
expect(de).not.toBeNull()
|
||||
expect(de).toEqual(box)
|
||||
|
||||
const unboxed = await de!.decrypt(k1)
|
||||
expect(unboxed).not.toBeNull()
|
||||
expect(unboxed).toEqual(message)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user