Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
Validate jwt: test cases fix (#322)
Browse files Browse the repository at this point in the history
* fix: did & added validation on expiresAt

* fix: did & added validation on expiresAt

* fix: lib version upgrade

* fix: linter issue

* fix: merge conditions

* fix: linter error

* fix: linter error

* fix: corrected changelog date

* fix: condition added to handle undefined exp

* fix: condition added to handle undefined exp

* fix: error codes and messages

---------

Co-authored-by: Mritunjay Kumar <mritunjaykumar@Mac-C02G429HMD6R.local>
  • Loading branch information
mritunjayk2 and Mritunjay Kumar authored Aug 24, 2023
1 parent c5e3b6d commit 2cdc8f6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion common-libs/common/test/unit/Affinity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe('Affinity', () => {
}

expect(expiredTokenError).to.be.not.undefined
expect(expiredTokenError.message).to.be.equal('Token expired')
expect(expiredTokenError.message).to.be.equal('Token expired or invalid expiration')
})

it('#validateJWT (When initial token do not match)', async () => {
Expand Down
2 changes: 1 addition & 1 deletion common-libs/tools-common/src/SdkError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const commonErrors = {
},
'COR-19': {
type: 'OperationError',
message: 'Token expired',
message: 'Token expired or invalid expiration',
httpStatusCode: 400,
},
'COR-20': {
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/src/services/HolderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class HolderService {
try {
await this._affinityService.validateJWT(credentialShareResponseToken, credentialShareRequestToken, didDocument)
} catch (error) {
if (error.message === 'Token expired') {
if (error.message === 'Token expired or invalid expiration') {
throw new SdkErrorFromCode('COR-19')
}

Expand Down Expand Up @@ -242,14 +242,14 @@ export default class HolderService {
}

if (payload.exp < Date.now()) {
throw new Error('Token expired')
throw new Error('Token expired or invalid expiration')
}
}
async verifyCredentialOfferRequest(credentialOfferRequestToken: string) {
try {
await this._affinityService.validateJWT(credentialOfferRequestToken)
} catch (error) {
if (error.message === 'Token expired') {
if (error.message === 'Token expired or invalid expiration') {
return { isValid: false, errorCode: 'COR-19', error: error.message }
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/test/integration/NetworkMember.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ describe('CommonNetworkMember', () => {
const { code, httpStatusCode, message } = responseError

expect(code).to.equal('COR-19')
expect(message).to.equal('Token expired')
expect(message).to.equal('Token expired or invalid expiration')
expect(httpStatusCode).to.equal(400)
})

Expand Down

0 comments on commit 2cdc8f6

Please sign in to comment.