diff --git a/test/signature-unit-tests.spec.ts b/test/signature-unit-tests.spec.ts index 133fe92..c52680d 100644 --- a/test/signature-unit-tests.spec.ts +++ b/test/signature-unit-tests.spec.ts @@ -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 = ""; + 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 = ""; + 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(); + }); });