< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.SignedXMLInternal
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/SignedXMLInternal.cs
Line coverage
75%
Covered lines: 9
Uncovered lines: 3
Coverable lines: 12
Total lines: 55
Line coverage: 75%
Branch coverage
50%
Covered branches: 6
Total branches: 12
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
.ctor(...)100%11100%
.ctor(...)100%110%
GetIdElement(...)50%66100%
GetSingleReferenceTarget(...)50%6680%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/SignedXMLInternal.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Security.Cryptography;
 5using System.Security.Cryptography.Xml;
 6using System.Xml;
 7
 8namespace CoreWCF.IdentityModel
 9{
 10    /// <summary>
 11    /// Internal class to override GetIdElement
 12    /// </summary>
 13    internal class SignedXMLInternal : SignedXml
 14    {
 015        public SignedXMLInternal() { }
 16
 4617        public SignedXMLInternal(XmlDocument document) : base(document) { }
 18
 019        public SignedXMLInternal(XmlElement elem) : base(elem) { }
 20
 21        public override XmlElement GetIdElement(XmlDocument document, string idValue)
 22        {
 23            // The default GetIdElement implementation can't find Id attributes which have a namespace specified
 24            // Only trying the base implementation as a last ditch effort.
 2525            return GetSingleReferenceTarget(document, "Id", idValue) ??
 2526                   GetSingleReferenceTarget(document, "id", idValue) ??
 2527                   GetSingleReferenceTarget(document, "ID", idValue) ??
 2528                   base.GetIdElement(document, idValue);
 29        }
 30
 31        private static XmlElement GetSingleReferenceTarget(XmlDocument document, string idAttributeName, string idValue)
 32        {
 33            // XmlDocument.GetElementById only works for elements specified in a DTD to have an IDREF.
 34            // As we don't use DTD's in SOAP, that method is ineffective.
 2535            string xPath = "//*[@*[local-name()='" + idAttributeName + "']='" + idValue + "']";
 36
 37            // http://www.w3.org/TR/xmldsig-core/#sec-ReferenceProcessingModel says that for the form URI="#chapter1":
 38            //
 39            //   Identifies a node-set containing the element with ID attribute value 'chapter1' ...
 40            //
 41            // Note that it uses the singular. Therefore, if the match is ambiguous, we should consider the document inv
 42            //
 43            // In this case, we'll treat it the same as having found nothing across all fallbacks (but shortcut so that 
 44            // fall into a trap of finding a secondary element which wasn't the originally signed one).
 45
 2546            XmlNodeList nodeList = document.SelectNodes(xPath);
 47
 2548            if (nodeList == null || nodeList.Count == 0) { return null; }
 5049            if (nodeList.Count == 1) { return nodeList[0] as XmlElement; }
 50
 51            //throw new CryptographicException(SR.Cryptography_Xml_InvalidReference);
 052            throw new CryptographicException("Cryptography_Xml_InvalidReference");
 53        }
 54    }
 55}