|
1 | | -const timekeeper = require('timekeeper'); |
2 | | -const expect = require('chai').expect; |
| 1 | +const timekeeper = require("timekeeper"); |
| 2 | +const DOMParser = require("@auth0/xmldom").DOMParser; |
| 3 | +const expect = require("chai").expect; |
3 | 4 |
|
4 | | -const utils = require('../lib/utils'); |
| 5 | +const utils = require("../lib/utils"); |
5 | 6 |
|
6 | | -describe('utils', function () { |
7 | | - describe('generateInstant', function () { |
8 | | - it('should pad the millis appropriately', function () { |
| 7 | +const signedResponse = require("./fixture/signed_response"); |
| 8 | + |
| 9 | +describe("utils", function () { |
| 10 | + describe("generateInstant", function () { |
| 11 | + it("should pad the millis appropriately", function () { |
9 | 12 | timekeeper.withFreeze(0, () => { |
10 | | - expect(utils.generateInstant()).to.equal('1970-01-01T00:00:00.000Z'); |
| 13 | + expect(utils.generateInstant()).to.equal("1970-01-01T00:00:00.000Z"); |
11 | 14 | }); |
12 | 15 | }); |
13 | 16 | }); |
14 | | - describe('generateUniqueID', function() { |
15 | | - it('should generate an ID 20 chars long', function() { |
| 17 | + describe("generateUniqueID", function () { |
| 18 | + it("should generate an ID 20 chars long", function () { |
16 | 19 | expect(utils.generateUniqueID().length).to.equal(20); |
17 | 20 | }); |
18 | 21 | }); |
19 | | - describe('generateUniqueID', function() { |
20 | | - it('should generate an ID from the alphabet', function() { |
21 | | - expect('abcdef0123456789'.split('')).to.include.members(utils.generateUniqueID().split('')); |
| 22 | + describe("generateUniqueID", function () { |
| 23 | + it("should generate an ID from the alphabet", function () { |
| 24 | + expect("abcdef0123456789".split("")).to.include.members( |
| 25 | + utils.generateUniqueID().split("") |
| 26 | + ); |
| 27 | + }); |
| 28 | + }); |
| 29 | + describe("validateSignature", function () { |
| 30 | + describe("with custom signing certificate", function () { |
| 31 | + it("should validate the signature correctly", function () { |
| 32 | + const response = signedResponse.response; |
| 33 | + |
| 34 | + const req = { body: { SAMLResponse: response }, query: {} }; |
| 35 | + const element_type = "LOGOUT_RESPONSE"; |
| 36 | + const xml = new DOMParser().parseFromString(signedResponse.xml); |
| 37 | + const options = { signingCert: signedResponse.cert, deflate: true }; |
| 38 | + |
| 39 | + // should not throw errors |
| 40 | + expect(utils.validateSignature(req, element_type, xml, options)).to.be |
| 41 | + .undefined; |
| 42 | + }); |
22 | 43 | }); |
23 | 44 | }); |
24 | 45 | }); |
0 commit comments