Skip to content

Commit b20fca8

Browse files
committed
add assertions that prove default key used when no storage values
1 parent 52b87c2 commit b20fca8

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

keeperapi/src/__tests__/endpoint.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ describe('KeeperEndpoint - Transmission Key ID Rotation', () => {
215215
expect(mockConfig.deviceConfig.mlKemPublicKeyId).toBe(defaultMlKemKeyId)
216216
expect(onDeviceConfigMock).toHaveBeenCalledTimes(1)
217217
expect(postSpy).toHaveBeenCalledTimes(2) // First fails, second succeeds
218+
219+
// Check that the first call used the default EC key, and second used the new EC key
220+
const firstCallArgs = postSpy.mock.calls[0]
221+
const firstRequest = Authentication.ApiRequest.decode(firstCallArgs[1])
222+
expect(firstRequest.qrcMessageKey).toBeNull()
223+
expect(firstRequest.publicKeyId).toBe(defaultEcKeyId)
224+
const secondCallArgs = postSpy.mock.calls[1]
225+
const secondRequest = Authentication.ApiRequest.decode(secondCallArgs[1])
226+
expect(secondRequest.qrcMessageKey).toBeNull()
227+
expect(secondRequest.publicKeyId).toBe(newEcKeyId)
218228
})
219229

220230
it('should use default keys when device config has no keys set (HPKE)', async () => {
@@ -239,6 +249,18 @@ describe('KeeperEndpoint - Transmission Key ID Rotation', () => {
239249
expect(mockConfig.deviceConfig.mlKemPublicKeyId).toBe(newMlKemKeyId)
240250
expect(onDeviceConfigMock).toHaveBeenCalledTimes(1)
241251
expect(postSpy).toHaveBeenCalledTimes(2) // First fails, second succeeds
252+
253+
// Check that the first call used the default keys, and second used the new keys
254+
const firstCallArgs = postSpy.mock.calls[0]
255+
const firstRequest = Authentication.ApiRequest.decode(firstCallArgs[1])
256+
expect(firstRequest.qrcMessageKey).toBeDefined()
257+
expect(firstRequest.qrcMessageKey!.ecKeyId).toBe(defaultEcKeyId)
258+
expect(firstRequest.publicKeyId).toBe(defaultMlKemKeyId)
259+
const secondCallArgs = postSpy.mock.calls[1]
260+
const secondRequest = Authentication.ApiRequest.decode(secondCallArgs[1])
261+
expect(secondRequest.qrcMessageKey).toBeDefined()
262+
expect(secondRequest.qrcMessageKey!.ecKeyId).toBe(newEcKeyId)
263+
expect(secondRequest.publicKeyId).toBe(newMlKemKeyId)
242264
})
243265

244266
it("should switch from HPKE to non-HPKE when server doesn't support HPKE", async () => {

0 commit comments

Comments
 (0)