Skip to content

Conversation

@kaibernhard
Copy link
Contributor

@kaibernhard kaibernhard commented Oct 13, 2025

This PR adds tests for the signature algorithm sha256-rsa-MGF1 as implemented in
#488

Summary by CodeRabbit

  • Tests
    • Added new SAML signature verification tests covering SHA-256 with RSA-MGF1 and multiple XMLDSig RSA algorithms, including tamper-detection cases.
    • Expanded parameterized sign-and-verify test coverage across several signature algorithms.
    • Added static SAML fixtures: valid signed, modified/invalid signed, and unsigned responses to support test scenarios.
    • No production code or public API changes.

valid_saml_sha256_rsa_mgf1.xml has been signed with:

xmlsectool --sign \
           --inFile unsigned_saml_response.xml \
           --outFile valid_saml_sha256_rsa_mgf1.xml \
           --keyFile idp_private_key.pem \
           --certificate idp_certificate.pem \
           --signatureAlgorithm http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1
@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

Walkthrough

Adds new unit tests for SAML XML signature verification (including SHA-256 with RSA-MGF1), plus three static SAML XML fixtures (valid signed, invalid/tampered signed, and unsigned). Tests exercise positive validation, tamper detection, and parameterized sign-and-verify checks across multiple XMLDSig RSA algorithms. No production code or public API changes.

Changes

Cohort / File(s) Summary
SAML response RSA-MGF1 tests
test/saml-response-tests.spec.ts
Adds two tests validating SAML responses signed with SHA-256 RSA-MGF1: one expected to pass (valid XML) and one expected to fail (modified/tampered XML).
Signature algorithm matrix tests
test/signature-unit-tests.spec.ts
Adds parameterized tests over a set of XMLDSig RSA signature URIs. Introduces helpers to sign XML with each algorithm, load signatures, verify them, and detect tampering.
Static SAML fixtures
test/static/valid_saml_sha256_rsa_mgf1.xml, test/static/invalid_saml_sha256_rsa_mgf1.xml, test/static/unsigned_saml_response.xml
Adds three test fixture XML files: a valid RSA-MGF1 (SHA-256) signed SAML Response, a tampered/invalid RSA-MGF1 signed SAML Response, and an unsigned SAML Response for testing verification behavior.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant T as Test Runner
  participant F as Fixture (XML)
  participant P as xmldom Parser
  participant S as SignedXml Validator

  T->>F: Load SAML response XML
  T->>P: Parse XML into DOM
  P-->>T: DOM with ds:Signature node
  T->>S: Initialize SignedXml with Signature node & cert
  S->>S: Compute digest(s) and verify signature (RSA variants)
  alt signature valid
    S-->>T: true (verification passes)
  else signature invalid / tampered
    S-->>T: false (verification fails)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my ears at XML delight,
Signatures shimmer in moonlit byte.
Valid hops left, tampered hops right—
Carrots for true, none for the blight. 🥕
With RSA whiskers and MGF1 flair,
I stamp "verified" with careful care.

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Tests for sha256-rsa-MGF1" directly and clearly describes the main objective of the changeset. The PR adds multiple test files and test cases specifically for validating the sha256-rsa-MGF1 signature algorithm, including new tests in test/saml-response-tests.spec.ts, test/signature-unit-tests.spec.ts, and three new static XML test resources. The title is concise, specific, and accurately reflects what the PR accomplishes. A teammate reviewing the history would immediately understand that this PR introduces tests for the sha256-rsa-MGF1 signature algorithm.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d657659 and 4df09cb.

📒 Files selected for processing (1)
  • test/signature-unit-tests.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/signature-unit-tests.spec.ts

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

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 9b91edf and d657659.

⛔ Files ignored due to path filters (2)
  • test/static/idp_certificate.pem is excluded by !**/*.pem
  • test/static/idp_private_key.pem is excluded by !**/*.pem
📒 Files selected for processing (5)
  • test/saml-response-tests.spec.ts (1 hunks)
  • test/signature-unit-tests.spec.ts (1 hunks)
  • test/static/invalid_saml_sha256_rsa_mgf1.xml (1 hunks)
  • test/static/unsigned_saml_response.xml (1 hunks)
  • test/static/valid_saml_sha256_rsa_mgf1.xml (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/signature-unit-tests.spec.ts (1)
src/signed-xml.ts (2)
  • SignedXml (29-1291)
  • loadSignature (604-693)
🔇 Additional comments (8)
test/static/valid_saml_sha256_rsa_mgf1.xml (1)

1-94: LGTM! Well-formed test fixture.

This static test fixture properly represents a SAML 2.0 Response signed with the sha256-rsa-MGF1 algorithm. The XML structure is valid, the signature block follows XMLDSig standards, and all required elements are present.

test/static/invalid_saml_sha256_rsa_mgf1.xml (1)

1-94: LGTM! Appropriate negative test fixture.

This fixture correctly simulates a tampered SAML response by modifying the NameID value (line 78) while keeping the original signature intact. This is an effective approach for testing signature verification failure scenarios.

test/saml-response-tests.spec.ts (3)

26-40: LGTM! Well-structured positive test case.

This test correctly validates a SAML response signed with sha256-rsa-MGF1. It follows the established testing pattern and includes appropriate assertions.


42-56: LGTM! Appropriate negative test case.

This test correctly verifies that signature verification fails for a tampered SAML response. The test structure and assertions are appropriate for detecting tampering.


35-35: Certificate file verified.
Verified that test/static/idp_certificate.pem exists; no further action required.

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

9-14: LGTM! Well-defined algorithm list for parameterized testing.

The constant provides a clear list of RSA signature algorithms to test, including the newly supported sha256-rsa-MGF1. This enables comprehensive parameterized testing across all supported algorithms.


18-74: LGTM! Excellent parameterized test suite.

This test suite provides comprehensive coverage for all RSA signature algorithms through parameterized testing:

  • Helper functions: signWith and loadSignature promote code reuse and maintainability
  • Positive testing: Verifies that signatures created with each algorithm validate successfully
  • Negative testing: Ensures tampered content is detected for all algorithms
  • Consistent approach: All algorithms are tested using the same logic

This design makes it easy to add support for additional algorithms in the future.

test/static/unsigned_saml_response.xml (1)

1-46: LGTM! Valid unsigned SAML fixture.

This is a well-formed unsigned SAML 2.0 Response fixture with a complete assertion structure. However, it doesn't appear to be used by any tests in this PR. If it's intended for future use, consider adding a comment in the code or commit message explaining its purpose. If it's not needed, consider removing it to keep the test fixtures minimal.

cjbarth
cjbarth previously approved these changes Oct 17, 2025
@cjbarth
Copy link
Contributor

cjbarth commented Oct 17, 2025

@kaibernhard , I was all set to merge this, but it needs to have master merged in for test to pass and it needs to be linted. I was going to do that for you, but it appears that you have disallowed edits from maintainers, so please take care of that (or let me edit).

@kaibernhard
Copy link
Contributor Author

@cjbarth thanks a lot, I merged master and hope we're good to go now. I would be happy to help on the related PR node-saml/node-saml#387 as well.

@cjbarth
Copy link
Contributor

cjbarth commented Oct 17, 2025

@kaibernhard , it appears that some linting needs to be done too.

@kaibernhard
Copy link
Contributor Author

@cjbarth oops, missed that, it's late here 😄

@cjbarth cjbarth merged commit 02a405a into node-saml:master Oct 17, 2025
6 checks passed
@kaibernhard kaibernhard deleted the sha256-rsa-mgf1-tests branch October 20, 2025 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants