Skip to content

Deprecate getOriginalXmlWithIds() - #516

Open
shunkica wants to merge 3 commits into
node-saml:masterfrom
shunkica:deprecate-originalxmlwithids
Open

Deprecate getOriginalXmlWithIds()#516
shunkica wants to merge 3 commits into
node-saml:masterfrom
shunkica:deprecate-originalxmlwithids

Conversation

@shunkica

@shunkica shunkica commented Oct 19, 2025

Copy link
Copy Markdown
Contributor

As per the discussion in issue #512 , this PR removes the internal usages of the getOriginalXmlWithIds() function and marks it deprecated.

Summary by CodeRabbit

  • Documentation
    • Updated guidance for the deprecated original-XML retrieval method, recommending the signature-location option with signed XML retrieval.
  • Public API
    • The original-XML retrieval method remains available and now emits a deprecation warning when used.
  • Tests
    • Updated assertions to validate signed XML output and confirm IDs and element attributes without including signature-related attributes.

@coderabbitai

coderabbitai Bot commented Oct 19, 2025

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 93db96f5-8328-4469-aaf1-888d1e757799

📥 Commits

Reviewing files that changed from the base of the PR and between be80e81 and d33e387.

📒 Files selected for processing (2)
  • README.md
  • src/signed-xml.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The PR adds a runtime deprecation warning for getOriginalXmlWithIds(), restores it as a method, and updates documentation to recommend computeSignature() with location followed by getSignedXml().

Changes

SignedXml deprecation

Layer / File(s) Summary
Deprecation warning and guidance
src/signed-xml.ts, README.md
getOriginalXmlWithIds() calls a shared deprecation warning before returning its existing value. Its JSDoc and the README now recommend the location option of computeSignature() followed by getSignedXml().

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to d33e3

This change preserves existing getOriginalXmlWithIds() behavior while warning callers and documenting the supported signature-location replacement. No merge-blocking current-head risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: deprecating getOriginalXmlWithIds().
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/signed-xml.ts (1)

1281-1283: Consider keeping it as a method to avoid per-instance overhead.

While the current implementation maintains backward compatibility, converting the method to a class field has memory implications: each SignedXml instance now allocates its own deprecate-wrapped function. Additionally, as a property, it could be inadvertently reassigned.

Consider this alternative that preserves the method signature:

  /**
   * Returns the original xml with Id attributes added on relevant elements, must be called only after {@link computeSignature}
   *
   * @returns The original XML with IDs.
   * @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.
   */
-  getOriginalXmlWithIds = deprecate((): string => {
+  getOriginalXmlWithIds(): string {
+    this.logDeprecation();
     return this.originalXmlWithIds;
-  }, "`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.");
+  }
+
+  private logDeprecation = deprecate(() => {}, "`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.");

This approach:

  • Keeps it as a method (avoiding per-instance function allocation)
  • Prevents reassignment
  • Maintains TypeScript method types
  • Still emits the deprecation warning when called

Alternatively, if the current pattern is preferred, it's functional and the memory overhead may be acceptable depending on instance count.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02a405a and b25ea5a.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • src/signed-xml.ts (1 hunks)
  • test/signature-unit-tests.spec.ts (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/signature-unit-tests.spec.ts (1)
example/example.js (4)
  • signedXml (39-39)
  • sig (9-9)
  • sig (22-22)
  • doc (17-17)
🔇 Additional comments (5)
README.md (1)

285-285: LGTM! Clear deprecation notice with migration guidance.

The deprecation documentation is well-written and provides users with a clear alternative approach using ComputeSignatureOptionsLocation.

test/signature-unit-tests.spec.ts (4)

112-113: LGTM! Correct migration to the new API.

The test correctly migrates from the deprecated getOriginalXmlWithIds() to getSignedXml().


175-180: LGTM! Correctly adjusted XPath query for the new API.

The XPath change to target only the 'x' element's attributes is appropriate since getSignedXml() returns the complete signed document including the Signature element, which has its own attributes. This prevents false positives in the attribute count.


539-549: LGTM! Verification ensures IDs are added correctly.

The new verification block properly validates that ID attributes are added to the signed elements in the output XML, maintaining test coverage for functionality previously verified through getOriginalXmlWithIds().


710-720: LGTM! Consistent ID verification pattern.

This verification block follows the same pattern as the earlier one, ensuring comprehensive test coverage for ID attribute addition.

@shunkica

Copy link
Copy Markdown
Contributor Author

This just seems like the users are not aware how the signature location can be used within the computeSignature function.

@shunkica

Copy link
Copy Markdown
Contributor Author

The biggest of these libraries vpulim/node-soap can just refactor from:

    this.signer.computeSignature(xmlWithSec, this.signerOptions);
    const originalXmlWithIds = this.signer.getOriginalXmlWithIds();
    const signatureXml = this.signer.getSignatureXml();
    return insertStr(signatureXml, originalXmlWithIds, originalXmlWithIds.indexOf('</wsse:Security>'));

to

    const computeOptions = {
      ...this.signerOptions,
      location: {
        reference: "//wsse:Security",
        action: "append"
      }
    };
    this.signer.computeSignature(xmlWithSec, computeOptions);
    return this.signer.getSignedXml();

I haven't tested if of course this is just off the cuff.

@shunkica
shunkica force-pushed the deprecate-originalxmlwithids branch from b25ea5a to 063b976 Compare October 25, 2025 06:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b25ea5a and 063b976.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • src/signed-xml.ts (1 hunks)
  • test/signature-unit-tests.spec.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/signed-xml.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: shunkica
PR: node-saml/xml-crypto#506
File: src/signed-xml.ts:1159-1159
Timestamp: 2025-10-22T20:36:00.734Z
Learning: In node-saml/xml-crypto PR #506, the maintainer (shunkica) prefers to address the ref.uri mutation inside addAllReferences in a separate PR; removing the in-loop assignment is the desired fix but may be treated as a breaking change. Future guidance: avoid behavioral changes to ref.uri in the current PR.
Learnt from: shunkica
PR: node-saml/xml-crypto#506
File: src/signed-xml.ts:1159-1159
Timestamp: 2025-10-22T21:03:38.309Z
Learning: In node-saml/xml-crypto PR #506, the maintainer (shunkica) requested an issue to separate the overloaded Reference interface into distinct SigningReference and ValidationReference types. Initial hypothesis: signing-only (xpath, isEmptyUri, id, type), validation-only (uri, digestValue, validationError, signedReference), shared (transforms, digestAlgorithm, inclusiveNamespacesPrefixList). This should be proposed and designed in a follow-up, not altered in the current PR.
📚 Learning: 2025-10-22T21:50:05.441Z
Learnt from: shunkica
PR: node-saml/xml-crypto#0
File: :0-0
Timestamp: 2025-10-22T21:50:05.441Z
Learning: In src/signed-xml.ts Line 1099, createReferences mutates ref.uri = id during signing. Maintain this behavior for now; remove/refactor in a separate PR as previously requested by the maintainer.

Applied to files:

  • test/signature-unit-tests.spec.ts
🔇 Additional comments (4)
test/signature-unit-tests.spec.ts (4)

112-113: LGTM!

The migration from getOriginalXmlWithIds() to getSignedXml() is correct. Both contain the added ID attributes, which is what this test verifies.


175-180: Excellent XPath fix with clear documentation.

The updated XPath //*[local-name(.)='x']/@* correctly isolates the 'x' element's attributes, preventing the count from including signature attributes introduced by getSignedXml(). The explanatory comment is helpful.


539-549: LGTM!

The ID verification logic correctly migrates to use getSignedXml(). The XPath queries properly locate ID attributes on the signed elements, and the assertions verify the expected incremental ID values.


710-720: LGTM!

Consistent with the earlier ID verification block at lines 539-549. The migration correctly verifies ID attributes in the signed XML for the prefixed signature test case.

Comment thread README.md Outdated
@shunkica

shunkica commented Oct 25, 2025

Copy link
Copy Markdown
Contributor Author

I ran some benchmarks with and without originalXmlWithIds. The speed difference is negligible, but the memory difference is significant.
I could create a separate branch for the benchmark etc. but I don't think it is necessary since it is very clear where these numbers are coming from.
The larger the XML file is the more relative impact this has.

# File Size Time Impact Abs Time Overhead Memory Impact Abs Mem Overhead WITH Time WITHOUT Time WITH Mem WITHOUT Mem
0 small-100kb 100KB +15.56% +4.56ms +12.35% 0.09 MB 33.89ms 29.33ms 0.86 MB 0.76 MB
1 medium-1mb 1024KB +2.08% +2.61ms +26.68% 1.00 MB 128.37ms 125.76ms 4.75 MB 3.75 MB
2 large-10mb 10240KB +8.07% +62.19ms +31.07% 10.00 MB 832.39ms 770.20ms 42.18 MB 32.18 MB

@cjbarth

cjbarth commented Oct 25, 2025

Copy link
Copy Markdown
Contributor

Honestly, getting rid of foot-guns (must be called after...) is a really good idea. I'd like to expand the README example section a little to cover some of the cases I found already existing on GitHub.

Also, a 5% increase in speed is nothing to sneeze at either. Did you just comment out the code that calls .toString() on doc to get these numbers?

@shunkica

Copy link
Copy Markdown
Contributor Author

Honestly, getting rid of foot-guns (must be called after...) is a really good idea. I'd like to expand the README example section a little to cover some of the cases I found already existing on GitHub.

Also, a 5% increase in speed is nothing to sneeze at either. Did you just comment out the code that calls .toString() on doc to get these numbers?

Basically yes. I added a options flag to skip assigning it it so I could run all the benchmarks at once.

@cjbarth

cjbarth commented Nov 16, 2025

Copy link
Copy Markdown
Contributor

@shunkica , I'm ready to land this if you're good with it.

cjbarth
cjbarth previously approved these changes Nov 16, 2025
@cjbarth
cjbarth self-requested a review November 16, 2025 00:17
@shunkica
shunkica force-pushed the deprecate-originalxmlwithids branch from d77d0fc to be80e81 Compare November 16, 2025 10:24
@codecov

codecov Bot commented Nov 16, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.46%. Comparing base (627d83f) to head (be80e81).
⚠️ Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #516      +/-   ##
==========================================
+ Coverage   73.05%   75.46%   +2.40%     
==========================================
  Files           9        9              
  Lines         902     1031     +129     
  Branches      239      268      +29     
==========================================
+ Hits          659      778     +119     
- Misses        143      145       +2     
- Partials      100      108       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shunkica

Copy link
Copy Markdown
Contributor Author

@cjbarth The only other thing I can think of is putting some migration guide ( eg: #516 (comment) ) in the readme.

@cjbarth cjbarth added this to the v6.2 milestone Sep 7, 2026
Adjust the deprecation mechanism for `getOriginalXmlWithIds()` to use a dedicated warning function.
This change also clarifies the recommended alternative usage in the JSDoc and README,
guiding users to employ the `location` option with `computeSignature()` followed by `getSignedXml()`.
@cjbarth

cjbarth commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@shunkica , I cleaned this up a bit. What do you think?

@shunkica

shunkica commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@shunkica , I cleaned this up a bit. What do you think?

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants