Skip to content

Commit 0ea6eee

Browse files
committed
Fix helper function error throwing and envelope tests variable allocation
Signed-off-by: PatStLouis <[email protected]>
1 parent b47e60b commit 0ea6eee

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

tests/4.13.2-envelopes.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ describe('Enveloped Verifiable Credentials', function() {
6868
negativeFixture = structuredClone(verifiableCredential);
6969
negativeFixture['@context'] = [];
7070
await assert.rejects(
71-
verifyCredential({verifier, negativeFixture}),
71+
verifyCredential({verifier, verifiableCredential: negativeFixture}),
7272
'Failed to reject an enveloped VC with invalid context.');
7373

7474
// Replace context with an invalid value
7575
negativeFixture = structuredClone(verifiableCredential);
7676
negativeFixture['@context'] = 'https://www.w3.org/ns/credentials/examples/v2';
7777
await assert.rejects(
78-
verifyCredential({verifier, negativeFixture}),
78+
verifyCredential({verifier, verifiableCredential: negativeFixture}),
7979
'Failed to reject an enveloped VC with invalid context.');
8080
}
8181
});
@@ -101,7 +101,7 @@ describe('Enveloped Verifiable Credentials', function() {
101101
negativeFixture = structuredClone(verifiableCredential);
102102
negativeFixture.id = negativeFixture.id.split(',').pop();
103103
await assert.rejects(
104-
verifyCredential({verifier, negativeFixture}),
104+
verifyCredential({verifier, verifiableCredential: negativeFixture}),
105105
'Failed to reject an enveloped VC with an invalid data url id.');
106106
}
107107
});
@@ -125,15 +125,17 @@ describe('Enveloped Verifiable Credentials', function() {
125125
negativeFixture = structuredClone(verifiableCredential);
126126
delete negativeFixture.type;
127127
await assert.rejects(
128-
verifyCredential({verifier, negativeFixture}),
128+
verifyCredential(
129+
{verifier, verifiableCredential: negativeFixture}),
129130
'Failed to reject an enveloped VC with an enveloped VC with a ' +
130131
'missing `type`.');
131132

132133
// Replace type field
133134
negativeFixture = structuredClone(verifiableCredential);
134135
negativeFixture.type = 'VerifiableCredential';
135136
await assert.rejects(
136-
verifyCredential({verifier, negativeFixture}),
137+
verifyCredential(
138+
{verifier, verifiableCredential: negativeFixture}),
137139
'Failed to reject an enveloped VC with an ' +
138140
'invalid `type`.');
139141
}
@@ -176,14 +178,16 @@ describe('Enveloped Verifiable Presentations', function() {
176178
negativeFixture = structuredClone(verifiablePresentation);
177179
negativeFixture['@context'] = [];
178180
await assert.rejects(
179-
verifyPresentation({vpVerifier, negativeFixture}),
181+
verifyPresentation(
182+
{vpVerifier, verifiablePresentation: negativeFixture}),
180183
'Failed to reject Enveloped VP missing contexts.');
181184

182185
// Replace context field with invalid context
183186
negativeFixture = structuredClone(verifiablePresentation);
184187
negativeFixture['@context'] = ['https://www.w3.org/ns/credentials/examples/v2'];
185188
await assert.rejects(
186-
verifyPresentation({vpVerifier, negativeFixture}),
189+
verifyPresentation(
190+
{vpVerifier, verifiablePresentation: negativeFixture}),
187191
'Failed to reject Enveloped VP missing contexts.');
188192
}
189193
});
@@ -203,7 +207,8 @@ describe('Enveloped Verifiable Presentations', function() {
203207
negativeFixture = structuredClone(verifiablePresentation);
204208
negativeFixture.id = negativeFixture.id.split(',').pop();
205209
await assert.rejects(
206-
verifyPresentation({vpVerifier, negativeFixture}),
210+
verifyPresentation(
211+
{vpVerifier, verifiablePresentation: negativeFixture}),
207212
'Failed to reject Enveloped VP with an id that is not a data url.');
208213
}
209214
});
@@ -221,7 +226,8 @@ describe('Enveloped Verifiable Presentations', function() {
221226
negativeFixture = structuredClone(verifiablePresentation);
222227
negativeFixture.type = ['VerifiablePresentation'];
223228
await assert.rejects(
224-
verifyPresentation({vpVerifier, negativeFixture}),
229+
verifyPresentation(
230+
{vpVerifier, verifiablePresentation: negativeFixture}),
225231
'Failed to reject VP w/o type "EnvelopedVerifiablePresentation".');
226232
}
227233
});

tests/helpers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const secureCredential = async ({
5454
const {data, result, error} = await issuer.post({json: body});
5555
if(!result || !result.ok) {
5656
error;
57-
return null;
57+
throw new Error('Request rejected.');
5858
}
5959
return data;
6060
}
@@ -73,7 +73,7 @@ export const verifyCredential = async ({
7373
const {data, result, error} = await verifier.post({json: body});
7474
if(!result || !result.ok) {
7575
error;
76-
return null;
76+
throw new Error('Request rejected.');
7777
}
7878
return data;
7979
}
@@ -93,7 +93,7 @@ export const verifyPresentation = async ({
9393
const {data, result, error} = await vpVerifier.post({json: body});
9494
if(!result || !result.ok) {
9595
error;
96-
return null;
96+
throw new Error('Request rejected.');
9797
}
9898
return data;
9999
}

0 commit comments

Comments
 (0)