Skip to content

Commit

Permalink
add catch block to NameID decryption (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryan-lockhart authored Oct 7, 2020
1 parent e0480e1 commit 43465d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/passport-saml/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,9 @@ SAML.prototype.getNameID = function(self, doc, callback) {
return callback(new Error('Invalid EncryptedAssertion content'));
}
return callBackWithNameID(decryptedIds[0], callback);
})
.catch(function (err) {
callback(err);
});
}
callback(new Error('Missing SAML NameID'));
Expand Down
19 changes: 18 additions & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,24 @@ describe( 'passport-saml /', function() {
}
});
});
it('errors if bad privateCert to requestToURL', function(done){
});
it('validatePostRequest errors for encrypted nameID with wrong decryptionPvk', function(done) {
var samlObj = new SAML({
cert: fs.readFileSync(__dirname + '/static/cert.pem', 'ascii'),
decryptionPvk: fs.readFileSync(__dirname + '/static/acme_tools_com.key', 'ascii')
});
var body = {
SAMLRequest: fs.readFileSync(__dirname + '/static/logout_request_with_encrypted_name_id.xml', 'base64')
};
samlObj.validatePostRequest(body, function(err) {
try {
should.exist(err);
done();
} catch (err2) {
done(err2);
}
});
it('errors if bad privateCert to requestToURL', function(done){
var samlObj = new SAML({
entryPoint: "foo",
privateCert: "-----BEGIN CERTIFICATE-----\n"+
Expand Down

0 comments on commit 43465d6

Please sign in to comment.