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