saml 3.0.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/lib/saml11.js +4 -0
- package/lib/saml20.js +4 -0
- package/lib/xml/encrypt.js +3 -1
- package/package.json +12 -12
- package/.github/workflows/semgrep.yml +0 -15
- package/.idea/modules.xml +0 -8
- package/.idea/node-saml.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/.travis.yml +0 -4
- package/CHANGELOG.md +0 -82
- package/commitlint.config.js +0 -1
- package/test/saml11.tests.js +0 -489
- package/test/saml20.tests.js +0 -688
- package/test/test-auth0-chain.pem +0 -160
- package/test/test-auth0.der +0 -0
- package/test/test-auth0.key +0 -27
- package/test/test-auth0.pem +0 -24
- package/test/test-auth0_rsa.pub +0 -9
- package/test/utils.js +0 -116
- package/test/utils.tests.js +0 -63
package/test/saml11.tests.js
DELETED
|
@@ -1,489 +0,0 @@
|
|
|
1
|
-
var assert = require('chai').assert;
|
|
2
|
-
var fs = require('fs');
|
|
3
|
-
var moment = require('moment');
|
|
4
|
-
var should = require('should');
|
|
5
|
-
var xmldom = require('@xmldom/xmldom');
|
|
6
|
-
var xmlenc = require('xml-encryption');
|
|
7
|
-
|
|
8
|
-
var utils = require('./utils');
|
|
9
|
-
var saml11 = require('../lib/saml11');
|
|
10
|
-
|
|
11
|
-
describe('saml 1.1', function () {
|
|
12
|
-
|
|
13
|
-
saml11TestSuite({
|
|
14
|
-
createAssertion: 'create',
|
|
15
|
-
assertSignature: Object.assign(function (assertion, options) {
|
|
16
|
-
assert.isTrue(utils.isValidSignature(assertion, options.cert));
|
|
17
|
-
}, {
|
|
18
|
-
it: it
|
|
19
|
-
})
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
saml11TestSuite({
|
|
23
|
-
createAssertion: 'createUnsignedAssertion',
|
|
24
|
-
assertSignature: Object.assign(function (assertion) {
|
|
25
|
-
assert.isEmpty(utils.getXmlSignatures(assertion));
|
|
26
|
-
}, {
|
|
27
|
-
it: it.skip
|
|
28
|
-
})
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
function saml11TestSuite(options) {
|
|
32
|
-
var createAssertion = options.createAssertion;
|
|
33
|
-
var assertSignature = options.assertSignature;
|
|
34
|
-
|
|
35
|
-
describe('#' + createAssertion, function () {
|
|
36
|
-
it('should create a saml 1.1 assertion', function () {
|
|
37
|
-
// cert created with:
|
|
38
|
-
// openssl req -x509 -new -newkey rsa:2048 -nodes -subj '/CN=auth0.auth0.com/O=Auth0 LLC/C=US/ST=Washington/L=Redmond' -keyout auth0.key -out auth0.pem
|
|
39
|
-
|
|
40
|
-
var options = {
|
|
41
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
42
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key')
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
46
|
-
assertSignature(signedAssertion, options);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should not error when cert is missing newlines', function () {
|
|
50
|
-
// cert created with:
|
|
51
|
-
// openssl req -x509 -new -newkey rsa:2048 -nodes -subj '/CN=auth0.auth0.com/O=Auth0 LLC/C=US/ST=Washington/L=Redmond' -keyout auth0.key -out auth0.pem
|
|
52
|
-
|
|
53
|
-
var options = {
|
|
54
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
55
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key')
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
var signedAssertion = saml11[createAssertion]({...options, cert: Buffer.from(options.cert.toString().replaceAll(/[\r\n]/g, ''))});
|
|
59
|
-
assertSignature(signedAssertion, options);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should not error when key is missing newlines', function () {
|
|
63
|
-
// cert created with:
|
|
64
|
-
// openssl req -x509 -new -newkey rsa:2048 -nodes -subj '/CN=auth0.auth0.com/O=Auth0 LLC/C=US/ST=Washington/L=Redmond' -keyout auth0.key -out auth0.pem
|
|
65
|
-
|
|
66
|
-
var options = {
|
|
67
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
68
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key')
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
var signedAssertion = saml11[createAssertion]({...options, key: Buffer.from(options.key.toString().replaceAll(/[\r\n]/g, ''))});
|
|
72
|
-
assertSignature(signedAssertion, options);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should support specifying Issuer property', function () {
|
|
76
|
-
var options = {
|
|
77
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
78
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
79
|
-
issuer: 'urn:issuer'
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
83
|
-
assert.equal('urn:issuer', utils.getIssuer(signedAssertion));
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('should create IssueInstant property', function () {
|
|
87
|
-
var options = {
|
|
88
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
89
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key')
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
93
|
-
// 2012-12-17T01:59:14.782Z
|
|
94
|
-
var now = moment.utc();
|
|
95
|
-
var issueInstant = moment(utils.getIssueInstant(signedAssertion)).utc();
|
|
96
|
-
assert.equal(now.year(), issueInstant.year());
|
|
97
|
-
assert.equal(now.month(), issueInstant.month());
|
|
98
|
-
assert.equal(now.day(), issueInstant.day());
|
|
99
|
-
assert.equal(now.hours(), issueInstant.hours());
|
|
100
|
-
assert.equal(now.minutes(), issueInstant.minutes());
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should create AssertionID and start with underscore', function () {
|
|
104
|
-
var options = {
|
|
105
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
106
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key')
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
110
|
-
var id = utils.getAssertionID(signedAssertion);
|
|
111
|
-
assert.equal('_', id[0]); // first char is underscore
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should create NotBefore and NotOnOrAfter properties', function () {
|
|
115
|
-
var options = {
|
|
116
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
117
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
118
|
-
lifetimeInSeconds: 600
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
122
|
-
var conditions = utils.getConditions(signedAssertion);
|
|
123
|
-
assert.equal(1, conditions.length);
|
|
124
|
-
var authenticationInstant = utils.getAuthenticationInstant(signedAssertion);
|
|
125
|
-
var notBefore = conditions[0].getAttribute('NotBefore');
|
|
126
|
-
var notOnOrAfter = conditions[0].getAttribute('NotOnOrAfter');
|
|
127
|
-
|
|
128
|
-
should.ok(notBefore);
|
|
129
|
-
should.ok(notOnOrAfter);
|
|
130
|
-
should.equal(authenticationInstant, notBefore);
|
|
131
|
-
|
|
132
|
-
var lifetime = Math.round((moment(notOnOrAfter).utc() - moment(notBefore).utc()) / 1000);
|
|
133
|
-
assert.equal(600, lifetime);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should set audience restriction', function () {
|
|
137
|
-
var options = {
|
|
138
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
139
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
140
|
-
audiences: 'urn:myapp'
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
144
|
-
var audiences = utils.getAudiences(signedAssertion);
|
|
145
|
-
assert.equal(1, audiences.length);
|
|
146
|
-
assert.equal('urn:myapp', audiences[0].textContent);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('should set multiple audience restriction', function () {
|
|
150
|
-
var options = {
|
|
151
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
152
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
153
|
-
audiences: ['urn:myapp', 'urn:myapp2']
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
157
|
-
var audiences = utils.getAudiences(signedAssertion);
|
|
158
|
-
assert.equal(2, audiences.length);
|
|
159
|
-
assert.equal('urn:myapp', audiences[0].textContent);
|
|
160
|
-
assert.equal('urn:myapp2', audiences[1].textContent);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should set attributes', function () {
|
|
164
|
-
var options = {
|
|
165
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
166
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
167
|
-
attributes: {
|
|
168
|
-
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress': 'foo@bar.com',
|
|
169
|
-
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name': 'Foo Bar',
|
|
170
|
-
'http://example.org/claims/testemptyarray': [], // should dont include empty arrays
|
|
171
|
-
'http://example.org/claims/testaccent': 'fóo', // should supports accents
|
|
172
|
-
'http://undefinedattribute/ws/com.com': undefined
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
177
|
-
|
|
178
|
-
assertSignature(signedAssertion, options);
|
|
179
|
-
|
|
180
|
-
var attributes = utils.getAttributes(signedAssertion);
|
|
181
|
-
assert.equal(3, attributes.length);
|
|
182
|
-
assert.equal('emailaddress', attributes[0].getAttribute('AttributeName'));
|
|
183
|
-
assert.equal('http://schemas.xmlsoap.org/ws/2005/05/identity/claims', attributes[0].getAttribute('AttributeNamespace'));
|
|
184
|
-
assert.equal('foo@bar.com', attributes[0].firstChild.textContent);
|
|
185
|
-
assert.equal('name', attributes[1].getAttribute('AttributeName'));
|
|
186
|
-
assert.equal('http://schemas.xmlsoap.org/ws/2005/05/identity/claims', attributes[1].getAttribute('AttributeNamespace'));
|
|
187
|
-
assert.equal('Foo Bar', attributes[1].firstChild.textContent);
|
|
188
|
-
assert.equal('testaccent', attributes[2].getAttribute('AttributeName'));
|
|
189
|
-
assert.equal('http://example.org/claims', attributes[2].getAttribute('AttributeNamespace'));
|
|
190
|
-
assert.equal('fóo', attributes[2].firstChild.textContent);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should set attributes with multiple values', function () {
|
|
194
|
-
var options = {
|
|
195
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
196
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
197
|
-
attributes: {
|
|
198
|
-
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role': ['admin','contributor']
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
203
|
-
var attributes = utils.getAttributes(signedAssertion);
|
|
204
|
-
assert.equal(1, attributes.length);
|
|
205
|
-
assert.equal('role', attributes[0].getAttribute('AttributeName'));
|
|
206
|
-
assert.equal('http://schemas.xmlsoap.org/ws/2005/05/identity/claims', attributes[0].getAttribute('AttributeNamespace'));
|
|
207
|
-
assert.equal('admin', attributes[0].childNodes[0].textContent);
|
|
208
|
-
assert.equal('contributor', attributes[0].childNodes[1].textContent);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('should set NameIdentifier', function () {
|
|
212
|
-
var options = {
|
|
213
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
214
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
215
|
-
nameIdentifier: 'foo'
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
219
|
-
var nameIdentifier = utils.getNameIdentifier(signedAssertion);
|
|
220
|
-
assert.equal('foo', nameIdentifier.textContent);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('should not contains line breaks', function () {
|
|
224
|
-
var options = {
|
|
225
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
226
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
227
|
-
nameIdentifier: 'foo'
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
231
|
-
assert.equal(-1, signedAssertion.indexOf('\n'));
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should set AuthenticationInstant', function () {
|
|
235
|
-
var options = {
|
|
236
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
237
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
238
|
-
nameIdentifier: 'foo'
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
242
|
-
var authenticationStatement = utils.getAuthenticationStatement(signedAssertion);
|
|
243
|
-
assert.ok(!!authenticationStatement.getAttribute('AuthenticationInstant'));
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('should set AuthenticationStatement NameIdentifier', function () {
|
|
247
|
-
var options = {
|
|
248
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
249
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
250
|
-
nameIdentifier: 'foo'
|
|
251
|
-
};
|
|
252
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
253
|
-
var nameIdentifier = utils.getAuthenticationStatement(signedAssertion)
|
|
254
|
-
.getElementsByTagName('saml:NameIdentifier')[0]
|
|
255
|
-
.textContent;
|
|
256
|
-
assert.equal('foo', nameIdentifier);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('should set AuthenticationStatement NameFormat', function () {
|
|
260
|
-
var options = {
|
|
261
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
262
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
263
|
-
nameIdentifier: 'foo'
|
|
264
|
-
};
|
|
265
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
266
|
-
var format = utils.getAuthenticationStatement(signedAssertion)
|
|
267
|
-
.getElementsByTagName('saml:NameIdentifier')[0]
|
|
268
|
-
.getAttribute('Format');
|
|
269
|
-
assert.equal('urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', format);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('should set AttirubteStatement NameFormat', function () {
|
|
273
|
-
var options = {
|
|
274
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
275
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
276
|
-
nameIdentifier: 'foo'
|
|
277
|
-
};
|
|
278
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
279
|
-
var format = utils.getNameIdentifier(signedAssertion)
|
|
280
|
-
.getAttribute('Format');
|
|
281
|
-
assert.equal('urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', format);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it('should override AttirubteStatement NameFormat', function () {
|
|
285
|
-
var options = {
|
|
286
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
287
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
288
|
-
nameIdentifier: 'foo',
|
|
289
|
-
nameIdentifierFormat: 'http://foo'
|
|
290
|
-
};
|
|
291
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
292
|
-
var format = utils.getAuthenticationStatement(signedAssertion)
|
|
293
|
-
.getElementsByTagName('saml:NameIdentifier')[0]
|
|
294
|
-
.getAttribute('Format');
|
|
295
|
-
|
|
296
|
-
assert.equal('http://foo', format);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
assertSignature.it('should place signature where specified', function () {
|
|
300
|
-
var options = {
|
|
301
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
302
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
303
|
-
xpathToNodeBeforeSignature: "//*[local-name(.)='Conditions']"
|
|
304
|
-
};
|
|
305
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
306
|
-
var doc = new xmldom.DOMParser().parseFromString(signedAssertion);
|
|
307
|
-
|
|
308
|
-
var signature = doc.documentElement.getElementsByTagName('Signature');
|
|
309
|
-
|
|
310
|
-
assert.equal('saml:Conditions', signature[0].previousSibling.nodeName);
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it('should test the whole thing', function () {
|
|
314
|
-
var options = {
|
|
315
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
316
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
317
|
-
issuer: 'urn:issuer',
|
|
318
|
-
lifetimeInSeconds: 600,
|
|
319
|
-
audiences: 'urn:myapp',
|
|
320
|
-
attributes: {
|
|
321
|
-
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress': 'foo@bar.com',
|
|
322
|
-
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name': 'Foo Bar'
|
|
323
|
-
},
|
|
324
|
-
nameIdentifier: 'foo',
|
|
325
|
-
nameIdentifierFormat: 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified'
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
var signedAssertion = saml11[createAssertion](options);
|
|
329
|
-
assertSignature(signedAssertion, options);
|
|
330
|
-
|
|
331
|
-
var nameIdentifier = utils.getNameIdentifier(signedAssertion);
|
|
332
|
-
assert.equal('foo', nameIdentifier.textContent);
|
|
333
|
-
assert.equal('urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', nameIdentifier.getAttribute('Format'));
|
|
334
|
-
|
|
335
|
-
var attributes = utils.getAttributes(signedAssertion);
|
|
336
|
-
assert.equal(2, attributes.length);
|
|
337
|
-
assert.equal('emailaddress', attributes[0].getAttribute('AttributeName'));
|
|
338
|
-
assert.equal('http://schemas.xmlsoap.org/ws/2005/05/identity/claims', attributes[0].getAttribute('AttributeNamespace'));
|
|
339
|
-
assert.equal('foo@bar.com', attributes[0].firstChild.textContent);
|
|
340
|
-
assert.equal('name', attributes[1].getAttribute('AttributeName'));
|
|
341
|
-
assert.equal('http://schemas.xmlsoap.org/ws/2005/05/identity/claims', attributes[1].getAttribute('AttributeNamespace'));
|
|
342
|
-
assert.equal('Foo Bar', attributes[1].firstChild.textContent);
|
|
343
|
-
|
|
344
|
-
assert.equal('urn:issuer', utils.getIssuer(signedAssertion));
|
|
345
|
-
|
|
346
|
-
var conditions = utils.getConditions(signedAssertion);
|
|
347
|
-
assert.equal(1, conditions.length);
|
|
348
|
-
var notBefore = conditions[0].getAttribute('NotBefore');
|
|
349
|
-
var notOnOrAfter = conditions[0].getAttribute('NotOnOrAfter');
|
|
350
|
-
should.ok(notBefore);
|
|
351
|
-
should.ok(notOnOrAfter);
|
|
352
|
-
|
|
353
|
-
var lifetime = Math.round((moment(notOnOrAfter).utc() - moment(notBefore).utc()) / 1000);
|
|
354
|
-
assert.equal(600, lifetime);
|
|
355
|
-
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
describe('encryption', function () {
|
|
359
|
-
|
|
360
|
-
it('should create a saml 1.1 encrypted assertion', function (done) {
|
|
361
|
-
var options = {
|
|
362
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
363
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
364
|
-
encryptionPublicKey: fs.readFileSync(__dirname + '/test-auth0_rsa.pub'),
|
|
365
|
-
encryptionCert: fs.readFileSync(__dirname + '/test-auth0.pem')
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
saml11[createAssertion](options, function(err, encrypted) {
|
|
369
|
-
if (err) return done(err);
|
|
370
|
-
|
|
371
|
-
xmlenc.decrypt(encrypted, { key: fs.readFileSync(__dirname + '/test-auth0.key')}, function(err, decrypted) {
|
|
372
|
-
if (err) return done(err);
|
|
373
|
-
assertSignature(decrypted, options);
|
|
374
|
-
done();
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
it('should not error when encryptionPublicKey is missing newlines', function (done) {
|
|
380
|
-
var options = {
|
|
381
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
382
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
383
|
-
encryptionPublicKey: Buffer.from(fs.readFileSync(__dirname + '/test-auth0_rsa.pub').toString().replaceAll(/[\r\n]/g, '')),
|
|
384
|
-
encryptionCert: fs.readFileSync(__dirname + '/test-auth0.pem')
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
saml11[createAssertion](options, function(err, encrypted) {
|
|
388
|
-
if (err) return done(err);
|
|
389
|
-
|
|
390
|
-
xmlenc.decrypt(encrypted, { key: fs.readFileSync(__dirname + '/test-auth0.key')}, function(err, decrypted) {
|
|
391
|
-
if (err) return done(err);
|
|
392
|
-
assertSignature(decrypted, options);
|
|
393
|
-
done();
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it('should not error when encryptionCert is missing newlines', function (done) {
|
|
399
|
-
var options = {
|
|
400
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
401
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
402
|
-
encryptionPublicKey: fs.readFileSync(__dirname + '/test-auth0_rsa.pub'),
|
|
403
|
-
encryptionCert: Buffer.from(fs.readFileSync(__dirname + '/test-auth0.pem').toString().replaceAll(/[\r\n]/g, ''))
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
saml11[createAssertion](options, function(err, encrypted) {
|
|
407
|
-
if (err) return done(err);
|
|
408
|
-
|
|
409
|
-
xmlenc.decrypt(encrypted, { key: fs.readFileSync(__dirname + '/test-auth0.key')}, function(err, decrypted) {
|
|
410
|
-
if (err) return done(err);
|
|
411
|
-
assertSignature(decrypted, options);
|
|
412
|
-
done();
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
it('should support holder-of-key suject confirmationmethod', function (done) {
|
|
418
|
-
var options = {
|
|
419
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
420
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
421
|
-
encryptionPublicKey: fs.readFileSync(__dirname + '/test-auth0_rsa.pub'),
|
|
422
|
-
encryptionCert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
423
|
-
subjectConfirmationMethod: 'holder-of-key'
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
saml11[createAssertion](options, function(err, encrypted, proofSecret) {
|
|
427
|
-
if (err) return done(err);
|
|
428
|
-
|
|
429
|
-
xmlenc.decrypt(encrypted, { key: fs.readFileSync(__dirname + '/test-auth0.key')}, function(err, decrypted) {
|
|
430
|
-
if (err) return done(err);
|
|
431
|
-
|
|
432
|
-
var doc = new xmldom.DOMParser().parseFromString(decrypted);
|
|
433
|
-
var subjectConfirmationNodes = doc.documentElement.getElementsByTagName('saml:SubjectConfirmation');
|
|
434
|
-
assert.equal(2, subjectConfirmationNodes.length);
|
|
435
|
-
for (var i=0;i<subjectConfirmationNodes.length;i++) {
|
|
436
|
-
var method = subjectConfirmationNodes[i].getElementsByTagName('saml:ConfirmationMethod')[0];
|
|
437
|
-
assert.equal(method.textContent, 'urn:oasis:names:tc:SAML:1.0:cm:holder-of-key');
|
|
438
|
-
|
|
439
|
-
var decryptedProofSecret = xmlenc.decryptKeyInfo(subjectConfirmationNodes[i], options);
|
|
440
|
-
assert.equal(proofSecret.toString('base64'), decryptedProofSecret.toString('base64'));
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
done();
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
it('should set attributes', function (done) {
|
|
449
|
-
var options = {
|
|
450
|
-
cert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
451
|
-
key: fs.readFileSync(__dirname + '/test-auth0.key'),
|
|
452
|
-
encryptionPublicKey: fs.readFileSync(__dirname + '/test-auth0_rsa.pub'),
|
|
453
|
-
encryptionCert: fs.readFileSync(__dirname + '/test-auth0.pem'),
|
|
454
|
-
attributes: {
|
|
455
|
-
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress': 'foo@bar.com',
|
|
456
|
-
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name': 'Foo Bar',
|
|
457
|
-
'http://example.org/claims/testaccent': 'fóo', // should supports accents
|
|
458
|
-
'http://undefinedattribute/ws/com.com': undefined
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
saml11[createAssertion](options, function(err, encrypted) {
|
|
463
|
-
if (err) return done(err);
|
|
464
|
-
|
|
465
|
-
xmlenc.decrypt(encrypted, { key: fs.readFileSync(__dirname + '/test-auth0.key')}, function(err, decrypted) {
|
|
466
|
-
if (err) return done(err);
|
|
467
|
-
|
|
468
|
-
assertSignature(decrypted, options);
|
|
469
|
-
|
|
470
|
-
var attributes = utils.getAttributes(decrypted);
|
|
471
|
-
assert.equal(3, attributes.length);
|
|
472
|
-
assert.equal('emailaddress', attributes[0].getAttribute('AttributeName'));
|
|
473
|
-
assert.equal('http://schemas.xmlsoap.org/ws/2005/05/identity/claims', attributes[0].getAttribute('AttributeNamespace'));
|
|
474
|
-
assert.equal('foo@bar.com', attributes[0].firstChild.textContent);
|
|
475
|
-
assert.equal('name', attributes[1].getAttribute('AttributeName'));
|
|
476
|
-
assert.equal('http://schemas.xmlsoap.org/ws/2005/05/identity/claims', attributes[1].getAttribute('AttributeNamespace'));
|
|
477
|
-
assert.equal('Foo Bar', attributes[1].firstChild.textContent);
|
|
478
|
-
assert.equal('testaccent', attributes[2].getAttribute('AttributeName'));
|
|
479
|
-
assert.equal('http://example.org/claims', attributes[2].getAttribute('AttributeNamespace'));
|
|
480
|
-
assert.equal('fóo', attributes[2].firstChild.textContent);
|
|
481
|
-
|
|
482
|
-
done();
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
});
|