Skip to content

Commit

Permalink
add test for missing vc context
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand committed Jan 13, 2025
1 parent bf67187 commit 588adbe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/test-fixtures/vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,17 @@ const getCredentialWithoutContext = (): any => {
return cred
}

const getCredentialWithoutVCContext = (): any => {
const cred = getVCv2()
cred['@context'] = cred['@context'].filter((context : string) => context !== 'https://www.w3.org/ns/credentials/v2') // remove the vc context
return cred
}

export {

getCredentialWithoutContext,
getCredentialWithoutVCContext,

getVCv2,
getVCv2Expired,
getVCv2Revoked,
Expand Down
17 changes: 15 additions & 2 deletions test/Verify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chai from 'chai'
import deepEqualInAnyOrder from 'deep-equal-in-any-order'
import { strict as assert } from 'assert';
import { verifyCredential } from '../src/Verify.js'
import { getVCv2Expired, getVCv1Tampered, getVCv1Expired, getVCv1Revoked, getVCv2Revoked, getVCv1ValidStatus, getVCv2ValidStatus, getVCv2Tampered, getVCv1NoProof, getVCv2NoProof, getCredentialWithoutContext } from '../src/test-fixtures/vc.js'
import { getVCv2Expired, getVCv1Tampered, getVCv1Expired, getVCv1Revoked, getVCv2Revoked, getVCv1ValidStatus, getVCv2ValidStatus, getVCv2Tampered, getVCv1NoProof, getVCv2NoProof, getCredentialWithoutContext, getCredentialWithoutVCContext } from '../src/test-fixtures/vc.js'
import { knownDIDRegistries } from '../.knownDidRegistries.js';
import { getExpectedVerifiedResult, getExpectedUnverifiedResult, getExpectedFatalResult } from '../src/test-fixtures/expectedResults.js';

Expand All @@ -13,7 +13,7 @@ describe('Verify', () => {

describe('.verifyCredential', () => {

describe('general fatal errors', () => {
describe('returns general fatal errors', () => {
it('when not jsonld', async () => {
const credential : any = getCredentialWithoutContext()
const result = await verifyCredential({credential, reloadIssuerRegistry: false, knownDIDRegistries})
Expand All @@ -25,6 +25,19 @@ describe('Verify', () => {
})
expect(result).to.deep.equalInAnyOrder(expectedResult)
})

it('when no vc context', async () => {
const credential : any = getCredentialWithoutVCContext()
const result = await verifyCredential({credential, reloadIssuerRegistry: false, knownDIDRegistries})

const expectedResult = getExpectedFatalResult({
credential,
errorMessage: "The credential doesn't have a verifiable credential context.",
errorName: 'no_vc_context'
})
expect(result).to.deep.equalInAnyOrder(expectedResult)
})

})

describe('with VC version 1', () => {
Expand Down

0 comments on commit 588adbe

Please sign in to comment.