< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.MessageSecurityOverTcp
Assembly: CoreWCF.NetTcp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/Security/MessageSecurityOverTcp.cs
Line coverage
55%
Covered lines: 21
Uncovered lines: 17
Coverable lines: 38
Total lines: 137
Line coverage: 55.2%
Branch coverage
28%
Covered branches: 4
Total branches: 14
Branch coverage: 28.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%
CreateSecurityBindingElement(...)30%101059.09%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/Security/MessageSecurityOverTcp.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.ComponentModel;
 6using System.Globalization;
 7using System.Runtime.CompilerServices;
 8using CoreWCF.Channels;
 9using CoreWCF.Runtime;
 10using CoreWCF.Security;
 11
 12namespace CoreWCF.Security
 13{
 14    public sealed class MessageSecurityOverTcp
 15    {
 16        internal const MessageCredentialType DefaultClientCredentialType = MessageCredentialType.Windows;
 17        internal const string DefaultServerIssuedTransitionTokenLifetimeString = "00:15:00";
 18
 19        private MessageCredentialType _clientCredentialType;
 20        private SecurityAlgorithmSuite _algorithmSuite;
 21        private bool _wasAlgorithmSuiteSet;
 22
 11723        public MessageSecurityOverTcp()
 24        {
 11725            _clientCredentialType = DefaultClientCredentialType;
 11726            _algorithmSuite = SecurityAlgorithmSuite.Default;
 11727        }
 28
 29        public MessageCredentialType ClientCredentialType
 30        {
 031            get { return _clientCredentialType; }
 32            set
 33            {
 1234                if (!MessageCredentialTypeHelper.IsDefined(value))
 35                {
 036                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 37                }
 1238                _clientCredentialType = value;
 1239            }
 40        }
 41
 42        public SecurityAlgorithmSuite AlgorithmSuite
 43        {
 3744            get { return _algorithmSuite; }
 45            set
 46            {
 047                if (value == null)
 48                {
 049                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 50                }
 051                _algorithmSuite = value;
 052                _wasAlgorithmSuiteSet = true;
 053            }
 54        }
 55
 056        internal bool WasAlgorithmSuiteSet => _wasAlgorithmSuiteSet;
 57
 58        [MethodImpl(MethodImplOptions.NoInlining)]
 59        public SecurityBindingElement CreateSecurityBindingElement(bool isSecureTransportMode, bool isReliableSession, B
 60        {
 61            SecurityBindingElement result;
 62            SecurityBindingElement oneShotSecurity;
 3763            if (isSecureTransportMode)
 64            {
 3765                switch (_clientCredentialType)
 66                {
 67                    case MessageCredentialType.None:
 068                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 69                    case MessageCredentialType.UserName:
 3770                        oneShotSecurity = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
 3771                        break;
 72                    case MessageCredentialType.Certificate:
 073                        oneShotSecurity = SecurityBindingElement.CreateCertificateOverTransportBindingElement();
 074                        break;
 75                    case MessageCredentialType.Windows:
 076                        oneShotSecurity = SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement(true);
 077                        break;
 78                    case MessageCredentialType.IssuedToken:
 079                        throw new NotImplementedException();
 80                       // oneShotSecurity = SecurityBindingElement.CreateIssuedTokenOverTransportBindingElement(IssuedSe
 81                    default:
 82                        Fx.Assert("unknown ClientCredentialType");
 083                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 84                }
 3785                result = SecurityBindingElement.CreateSecureConversationBindingElement(oneShotSecurity);
 86            }
 87            else
 88            {
 089                throw new NotSupportedException();
 90               /* switch (this.clientCredentialType)
 91                {
 92                    case MessageCredentialType.None:
 93                        oneShotSecurity = SecurityBindingElement.CreateSslNegotiationBindingElement(false, true);
 94                        break;
 95                    case MessageCredentialType.UserName:
 96                        // require cancellation so that impersonation is possible
 97                        oneShotSecurity = SecurityBindingElement.CreateUserNameForSslBindingElement(true);
 98                        break;
 99                    case MessageCredentialType.Certificate:
 100                        oneShotSecurity = SecurityBindingElement.CreateSslNegotiationBindingElement(true, true);
 101                        break;
 102                    case MessageCredentialType.Windows:
 103                        // require cancellation so that impersonation is possible
 104                        oneShotSecurity = SecurityBindingElement.CreateSspiNegotiationBindingElement(true);
 105                        break;
 106                    case MessageCredentialType.IssuedToken:
 107                        oneShotSecurity = SecurityBindingElement.CreateIssuedTokenForSslBindingElement(IssuedSecurityTok
 108                        break;
 109                    default:
 110                        Fx.Assert("unknown ClientCredentialType");
 111                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 112                }
 113                result = SecurityBindingElement.CreateSecureConversationBindingElement(oneShotSecurity, true);*/
 114            }
 115
 116            // set the algorithm suite and issued token params if required
 37117            result.DefaultAlgorithmSuite = oneShotSecurity.DefaultAlgorithmSuite = AlgorithmSuite;
 118
 37119            result.IncludeTimestamp = true;
 37120            if (!isReliableSession)
 121            {
 37122                result.LocalServiceSettings.ReconnectTransportOnFailure = false;
 123            }
 124            else
 125            {
 0126                result.LocalServiceSettings.ReconnectTransportOnFailure = true;
 127            }
 128
 129            // since a session is always bootstrapped, configure the transition sct to live for a short time only
 37130            oneShotSecurity.LocalServiceSettings.IssuedCookieLifetime = TimeSpan.Parse(DefaultServerIssuedTransitionToke
 37131            result.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFe
 37132            oneShotSecurity.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConve
 133
 37134            return result;
 135        }
 136    }
 137}