From 615cffd8544d6f88fc50546abf318c18225014f8 Mon Sep 17 00:00:00 2001 From: Sergii Biienko Date: Tue, 20 Oct 2020 18:14:38 +0200 Subject: [PATCH 1/3] fix!(nameIdentifier): handle the case of not found nameIdentifier BREAKING CHANGE: an error will be returned in case no `nameIdentifier` is returned from the profile mapper --- lib/wsfed.js | 4 ++++ test/fixture/server.js | 25 +++++++++++++++++-------- test/wsfed.tests.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) 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/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(); + }); + }); + }); + }); }); From 37966758f1d4e9c64100cc1b8cf783af469e05a2 Mon Sep 17 00:00:00 2001 From: Sergii Biienko Date: Wed, 21 Oct 2020 10:06:40 +0200 Subject: [PATCH 2/3] chore: use `debug` dep version compatible with node v4 --- .travis.yml | 2 ++ package.json | 1 + 2 files changed, 3 insertions(+) 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/package.json b/package.json index 6ac8349..530a4e0 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "devDependencies": { "chai": "~1.5.0", + "debug": "~3.2.6", "express": "~3.1.0", "mocha": "~1.8.1", "request": "~2.14.0", From 3bde2f783f38eacad14562c0b9879a63ed642b2f Mon Sep 17 00:00:00 2001 From: Sergii Biienko Date: Wed, 28 Oct 2020 12:18:02 +0100 Subject: [PATCH 3/3] chore: enable commitlint and add standard-version --- commitlint.config.js | 1 + package.json | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 commitlint.config.js 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/package.json b/package.json index 530a4e0..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,16 +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" + } } }