rewrite tests
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import {beforeAll, expect, test} from 'bun:test'
|
||||
import {PwdWrap, SecretBox} from '..'
|
||||
|
||||
let k1!: string;
|
||||
let k2!: string;
|
||||
let message!: CryptoKey;
|
||||
|
||||
beforeAll(async () => {
|
||||
k1 = "abc"
|
||||
k2 = "def"
|
||||
message = await SecretBox.gen(true)
|
||||
})
|
||||
|
||||
test('base case', async () => {
|
||||
const box = await PwdWrap.encrypt(message, k1)
|
||||
const unboxed = await box.decrypt(k1)
|
||||
expect(unboxed).toEqual(message)
|
||||
})
|
||||
test("Different key can't decrypt", async () => {
|
||||
const box = await PwdWrap.encrypt(message, k1)
|
||||
const unboxed = await box.decrypt(k2)
|
||||
expect(unboxed).toBeNull()
|
||||
})
|
||||
|
||||
test('serialization', async () => {
|
||||
const box = await PwdWrap.encrypt(message, k1)
|
||||
|
||||
const ser = box.toString()
|
||||
const de = PwdWrap.fromString(ser)
|
||||
expect(de).not.toBeNull()
|
||||
|
||||
expect(de).toEqual(box)
|
||||
})
|
||||
Reference in New Issue
Block a user