Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move the error type test into verifyJWT() tests
  • Loading branch information
lahirumaramba committed Mar 9, 2021
commit bba0b022694e2fa665694a2f1f4f20562bdea0a3
56 changes: 28 additions & 28 deletions test/unit/auth/token-verifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,34 +312,6 @@ describe('FirebaseTokenVerifier', () => {
});
});

const errorTypes = [
{ type: FirebaseAuthError, code: AUTH_ERROR_CODE_CONFIG },
];
errorTypes.forEach((errorType) => {
const tokenVerifier = new verifier.FirebaseTokenVerifier(
'https://www.example.com/publicKeys',
'RS256',
'https://www.example.com/issuer/',
{
url: 'https://docs.example.com/verify-tokens',
verifyApiName: 'verifyToken()',
jwtName: 'Important Token',
shortName: 'token',
expiredErrorCode: errorType.code.invalidArg,
errorCodeConfig: errorType.code,
errorType: errorType.type,
},
app,
);
it('should throw with the correct error type and code set in token info', () => {
expect(() => {
(tokenVerifier as any).verifyJWT();
}).to.throw(errorType.type).with.property('code').match(
new RegExp(`(.*)/${errorType.code.invalidArg.code}`)
);
});
});

describe('verifyJWT()', () => {
let mockedRequests: nock.Scope[] = [];

Expand All @@ -354,6 +326,34 @@ describe('FirebaseTokenVerifier', () => {
}).to.throw('First argument to verifyIdToken() must be a Firebase ID token');
});

const errorTypes = [
{ type: FirebaseAuthError, config: AUTH_ERROR_CODE_CONFIG },
];
errorTypes.forEach((errorType) => {
const tokenVerifier = new verifier.FirebaseTokenVerifier(
'https://www.example.com/publicKeys',
'RS256',
'https://www.example.com/issuer/',
{
url: 'https://docs.example.com/verify-tokens',
verifyApiName: 'verifyToken()',
jwtName: 'Important Token',
shortName: 'token',
expiredErrorCode: errorType.config.invalidArg,
errorCodeConfig: errorType.config,
errorType: errorType.type,
},
app,
);
it('should throw with the correct error type and code set in token info', () => {
expect(() => {
(tokenVerifier as any).verifyJWT();
}).to.throw(errorType.type).with.property('code').match(
new RegExp(`(.*)/${errorType.config.invalidArg.code}`)
);
});
});

const invalidIdTokens = [null, NaN, 0, 1, true, false, [], {}, { a: 1 }, _.noop];
invalidIdTokens.forEach((invalidIdToken) => {
it('should throw given a non-string Firebase JWT token: ' + JSON.stringify(invalidIdToken), () => {
Expand Down