Skip to content

Commit 9443fb2

Browse files
committed
Add failing test for issue #525
1 parent b673581 commit 9443fb2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/signature-integration-tests.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,37 @@ describe("Signature integration tests", function () {
223223
"<library> should have two child nodes : <book> and <Signature>",
224224
).to.equal(2);
225225
});
226+
227+
it("should create valid signature when signature location is nested in child element", function () {
228+
const xml = "<root><child/></root>";
229+
230+
const sig = new SignedXml();
231+
sig.privateKey = fs.readFileSync("./test/static/client.pem");
232+
sig.addReference({
233+
xpath: "/*",
234+
transforms: [
235+
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",
236+
"http://www.w3.org/2001/10/xml-exc-c14n#",
237+
],
238+
digestAlgorithm: "http://www.w3.org/2001/04/xmlenc#sha256",
239+
});
240+
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
241+
sig.signatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
242+
243+
sig.computeSignature(xml, {
244+
location: { action: "append", reference: "//*[local-name()='child']" },
245+
});
246+
247+
const signedXml = sig.getSignedXml();
248+
249+
const doc = new xmldom.DOMParser().parseFromString(signedXml);
250+
const signatureNode = xpath.select1("//*[local-name(.)='Signature']", doc);
251+
isDomNode.assertIsNodeLike(signatureNode);
252+
253+
const verifier = new SignedXml();
254+
verifier.publicCert = fs.readFileSync("./test/static/client_public.pem");
255+
verifier.loadSignature(signatureNode);
256+
257+
expect(verifier.checkSignature(signedXml)).to.be.true;
258+
});
226259
});

0 commit comments

Comments
 (0)