Skip to content

Commit

Permalink
Enforce valid setting for validateInResponseTo (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamandreasson committed Aug 18, 2023
1 parent 045e3b9 commit cbe102a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class SAML {
racComparison: ctorOptions.racComparison ?? "exact",
};

if (!Object.values(ValidateInResponseTo).includes(options.validateInResponseTo)) {
throw new TypeError("validateInResponseTo must be one of ['never', 'ifPresent', 'always']");
}

/**
* List of possible values:
* - exact : Assertion context must exactly match a context in the list
Expand Down
28 changes: 28 additions & 0 deletions test/tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,34 @@ describe("node-saml /", function () {
expect(samlObjValidComparisonType.options.racComparison).to.equal(racComparison);
});
});

it("should check the value of the option `validateInResponseTo`", function () {
expect(() => {
new SAML({
callbackUrl: "http://localhost/saml/consume",
validateInResponseTo: "bad_value" as ValidateInResponseTo,
cert: FAKE_CERT,
issuer: "onesaml_login",
}).options;
}).to.throw("validateInResponseTo must be one of ['never', 'ifPresent', 'always']");

const validInResponseToTypes: string[] = Object.keys(ValidateInResponseTo);
let samlObjValidInResponseToType: SAML;
validInResponseToTypes.forEach(function (validateInResponseTo) {
samlObjValidInResponseToType = new SAML({
callbackUrl: "http://localhost/saml/consume",
validateInResponseTo: validateInResponseTo as ValidateInResponseTo,
cert: FAKE_CERT,
issuer: "onesaml_login",
});
expect(samlObjValidInResponseToType.options.validateInResponseTo).to.equal(
validateInResponseTo,
);
expect(samlObjValidInResponseToType.options.validateInResponseTo).to.equal(
validateInResponseTo,
);
});
});
});

describe("getAuthorizeMessageAsync checks /", function () {
Expand Down

0 comments on commit cbe102a

Please sign in to comment.