6
6
7
7
import { addPerTestMetadata , setupMatrix }
8
8
from './helpers.js' ;
9
+ import { createLocalVp , localIssuer } from './data-generator.js' ;
9
10
import assert from 'node:assert/strict' ;
10
11
import chai from 'chai' ;
11
- import { createLocalVp } from './data-generator.js' ;
12
12
import { createRequire } from 'module' ;
13
13
import { filterByTag } from 'vc-test-suite-implementations' ;
14
14
import { TestEndpoints } from './TestEndpoints.js' ;
@@ -33,7 +33,6 @@ describe('Verifiable Presentations', function() {
33
33
it ( 'If [the `id` field is] present, the normative guidance in Section ' +
34
34
'4.4 Identifiers MUST be followed.' , async function ( ) {
35
35
this . test . link = `https://w3c.github.io/vc-data-model/#verifiable-presentations:~:text=verifiable%20presentation.-,If%20present%2C%20the%20normative%20guidance%20in%20Section%204.4%20Identifiers%20MUST%20be%20followed.,-type` ;
36
- // a presentation with a valid id should verify
37
36
const presentationValidId = await createLocalVp ( {
38
37
presentation : require ( './input/presentation-id-ok.json' )
39
38
} ) ;
@@ -43,19 +42,33 @@ describe('Verifiable Presentations', function() {
43
42
) ;
44
43
} ) ;
45
44
46
- it ( 'The type property MUST be present. One value of this property MUST ' +
45
+ it ( 'The type property MUST be present.' ,
46
+ async function ( ) {
47
+ this . test . link = `https://w3c.github.io/vc-data-model/#verifiable-presentations:~:text=The%20type%20property%20MUST%20be%20present.%20It%20is%20used%20to%20express%20the%20type%20of%20verifiable%20presentation.%20One%20value%20of%20this%20property%20MUST%20be%20VerifiablePresentation%2C%20but%20additional%20types%20MAY%20be%20included.%20The%20related%20normative%20guidance%20in%20Section%204.5%20Types%20MUST%20be%20followed.` ;
48
+ const presentationWithType = await createLocalVp ( {
49
+ presentation : require ( './input/presentation-ok.json' )
50
+ } ) ;
51
+ await assert . doesNotReject (
52
+ endpoints . verifyVp ( presentationWithType ) ,
53
+ `Expected verifier ${ name } to verify a VP with initial ` +
54
+ `type VerifiablePresentation.` ) ;
55
+ // TODO, how to create negative fixture (missing type)
56
+ } ) ;
57
+
58
+ it ( 'One value of this property MUST ' +
47
59
'be VerifiablePresentation, but additional types MAY be included.' +
48
60
'The related normative guidance in Section 4.5 Types MUST be followed.' ,
49
61
async function ( ) {
50
62
this . test . link = `https://w3c.github.io/vc-data-model/#verifiable-presentations:~:text=The%20type%20property%20MUST%20be%20present.%20It%20is%20used%20to%20express%20the%20type%20of%20verifiable%20presentation.%20One%20value%20of%20this%20property%20MUST%20be%20VerifiablePresentation%2C%20but%20additional%20types%20MAY%20be%20included.%20The%20related%20normative%20guidance%20in%20Section%204.5%20Types%20MUST%20be%20followed.` ;
51
63
const presentationWithType = await createLocalVp ( {
52
- presentation : require ( './input/presentation-vc- ok.json' )
64
+ presentation : require ( './input/presentation-ok.json' )
53
65
} ) ;
54
66
await assert . doesNotReject (
55
67
endpoints . verifyVp ( presentationWithType ) ,
56
68
`Expected verifier ${ name } to verify a VP with initial ` +
57
69
`type VerifiablePresentation.`
58
70
) ;
71
+ // TODO, how to create negative fixture (wrong type)
59
72
} ) ;
60
73
61
74
it ( 'The verifiableCredential property MAY be present. The value MUST be' +
@@ -71,13 +84,38 @@ describe('Verifiable Presentations', function() {
71
84
await assert . doesNotReject ( endpoints . verifyVp (
72
85
presentationWithCredentials
73
86
) , 'Failed to verify a valid VP.' ) ;
74
- await assert . rejects ( endpoints . verifyVp ( require (
75
- './input/presentation-vc-missing-required-type-fail.json' ) ) ,
87
+ // TODO, how to create negative fixture (bad vc values)
88
+ } ) ;
89
+
90
+ it ( 'If present (holder), the value MUST be either a URL or ' +
91
+ 'an object containing an id property.' ,
92
+ async function ( ) {
93
+ this . test . link = `https://w3c.github.io/vc-data-model/#verifiable-presentations:~:text=The%20verifiableCredential%20property%20MAY%20be%20present.%20The%20value%20MUST%20be%20one%20or%20more%20verifiable%20credential%20and/or%20enveloped%20verifiable%20credential%20objects%20(the%20values%20MUST%20NOT%20be%20non%2Dobject%20values%20such%20as%20numbers%2C%20strings%2C%20or%20URLs).` ;
94
+ // TODO: Test with remote presentation creation or querying if/when
95
+ // supported by the implementation
96
+ const presentationWithHolder = await createLocalVp ( {
97
+ presentation : require ( './input/presentation-holder-ok.json' )
98
+ } ) ;
99
+ await assert . doesNotReject ( endpoints . verifyVp (
100
+ presentationWithHolder
101
+ ) , 'Failed to verify a valid VP with holder.' ) ;
102
+
103
+ // presentation.holder = {id: localIssuer};
104
+ const presentationWithHolderObject = await createLocalVp ( {
105
+ presentation : require ( './input/presentation-holder-object-ok.json' )
106
+ } ) ;
107
+ await assert . doesNotReject ( endpoints . verifyVp (
108
+ presentationWithHolderObject
109
+ ) , 'Failed to verify a valid VP with holder object.' ) ;
76
110
77
- 'Failed to reject a VP containing a VC with no `type` value.' ) ;
78
- await assert . rejects ( endpoints . verifyVp ( require (
79
- './input/presentation-vc-as-string-fail.json' ) ) ,
80
- 'Failed to reject a VP containing a VC represented as a string.' ) ;
111
+ const presentationMissingHolderId = await createLocalVp ( {
112
+ presentation : require ( './input/presentation-holder-object-fail.json' )
113
+ } ) ;
114
+ await assert . rejects ( endpoints . verifyVp (
115
+ presentationMissingHolderId
116
+ ) , 'Failed to reject a VP with an invalid holder.' ) ;
117
+
118
+ // TODO, how to create negative fixture (bad holder values)
81
119
} ) ;
82
120
} ) ;
83
121
}
@@ -86,7 +124,8 @@ describe('Verifiable Presentations', function() {
86
124
// 4.12.4 Presentations Including Holder Claims https://w3c.github.io/vc-data-model/#presentations-including-holder-claims
87
125
describe ( 'VP - Presentations Including Holder Claims' , function ( ) {
88
126
setupMatrix . call ( this , match ) ;
89
- for ( const [ name ] of match ) {
127
+ for ( const [ name , implementation ] of match ) {
128
+ const endpoints = new TestEndpoints ( { implementation, tag} ) ;
90
129
91
130
describe ( name , function ( ) {
92
131
beforeEach ( addPerTestMetadata ) ;
@@ -96,9 +135,15 @@ describe('VP - Presentations Including Holder Claims', function() {
96
135
'verifiable presentation MUST include a holder property.' ,
97
136
async function ( ) {
98
137
this . test . link = `https://w3c.github.io/vc-data-model/#presentations-including-holder-claims:~:text=A%20verifiable%20presentation%20that%20includes%20a%20self%2Dasserted%20verifiable%20credential%20that%20is%20only%20secured%20using%20the%20same%20mechanism%20as%20the%20verifiable%20presentation%20MUST%20include%20a%20holder%20property.` ;
99
- // TODO: implement test
100
- this . test . cell . skipMessage = 'TBD' ;
101
- this . skip ( ) ;
138
+ const presentation = require ( './input/presentation-vc-ok.json' ) ;
139
+
140
+ presentation . verifiableCredential [ 0 ] . issuer = localIssuer ;
141
+ const presentationMissingHolder = await createLocalVp ( {
142
+ presentation
143
+ } ) ;
144
+ await assert . rejects ( endpoints . verifyVp (
145
+ presentationMissingHolder
146
+ ) , 'Failed to reject a VP with self-asserted VC without holder.' ) ;
102
147
} ) ;
103
148
104
149
it ( 'When a self-asserted verifiable credential is secured using the ' +
@@ -107,9 +152,36 @@ describe('VP - Presentations Including Holder Claims', function() {
107
152
'the holder property of the verifiable presentation.' ,
108
153
async function ( ) {
109
154
this . test . link = `https://w3c.github.io/vc-data-model/#presentations-including-holder-claims:~:text=When%20a%20self%2Dasserted%20verifiable%20credential%20is%20secured%20using%20the%20same%20mechanism%20as%20the%20verifiable%20presentation%2C%20the%20value%20of%20the%20issuer%20property%20of%20the%20verifiable%20credential%20MUST%20be%20identical%20to%20the%20holder%20property%20of%20the%20verifiable%20presentation.` ;
110
- // TODO: implement test
111
- this . test . cell . skipMessage = 'TBD' ;
112
- this . skip ( ) ;
155
+ const presentation = require ( './input/presentation-vc-ok.json' ) ;
156
+
157
+ presentation . verifiableCredential [ 0 ] . issuer = localIssuer ;
158
+ presentation . holder = localIssuer ;
159
+ const presentationHolderMatch = await createLocalVp ( {
160
+ presentation
161
+ } ) ;
162
+ await assert . doesNotReject ( endpoints . verifyVp (
163
+ presentationHolderMatch
164
+ ) , 'Failed to verify a VP containing a self-asserted VC.' ) ;
165
+
166
+ presentation . verifiableCredential [ 0 ] . issuer = localIssuer ;
167
+ presentation . holder = 'did:example:acme' ;
168
+ const presentationHolderMismatch = await createLocalVp ( {
169
+ presentation
170
+ } ) ;
171
+ await assert . rejects ( endpoints . verifyVp (
172
+ presentationHolderMismatch
173
+ ) , 'Failed to reject a VP with self-asserted VC ' +
174
+ 'with a holder/issuer mismatch.' ) ;
175
+
176
+ presentation . verifiableCredential [ 0 ] . issuer = 'did:example:acme' ;
177
+ presentation . holder = localIssuer ;
178
+ const presentationIssuerMismatch = await createLocalVp ( {
179
+ presentation
180
+ } ) ;
181
+ await assert . rejects ( endpoints . verifyVp (
182
+ presentationIssuerMismatch
183
+ ) , 'Failed to reject a VP with self-asserted VC ' +
184
+ 'with a holder/issuer mismatch.' ) ;
113
185
} ) ;
114
186
} ) ;
115
187
}
0 commit comments