-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Improve code coverage for CanonicalXmlEntityReference class (0% → 92.8%) #120640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@copilot, are there any other notable areas of the library that need improvements in code coverage, beyond this particular class? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds new unit tests to raise coverage for CanonicalXmlEntityReference from 0% to 92.8% by exercising canonicalization transforms with XML entity references and hashing.
- Adds CanonicalXmlEntityReferenceTest.cs with 6 test cases covering normal, subset, comments, exclusive, hashing, and multiple entity scenarios.
- Updates the test project file to include the new test source.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
File | Description |
---|---|
System.Security.Cryptography.Xml.Tests.csproj | Registers the new test file for compilation. |
CanonicalXmlEntityReferenceTest.cs | Implements the added test cases targeting CanonicalXmlEntityReference behavior. |
src/libraries/System.Security.Cryptography.Xml/tests/CanonicalXmlEntityReferenceTest.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Xml/tests/CanonicalXmlEntityReferenceTest.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Xml/tests/CanonicalXmlEntityReferenceTest.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Xml/tests/CanonicalXmlEntityReferenceTest.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Xml/tests/CanonicalXmlEntityReferenceTest.cs
Show resolved
Hide resolved
src/libraries/System.Security.Cryptography.Xml/tests/CanonicalXmlEntityReferenceTest.cs
Show resolved
Hide resolved
Based on the original issue #16166, most areas have been addressed. The main remaining item is: KeyInfoClause - The internal virtual method All other areas mentioned in the issue have been marked as completed (SignedXml.CheckSignature, XmlDecryptionTransform, SymmetricKeyWrap, EncryptedXml, and EncryptionMethod). |
@copilot, please don't base it just on the issue. Please run the tests with coverage enabled and review the resulting code coverage information. |
I've run the tests with coverage enabled. Here's a summary of notable areas needing improvement: Classes with 0% coverage (12+ lines):
Classes with very low coverage (<30%):
Classes with moderate-low coverage (30-50%):
High-impact targets (50-70%):
The highest value improvements would be:
|
@copilot, please add tests for all of the identified areas you mentioned (not just the highest value improvements) |
@copilot, please add tests for all of the identified areas you mentioned (not just the highest value improvements): Classes with 0% coverage (12+ lines): KeyReference (12 lines) - Encrypted key reference class SignedXmlDebugLog (20%, 559 lines) - Debug tracing utility, low priority ExcCanonicalXml (35.8%, 78 lines) - Exclusive canonicalization SignedXml (69.9%, 592 lines) - Core signing class |
@copilot, my last request to you is not old. Please do the work I'm asking. Run code coverage for the tests on main, fill the gaps with new tests, re-run coverage, and share the updated numbers. |
Summary
This PR adds comprehensive test coverage for the
CanonicalXmlEntityReference
class, which previously had 0% code coverage. The new tests improve coverage from 0% to 92.8% (13 of 14 lines covered) and contribute to the overall goal of improving code coverage forSystem.Security.Cryptography.Xml
.Fixes #16166 (partial - addresses the
CanonicalXmlEntityReference
item)Changes
Added a new test file
CanonicalXmlEntityReferenceTest.cs
containing 6 test cases that exercise theCanonicalXmlEntityReference
class through various canonicalization scenarios:WriteHash()
code path used for digest computationTechnical Approach
The
CanonicalXmlEntityReference
class is internal and created automatically byCanonicalXmlDocument.CreateEntityReference()
during XML document loading. The tests exercise this by:<!ENTITY test "value">
)XmlDsigC14NTransform
,XmlDsigExcC14NTransform
)CanonicalXmlDocument
which loads viaXmlNodeReader
XmlNodeReader
preserves entity reference nodes, triggeringCreateEntityReference()
CanonicalXmlEntityReference
instances participate in canonicalization, exercising bothWrite()
andWriteHash()
methodsTest Results
Original prompt
This section details on the original issue you should resolve
<issue_title>Improve Code Coverage for System.Security.Cryptography.Xml (66.3%)</issue_title>
<issue_description>Here are the main areas which need improvement:
SignedXml.CheckSignature(X509Certificate2 certificate, bool verifySignatureOnly)
- currently no coverage - sample code should be sufficient for nowSystem.Security.Cryptography.Xml.XmlDecryptionTransform
- https://ci.dot.net/job/dotnet_corefx/job/master/job/code_coverage_windows/Code_Coverage_Report/System.Security.Cryptography.Xml_XmlDecryptionTransform.htmSystem.Security.Cryptography.Xml.SymmetricKeyWrap
- https://ci.dot.net/job/dotnet_corefx/job/master/job/code_coverage_windows/Code_Coverage_Report/System.Security.Cryptography.Xml_SymmetricKeyWrap.htmSystem.Security.Cryptography.Xml.KeyInfoClause
- https://ci.dot.net/job/dotnet_corefx/job/master/job/code_coverage_windows/Code_Coverage_Report/System.Security.Cryptography.Xml_KeyInfoClause.htmSystem.Security.Cryptography.Xml.EncryptedXml
- https://ci.dot.net/job/dotnet_corefx/job/master/job/code_coverage_windows/Code_Coverage_Report/System.Security.Cryptography.Xml_EncryptedXml.htm - only most common scenariosSystem.Security.Cryptography.Xml.EncryptionMethod
- https://ci.dot.net/job/dotnet_corefx/job/master/job/code_coverage_windows/Code_Coverage_Report/System.Security.Cryptography.Xml_EncryptionMethod.htmSystem.Security.Cryptography.Xml.CanonicalXmlEntityReference
- https://ci.dot.net/job/dotnet_corefx/job/master/job/code_coverage_windows/Code_Coverage_Report/System.Security.Cryptography.Xml_CanonicalXmlEntityReference.htm - at minimum one or two tests triggering use of this classGuidelines:
cc: @anthonylangsworth @tintoy @peterwurzinger </issue_description>
Comments on the Issue (you are @copilot in this section)
@krwq @StanislavUshakov thank you for spotting this! If that is a simple fix then you may fix it either together or separately. If it will resurface some bug in the product please do it separately. @krwq @StanislavUshakov - I haven't investigated this code path too much but can we possibly make SignedXml create us an instance of CanonicalXmlDocument (possibly some API returns it) and then manually create entity reference by simply calling an API?If we can't:
Is this also true for netfx? (not being able to test that)
If it is possible to do it on netfx we need to figure out what is the diff and fix that.
If we could never create an instance of that class then we should not test it for 2.0 (that would be a new feature which is not a target for 2.0) and for post 2.0 we should figure out if this is something we should support or not - do you possibly know of any E2E scenarios we would be missing?</comment_new>
<comment_new>@krwq
Hello @garg000dhruv, thanks for offering your help. I believe no one else is working on this at the moment so you can go ahead and start 😄 Please let me know if you need any help</comment_new>
<comment_new>@krwq
@KindOfANiceGuy I'm not aware of anyone working on it at the moment and I believe it's free to being picked up.
Please make sure to read https://github.com/dotnet/corefx/#reporting-security-issues-and-security-bugs before sending out PRs/filing issues 😄 </comment_new>
<comment_new>@krwq
@KindOfANiceGuy I haven't touched this code in a while so my memory might be a bit fuzzy
<comment_new>@bartonjs
FWIW, I don't think that the
internal virtual
can be madeinternal abstract
, because then out-of-assembly derived types would be unable to provide a method for it. But it could beinternal virtual WhateverTheRestOfTheSignatureIs() { Debug.Fail($"Internal types are expected to override {nameof(TheMethod)}"); throw new NotImplementedException(); }
</comment_new><comment_new>@krwq
@bartonjs I thought this was entirely internal type, in that case it might be possible to test this method by simply inheriting from this class and touching something which calls it</comment_new>
<comment_new>@krwq
@KindOfANiceGuy I thought there was something to...
Fixes #20508
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.