Skip to content

Commit

Permalink
test(webauthn): add test when rpId set in environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
onehassan committed Nov 24, 2023
1 parent 7037935 commit b85482e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/routes/signin/webauthn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,40 @@ describe('webauthn', () => {
});
});

it('should return authentication options with rpId set in the environement variables', async () => {
const email = faker.internet.email();
const password = faker.internet.password();

const record = await insertDbUser(client, email, password, true, false);
expect(record.rowCount).toEqual(1);

const userRecord = await client.query(`SELECT id FROM auth.users LIMIT 1;`);
expect(userRecord.rows).toBeArrayOfSize(1);
expect(userRecord.rows[0]).toHaveProperty('id');

const rpId = 'example.io';

await request.post('/change-env').send({
AUTH_WEBAUTHN_RP_ID: rpId,
});

const { body } = await request
.post('/signin/webauthn')
.send({ email })
.expect(StatusCodes.OK);

// checking its persist and remove it as cannot compare
expect(body).toHaveProperty('challenge');
delete body.challenge;

expect(body).toEqual({
allowCredentials: [],
rpId,
timeout: 60000,
userVerification: 'preferred',
});
});

it('should fail verify user is webauth is not enabled', async () => {
const email = faker.internet.email();

Expand Down

0 comments on commit b85482e

Please sign in to comment.