Skip to content

Commit

Permalink
add test when privateKeyPassword is wrong or not set
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Novak committed Apr 26, 2024
1 parent ff1c563 commit 3f85586
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/signature-unit-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1275,4 +1275,23 @@ describe("Signature unit tests", function () {
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
expect(() => sig.computeSignature(xml)).to.not.throw();
});

it("throws when privateKeyPassword is wrong", function () {
const xml = "<root><x /></root>";
const sig = new SignedXml();
sig.privateKey = fs.readFileSync("./test/static/client_encrypted.pem");
sig.privateKeyPassword = "wrong password";
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
expect(() => sig.computeSignature(xml)).to.throw();
});

it("throws when privateKeyPassword is not set and private key is encrypted", function () {
const xml = "<root><x /></root>";
const sig = new SignedXml();
sig.privateKey = fs.readFileSync("./test/static/client_encrypted.pem");
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
expect(() => sig.computeSignature(xml)).to.throw();
});
});

0 comments on commit 3f85586

Please sign in to comment.