├── .gitignore
├── .travis.yml
├── lib
├── utils.js
├── index.js
├── templates.js
├── interpolate.js
├── encoders.js
├── federationServerService.js
├── metadata.js
├── claims
│ └── PassportProfileMapper.js
└── wsfed.js
├── test
├── interpolate.tests.js
├── fixture
│ ├── wsfed.test-cert.pub
│ ├── wsfed.test-cert.pem
│ ├── wsfed.test-cert.pb7
│ ├── wsfed.test-cert.key
│ └── server.js
├── custom_form.html
├── wsfed-sha1.tests.js
├── metadata.tests.js
├── jwt.tests.js
├── wsfed-encryption.tests.js
├── xmlhelper.js
├── federationServerService.tests.js
├── wsfed.tests.js
└── wsfed.custom_form.tests.js
├── templates
├── form_el.ejs
├── form.ejs
├── federationServerServiceWsdl.ejs
├── federationServerServiceResponse.ejs
├── metadata.ejs
└── federationServerService.ejs
├── package.json
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/*
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 0.8
--------------------------------------------------------------------------------
/lib/utils.js:
--------------------------------------------------------------------------------
1 |
2 | exports.escape = function(html) {
3 | return String(html)
4 | .replace(/&/g, '&')
5 | .replace(//g, '>')
7 | .replace(/"/g, '"');
8 | };
9 |
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | exports.auth = require('./wsfed');
2 | exports.metadata = require('./metadata');
3 | exports.federationServerService = {};
4 | exports.federationServerService.wsdl = require('./federationServerService').wsdl;
5 | exports.federationServerService.thumbprint = require('./federationServerService').thumbprint;
--------------------------------------------------------------------------------
/test/interpolate.tests.js:
--------------------------------------------------------------------------------
1 | var interpolate = require('../lib/interpolate');
2 | var expect = require('chai').expect;
3 |
4 | describe('interpolation template', function () {
5 | it('should work', function () {
6 | var r = interpolate('aaa@@test@@')({
7 | test:'bbb'
8 | });
9 | expect(r).to.equal('aaabbb');
10 | });
11 | });
--------------------------------------------------------------------------------
/lib/templates.js:
--------------------------------------------------------------------------------
1 | var ejs = require('ejs');
2 | var fs = require('fs');
3 | var path = require('path');
4 |
5 | var templates = fs.readdirSync(path.join(__dirname, '../templates'));
6 |
7 | templates.forEach(function (tmplFile) {
8 | var content = fs.readFileSync(path.join(__dirname, '../templates', tmplFile));
9 | var template = ejs.compile(content.toString());
10 | exports[tmplFile.slice(0, -4)] = template;
11 | });
--------------------------------------------------------------------------------
/templates/form_el.ejs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/fixture/wsfed.test-cert.pub:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvtH4wKLYlIXZlfYQFJtX
3 | ZVC3fD8XMarzwvb/fHUyJ6NvNStN+H7GHp3/QhZbSaRyqK5hu5xXtFLgnI0QG8oE
4 | 1NlXbczjH45LeHWhPIdc2uHSpzXic78kOugMY1vng4J10PF6+T2FNaiv0iXeIQq9
5 | xbwwPYpflViQyJnzGCIZ7VGan6GbRKzyTKcB58yx24pJq+CviLXEY52TIW1l5imc
6 | jGvLtlCp1za9qBZa4XGoVqHi1kRXkdDSHty6lZWj3KxoRvTbiaBCH+75U7rifS6f
7 | R9lqjWE57bCGoz7+BBu9YmPKtI1KkyHFqWpxaJc/AKf9xgg+UumeqVcirUmAsHJr
8 | MwIDAQAB
9 | -----END PUBLIC KEY-----
--------------------------------------------------------------------------------
/lib/interpolate.js:
--------------------------------------------------------------------------------
1 | function getProp(obj, path) {
2 | return path.split('.').reduce(function (prev, curr) {
3 | return prev[curr];
4 | }, obj);
5 | }
6 |
7 | function escape (html){
8 | return String(html)
9 | .replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
10 | .replace(//g, '>')
12 | .replace(/'/g, ''')
13 | .replace(/"/g, '"');
14 | }
15 |
16 | module.exports = function (tmpl) {
17 | return function (model) {
18 | return tmpl.replace(/\@\@([^\@]*)\@\@/g,
19 | function (a, b) {
20 | var r = getProp(model, b);
21 | var value = typeof r === 'string' || typeof r === 'number' ? r : a;
22 | return escape(value);
23 | }
24 | );
25 | };
26 | };
--------------------------------------------------------------------------------
/test/custom_form.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Working...
4 |
5 |
6 |
18 |
21 |
22 |
--------------------------------------------------------------------------------
/templates/form.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 | Working...
4 |
5 |
6 |
18 |
21 |
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wsfed",
3 | "version": "1.0.3",
4 | "description": "WSFed server middleware",
5 | "main": "lib/index.js",
6 | "scripts": {
7 | "test": "mocha"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/auth0/node-wsfed.git"
12 | },
13 | "keywords": [
14 | "wsfed",
15 | "saml",
16 | "auth"
17 | ],
18 | "author": "Auth0",
19 | "license": "mit",
20 | "dependencies": {
21 | "ejs": "~0.8.3",
22 | "thumbprint": "0.0.1",
23 | "saml": "~0.6.1",
24 | "jsonwebtoken": "~0.4.1"
25 | },
26 | "devDependencies": {
27 | "chai": "~1.5.0",
28 | "express": "~3.1.0",
29 | "mocha": "~1.8.1",
30 | "request": "~2.14.0",
31 | "xmldom": "~0.1.13",
32 | "cheerio": "~0.10.7",
33 | "xml-crypto": "0.0.10",
34 | "xpath": "0.0.5",
35 | "xtend": "~2.0.3",
36 | "xml-encryption": "~0.3.0"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 AUTH10 LLC
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/lib/encoders.js:
--------------------------------------------------------------------------------
1 | var thumbprint = require('thumbprint');
2 |
3 | var removeHeaders = module.exports.removeHeaders = function (cert) {
4 | var pem = /-----BEGIN (\w*)-----([^-]*)-----END (\w*)-----/g.exec(cert.toString());
5 | if (pem && pem.length > 0) {
6 | return pem[2].replace(/[\n|\r\n]/g, '');
7 | }
8 | return null;
9 | };
10 |
11 | module.exports.thumbprint = function (pem) {
12 | var cert = removeHeaders(pem);
13 | return thumbprint.calculate(cert).toUpperCase();
14 | };
15 |
16 | module.exports.toCertifiedStore = function (pem) {
17 | var cert = removeHeaders(pem);
18 | var certBuffer = new Buffer(cert, 'base64');
19 |
20 | var header = new Buffer(8);
21 | header.writeUInt32LE(0x00000000, 0);
22 | header.writeUInt32LE(0x54524543, 4);
23 |
24 |
25 | var start = new Buffer(12);
26 | start.writeUInt32LE(0x00000020, 0);
27 | start.writeUInt32LE(0x00000001, 4);
28 | start.writeUInt32LE(certBuffer.length, 8);
29 |
30 | var ending = new Buffer(12);
31 | ending.writeUInt32LE(0x00000000, 0);
32 | ending.writeUInt32LE(0x00000000, 4);
33 |
34 | return Buffer.concat([header, start, certBuffer, ending]).toString('base64');
35 | };
--------------------------------------------------------------------------------
/templates/federationServerServiceWsdl.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/fixture/wsfed.test-cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDtTCCAp2gAwIBAgIJAMKR/NsyfcazMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
3 | BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
4 | aWRnaXRzIFB0eSBMdGQwHhcNMTIxMTEyMjM0MzQxWhcNMTYxMjIxMjM0MzQxWjBF
5 | MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50
6 | ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
7 | CgKCAQEAvtH4wKLYlIXZlfYQFJtXZVC3fD8XMarzwvb/fHUyJ6NvNStN+H7GHp3/
8 | QhZbSaRyqK5hu5xXtFLgnI0QG8oE1NlXbczjH45LeHWhPIdc2uHSpzXic78kOugM
9 | Y1vng4J10PF6+T2FNaiv0iXeIQq9xbwwPYpflViQyJnzGCIZ7VGan6GbRKzyTKcB
10 | 58yx24pJq+CviLXEY52TIW1l5imcjGvLtlCp1za9qBZa4XGoVqHi1kRXkdDSHty6
11 | lZWj3KxoRvTbiaBCH+75U7rifS6fR9lqjWE57bCGoz7+BBu9YmPKtI1KkyHFqWpx
12 | aJc/AKf9xgg+UumeqVcirUmAsHJrMwIDAQABo4GnMIGkMB0GA1UdDgQWBBTs83nk
13 | LtoXFlmBUts3EIxcVvkvcjB1BgNVHSMEbjBsgBTs83nkLtoXFlmBUts3EIxcVvkv
14 | cqFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNV
15 | BAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJAMKR/NsyfcazMAwGA1UdEwQF
16 | MAMBAf8wDQYJKoZIhvcNAQEFBQADggEBABw7w/5k4d5dVDgd/OOOmXdaaCIKvt7d
17 | 3ntlv1SSvAoKT8d8lt97Dm5RrmefBI13I2yivZg5bfTge4+vAV6VdLFdWeFp1b/F
18 | OZkYUv6A8o5HW0OWQYVX26zIqBcG2Qrm3reiSl5BLvpj1WSpCsYvs5kaO4vFpMak
19 | /ICgdZD+rxwxf8Vb/6fntKywWSLgwKH3mJ+Z0kRlpq1g1oieiOm1/gpZ35s0Yuor
20 | XZba9ptfLCYSggg/qc3d3d0tbHplKYkwFm7f5ORGHDSD5SJm+gI7RPE+4bO8q79R
21 | PAfbG1UGuJ0b/oigagciHhJp851SQRYf3JuNSc17BnK2L5IEtzjqr+Q=
22 | -----END CERTIFICATE-----
23 |
--------------------------------------------------------------------------------
/templates/federationServerServiceResponse.ejs:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 | true
9 |
10 | 1
11 | 26886a27-50ad-9695-3511-8d24a1a3a23b
12 | 1
13 |
14 |
15 |
16 |
17 |
18 | <%= thumbprint %>
19 |
20 |
21 | None
22 |
23 |
24 | <%= cert %>
25 |
26 | <%= location %>
27 | <%= location %>
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/test/fixture/wsfed.test-cert.pb7:
--------------------------------------------------------------------------------
1 | -----BEGIN PKCS7-----
2 | MIID5gYJKoZIhvcNAQcCoIID1zCCA9MCAQExADALBgkqhkiG9w0BBwGgggO5MIID
3 | tTCCAp2gAwIBAgIJAMKR/NsyfcazMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNVBAYT
4 | AkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRn
5 | aXRzIFB0eSBMdGQwHhcNMTIxMTEyMjM0MzQxWhcNMTYxMjIxMjM0MzQxWjBFMQsw
6 | CQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJu
7 | ZXQgV2lkZ2l0cyBQdHkg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 |
--------------------------------------------------------------------------------
/lib/federationServerService.js:
--------------------------------------------------------------------------------
1 | var templates = require('./templates');
2 | var URL_PATH = '/wsfed/adfs/fs/federationserverservice.asmx';
3 | var encoders = require('./encoders');
4 |
5 | function getLocation (req) {
6 | var protocol = req.headers['x-iisnode-https'] && req.headers['x-iisnode-https'] == 'ON' ?
7 | 'https' :
8 | (req.headers['x-forwarded-proto'] || req.protocol);
9 |
10 | return protocol + '://' + req.headers['host'] + req.originalUrl;
11 | }
12 |
13 | function getEndpointAddress (req, endpointPath) {
14 | endpointPath = endpointPath ||
15 | (req.originalUrl.substr(0, req.originalUrl.length - URL_PATH.length));
16 |
17 | var protocol = req.headers['x-iisnode-https'] && req.headers['x-iisnode-https'] == 'ON' ?
18 | 'https' :
19 | (req.headers['x-forwarded-proto'] || req.protocol);
20 |
21 | return protocol + '://' + req.headers['host'] + endpointPath;
22 | }
23 |
24 |
25 | module.exports.wsdl = function (req, res) {
26 | res.set('Content-Type', 'text/xml; charset=UTF-8');
27 | if(req.query.wsdl){
28 | return res.send(templates.federationServerServiceWsdl());
29 | }
30 | res.send(templates.federationServerService({
31 | location: getLocation(req)
32 | }));
33 | };
34 |
35 | module.exports.thumbprint = function (options) {
36 | return function (req, res) {
37 | res.set('Content-Type', 'text/xml; charset=UTF-8');
38 | res.send(templates.federationServerServiceResponse({
39 | location: getEndpointAddress(req, options.endpointPath),
40 | cert: encoders.removeHeaders(options.pkcs7.toString()),
41 | thumbprint: encoders.thumbprint(options.cert)
42 | }));
43 | };
44 | };
--------------------------------------------------------------------------------
/test/wsfed-sha1.tests.js:
--------------------------------------------------------------------------------
1 | var expect = require('chai').expect;
2 | var server = require('./fixture/server');
3 | var request = require('request');
4 | var cheerio = require('cheerio');
5 | var xmlhelper = require('./xmlhelper');
6 |
7 | describe('wsfed with sha1', function () {
8 | before(function (done) {
9 | server.start({
10 | signatureAlgorithm: 'rsa-sha1',
11 | digestAlgorithm: 'sha1'
12 | }, done);
13 | });
14 |
15 | after(function (done) {
16 | server.close(done);
17 | });
18 |
19 | describe('authorizing', function () {
20 | var body, $, signedAssertion, attributes;
21 |
22 | before(function (done) {
23 | request.get({
24 | jar: request.jar(),
25 | uri: 'http://localhost:5050/wsfed?wa=wsignin1.0&wctx=123&wtrealm=urn:the-super-client-id'
26 | }, function (err, response, b){
27 | if(err) return done(err);
28 | body = b;
29 | $ = cheerio.load(body);
30 | var wresult = $('input[name="wresult"]').attr('value');
31 | signedAssertion = /(.*)<\/t:RequestedSecurityToken>/.exec(wresult)[1];
32 | attributes = xmlhelper.getAttributes(signedAssertion);
33 | done();
34 | });
35 | });
36 |
37 | it('should use sha1 as signature algorithm', function(){
38 | var algorithm = xmlhelper.getSignatureMethodAlgorithm(signedAssertion);
39 | expect(algorithm).to.equal('http://www.w3.org/2000/09/xmldsig#rsa-sha1');
40 | });
41 |
42 | it('should use sha1 as digest algorithm', function(){
43 | var algorithm = xmlhelper.getDigestMethodAlgorithm(signedAssertion);
44 | expect(algorithm).to.equal('http://www.w3.org/2000/09/xmldsig#sha1');
45 | });
46 |
47 | });
48 | });
--------------------------------------------------------------------------------
/test/fixture/wsfed.test-cert.key:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | MIIEpAIBAAKCAQEAvtH4wKLYlIXZlfYQFJtXZVC3fD8XMarzwvb/fHUyJ6NvNStN
3 | +H7GHp3/QhZbSaRyqK5hu5xXtFLgnI0QG8oE1NlXbczjH45LeHWhPIdc2uHSpzXi
4 | c78kOugMY1vng4J10PF6+T2FNaiv0iXeIQq9xbwwPYpflViQyJnzGCIZ7VGan6Gb
5 | RKzyTKcB58yx24pJq+CviLXEY52TIW1l5imcjGvLtlCp1za9qBZa4XGoVqHi1kRX
6 | kdDSHty6lZWj3KxoRvTbiaBCH+75U7rifS6fR9lqjWE57bCGoz7+BBu9YmPKtI1K
7 | kyHFqWpxaJc/AKf9xgg+UumeqVcirUmAsHJrMwIDAQABAoIBAQCYKw05YSNhXVPk
8 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luDwfktNTnyW/Uk2dgXuMaXSHHN5
24 | XZt59K8CgYArGVOWK7LUmf3dkTIs3tXBm4/IMtUZmWmcP9C8Xe/Dg/IdQhK5CIx4
25 | VXl8rgZNeX/5/4nJ8Q3LrdLau1Iz620trNRGU6sGMs3x4WQbSq93RRbFzfG1oK74
26 | IOo5yIBxImQOSk5jz31gF9RJb15SDBIxonuWv8qAERyUfvrmEwR0kg==
27 | -----END RSA PRIVATE KEY-----
28 |
--------------------------------------------------------------------------------
/test/metadata.tests.js:
--------------------------------------------------------------------------------
1 | var expect = require('chai').expect;
2 | var server = require('./fixture/server');
3 | var request = require('request');
4 | var xmldom = require('xmldom');
5 |
6 | function certToPem (cert) {
7 | var pem = /-----BEGIN CERTIFICATE-----([^-]*)-----END CERTIFICATE-----/g.exec(cert.toString());
8 | if (pem.length > 0) {
9 | return pem[1].replace(/[\n|\r\n]/g, '');
10 | }
11 | return null;
12 | }
13 |
14 | describe('wsfed metadata', function () {
15 | before(function (done) {
16 | server.start(done);
17 | });
18 |
19 | after(function (done) {
20 | server.close(done);
21 | });
22 |
23 | describe('request to metadata', function (){
24 | var doc, content;
25 | before(function (done) {
26 | request.get({
27 | jar: request.jar(),
28 | uri: 'http://localhost:5050/wsfed/FederationMetadata/2007-06/FederationMetadata.xml'
29 | }, function (err, response, b){
30 | if(err) return done(err);
31 | content = b;
32 | doc = new xmldom.DOMParser().parseFromString(b).documentElement;
33 | done();
34 | });
35 | });
36 |
37 | it('sholud have the endpoint url', function(){
38 | expect(doc.getElementsByTagName('EndpointReference')[0].firstChild.textContent)
39 | .to.equal('http://localhost:5050/wsfed');
40 | });
41 |
42 | it('sholud have the claim types', function(){
43 | expect(doc.getElementsByTagName('auth:ClaimType'))
44 | .to.not.be.empty;
45 | });
46 |
47 | it('sholud have the issuer', function(){
48 | expect(doc.getAttribute('entityID'))
49 | .to.equal('fixture-test');
50 | });
51 |
52 | it('sholud have the pem', function(){
53 | expect(doc.getElementsByTagName('X509Certificate')[0].textContent)
54 | .to.equal(certToPem(server.credentials.cert));
55 | });
56 |
57 | it('should not contain line breaks', function(){
58 | expect(content)
59 | .to.not.contain('\n');
60 | });
61 |
62 | });
63 | });
--------------------------------------------------------------------------------
/test/jwt.tests.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs');
2 | var path = require('path');
3 | var expect = require('chai').expect;
4 | var server = require('./fixture/server');
5 | var request = require('request');
6 | var cheerio = require('cheerio');
7 | var xmlhelper = require('./xmlhelper');
8 | var jwt = require('jsonwebtoken');
9 |
10 | var credentials = {
11 | cert: fs.readFileSync(path.join(__dirname, '/fixture/wsfed.test-cert.pem')),
12 | key: fs.readFileSync(path.join(__dirname, '/fixture/wsfed.test-cert.key')),
13 | pkcs7: fs.readFileSync(path.join(__dirname, '/fixture/wsfed.test-cert.pb7'))
14 | };
15 |
16 |
17 | describe('wsfed+jwt', function () {
18 | before(function (done) {
19 | server.start({
20 | jwt: true
21 | }, done);
22 | });
23 |
24 | after(function (done) {
25 | server.close(done);
26 | });
27 |
28 | describe('authorizing', function () {
29 | var body, $, signedAssertion, profile;
30 |
31 | before(function (done) {
32 | request.get({
33 | jar: request.jar(),
34 | uri: 'http://localhost:5050/wsfed?wa=wsignin1.0&wctx=123&wtrealm=urn:the-super-client-id'
35 | }, function (err, response, b){
36 | if(err) return done(err);
37 | body = b;
38 | $ = cheerio.load(body);
39 | var signedAssertion = $('input[name="wresult"]').attr('value');
40 | jwt.verify(signedAssertion, credentials.cert.toString(), function (err, decoded) {
41 | if (err) return done(err);
42 | profile = decoded;
43 | done();
44 | });
45 | });
46 | });
47 |
48 | it('should have the attributes', function(){
49 | expect(profile).to.have.property('displayName');
50 | expect(profile.id).to.equal('12334444444');
51 | });
52 |
53 | it('should have jwt attributes', function(){
54 | expect(profile).to.have.property('aud');
55 | expect(profile).to.have.property('iss');
56 | expect(profile).to.have.property('iat');
57 | });
58 |
59 | });
60 | });
--------------------------------------------------------------------------------
/test/wsfed-encryption.tests.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs');
2 | var path = require('path');
3 | var expect = require('chai').expect;
4 | var server = require('./fixture/server');
5 | var request = require('request');
6 | var cheerio = require('cheerio');
7 | var xmlenc = require('xml-encryption');
8 | var xmlhelper = require('./xmlhelper');
9 |
10 | var credentials = {
11 | cert: fs.readFileSync(path.join(__dirname, '/fixture/wsfed.test-cert.pem')),
12 | key: fs.readFileSync(path.join(__dirname, '/fixture/wsfed.test-cert.key')),
13 | pkcs7: fs.readFileSync(path.join(__dirname, '/fixture/wsfed.test-cert.pb7')),
14 | pub: fs.readFileSync(path.join(__dirname, '/fixture/wsfed.test-cert.pub'))
15 | };
16 |
17 |
18 | describe('when dwdw encrypting the assertion', function () {
19 | before(function (done) {
20 | server.start({
21 | encryptionPublicKey: credentials.pub,
22 | encryptionCert: credentials.cert
23 | }, done);
24 | });
25 |
26 | after(function (done) {
27 | server.close(done);
28 | });
29 |
30 | var body, $, encryptedAssertion;
31 |
32 | describe('when encrypting the assertion', function () {
33 | before(function (done) {
34 | request.get({
35 | jar: request.jar(),
36 | uri: 'http://localhost:5050/wsfed?wa=wsignin1.0&wctx=123&wtrealm=urn:the-super-client-id'
37 | }, function (err, response, b){
38 | if(err) return done(err);
39 | body = b;
40 | $ = cheerio.load(body);
41 | var wresult = $('input[name="wresult"]').attr('value');
42 | encryptedAssertion = /(.*)<\/t:RequestedSecurityToken>/.exec(wresult)[1];
43 | done();
44 | });
45 | });
46 |
47 | it('should contain a form in the result', function(){
48 | expect(body).to.match(/