diff options
-rw-r--r-- | packages/server/src/attestation/verifyAttestationResponse.test.ts | 55 | ||||
-rw-r--r-- | packages/server/src/setupTests.ts | 1 |
2 files changed, 56 insertions, 0 deletions
diff --git a/packages/server/src/attestation/verifyAttestationResponse.test.ts b/packages/server/src/attestation/verifyAttestationResponse.test.ts index 5d5f156..16763ce 100644 --- a/packages/server/src/attestation/verifyAttestationResponse.test.ts +++ b/packages/server/src/attestation/verifyAttestationResponse.test.ts @@ -1,5 +1,21 @@ import verifyAttestationResponse from './verifyAttestationResponse'; +import * as decodeAttestationObject from '../helpers/decodeAttestationObject'; +import * as decodeClientDataJSON from '../helpers/decodeClientDataJSON'; + +let mockDecodeAttestation: jest.SpyInstance; +let mockDecodeClientData: jest.SpyInstance; + +beforeEach(() => { + mockDecodeAttestation = jest.spyOn(decodeAttestationObject, 'default'); + mockDecodeClientData = jest.spyOn(decodeClientDataJSON, 'default'); +}); + +afterEach(() => { + mockDecodeAttestation.mockRestore(); + mockDecodeClientData.mockRestore(); +}); + test('should verify FIDO U2F attestation', () => { const verification = verifyAttestationResponse( attestationFIDOU2F, @@ -69,6 +85,45 @@ test('should verify Android SafetyNet attestation', () => { ); }); +test('should throw when response origin is not expected value', () => { + expect(() => { + verifyAttestationResponse( + attestationNone, + 'https://different.address' + ); + }).toThrow('Attestation origin was an unexpected value'); +}); + +test('should throw when attestation type is not webauthn.create', () => { + const origin = 'https://dev.dontneeda.pw'; + + // @ts-ignore 2345 + mockDecodeClientData.mockReturnValue({ origin, type: 'webauthn.badtype' }); + + expect(() => { + verifyAttestationResponse( + attestationNone, + origin, + ); + }).toThrow('Attestation type was an unexpected value'); +}); + +test('should throw if an unexpected attestation format is specified', () => { + const fmt = 'fizzbuzz'; + + mockDecodeAttestation.mockReturnValue({ + // @ts-ignore 2322 + fmt, + }); + + expect(() => { + verifyAttestationResponse( + attestationNone, + 'https://dev.dontneeda.pw', + ); + }).toThrow(`Unsupported Attestation Format: ${fmt}`); +}); + const attestationFIDOU2F = { base64AttestationObject: 'o2NmbXRoZmlkby11MmZnYXR0U3RtdKJjc2lnWEgwRgIhAK40WxA0t7py7AjEXvwGw' + 'TlmqlvrOks5g9lf+9zXzRiVAiEA3bv60xyXveKDOusYzniD7CDSostCet9PYK7FLdnTdZNjeDVjgVkCwTCCAr0wg' + diff --git a/packages/server/src/setupTests.ts b/packages/server/src/setupTests.ts index 4cf23af..d515122 100644 --- a/packages/server/src/setupTests.ts +++ b/packages/server/src/setupTests.ts @@ -1,3 +1,4 @@ // Silence some console output jest.spyOn(console, 'log').mockImplementation(); jest.spyOn(console, 'debug').mockImplementation(); +jest.spyOn(console, 'error').mockImplementation(); |