summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods/startAttestation.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src/methods/startAttestation.test.ts')
-rw-r--r--packages/browser/src/methods/startAttestation.test.ts85
1 files changed, 49 insertions, 36 deletions
diff --git a/packages/browser/src/methods/startAttestation.test.ts b/packages/browser/src/methods/startAttestation.test.ts
index 0efec48..539ffe5 100644
--- a/packages/browser/src/methods/startAttestation.test.ts
+++ b/packages/browser/src/methods/startAttestation.test.ts
@@ -1,6 +1,9 @@
import base64js from 'base64-js';
-import { AttestationCredential, PublicKeyCredentialCreationOptionsJSON } from '@webauthntine/typescript-types';
+import {
+ AttestationCredential,
+ PublicKeyCredentialCreationOptionsJSON,
+} from '@webauthntine/typescript-types';
import toUint8Array from '../helpers/toUint8Array';
import supportsWebauthn from '../helpers/supportsWebauthn';
@@ -9,8 +12,8 @@ import startAttestation from './startAttestation';
jest.mock('../helpers/supportsWebauthn');
-const mockNavigatorCreate = (window.navigator.credentials.create as jest.Mock);
-const mockSupportsWebauthn = (supportsWebauthn as jest.Mock);
+const mockNavigatorCreate = window.navigator.credentials.create as jest.Mock;
+const mockSupportsWebauthn = supportsWebauthn as jest.Mock;
const mockAttestationObject = 'mockAtte';
const mockClientDataJSON = 'mockClie';
@@ -19,10 +22,12 @@ const goodOpts1: PublicKeyCredentialCreationOptionsJSON = {
publicKey: {
challenge: 'fizz',
attestation: 'direct',
- pubKeyCredParams: [{
- alg: -7,
- type: "public-key",
- }],
+ pubKeyCredParams: [
+ {
+ alg: -7,
+ type: 'public-key',
+ },
+ ],
rp: {
id: '1234',
name: 'webauthntine',
@@ -41,15 +46,17 @@ beforeEach(() => {
mockSupportsWebauthn.mockReset();
});
-test('should convert options before passing to navigator.credentials.create(...)', async (done) => {
+test('should convert options before passing to navigator.credentials.create(...)', async done => {
mockSupportsWebauthn.mockReturnValue(true);
// Stub out a response so the method won't throw
- mockNavigatorCreate.mockImplementation((): Promise<any> => {
- return new Promise((resolve) => {
- resolve({ response: {} });
- });
- });
+ mockNavigatorCreate.mockImplementation(
+ (): Promise<any> => {
+ return new Promise(resolve => {
+ resolve({ response: {} });
+ });
+ },
+ );
await startAttestation(goodOpts1);
@@ -61,23 +68,25 @@ test('should convert options before passing to navigator.credentials.create(...)
done();
});
-test('should return base64-encoded response values', async (done) => {
+test('should return base64-encoded response values', async done => {
mockSupportsWebauthn.mockReturnValue(true);
- mockNavigatorCreate.mockImplementation((): Promise<AttestationCredential> => {
- return new Promise((resolve) => {
- resolve({
- id: 'foobar',
- rawId: toUint8Array('foobar'),
- response: {
- attestationObject: base64js.toByteArray(mockAttestationObject),
- clientDataJSON: base64js.toByteArray(mockClientDataJSON),
- },
- getClientExtensionResults: () => ({}),
- type: 'webauthn.create',
+ mockNavigatorCreate.mockImplementation(
+ (): Promise<AttestationCredential> => {
+ return new Promise(resolve => {
+ resolve({
+ id: 'foobar',
+ rawId: toUint8Array('foobar'),
+ response: {
+ attestationObject: base64js.toByteArray(mockAttestationObject),
+ clientDataJSON: base64js.toByteArray(mockClientDataJSON),
+ },
+ getClientExtensionResults: () => ({}),
+ type: 'webauthn.create',
+ });
});
- });
- });
+ },
+ );
const response = await startAttestation(goodOpts1);
@@ -87,24 +96,28 @@ test('should return base64-encoded response values', async (done) => {
});
done();
-})
+});
-test('should throw error if WebAuthn isn\'t supported', async (done) => {
+test("should throw error if WebAuthn isn't supported", async done => {
mockSupportsWebauthn.mockReturnValue(false);
- await expect(startAttestation(goodOpts1)).rejects.toThrow('WebAuthn is not supported in this browser');
+ await expect(startAttestation(goodOpts1)).rejects.toThrow(
+ 'WebAuthn is not supported in this browser',
+ );
done();
});
-test('should throw error if attestation is cancelled for some reason', async (done) => {
+test('should throw error if attestation is cancelled for some reason', async done => {
mockSupportsWebauthn.mockReturnValue(true);
- mockNavigatorCreate.mockImplementation((): Promise<null> => {
- return new Promise((resolve) => {
- resolve(null);
- });
- });
+ mockNavigatorCreate.mockImplementation(
+ (): Promise<null> => {
+ return new Promise(resolve => {
+ resolve(null);
+ });
+ },
+ );
await expect(startAttestation(goodOpts1)).rejects.toThrow('Attestation was not completed');