-
Notifications
You must be signed in to change notification settings - Fork 7
/
10-issuer.js
198 lines (196 loc) · 7.56 KB
/
10-issuer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*!
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
*/
import {createISOTimeStamp, createRequestBody} from './mock.data.js';
import {
shouldBeIssuedVc,
shouldReturnResult,
shouldThrowInvalidInput
} from './assertions.js';
import chai from 'chai';
import {filterByTag} from 'vc-test-suite-implementations';
const should = chai.should();
const tag = 'vc-api';
const {match} = filterByTag({property: 'issuers', tags: [tag]});
describe('Issue Credential - Data Integrity', function() {
const summaries = new Set();
this.summary = summaries;
const reportData = [];
// this will tell the report
// to make an interop matrix with this suite
this.matrix = true;
this.report = true;
this.implemented = [...match.keys()];
this.rowLabel = 'Test Name';
this.columnLabel = 'Issuer';
// the reportData will be displayed under the test title
this.reportData = reportData;
for(const [name, implementation] of match) {
const issuer = implementation.issuers.find(
issuer => issuer.tags.has(tag));
describe(name, function() {
it('MUST successfully issue a credential.', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
const {result, data: issuedVc, error} = await issuer.post({json: body});
shouldReturnResult({result, error});
should.exist(issuedVc, 'Expected result to have data.');
result.status.should.equal(201, 'Expected statusCode 201.');
shouldBeIssuedVc({issuedVc});
});
it('Request body MUST have property "credential".', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
body.verifiableCredential = {...body.credential};
delete body.credential;
const {result, error} = await issuer.post({json: body});
shouldThrowInvalidInput({result, error});
});
it('credential MUST have property "@context".', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
delete body.credential['@context'];
const {result, error} = await issuer.post({json: body});
shouldThrowInvalidInput({result, error});
});
it('credential "@context" MUST be an array.', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
body.credential['@context'] = 4;
const {result, error} = await issuer.post({json: body});
shouldThrowInvalidInput({result, error});
});
it('credential "@context" items MUST be strings.', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
const invalidContextTypes = [{foo: true}, 4, false, null];
for(const invalidContextType of invalidContextTypes) {
body.credential['@context'] = invalidContextType;
const {result, error} = await issuer.post({json: {...body}});
shouldThrowInvalidInput({result, error});
}
});
it('credential MUST have property "type"', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
delete body.credential.type;
const {result, error} = await issuer.post({json: body});
shouldThrowInvalidInput({result, error});
});
it('"credential.type" MUST be an array.', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
body.credential.type = 4;
const {result, error} = await issuer.post({json: body});
shouldThrowInvalidInput({result, error});
});
it('"credential.type" items MUST be strings', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
const invalidCredentialTypes = [null, true, 4, []];
for(const invalidCredentialType of invalidCredentialTypes) {
body.credential.type = invalidCredentialType;
const {result, error} = await issuer.post({json: {...body}});
shouldThrowInvalidInput({result, error});
}
});
it('credential MUST have property "issuer"', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
delete body.credential.issuer;
const {result, error} = await issuer.post({json: body});
shouldThrowInvalidInput({result, error});
});
it('"credential.issuer" MUST be a string or an object', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
const invalidIssuerTypes = [null, true, 4, []];
for(const invalidIssuerType of invalidIssuerTypes) {
body.credential.issuer = invalidIssuerType;
const {result, error} = await issuer.post({json: {...body}});
shouldThrowInvalidInput({result, error});
}
});
it('credential MUST have property "credentialSubject"', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
delete body.credential.credentialSubject;
const {result, error} = await issuer.post({json: body});
shouldThrowInvalidInput({result, error});
});
it('"credential.credentialSubject" MUST be an object', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
const invalidCredentialSubjectTypes =
[null, true, 4, [], 'did:example:1234'];
for(const invalidCredentialSubjectType of
invalidCredentialSubjectTypes) {
body.credential.credentialSubject = invalidCredentialSubjectType;
const {result, error} = await issuer.post({json: {...body}});
shouldThrowInvalidInput({result, error});
}
});
// this test is probably redudant as the vc-data-model spec
// requires issuanceDate
it.skip('credential MAY have property "issuanceDate"', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
const {result, error} = await issuer.post({json: body});
shouldReturnResult({result, error});
result.status.should.equal(201, 'Expected statusCode 201.');
});
it('credential MAY have property "expirationDate"', async function() {
this.test.cell = {
columnId: name,
rowId: this.test.title
};
const body = createRequestBody({issuer});
// expires in a year
const oneYearLater = Date.now() + 365 * 24 * 60 * 60 * 1000;
body.credential.expirationDate = createISOTimeStamp(oneYearLater);
const {result, error} = await issuer.post({json: body});
shouldReturnResult({result, error});
result.status.should.equal(201, 'Expected statusCode 201.');
});
});
}
});