Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/signed-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ export class SignedXml {
id,
);
} else {
node.setAttribute("Id", id);
node.setAttribute(this.idAttributes[0], id);
}

return id;
Expand Down
10 changes: 7 additions & 3 deletions test/signature-unit-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,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 = '<root><x xmlns="ns"></x><y attr="value"></y><z><w></w></z></root>';
const sig = new SignedXml({ idMode: mode });
const sig = new SignedXml({ idMode: mode, idAttribute });
sig.privateKey = fs.readFileSync("./test/static/client.pem");

sig.addReference({
Expand All @@ -114,14 +114,18 @@ 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"));
nodeExists(doc, xpathArg.replace("{id}", "1").replace("{elem}", "y"));
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");
});
Expand Down