-
Notifications
You must be signed in to change notification settings - Fork 8
/
issueCredential.spec.js
194 lines (176 loc) · 8.06 KB
/
issueCredential.spec.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
let { suiteConfig } = global;
const httpClient = require('../services/httpClient');
if (suiteConfig.issueCredentialConfiguration) {
describe("Issue Credential API - Conformance", () => {
// Load in the static test fixtures
const credentials = suiteConfig.credentials;
// Deal with possible polymorphic issuer configuration
const issuerConfiguration = Array.isArray(suiteConfig.issueCredentialConfiguration) ? suiteConfig.issueCredentialConfiguration : [ suiteConfig.issueCredentialConfiguration ];
issuerConfiguration.forEach((value) => {
describe(`with issuer: ${value.id}`, () => {
it('1. The Issuer\'s Issue Credential HTTP API MUST return a 201 HTTP response status code after successful credential issuance.', async () => {
const body = {
credential: { ...credentials[0].data, issuer: value.id },
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(201);
expect(res.body.proof).toBeDefined();
expect(res.body.proof.type).toEqual(value.proofType);
});
it(`2. The Issuer's Issue Credential HTTP API MUST require "credential" in the body of the POST request. The field "credential" MUST be conformant to [Verifiable Credentials Data Model 1.0](https://www.w3.org/TR/vc-data-model/).`, async () => {
const body = {
credential: { ...credentials[0].data, issuer: value.id },
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(201);
expect(res.body.proof).toBeDefined();
expect(res.body.proof.type).toEqual(value.proofType);
});
it(`3. The Issuer's Issue Credential HTTP API MUST return a 400 HTTP response status code when the request is rejected.`, async () => {
const body = {
credential: {
...credentials[0],
'@context': 'force_error',
},
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(400);
});
it(`4. The Issuer's Issue Credential HTTP API MUST return a Verifiable Credential with the value of its "issuer" or "issuer.id" as a URI in the body of the response.`, async () => {
const body = {
credential: { ...credentials[0].data, issuer: value.id },
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(201);
expect(res.body).toBeDefined();
expect(res.body.issuer).toBeDefined();
const issuerId = res.body.issuer || res.body.issuer.id;
expect(issuerId).toBeDefined();
});
it(`5. The Issuer's Issue Credential HTTP API MUST reject if the value of "options.proofPurpose" in the body of the POST request is not supported.`, async () => {
const body = {
credential: {
...credentials[0].data,
issuer: value.id
},
options: {
proofPurpose: 'foo',
},
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(400);
});
it(`6. The Issuer's Issue Credential HTTP API MUST reject if the value of "options.verificationMethod" in the body of the POST request does not exist.`, async () => {
const body = {
credential: {
...credentials[0].data,
issuer: value.id
},
options: {
...value.options[0],
verificationMethod: 'foo',
},
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(400);
});
it(`7. The Issuer's Issue Credential HTTP API MUST reject if the value of "credential" in the body of the POST request does not contain a context.`, async () => {
const body = {
credential: {
...credentials[0].data,
issuer: value.id
},
};
delete body.credential['@context'];
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(400);
});
it(`8. The Issuer's Issue Credential HTTP API MUST reject if the value of "credential" in the body of the POST request contains a malformed JSON-LD context.`, async () => {
const body = {
credential: {
...credentials[0].data,
issuer: value.id
},
};
body.credential['@context'] = [
'https://www.w3.org/2018/credentials/v1',
'broken',
];
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(400);
});
it(`9. The Issuer's Issue Credential HTTP API MUST support no "options" in the body of the POST request.`, async () => {
const body = {
credential: {
...credentials[0].data,
issuer: value.id
}
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(201);
expect(res.body.proof).toBeDefined();
});
if (value.credentialStatusesSupported) {
const credentialStatusesSupported = Array.isArray(value.credentialStatusesSupported) ? value.credentialStatusesSupported : [ value.credentialStatusesSupported ];
credentialStatusesSupported.forEach((credStatusType) => {
it(`10. The Issuer's Issue Credential HTTP API MAY support issuing a credential with a credential status type of ${credStatusType}`, async () => {
const body = {
credential: {
...credentials[0].data,
issuer: value.id
},
options: {
...value.options[0],
credentialStatus: {
type: credStatusType
},
},
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(201);
expect(res.body).toBeDefined();
expect(res.body.credentialStatus).toBeDefined();
expect(res.body.credentialStatus.type).toEqual(credStatusType);
});
});
it(`11. The Issuer's Issue Credential HTTP API MUST return 400 if credential status type not recognized`, async () => {
const body = {
credential: {
...credentials[0].data,
issuer: value.id
},
options: {
...value.options[0],
credentialStatus: {
type: "BadType"
},
},
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(400);
});
}
});
});
});
describe("Issue Credential API - Credential Type Interop", () => {
// Load in the static test fixtures
const credentials = suiteConfig.credentials;
// Deal with possible polymorphic issuer configuration
const issuerConfiguration = Array.isArray(suiteConfig.issueCredentialConfiguration) ? suiteConfig.issueCredentialConfiguration : [ suiteConfig.issueCredentialConfiguration ];
issuerConfiguration.forEach((value) => {
describe(`With issuer: ${value.id}`, () => {
credentials.forEach((credential) => {
it(`Can issue ${credential.name} credential, fixture ${credential.fileName}`, async () => {
const body = {
credential: { ...credentials[0].data, issuer: value.id },
};
const res = await httpClient.postJson(value.endpoint, body, {});
expect(res.status).toBe(201);
expect(res.body.proof).toBeDefined();
})
})
});
});
});
}