< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.SymmetricSecurityBindingElement
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/SymmetricSecurityBindingElement.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 62
Coverable lines: 62
Total lines: 182
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 26
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%220%
.ctor()100%110%
.ctor(...)100%110%
GetIndividualISecurityCapabilities()0%880%
SetKeyDerivation(...)0%220%
GetProperty(...)0%880%
ToString()0%220%
Clone()100%110%
CreateSecurityProtocolFactory(...)100%110%
BuildServiceDispatcherCore(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/SymmetricSecurityBindingElement.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;
 5using System.Globalization;
 6using System.Net.Security;
 7using System.Text;
 8using CoreWCF.Configuration;
 9using CoreWCF.Security;
 10using CoreWCF.Security.Tokens;
 11
 12namespace CoreWCF.Channels
 13{
 14    public sealed class SymmetricSecurityBindingElement : SecurityBindingElement //, IPolicyExportExtension
 15    {
 16        private MessageProtectionOrder _messageProtectionOrder;
 17
 18        private SymmetricSecurityBindingElement(SymmetricSecurityBindingElement elementToBeCloned)
 019            : base(elementToBeCloned)
 20        {
 021            _messageProtectionOrder = elementToBeCloned._messageProtectionOrder;
 022            if (elementToBeCloned.ProtectionTokenParameters != null)
 23            {
 024                ProtectionTokenParameters = (SecurityTokenParameters)elementToBeCloned.ProtectionTokenParameters.Clone()
 25            }
 26
 027            RequireSignatureConfirmation = elementToBeCloned.RequireSignatureConfirmation;
 028        }
 29
 30        public SymmetricSecurityBindingElement()
 031            : this((SecurityTokenParameters)null)
 32        {
 33            // empty
 034        }
 35
 36        public SymmetricSecurityBindingElement(SecurityTokenParameters protectionTokenParameters)
 037            : base()
 38        {
 039            _messageProtectionOrder = DefaultMessageProtectionOrder;
 040            RequireSignatureConfirmation = DefaultRequireSignatureConfirmation;
 041            ProtectionTokenParameters = protectionTokenParameters;
 042        }
 43
 044        public bool RequireSignatureConfirmation { get; set; }
 45
 46        public MessageProtectionOrder MessageProtectionOrder
 47        {
 48            get
 49            {
 050                return _messageProtectionOrder;
 51            }
 52            set
 53            {
 054                if (!MessageProtectionOrderHelper.IsDefined(value))
 55                {
 056                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 57                }
 58
 059                _messageProtectionOrder = value;
 060            }
 61        }
 62
 063        public SecurityTokenParameters ProtectionTokenParameters { get; set; }
 64
 65        internal override ISecurityCapabilities GetIndividualISecurityCapabilities()
 66        {
 067            bool supportsServerAuthentication = false;
 068            GetSupportingTokensCapabilities(out bool supportsClientAuthentication, out bool supportsClientWindowsIdentit
 069            if (ProtectionTokenParameters != null)
 70            {
 071                supportsClientAuthentication = supportsClientAuthentication || ProtectionTokenParameters.SupportsClientA
 072                supportsClientWindowsIdentity = supportsClientWindowsIdentity || ProtectionTokenParameters.SupportsClien
 73
 074                if (ProtectionTokenParameters.HasAsymmetricKey)
 75                {
 076                    supportsServerAuthentication = ProtectionTokenParameters.SupportsClientAuthentication;
 77                }
 78                else
 79                {
 080                    supportsServerAuthentication = ProtectionTokenParameters.SupportsServerAuthentication;
 81                }
 82            }
 83
 084            return new SecurityCapabilities(supportsClientAuthentication, supportsServerAuthentication, supportsClientWi
 085                ProtectionLevel.EncryptAndSign, ProtectionLevel.EncryptAndSign);
 86        }
 87
 88        internal override bool SessionMode
 89        {
 90            get
 91            {
 092                if (ProtectionTokenParameters is SecureConversationSecurityTokenParameters secureConversationTokenParame
 93                {
 094                    return secureConversationTokenParameters.RequireCancellation;
 95                }
 96                else
 97                {
 098                    return false;
 99                }
 100            }
 101        }
 102
 103        internal override bool SupportsDuplex
 104        {
 0105            get { return SessionMode; }
 106        }
 107
 108        internal override bool SupportsRequestReply
 109        {
 0110            get { return true; }
 111        }
 112
 113        public override void SetKeyDerivation(bool requireDerivedKeys)
 114        {
 0115            base.SetKeyDerivation(requireDerivedKeys);
 0116            if (ProtectionTokenParameters != null)
 117            {
 0118                ProtectionTokenParameters.RequireDerivedKeys = requireDerivedKeys;
 119            }
 0120        }
 121
 122        public override T GetProperty<T>(BindingContext context)
 123        {
 0124            if (context == null)
 125            {
 0126                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 127            }
 128
 0129            if (typeof(T) == typeof(ChannelProtectionRequirements))
 130            {
 0131                AddressingVersion addressing = MessageVersion.Default.Addressing;
 0132                MessageEncodingBindingElement encoding = context.Binding.Elements.Find<MessageEncodingBindingElement>();
 0133                if (encoding != null)
 134                {
 0135                    addressing = encoding.MessageVersion.Addressing;
 136                }
 0137                ChannelProtectionRequirements myRequirements = GetProtectionRequirements(addressing, ProtectionLevel.Enc
 0138                myRequirements.Add(context.GetInnerProperty<ChannelProtectionRequirements>() ?? new ChannelProtectionReq
 0139                return (T)(object)myRequirements;
 140            }
 141            else
 142            {
 0143                return base.GetProperty<T>(context);
 144            }
 145        }
 146
 147        public override string ToString()
 148        {
 0149            StringBuilder sb = new StringBuilder();
 0150            sb.AppendLine(base.ToString());
 151
 0152            sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "MessageProtectionOrder: {0}", _messageProtectionO
 0153            sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "RequireSignatureConfirmation: {0}", RequireSignat
 0154            sb.Append("ProtectionTokenParameters: ");
 0155            if (ProtectionTokenParameters != null)
 156            {
 0157                sb.AppendLine(ProtectionTokenParameters.ToString().Trim().Replace("\n", "\n  "));
 158            }
 159            else
 160            {
 0161                sb.AppendLine("null");
 162            }
 163
 0164            return sb.ToString().Trim();
 165        }
 166
 167        public override BindingElement Clone()
 168        {
 0169            return new SymmetricSecurityBindingElement(this);
 170        }
 171
 172        internal override SecurityProtocolFactory CreateSecurityProtocolFactory<TChannel>(BindingContext context, Securi
 173        {
 0174            throw new NotImplementedException();
 175        }
 176
 177        protected override IServiceDispatcher BuildServiceDispatcherCore<TChannel>(BindingContext context, IServiceDispa
 178        {
 0179            throw new NotImplementedException();
 180        }
 181    }
 182}