add unverified URL data test case

This commit is contained in:
Felicio Mununga 2023-03-21 12:41:49 +01:00
parent 672b7c2c62
commit a5830bec1c
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 22 additions and 15 deletions

View File

@ -1,24 +1,31 @@
import { describe, expect, test } from 'vitest'
import { expect, test } from 'vitest'
import { signEncodedURLData, verifyEncodedURLData } from './sign-url-data'
import type { EncodedURLData } from './encode-url-data'
describe('Sign URL data', () => {
const privateKey = new Uint8Array([
233, 34, 68, 49, 2, 175, 16, 66, 41, 112, 38, 154, 139, 197, 117, 203, 223,
215, 4, 135, 228, 217, 5, 31, 75, 9, 30, 221, 141, 239, 82, 84,
])
const privateKey = new Uint8Array([
233, 34, 68, 49, 2, 175, 16, 66, 41, 112, 38, 154, 139, 197, 117, 203, 223,
215, 4, 135, 228, 217, 5, 31, 75, 9, 30, 221, 141, 239, 82, 84,
])
test('should sign and verify URL data', async () => {
const encodedURLData =
'G74AgK0ObFNmYT-WC_Jcc9KfSjHXAQo9THKEEbgPaJoItceMES-bUxr2Tj9efv447rRefBIUg9CEsSFyjBOFTRdZ9PH2wUOW8hVNYqIje3BC96mZ8uFogqM6k7gCCJnMHy4ulsmsgHTdeh5dAzTNNuG8m9XB8oVeildTCKlRhINnTZh4kAl5sP8SzBB4V2_I41a8PKl3mcS0z_eF5gA=' as EncodedURLData
const encodedURLData =
'G74AgK0ObFNmYT-WC_Jcc9KfSjHXAQo9THKEEbgPaJoItceMES-bUxr2Tj9efv447rRefBIUg9CEsSFyjBOFTRdZ9PH2wUOW8hVNYqIje3BC96mZ8uFogqM6k7gCCJnMHy4ulsmsgHTdeh5dAzTNNuG8m9XB8oVeildTCKlRhINnTZh4kAl5sP8SzBB4V2_I41a8PKl3mcS0z_eF5gA=' as EncodedURLData
const signature = await signEncodedURLData(encodedURLData, privateKey)
test('should sign and verify URL data', async () => {
const signature = await signEncodedURLData(encodedURLData, privateKey)
expect(signature).toBe(
'k-n7d-9Pcx6ht87F4riP5xAw1v7S-e1HGMRaeaO068Q3IF1Jo8xOyeMT9Yr3Wv349Z2CdBzylw8M83CgQhcMogA='
)
expect(verifyEncodedURLData(signature, encodedURLData)).toBe(true)
})
expect(signature).toBe(
'k-n7d-9Pcx6ht87F4riP5xAw1v7S-e1HGMRaeaO068Q3IF1Jo8xOyeMT9Yr3Wv349Z2CdBzylw8M83CgQhcMogA='
)
expect(verifyEncodedURLData(signature, encodedURLData)).toBe(true)
})
test.todo('should not verify URL data', async () => {
const signatureForAnotherContent =
'OyOgY6Zta8S7U4l5Bv_9E_7snALhixwvjxORVAVJ-YJk-tMSGgstOy5XEEQx25TQJIAtpWf8eHnEmV8V-GmouQA='
expect(verifyEncodedURLData(signatureForAnotherContent, encodedURLData)).toBe(
false
)
})