diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-21 18:44:29 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-05-21 18:44:29 -0700 |
commit | 54482eb74590feaee0c44829630e750fb724a5dd (patch) | |
tree | 12e8c6f70497a688604f03cbac0a679350011725 /packages/server/src | |
parent | e8c2c3171f6143409759f6d9ef06fab53600448c (diff) |
Add unit tests for edge cases in convertCOSEtoPKCS
Diffstat (limited to 'packages/server/src')
-rw-r--r-- | packages/server/src/helpers/convertCOSEtoPKCS.test.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/server/src/helpers/convertCOSEtoPKCS.test.ts b/packages/server/src/helpers/convertCOSEtoPKCS.test.ts new file mode 100644 index 0000000..1d0ad6e --- /dev/null +++ b/packages/server/src/helpers/convertCOSEtoPKCS.test.ts @@ -0,0 +1,29 @@ +import cbor from 'cbor'; +import { COSEKEYS } from '@webauthntine/typescript-types'; + +import convertCOSEtoPKCS from './convertCOSEtoPKCS'; + + +test('should throw an error curve if, somehow, curve coordinate x is missing', () => { + const mockCOSEKey = new Map<number, number | Buffer>(); + + mockCOSEKey.set(COSEKEYS.y, 1); + + jest.spyOn(cbor, 'decodeFirstSync').mockReturnValue(mockCOSEKey); + + expect(() => { + convertCOSEtoPKCS(Buffer.from('123', 'ascii')); + }).toThrow(); +}); + +test('should throw an error curve if, somehow, curve coordinate y is missing', () => { + const mockCOSEKey = new Map<number, number | Buffer>(); + + mockCOSEKey.set(COSEKEYS.x, 1); + + jest.spyOn(cbor, 'decodeFirstSync').mockReturnValue(mockCOSEKey); + + expect(() => { + convertCOSEtoPKCS(Buffer.from('123', 'ascii')); + }).toThrow(); +}); |