< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.LaxModeSecurityHeaderElementInferenceEngine
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/LaxModeSecurityHeaderElementInferenceEngine.cs
Line coverage
35%
Covered lines: 14
Uncovered lines: 25
Coverable lines: 39
Total lines: 97
Line coverage: 35.8%
Branch coverage
11%
Covered branches: 3
Total branches: 26
Branch coverage: 11.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
ExecuteProcessingPassesAsync()100%11100%
MarkElements(...)11.53%262616.66%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/LaxModeSecurityHeaderElementInferenceEngine.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.Xml;
 5using System.Threading.Tasks;
 6using System.Xml;
 7
 8namespace CoreWCF.Security
 9{
 10    internal class LaxModeSecurityHeaderElementInferenceEngine : SecurityHeaderElementInferenceEngine
 11    {
 212        protected LaxModeSecurityHeaderElementInferenceEngine() { }
 13
 714        internal static LaxModeSecurityHeaderElementInferenceEngine Instance { get; } = new LaxModeSecurityHeaderElement
 15
 16        public override async ValueTask ExecuteProcessingPassesAsync(ReceiveSecurityHeader securityHeader, XmlDictionary
 17        {
 18            // pass 1
 619            await securityHeader.ExecuteReadingPassAsync(reader);
 20
 21            // pass 1.5
 522            securityHeader.ExecuteDerivedKeyTokenStubPass(false);
 23
 24            // pass 2
 525            await securityHeader.ExecuteSubheaderDecryptionPassAsync();
 26
 27            // pass 2.5
 528            securityHeader.ExecuteDerivedKeyTokenStubPass(true);
 29
 30            // layout-specific inferences
 531            MarkElements(securityHeader.ElementManager, securityHeader.RequireMessageProtection);
 32
 33            // pass 3
 534            await securityHeader.ExecuteSignatureEncryptionProcessingPassAsync();
 535        }
 36
 37        public override void MarkElements(ReceiveSecurityHeaderElementManager elementManager, bool messageSecurityMode)
 38        {
 539            bool primarySignatureFound = false;
 3040            for (int position = 0; position < elementManager.Count; position++)
 41            {
 1042                elementManager.GetElementEntry(position, out ReceiveSecurityHeaderEntry entry);
 1043                if (entry.elementCategory == ReceiveSecurityHeaderElementCategory.Signature)
 44                {
 045                    if (!messageSecurityMode)
 46                    {
 047                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Endorsing);
 048                        continue;
 49                    }
 050                    SignedXml signedXml = (SignedXml)entry.element;
 51
 052                    SignedInfo signedInfo = signedXml.Signature.SignedInfo;
 053                    bool targetsSignature = false;
 054                    if (signedInfo.References.Count == 1)
 55                    {
 056                        Reference signedXmlReference = (Reference)signedInfo.References[0];
 057                        string uri = signedXmlReference.Uri;
 58                        string id;
 059                        if (uri != null && uri.Length > 1 && uri[0] == '#')
 60                        {
 061                            id = uri.Substring(1);
 62                        }
 63                        else
 64                        {
 065                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 066                                new MessageSecurityException(SR.Format(SR.UnableToResolveReferenceUriForSignature, uri))
 67                        }
 068                        for (int j = 0; j < elementManager.Count; j++)
 69                        {
 070                            elementManager.GetElementEntry(j, out ReceiveSecurityHeaderEntry inner);
 071                            if (j != position && inner.elementCategory == ReceiveSecurityHeaderElementCategory.Signature
 72                            {
 073                                targetsSignature = true;
 074                                break;
 75                            }
 76                        }
 77                    }
 078                    if (targetsSignature)
 79                    {
 080                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Endorsing);
 081                        continue;
 82                    }
 83                    else
 84                    {
 085                        if (primarySignatureFound)
 86                        {
 087                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.Fo
 88                        }
 089                        primarySignatureFound = true;
 090                        elementManager.SetBindingMode(position, ReceiveSecurityHeaderBindingModes.Primary);
 91                        continue;
 92                    }
 93                }
 94            }
 595        }
 96    }
 97}