diff --git a/src/signed-xml.ts b/src/signed-xml.ts index 05dae41..a02f18a 100644 --- a/src/signed-xml.ts +++ b/src/signed-xml.ts @@ -1195,7 +1195,7 @@ export class SignedXml { id, ); } else { - node.setAttribute("Id", id); + node.setAttribute(this.idAttributes[0], id); } return id; diff --git a/test/signature-unit-tests.spec.ts b/test/signature-unit-tests.spec.ts index baa382d..91ba051 100644 --- a/test/signature-unit-tests.spec.ts +++ b/test/signature-unit-tests.spec.ts @@ -17,9 +17,9 @@ describe("Signature unit tests", function () { expect(node.length, `xpath ${xpathArg} not found`).to.equal(1); } - function verifyAddsId(mode, nsMode) { + function verifyAddsId(mode, nsMode, idAttribute:string|undefined = undefined) { const xml = ''; - const sig = new SignedXml({ idMode: mode }); + const sig = new SignedXml({ idMode: mode, idAttribute }); sig.privateKey = fs.readFileSync("./test/static/client.pem"); sig.addReference({ @@ -46,7 +46,7 @@ describe("Signature unit tests", function () { const op = nsMode === "equal" ? "=" : "!="; - const xpathArg = `//*[local-name(.)='{elem}' and '_{id}' = @*[local-name(.)='Id' and namespace-uri(.)${op}'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd']]`; + const xpathArg = `//*[local-name(.)='{elem}' and '_{id}' = @*[local-name(.)='${idAttribute || 'Id'}' and namespace-uri(.)${op}'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd']]`; //verify each of the signed nodes now has an "Id" attribute with the right value nodeExists(doc, xpathArg.replace("{id}", "0").replace("{elem}", "x")); @@ -54,6 +54,10 @@ describe("Signature unit tests", function () { nodeExists(doc, xpathArg.replace("{id}", "2").replace("{elem}", "w")); } + it("signer adds increasing different id attributes to elements with custom idAttribute", function () { + verifyAddsId(null, "different", 'myIdAttribute'); + }); + it("signer adds increasing different id attributes to elements", function () { verifyAddsId(null, "different"); });