Skip to content

Commit

Permalink
Fix helper function error throwing and envelope tests variable alloca…
Browse files Browse the repository at this point in the history
…tion

Signed-off-by: PatStLouis <[email protected]>
  • Loading branch information
PatStLouis committed Jan 8, 2025
1 parent b47e60b commit 0ea6eee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
24 changes: 15 additions & 9 deletions tests/4.13.2-envelopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ describe('Enveloped Verifiable Credentials', function() {
negativeFixture = structuredClone(verifiableCredential);
negativeFixture['@context'] = [];
await assert.rejects(
verifyCredential({verifier, negativeFixture}),
verifyCredential({verifier, verifiableCredential: negativeFixture}),
'Failed to reject an enveloped VC with invalid context.');

// Replace context with an invalid value
negativeFixture = structuredClone(verifiableCredential);
negativeFixture['@context'] = 'https://www.w3.org/ns/credentials/examples/v2';
await assert.rejects(
verifyCredential({verifier, negativeFixture}),
verifyCredential({verifier, verifiableCredential: negativeFixture}),
'Failed to reject an enveloped VC with invalid context.');
}
});
Expand All @@ -101,7 +101,7 @@ describe('Enveloped Verifiable Credentials', function() {
negativeFixture = structuredClone(verifiableCredential);
negativeFixture.id = negativeFixture.id.split(',').pop();
await assert.rejects(
verifyCredential({verifier, negativeFixture}),
verifyCredential({verifier, verifiableCredential: negativeFixture}),
'Failed to reject an enveloped VC with an invalid data url id.');
}
});
Expand All @@ -125,15 +125,17 @@ describe('Enveloped Verifiable Credentials', function() {
negativeFixture = structuredClone(verifiableCredential);
delete negativeFixture.type;
await assert.rejects(
verifyCredential({verifier, negativeFixture}),
verifyCredential(
{verifier, verifiableCredential: negativeFixture}),
'Failed to reject an enveloped VC with an enveloped VC with a ' +
'missing `type`.');

// Replace type field
negativeFixture = structuredClone(verifiableCredential);
negativeFixture.type = 'VerifiableCredential';
await assert.rejects(
verifyCredential({verifier, negativeFixture}),
verifyCredential(
{verifier, verifiableCredential: negativeFixture}),
'Failed to reject an enveloped VC with an ' +
'invalid `type`.');
}
Expand Down Expand Up @@ -176,14 +178,16 @@ describe('Enveloped Verifiable Presentations', function() {
negativeFixture = structuredClone(verifiablePresentation);
negativeFixture['@context'] = [];
await assert.rejects(
verifyPresentation({vpVerifier, negativeFixture}),
verifyPresentation(
{vpVerifier, verifiablePresentation: negativeFixture}),
'Failed to reject Enveloped VP missing contexts.');

// Replace context field with invalid context
negativeFixture = structuredClone(verifiablePresentation);
negativeFixture['@context'] = ['https://www.w3.org/ns/credentials/examples/v2'];
await assert.rejects(
verifyPresentation({vpVerifier, negativeFixture}),
verifyPresentation(
{vpVerifier, verifiablePresentation: negativeFixture}),
'Failed to reject Enveloped VP missing contexts.');
}
});
Expand All @@ -203,7 +207,8 @@ describe('Enveloped Verifiable Presentations', function() {
negativeFixture = structuredClone(verifiablePresentation);
negativeFixture.id = negativeFixture.id.split(',').pop();
await assert.rejects(
verifyPresentation({vpVerifier, negativeFixture}),
verifyPresentation(
{vpVerifier, verifiablePresentation: negativeFixture}),
'Failed to reject Enveloped VP with an id that is not a data url.');
}
});
Expand All @@ -221,7 +226,8 @@ describe('Enveloped Verifiable Presentations', function() {
negativeFixture = structuredClone(verifiablePresentation);
negativeFixture.type = ['VerifiablePresentation'];
await assert.rejects(
verifyPresentation({vpVerifier, negativeFixture}),
verifyPresentation(
{vpVerifier, verifiablePresentation: negativeFixture}),
'Failed to reject VP w/o type "EnvelopedVerifiablePresentation".');
}
});
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const secureCredential = async ({
const {data, result, error} = await issuer.post({json: body});
if(!result || !result.ok) {
error;
return null;
throw new Error('Request rejected.');
}
return data;
}
Expand All @@ -73,7 +73,7 @@ export const verifyCredential = async ({
const {data, result, error} = await verifier.post({json: body});
if(!result || !result.ok) {
error;
return null;
throw new Error('Request rejected.');
}
return data;
}
Expand All @@ -93,7 +93,7 @@ export const verifyPresentation = async ({
const {data, result, error} = await vpVerifier.post({json: body});
if(!result || !result.ok) {
error;
return null;
throw new Error('Request rejected.');
}
return data;
}
Expand Down

0 comments on commit 0ea6eee

Please sign in to comment.