-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
250 lines (196 loc) · 9.98 KB
/
index.test.ts
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import {
VerifiablePresentationManagerFactory
} from '../index';
import {
CredentialArtifacts
} from '../VerifiablePresentationManager';
import phoneNumberCredential from './fixtures/phoneNumberCredential.json';
import invalidEmailCredential from './fixtures/invalidEmailCredential.json';
import idDocumentCredential from './fixtures/idDocumentCredential.json';
import idDocumentEvidence from './fixtures/idDocumentSelfieEvidence.json';
import { schemaLoader, CVCSchemaLoader } from '@identity.com/credential-commons';
schemaLoader.addLoader(new CVCSchemaLoader());
describe('Index', () => {
it('should perform a validation on every operation with a secure redundant presentation manager', async () => {
const artifacts = {
presentations: [
phoneNumberCredential,
idDocumentCredential
],
evidences: [
idDocumentEvidence
]
} as CredentialArtifacts;
// should validate presentations when adding
const secureRedundantManager = VerifiablePresentationManagerFactory.createSecureRedundantManager();
const status = await secureRedundantManager.addCredentialArtifacts(artifacts);
expect(status.totalPresentations).toEqual(2);
expect(status.totalEvidences).toEqual(1);
expect(status.verifiedPresentations).toEqual(2);
expect(status.verifiedEvidences).toEqual(1);
const invalidArtifacts = {
presentations: [
invalidEmailCredential
]
} as CredentialArtifacts;
// should throw an exception if there is any invalid credential on add
await expect(secureRedundantManager.addCredentialArtifacts(invalidArtifacts)).rejects.toThrow();
// should throw an exception if there is any invalid credential on read
await expect(secureRedundantManager.listPresentations()).rejects.toThrow();
const statusAfterPurge = await secureRedundantManager.purgeInvalidArtifacts();
expect(statusAfterPurge).toEqual(status);
const presentations = await secureRedundantManager.listPresentations();
expect(presentations).toHaveLength(2);
const evidences = await secureRedundantManager.listEvidences();
expect(evidences).toHaveLength(1);
const claims = await secureRedundantManager.listClaims();
expect(claims).toHaveLength(
phoneNumberCredential.proof.leaves.length + idDocumentCredential.proof.leaves.length
);
const presentationClaims = await secureRedundantManager.listPresentationClaims(presentations[0]);
expect(presentationClaims).toHaveLength(
phoneNumberCredential.proof.leaves.length
);
const claimValue = await secureRedundantManager.getClaimValue(claims[0]);
expect(claimValue).toBeDefined();
});
it('should perform a validation on every READ operation with a secure fast ingest manager', async () => {
const artifacts = {
presentations: [
phoneNumberCredential,
idDocumentCredential
],
evidences: [
idDocumentEvidence
]
} as CredentialArtifacts;
// should NOT validate presentations when adding
const secureFastIngestManager = VerifiablePresentationManagerFactory.createSecureFastIngestManager();
const status = await secureFastIngestManager.addCredentialArtifacts(artifacts);
expect(status.totalPresentations).toEqual(2);
expect(status.totalEvidences).toEqual(1);
expect(status.verifiedPresentations).toEqual(0);
expect(status.verifiedEvidences).toEqual(0);
const invalidArtifacts = {
presentations: [
invalidEmailCredential
]
} as CredentialArtifacts;
// should NOT validate presentations when adding
const statusAfterInvalid = await secureFastIngestManager.addCredentialArtifacts(invalidArtifacts);
expect(statusAfterInvalid.totalPresentations).toEqual(3);
expect(statusAfterInvalid.totalEvidences).toEqual(1);
expect(statusAfterInvalid.verifiedPresentations).toEqual(0);
expect(statusAfterInvalid.verifiedEvidences).toEqual(0);
// should throw an exception if there is any invalid credential on read
await expect(secureFastIngestManager.listPresentations()).rejects.toThrow();
const statusAfterPurge = await secureFastIngestManager.purgeInvalidArtifacts();
expect(statusAfterPurge).toEqual(status);
const presentations = await secureFastIngestManager.listPresentations();
expect(presentations).toHaveLength(2);
const evidences = await secureFastIngestManager.listEvidences();
expect(evidences).toHaveLength(1);
const claims = await secureFastIngestManager.listClaims();
expect(claims).toHaveLength(
phoneNumberCredential.proof.leaves.length + idDocumentCredential.proof.leaves.length
);
const presentationClaims = await secureFastIngestManager.listPresentationClaims(presentations[0]);
expect(presentationClaims).toHaveLength(
phoneNumberCredential.proof.leaves.length
);
const claimValue = await secureFastIngestManager.getClaimValue(claims[0]);
expect(claimValue).toBeDefined();
});
it('should perform a validation on every ADD operation with a secure fast read manager', async () => {
const artifacts = {
presentations: [
phoneNumberCredential,
idDocumentCredential
],
evidences: [
idDocumentEvidence
]
} as CredentialArtifacts;
// should validate presentations when adding
const secureFastReadManager = VerifiablePresentationManagerFactory.createSecureFastReadManager();
const status = await secureFastReadManager.addCredentialArtifacts(artifacts);
expect(status.totalPresentations).toEqual(2);
expect(status.totalEvidences).toEqual(1);
expect(status.verifiedPresentations).toEqual(2);
expect(status.verifiedEvidences).toEqual(1);
const invalidArtifacts = {
presentations: [
invalidEmailCredential
]
} as CredentialArtifacts;
// should throw an exception if there is any invalid credential on add
await expect(secureFastReadManager.addCredentialArtifacts(invalidArtifacts)).rejects.toThrow();
// should not validate credentials when reading
const presentationsWithInvalid = await secureFastReadManager.listPresentations();
expect(presentationsWithInvalid).toHaveLength(3);
const statusAfterPurge = await secureFastReadManager.purgeInvalidArtifacts();
expect(statusAfterPurge).toEqual(status);
const presentations = await secureFastReadManager.listPresentations();
expect(presentations).toHaveLength(2);
const evidences = await secureFastReadManager.listEvidences();
expect(evidences).toHaveLength(1);
const claims = await secureFastReadManager.listClaims();
expect(claims).toHaveLength(
phoneNumberCredential.proof.leaves.length + idDocumentCredential.proof.leaves.length
);
const presentationClaims = await secureFastReadManager.listPresentationClaims(presentations[0]);
expect(presentationClaims).toHaveLength(
phoneNumberCredential.proof.leaves.length
);
const claimValue = await secureFastReadManager.getClaimValue(claims[0]);
expect(claimValue).toBeDefined();
});
it('should skip validation for all ADD or GET operations with an insecure manager', async () => {
const artifacts = {
presentations: [
phoneNumberCredential,
idDocumentCredential
],
evidences: [
idDocumentEvidence
]
} as CredentialArtifacts;
// should NOT validate presentations when adding
const insecureManager = VerifiablePresentationManagerFactory.createInsecureManager();
const status = await insecureManager.addCredentialArtifacts(artifacts);
expect(status.totalPresentations).toEqual(2);
expect(status.totalEvidences).toEqual(1);
expect(status.verifiedPresentations).toEqual(0);
expect(status.verifiedEvidences).toEqual(0);
const invalidArtifacts = {
presentations: [
invalidEmailCredential
]
} as CredentialArtifacts;
// should NOT validate presentations when adding
const statusAfterInvalid = await insecureManager.addCredentialArtifacts(invalidArtifacts);
expect(statusAfterInvalid.totalPresentations).toEqual(3);
expect(statusAfterInvalid.totalEvidences).toEqual(1);
expect(statusAfterInvalid.verifiedPresentations).toEqual(0);
expect(statusAfterInvalid.verifiedEvidences).toEqual(0);
// should NOT validate credentials when reading
const presentationsWithInvalid = await insecureManager.listPresentations();
expect(presentationsWithInvalid).toHaveLength(3);
const statusAfterPurge = await insecureManager.purgeInvalidArtifacts();
expect(statusAfterPurge).toEqual(status);
const presentations = await insecureManager.listPresentations();
expect(presentations).toHaveLength(2);
const evidences = await insecureManager.listEvidences();
expect(evidences).toHaveLength(1);
const claims = await insecureManager.listClaims();
expect(claims).toHaveLength(
phoneNumberCredential.proof.leaves.length + idDocumentCredential.proof.leaves.length
);
const presentationClaims = await insecureManager.listPresentationClaims(presentations[0]);
expect(presentationClaims).toHaveLength(
phoneNumberCredential.proof.leaves.length
);
const claimValue = await insecureManager.getClaimValue(claims[0]);
expect(claimValue).toBeDefined();
});
});