Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always throw error objects instead of strings #412

Merged
merged 2 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/passport-saml/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ class SAML {
});

if (!hasValidQuerySignature) {
throw 'Invalid signature';
throw new Error('Invalid signature');
}
});
} else {
Expand All @@ -906,7 +906,7 @@ class SAML {
matchingAlgo = crypto.getHashes()[i];
}
else {
throw alg + ' is not supported';
throw new Error(alg + ' is not supported');
}

const verifier = crypto.createVerify(matchingAlgo);
Expand All @@ -931,7 +931,7 @@ class SAML {
return (async () => {
const statusCode = doc.LogoutResponse.Status[0].StatusCode[0].$.Value;
if (statusCode !== "urn:oasis:names:tc:SAML:2.0:status:Success")
throw 'Bad status code: ' + statusCode;
throw new Error('Bad status code: ' + statusCode);

this.verifyIssuer(doc.LogoutResponse);
const inResponseTo = doc.LogoutResponse.$.InResponseTo;
Expand All @@ -948,9 +948,9 @@ class SAML {
const issuer = samlMessage.Issuer;
if (issuer) {
if (issuer[0]._ !== this.options.idpIssuer)
throw 'Unknown SAML issuer. Expected: ' + this.options.idpIssuer + ' Received: ' + issuer[0]._;
throw new Error('Unknown SAML issuer. Expected: ' + this.options.idpIssuer + ' Received: ' + issuer[0]._);
} else {
throw 'Missing SAML issuer';
throw new Error('Missing SAML issuer');
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ describe( 'passport-saml /', function() {
samlObj.validateRedirect(this.request, this.request.originalQuery, function(err) {
try {
should.exist(err);
err.should.eql(
err.message.should.eql(
'Unknown SAML issuer. Expected: foo Received: http://localhost:20000/saml2/idp/metadata.php'
);
done();
Expand All @@ -2441,7 +2441,7 @@ describe( 'passport-saml /', function() {
samlObj.validateRedirect(this.request, this.request.originalQuery, function(err) {
try {
should.exist(err);
err.should.eql('Invalid signature');
err.message.should.eql('Invalid signature');
done();
} catch (err2) {
done(err2);
Expand Down Expand Up @@ -2499,7 +2499,7 @@ describe( 'passport-saml /', function() {
samlObj.validateRedirect(this.request, this.request.originalQuery, function(err) {
try {
should.exist(err);
err.should.eql(
err.message.should.eql(
'Unknown SAML issuer. Expected: foo Received: http://localhost:20000/saml2/idp/metadata.php'
);
done();
Expand All @@ -2513,7 +2513,7 @@ describe( 'passport-saml /', function() {
samlObj.validateRedirect(this.request, this.request.originalQuery, function(err) {
try {
should.exist(err);
err.should.eql(
err.message.should.eql(
'Bad status code: urn:oasis:names:tc:SAML:2.0:status:Requester'
);
done();
Expand All @@ -2539,7 +2539,7 @@ describe( 'passport-saml /', function() {
samlObj.validateRedirect(this.request, this.request.originalQuery, function(err) {
try {
should.exist(err);
err.should.eql('Invalid signature');
err.message.should.eql('Invalid signature');
done();
} catch (err2) {
done(err2);
Expand Down