diff --git a/.travis.yml b/.travis.yml index de50a1f..f04f381 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,5 @@ node_js: - 4 - 6 - 8 + - 10 + - 12 diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..422b194 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1 @@ +module.exports = { extends: ['@commitlint/config-conventional'] }; diff --git a/lib/wsfed.js b/lib/wsfed.js index dd98e0f..fe26347 100644 --- a/lib/wsfed.js +++ b/lib/wsfed.js @@ -79,6 +79,10 @@ module.exports = function(options) { var profileMap = options.profileMapper(user); var claims = profileMap.getClaims(options); var ni = profileMap.getNameIdentifier(options); + if (!ni || !ni.nameIdentifier) { + return next(new Error('No attribute was found to generate the nameIdentifier')); + } + saml11.create({ signatureAlgorithm: options.signatureAlgorithm, digestAlgorithm: options.digestAlgorithm, diff --git a/package.json b/package.json index 6ac8349..2ee0053 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "WSFed server middleware", "main": "lib/index.js", "scripts": { - "test": "mocha" + "test": "mocha", + "release": "standard-version" }, "repository": { "type": "git", @@ -24,15 +25,25 @@ "saml": "^0.12.1" }, "devDependencies": { + "@commitlint/cli": "^9.1.2", + "@commitlint/config-conventional": "^9.1.2", "chai": "~1.5.0", + "cheerio": "0.22.0", + "debug": "~3.2.6", "express": "~3.1.0", + "husky": "^4.3.0", "mocha": "~1.8.1", "request": "~2.14.0", - "xmldom": "=0.1.15", - "cheerio": "0.22.0", + "standard-version": "^9.0.0", "xml-crypto": "~0.10.1", + "xml-encryption": "0.11.0", + "xmldom": "=0.1.15", "xpath": "0.0.5", - "xtend": "~2.0.3", - "xml-encryption": "0.11.0" + "xtend": "~2.0.3" + }, + "husky": { + "hooks": { + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" + } } } diff --git a/test/fixture/server.js b/test/fixture/server.js index 11977cc..06719e3 100644 --- a/test/fixture/server.js +++ b/test/fixture/server.js @@ -26,10 +26,13 @@ var credentials = { pkcs7: fs.readFileSync(path.join(__dirname, 'wsfed.test-cert.pb7')) }; +module.exports.options = {}; + module.exports.start = function(options, callback){ + module.exports.options = options; if (typeof options === 'function') { callback = options; - options = {}; + module.exports.options = {}; } var app = express(); @@ -64,13 +67,19 @@ module.exports.start = function(options, callback){ } //configure wsfed middleware - app.get('/wsfed', - wsfed.auth(xtend({}, { - issuer: 'fixture-test', - getPostURL: getPostURL, - cert: credentials.cert, - key: credentials.key - }, options))); + app.get('/wsfed', function(req, res, next) { + wsfed.auth(xtend({}, { + issuer: 'fixture-test', + getPostURL: getPostURL, + cert: credentials.cert, + key: credentials.key + }, module.exports.options))(req, res, function(err){ + if (err) { + return res.send(400, err.message); + } + next(); + }) + }); var server = http.createServer(app).listen(5050, callback); module.exports.close = server.close.bind(server); diff --git a/test/wsfed.tests.js b/test/wsfed.tests.js index dcaf80b..6dff6fd 100644 --- a/test/wsfed.tests.js +++ b/test/wsfed.tests.js @@ -169,5 +169,39 @@ describe('wsfed', function () { }); }); }); + + describe('using custom profile mapper', function() { + describe('when NameIdentifier is not found', function(){ + function ProfileMapper(user) { + this.user = user; + } + ProfileMapper.prototype.getClaims = function () { + return this.user; + } + ProfileMapper.prototype.getNameIdentifier = function () { + return null; + } + + before(function () { + server.options = { + profileMapper: function createProfileMapper(user) { + return new ProfileMapper(user) + } + }; + }); + + it('should return an error', function(done){ + request.get({ + jar: request.jar(), + uri: 'http://localhost:5050/wsfed?wa=wsignin1.0&wctx=123&wtrealm=urn:the-super-client-id' + }, function (err, response){ + if(err) return done(err); + expect(response.statusCode).to.equal(400); + expect(response.body).to.equal('No attribute was found to generate the nameIdentifier'); + done(); + }); + }); + }); + }); });