4
4
* SPDX-License-Identifier: LicenseRef-w3c-3-clause-bsd-license-2008 OR LicenseRef-w3c-test-suite-license-2023
5
5
*/
6
6
7
- import { addPerTestMetadata , extractIfEnveloped , setupMatrix }
8
- from './helpers.js' ;
7
+ import {
8
+ addPerTestMetadata ,
9
+ generateCredential ,
10
+ generateEnvelope ,
11
+ secureCredential ,
12
+ setupMatrix
13
+ } from './helpers.js' ;
14
+ import {
15
+ vc_jwt ,
16
+ vp_jwt
17
+ } from './fixtures.js' ;
9
18
import assert from 'node:assert/strict' ;
10
19
import chai from 'chai' ;
11
- import { createRequire } from 'module' ;
12
20
import { filterByTag } from 'vc-test-suite-implementations' ;
13
- import { shouldBeCredential } from './assertions.js' ;
14
21
import { TestEndpoints } from './TestEndpoints.js' ;
15
22
16
- // eslint-disable-next-line no-unused-vars
17
23
const should = chai . should ( ) ;
18
24
19
- const require = createRequire ( import . meta. url ) ;
20
-
21
- const tag = 'vc2.0' ;
25
+ const tag = 'EnvelopingProof' ;
22
26
const { match} = filterByTag ( { tags : [ tag ] } ) ;
23
27
24
28
// 4.12.1 Enveloped Verifiable Credentials https://w3c.github.io/vc-data-model/#enveloped-verifiable-credentials
25
- describe ( 'VP - Enveloped Verifiable Credentials' , function ( ) {
29
+ describe ( 'Enveloped Verifiable Credentials' , function ( ) {
26
30
setupMatrix . call ( this , match ) ;
27
31
for ( const [ name , implementation ] of match ) {
28
32
const endpoints = new TestEndpoints ( { implementation, tag} ) ;
29
- const issuerEnvelopeSupport =
30
- endpoints . issuer . settings . tags . includes (
31
- 'EnvelopingProof' ) ;
32
- const vpVerifierEnvelopeSupport = endpoints . vpVerifier &&
33
- endpoints . vpVerifier . settings . tags . includes (
34
- 'EnvelopingProof' ) ;
33
+ const issuer = implementation . issuers ?. find (
34
+ issuer => issuer . tags . has ( tag ) ) || null ;
35
+ const verifier = implementation . verifiers ?. find (
36
+ verifier => verifier . tags . has ( tag ) ) || null ;
35
37
36
38
describe ( name , function ( ) {
37
- let issuedVc ;
39
+ let envelopedCredential ;
40
+ let negativeFixture ;
38
41
before ( async function ( ) {
39
- if ( issuerEnvelopeSupport ) {
40
- try {
41
- issuedVc = await endpoints . issue ( require (
42
- './input/credential-ok.json' ) ) ;
43
- } catch ( e ) {
44
- console . error (
45
- `Issuer: ${ name } failed to issue "credential-ok.json".` ,
46
- e
47
- ) ;
48
- }
49
- } else {
50
- issuedVc = null ;
51
- }
42
+ envelopedCredential = generateEnvelope ( {
43
+ type : 'EnvelopedVerifiableCredential' ,
44
+ id : `data:application/vc+jwt,${ vc_jwt } `
45
+ } ) ;
52
46
} ) ;
53
47
beforeEach ( addPerTestMetadata ) ;
54
48
@@ -58,18 +52,27 @@ describe('VP - Enveloped Verifiable Credentials', function() {
58
52
'terms as defined by the base context provided by this specification.' ,
59
53
async function ( ) {
60
54
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-credentials:~:text=The%20%40context%20property%20of%20the%20object%20MUST%20be%20present%20and%20include%20a%20context%2C%20such%20as%20the%20base%20context%20for%20this%20specification%2C%20that%20defines%20at%20least%20the%20id%2C%20type%2C%20and%20EnvelopedVerifiableCredential%20terms%20as%20defined%20by%20the%20base%20context%20provided%20by%20this%20specification.` ;
61
- if ( ! vpVerifierEnvelopeSupport ) {
62
- this . test . cell . skipMessage = 'No envelope support.' ;
63
- this . skip ( ) ;
64
- } else {
65
- await assert . doesNotReject ( endpoints . verifyVp ( require (
66
- './input/presentation-enveloped-vc-ok.json' ) ) ,
67
- 'Failed to accept a VP containing a enveloped VC.' ) ;
68
- // TODO: add more `@context` variations to test handling?
69
- await assert . rejects ( endpoints . verifyVp ( require (
70
- './input/presentation-enveloped-vc-missing-type-fail.json' ) ) ,
71
- 'Failed to reject a VP containing an enveloped VC with a missing ' +
72
- '`type`.' ) ;
55
+ if ( issuer ) {
56
+ const issuedVc = await secureCredential (
57
+ { issuer, credential : generateCredential ( ) } ) ;
58
+ should . exist ( issuedVc , 'Expected credential to be issued.' ) ;
59
+ issuedVc . should . have . property ( '@context' ) ;
60
+ }
61
+ if ( verifier ) {
62
+ await assert . doesNotReject ( endpoints . verify ( envelopedCredential ) ,
63
+ 'Failed to accept an enveloped VC.' ) ;
64
+
65
+ // Replace context with an empty array
66
+ negativeFixture = structuredClone ( envelopedCredential ) ;
67
+ negativeFixture [ '@context' ] = [ ] ;
68
+ await assert . rejects ( endpoints . verify ( negativeFixture ) ,
69
+ 'Failed to reject an enveloped VC with an empty context.' ) ;
70
+
71
+ // Replace context with an invalid value
72
+ negativeFixture = structuredClone ( envelopedCredential ) ;
73
+ negativeFixture [ '@context' ] = 'https://www.w3.org/ns/credentials/examples/v2' ;
74
+ await assert . rejects ( endpoints . verify ( negativeFixture ) ,
75
+ 'Failed to reject an enveloped VC with an invalid context.' ) ;
73
76
}
74
77
} ) ;
75
78
@@ -78,44 +81,77 @@ describe('VP - Enveloped Verifiable Credentials', function() {
78
81
'security scheme, such as Securing Verifiable Credentials using JOSE ' +
79
82
'and COSE [VC-JOSE-COSE].' , async function ( ) {
80
83
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-credentials:~:text=The%20id%20value%20of%20the%20object%20MUST%20be%20a%20data%3A%20URL%20%5BRFC2397%5D%20that%20expresses%20a%20secured%20verifiable%20credential%20using%20an%20enveloping%20security%20scheme%2C%20such%20as%20Securing%20Verifiable%20Credentials%20using%20JOSE%20and%20COSE%20%5BVC%2DJOSE%2DCOSE%5D.` ;
81
- if ( ! issuerEnvelopeSupport ) {
82
- this . test . cell . skipMessage = 'No envelope support.' ;
83
- this . skip ( ) ;
84
- } else {
84
+ if ( issuer ) {
85
+ const issuedVc = await secureCredential (
86
+ { issuer , credential : generateCredential ( ) } ) ;
87
+ should . exist ( issuedVc , 'Expected credential to be issued.' ) ;
85
88
issuedVc . should . have . property ( 'id' ) . that . does
86
89
. include ( 'data:' ,
87
90
`Expecting id field to be a 'data:' scheme URL [RFC2397].` ) ;
88
- const extractedCredential = extractIfEnveloped ( issuedVc ) ;
89
- shouldBeCredential ( extractedCredential ) ;
91
+ }
92
+ if ( verifier ) {
93
+ await assert . doesNotReject ( endpoints . verify ( envelopedCredential ) ,
94
+ 'Failed to accept an enveloped VC.' ) ;
95
+
96
+ // Remove data uri portion of the id field
97
+ negativeFixture = structuredClone ( envelopedCredential ) ;
98
+ negativeFixture . id = negativeFixture . id . split ( ',' ) . pop ( ) ;
99
+ await assert . rejects ( endpoints . verify ( negativeFixture ) ,
100
+ 'Failed to reject an enveloped VC with an invalid data url id.' ) ;
90
101
}
91
102
} ) ;
92
103
93
104
it ( 'The type value of the object MUST be EnvelopedVerifiableCredential.' ,
94
105
async function ( ) {
95
106
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-credentials:~:text=The%20type%20value%20of%20the%20object%20MUST%20be%20EnvelopedVerifiableCredential.` ;
96
- if ( ! issuerEnvelopeSupport ) {
97
- this . test . cell . skipMessage = 'No envelope support.' ;
98
- this . skip ( ) ;
99
- } else {
100
- issuedVc . should . have . property ( 'type' ) . that . does
101
- . include ( 'EnvelopedVerifiableCredential' ,
102
- `Expecting type field to be EnvelopedVerifiableCredential` ) ;
107
+ if ( issuer ) {
108
+ const issuedVc = await secureCredential (
109
+ { issuer, credential : generateCredential ( ) } ) ;
110
+ should . exist ( issuedVc , 'Expected credential to be issued.' ) ;
111
+ issuedVc . should . have . property ( 'type' ) . that . is . equal (
112
+ 'EnvelopedVerifiableCredential' ,
113
+ `Expecting type field to be EnvelopedVerifiableCredential` ) ;
114
+ }
115
+ if ( verifier ) {
116
+ await assert . doesNotReject ( endpoints . verify ( envelopedCredential ) ,
117
+ 'Failed to accept an enveloped VC.' ) ;
118
+
119
+ // Remove type field
120
+ negativeFixture = structuredClone ( envelopedCredential ) ;
121
+ delete negativeFixture . type ;
122
+ await assert . rejects ( endpoints . verify ( negativeFixture ) ,
123
+ 'Failed to reject an enveloped VC with an enveloped VC with a ' +
124
+ 'missing `type`.' ) ;
125
+
126
+ // Replace type field
127
+ negativeFixture = structuredClone ( envelopedCredential ) ;
128
+ negativeFixture . type = [ 'VerifiableCredential' ] ;
129
+ await assert . rejects ( endpoints . verify ( negativeFixture ) ,
130
+ 'Failed to reject an enveloped VC with an ' +
131
+ 'invalid `type`.' ) ;
103
132
}
104
133
} ) ;
105
134
} ) ;
106
135
}
107
136
} ) ;
108
137
109
138
// 4.12.2 Enveloped Verifiable Presentations https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations
110
- describe ( 'VP - Enveloped Verifiable Presentations' , function ( ) {
139
+ describe ( 'Enveloped Verifiable Presentations' , function ( ) {
111
140
setupMatrix . call ( this , match ) ;
112
141
for ( const [ name , implementation ] of match ) {
113
142
const endpoints = new TestEndpoints ( { implementation, tag} ) ;
114
- const vpVerifierEnvelopeSupport = endpoints . vpVerifier &&
115
- endpoints . vpVerifier . settings . tags . includes (
116
- 'EnvelopingProof' ) ;
143
+ const vpVerifier = implementation . vpVerifiers ?. find (
144
+ vpVerifier => vpVerifier . tags . has ( tag ) ) || null ;
117
145
118
146
describe ( name , function ( ) {
147
+ let envelopedPresentation ;
148
+ let negativeFixture ;
149
+ before ( async function ( ) {
150
+ envelopedPresentation = generateEnvelope ( {
151
+ type : 'EnvelopedVerifiablePresentation' ,
152
+ id : `data:application/vp+jwt,${ vp_jwt } `
153
+ } ) ;
154
+ } ) ;
119
155
beforeEach ( addPerTestMetadata ) ;
120
156
121
157
it ( 'The @context property of the object MUST be present and include a ' +
@@ -124,14 +160,23 @@ describe('VP - Enveloped Verifiable Presentations', function() {
124
160
'terms as defined by the base context provided by this specification.' ,
125
161
async function ( ) {
126
162
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20%40context%20property%20of%20the%20object%20MUST%20be%20present%20and%20include%20a%20context%2C%20such%20as%20the%20base%20context%20for%20this%20specification%2C%20that%20defines%20at%20least%20the%20id%2C%20type%2C%20and%20EnvelopedVerifiablePresentation%20terms%20as%20defined%20by%20the%20base%20context%20provided%20by%20this%20specification.` ;
127
- if ( ! vpVerifierEnvelopeSupport ) {
128
- this . test . cell . skipMessage = 'No envelope support.' ;
129
- this . skip ( ) ;
130
- } else {
163
+
164
+ if ( vpVerifier ) {
165
+ await assert . doesNotReject ( endpoints . verifyVp ( envelopedPresentation ) ,
166
+ 'Failed to accept an enveloped VP.' ) ;
167
+
168
+ // Replace context field with empty array
169
+ negativeFixture = structuredClone ( envelopedPresentation ) ;
170
+ negativeFixture [ '@context' ] = [ ] ;
131
171
await assert . rejects (
132
- endpoints . verifyVp ( require (
133
- './input/enveloped-presentation-context-fail.json' ) ) ,
172
+ endpoints . verifyVp ( negativeFixture ) ,
173
+ 'Failed to reject Enveloped VP missing contexts.' ) ;
134
174
175
+ // Replace context field with invalid context
176
+ negativeFixture = structuredClone ( envelopedPresentation ) ;
177
+ negativeFixture [ '@context' ] = [ 'https://www.w3.org/ns/credentials/examples/v2' ] ;
178
+ await assert . rejects (
179
+ endpoints . verifyVp ( negativeFixture ) ,
135
180
'Failed to reject Enveloped VP missing contexts.' ) ;
136
181
}
137
182
} ) ;
@@ -141,29 +186,33 @@ describe('VP - Enveloped Verifiable Presentations', function() {
141
186
'securing mechanism, such as Securing Verifiable Credentials using ' +
142
187
'JOSE and COSE [VC-JOSE-COSE].' , async function ( ) {
143
188
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20id%20value%20of%20the%20object%20MUST%20be%20a%20data%3A%20URL%20%5BRFC2397%5D%20that%20expresses%20a%20secured%20verifiable%20presentation%20using%20an%20enveloping%20securing%20mechanism%2C%20such%20as%20Securing%20Verifiable%20Credentials%20using%20JOSE%20and%20COSE%20%5BVC%2DJOSE%2DCOSE%5D.` ;
144
- if ( ! vpVerifierEnvelopeSupport ) {
145
- this . test . cell . skipMessage = 'No envelope support.' ;
146
- this . skip ( ) ;
147
- } else {
148
- await assert . rejects (
149
- endpoints . verifyVp ( require (
150
- './input/enveloped-presentation-id-fail.json' ) ) ,
151
189
190
+ if ( vpVerifier ) {
191
+ await assert . doesNotReject ( endpoints . verifyVp ( envelopedPresentation ) ,
192
+ 'Failed to accept an enveloped VP.' ) ;
193
+
194
+ // Remove data uri portion from id field
195
+ negativeFixture = structuredClone ( envelopedPresentation ) ;
196
+ negativeFixture . id = negativeFixture . id . split ( ',' ) . pop ( ) ;
197
+ await assert . rejects (
198
+ endpoints . verifyVp ( negativeFixture ) ,
152
199
'Failed to reject Enveloped VP with an id that is not a data url.' ) ;
153
200
}
154
201
} ) ;
155
202
156
203
it ( 'The type value of the object MUST be ' +
157
204
'EnvelopedVerifiablePresentation.' , async function ( ) {
158
205
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20type%20value%20of%20the%20object%20MUST%20be%20EnvelopedVerifiablePresentation.` ;
159
- if ( ! vpVerifierEnvelopeSupport ) {
160
- this . test . cell . skipMessage = 'No envelope support.' ;
161
- this . skip ( ) ;
162
- } else {
163
- await assert . rejects (
164
- endpoints . verifyVp ( require (
165
- './input/enveloped-presentation-type-fail.json' ) ) ,
166
206
207
+ if ( vpVerifier ) {
208
+ await assert . doesNotReject ( endpoints . verifyVp ( envelopedPresentation ) ,
209
+ 'Failed to accept an enveloped VP.' ) ;
210
+
211
+ // Replace type field
212
+ negativeFixture = structuredClone ( envelopedPresentation ) ;
213
+ negativeFixture . type = [ 'VerifiablePresentation' ] ;
214
+ await assert . rejects (
215
+ endpoints . verifyVp ( negativeFixture ) ,
167
216
'Failed to reject VP w/o type "EnvelopedVerifiablePresentation".' ) ;
168
217
}
169
218
} ) ;
0 commit comments