Skip to content

Commit 063b976

Browse files
committed
deprecate: originalXmlWithIds and getOriginalXmlWithIds() as per issue #512
1 parent 0c4813d commit 063b976

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ To sign xml documents:
281281
- `existingPrefixes` - A hash of prefixes and namespaces `prefix: namespace` that shouldn't be in the signature because they already exist in the xml
282282
- `getSignedXml()` - returns the original xml document with the signature in it, **must be called only after `computeSignature`**
283283
- `getSignatureXml()` - returns just the signature part, **must be called only after `computeSignature`**
284-
- `getOriginalXmlWithIds()` - returns the original xml with Id attributes added on relevant elements (required for validation), **must be called only after `computeSignature`**
284+
- `getOriginalXmlWithIds()` - **[deprecated]** returns the original xml with Id attributes added on relevant elements, **must be called only after `computeSignature`**. This method is deprecated and will be removed in a future version. Use `ComputeSignatureOptionsLocation` to control where the signature will be placed in the original XML.
285285

286286
To verify xml documents:
287287

src/signed-xml.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,13 +1423,14 @@ export class SignedXml {
14231423
}
14241424

14251425
/**
1426-
* Returns the original xml with Id attributes added on relevant elements (required for validation), must be called only after {@link computeSignature}
1426+
* Returns the original xml with Id attributes added on relevant elements, must be called only after {@link computeSignature}
14271427
*
14281428
* @returns The original XML with IDs.
1429+
* @deprecated This function is deprecated and will be removed in a future version. Use ComputeSignatureOptionsLocation to control where the signature will be placed in the original XML.
14291430
*/
1430-
getOriginalXmlWithIds(): string {
1431+
getOriginalXmlWithIds = deprecate((): string => {
14311432
return this.originalXmlWithIds;
1432-
}
1433+
}, "`getOriginalXmlWithIds()` is deprecated and will be removed in a future version. Use ComputeSignatureOptionsLocation to control where the signature will be placed in the original XML.");
14331434

14341435
/**
14351436
* Returns the original xml document with the signature in it, must be called only after {@link computeSignature}

test/signature-unit-tests.spec.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe("Signature unit tests", function () {
109109
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
110110
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
111111
sig.computeSignature(xml);
112-
const signedXml = sig.getOriginalXmlWithIds();
112+
const signedXml = sig.getSignedXml();
113113
const doc = new xmldom.DOMParser().parseFromString(signedXml);
114114

115115
const op = nsMode === "equal" ? "=" : "!=";
@@ -172,9 +172,10 @@ describe("Signature unit tests", function () {
172172
sig.canonicalizationAlgorithm = "http://www.w3.org/2001/10/xml-exc-c14n#";
173173
sig.signatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
174174
sig.computeSignature(xml);
175-
const signedXml = sig.getOriginalXmlWithIds();
175+
const signedXml = sig.getSignedXml();
176176
const doc = new xmldom.DOMParser().parseFromString(signedXml);
177-
const attrs = xpath.select("//@*", doc);
177+
// Only count attributes on the 'x' element, not the entire document (which includes signature attributes)
178+
const attrs = xpath.select("//*[local-name(.)='x']/@*", doc);
178179
isDomNode.assertIsArrayOfNodes(attrs);
179180
expect(attrs.length, "wrong number of attributes").to.equal(2);
180181
}
@@ -535,10 +536,17 @@ describe("Signature unit tests", function () {
535536

536537
expect(expectedSignedXml, "wrong signedXml format").to.equal(signedXml);
537538

538-
const originalXmlWithIds = sig.getOriginalXmlWithIds();
539-
const expectedOriginalXmlWithIds =
540-
'<root><x xmlns="ns" Id="_0"/><y attr="value" Id="_1"/><z><w Id="_2"/></z></root>';
541-
expect(expectedOriginalXmlWithIds, "wrong OriginalXmlWithIds").to.equal(originalXmlWithIds);
539+
// Verify IDs were added to the signed XML document
540+
const signedDoc = new xmldom.DOMParser().parseFromString(signedXml);
541+
const xId = xpath.select1("//*[local-name(.)='x']/@*[local-name(.)='Id']", signedDoc);
542+
isDomNode.assertIsAttributeNode(xId);
543+
expect(xId.value).to.equal("_0");
544+
const yId = xpath.select1("//*[local-name(.)='y']/@*[local-name(.)='Id']", signedDoc);
545+
isDomNode.assertIsAttributeNode(yId);
546+
expect(yId.value).to.equal("_1");
547+
const wId = xpath.select1("//*[local-name(.)='w']/@*[local-name(.)='Id']", signedDoc);
548+
isDomNode.assertIsAttributeNode(wId);
549+
expect(wId.value).to.equal("_2");
542550
});
543551

544552
it("signer creates signature with correct structure (with prefix)", function () {
@@ -699,10 +707,17 @@ describe("Signature unit tests", function () {
699707

700708
expect(signedXml, "wrong signedXml format").to.equal(expectedSignedXml);
701709

702-
const originalXmlWithIds = sig.getOriginalXmlWithIds();
703-
const expectedOriginalXmlWithIds =
704-
'<root><x xmlns="ns" Id="_0"/><y attr="value" Id="_1"/><z><w Id="_2"/></z></root>';
705-
expect(originalXmlWithIds, "wrong OriginalXmlWithIds").to.equal(expectedOriginalXmlWithIds);
710+
// Verify IDs were added to the signed XML document
711+
const signedDoc = new xmldom.DOMParser().parseFromString(signedXml);
712+
const xId = xpath.select1("//*[local-name(.)='x']/@*[local-name(.)='Id']", signedDoc);
713+
isDomNode.assertIsAttributeNode(xId);
714+
expect(xId.value).to.equal("_0");
715+
const yId = xpath.select1("//*[local-name(.)='y']/@*[local-name(.)='Id']", signedDoc);
716+
isDomNode.assertIsAttributeNode(yId);
717+
expect(yId.value).to.equal("_1");
718+
const wId = xpath.select1("//*[local-name(.)='w']/@*[local-name(.)='Id']", signedDoc);
719+
isDomNode.assertIsAttributeNode(wId);
720+
expect(wId.value).to.equal("_2");
706721
});
707722

708723
it("signer creates correct signature values", function () {

0 commit comments

Comments
 (0)