Skip to content

Commit

Permalink
replace nullish coalescing with logical or for registry check
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand committed Jan 13, 2025
1 parent 9aff772 commit 0bb989a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/issuerRegistries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function getTrustedRegistryListForIssuer({ issuer, knownDIDRegistri
reloadIssuerRegistry: boolean | null
}): Promise<string[] | null> {

if (reloadIssuerRegistry ?? registryNotYetLoaded) {
if (reloadIssuerRegistry || registryNotYetLoaded) {
await registries.load({ config: knownDIDRegistries })
}
const issuerDid = typeof issuer === 'string' ? issuer : issuer.id;
Expand Down
21 changes: 13 additions & 8 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, getVCv1ValidStatus, getVCv2ValidStatus, getVCv2Tampered } from '../src/test-fixtures/vc.js'
import { getVCv2Expired, getVCv1Tampered, getVCv1Expired, getVCv1Revoked, getVCv2Revoked, getVCv1ValidStatus, getVCv2ValidStatus, getVCv2Tampered } from '../src/test-fixtures/vc.js'
import { knownDIDRegistries } from '../.knownDidRegistries.js';
import { getExpectedVerifiedResult, getExpectedUnverifiedResult } from '../src/test-fixtures/expectedResults.js';

Expand All @@ -18,7 +18,7 @@ describe('Verify', () => {
describe('returns fatal error', () => {
it('when tampered with', async () => {
const tamperedVC1 : any = getVCv1Tampered()
const result = await verifyCredential({credential: tamperedVC1, reloadIssuerRegistry: true, knownDIDRegistries})
const result = await verifyCredential({credential: tamperedVC1, reloadIssuerRegistry: false, knownDIDRegistries})
assert.ok(result.verified === false);
})
})
Expand All @@ -27,20 +27,20 @@ describe('Verify', () => {
it('when status is valid', async () => {
const credential : any = getVCv1ValidStatus()
const expectedResult = getExpectedVerifiedResult({credential, withStatus: true})
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
const result = await verifyCredential({credential, reloadIssuerRegistry: false, knownDIDRegistries})
expect(result).to.deep.equalInAnyOrder(expectedResult) // eslint-disable-line no-use-before-define
})
})

describe('returns as unverified', () => {
it('when expired', async () => {
const credential : any = getVCv1Expired()
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
const result = await verifyCredential({credential, reloadIssuerRegistry: false, knownDIDRegistries})
assert.ok(result.log);
})
it('when revoked', async () => {
const credential : any = getVCv1Revoked()
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
const result = await verifyCredential({credential, reloadIssuerRegistry: false, knownDIDRegistries})
assert.ok(result.log);
})
})
Expand All @@ -53,15 +53,15 @@ describe('Verify', () => {
describe('returns fatal error', () => {
it('when tampered with', async () => {
const tamperedVC2 : any = getVCv2Tampered()
const result = await verifyCredential({credential: tamperedVC2, reloadIssuerRegistry: true, knownDIDRegistries})
const result = await verifyCredential({credential: tamperedVC2, reloadIssuerRegistry: false, knownDIDRegistries})
})
})

describe('returns as verified', () => {
it('when status is valid', async () => {
const credential : any = getVCv2ValidStatus()
const expectedResult = getExpectedVerifiedResult({credential, withStatus: true})
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
const result = await verifyCredential({credential, reloadIssuerRegistry: false, knownDIDRegistries})
expect(result).to.deep.equalInAnyOrder(expectedResult) // eslint-disable-line no-use-before-define
})
})
Expand All @@ -70,9 +70,14 @@ describe('Verify', () => {
it('when expired', async () => {
const credential : any = getVCv2Expired()
const expectedResult = getExpectedUnverifiedResult({credential, unVerifiedStep: 'expiration', withStatus:false})
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
const result = await verifyCredential({credential, reloadIssuerRegistry: false, knownDIDRegistries})
expect(result).to.deep.equalInAnyOrder(expectedResult)
})
it('when revoked', async () => {
const credential : any = getVCv2Revoked()
const result = await verifyCredential({credential, reloadIssuerRegistry: false, knownDIDRegistries})
assert.ok(result.log);
})
})
})
})
Expand Down

0 comments on commit 0bb989a

Please sign in to comment.