< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.NegotiateInternal.NegotiateInternalState
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/NegotiateInternal/NegotiateInternalState.cs
Line coverage
5%
Covered lines: 3
Uncovered lines: 49
Coverable lines: 52
Total lines: 109
Line coverage: 5.7%
Branch coverage
0%
Covered branches: 0
Total branches: 54
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()100%11100%
SetChannelBinding(...)100%110%
SetExtendedProtectionPolicy(...)100%110%
GetOutgoingBlob(...)0%10100%
GetIdentity()100%110%
Encrypt(...)0%220%
Dispose()100%110%
IsCredentialError(...)0%14140%
IsClientError(...)0%28280%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/NegotiateInternal/NegotiateInternalState.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.Reflection;
 6using System.Runtime.ExceptionServices;
 7using System.Security.Authentication.ExtendedProtection;
 8using System.Security.Principal;
 9
 10namespace CoreWCF.Security.NegotiateInternal
 11{
 12    internal class NegotiateInternalState : INegotiateInternalState
 13    {
 14        private readonly INTAuthenticationFacade _ntAuthentication;
 15
 116        public NegotiateInternalState()
 17        {
 118            _ntAuthentication = NTAuthenticationFacade.Build();
 119        }
 20
 021        public void SetChannelBinding(ChannelBinding channelBinding) => _ntAuthentication.SetChannelBinding(channelBindi
 22
 023        public void SetExtendedProtectionPolicy(ExtendedProtectionPolicy protectionPolicy) => _ntAuthentication.SetExten
 24
 25        public byte[] GetOutgoingBlob(byte[] incomingBlob, out BlobErrorType status, out Exception error)
 26        {
 27            try
 28            {
 029                byte[] blob = _ntAuthentication.GetOutgoingBlob(incomingBlob, out var securityStatus);
 30
 031                var errorCode = securityStatus.ErrorCode;
 32
 033                error = securityStatus.Exception;
 34
 035                if (errorCode == NegotiateInternalSecurityStatusErrorCode.OK
 036                    || errorCode == NegotiateInternalSecurityStatusErrorCode.ContinueNeeded
 037                    || errorCode == NegotiateInternalSecurityStatusErrorCode.CompleteNeeded)
 38                {
 039                    status = BlobErrorType.None;
 40                }
 041                else if (IsCredentialError(errorCode))
 42                {
 043                    status = BlobErrorType.CredentialError;
 44                }
 045                else if (IsClientError(errorCode))
 46                {
 047                    status = BlobErrorType.ClientError;
 48                }
 49                else
 50                {
 051                    status = BlobErrorType.Other;
 52                }
 53
 054                return blob;
 55            }
 56            catch (TargetInvocationException tex)
 57            {
 58                // Unwrap
 059                ExceptionDispatchInfo.Capture(tex.InnerException).Throw();
 060                throw;
 61            }
 062        }
 63
 064        public bool IsCompleted => _ntAuthentication.IsCompleted;
 65
 066        public string Protocol => _ntAuthentication.Protocol;
 67
 068        public bool IsValidContext => _ntAuthentication.IsValidContext;
 69
 070        public IIdentity GetIdentity() => _ntAuthentication.GetIdentity();
 71
 72        public byte[] Encrypt(byte[] input)
 73        {
 074            if (input == null)
 75            {
 076                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(input));
 77            }
 78
 079            return _ntAuthentication.Encrypt(input);
 80        }
 81
 082        public void Dispose() => _ntAuthentication.Dispose();
 83
 084        private bool IsCredentialError(NegotiateInternalSecurityStatusErrorCode error) => error == NegotiateInternalSecu
 085                error == NegotiateInternalSecurityStatusErrorCode.UnknownCredentials ||
 086                error == NegotiateInternalSecurityStatusErrorCode.NoImpersonation ||
 087                error == NegotiateInternalSecurityStatusErrorCode.NoAuthenticatingAuthority ||
 088                error == NegotiateInternalSecurityStatusErrorCode.UntrustedRoot ||
 089                error == NegotiateInternalSecurityStatusErrorCode.CertExpired ||
 090                error == NegotiateInternalSecurityStatusErrorCode.SmartcardLogonRequired ||
 091                error == NegotiateInternalSecurityStatusErrorCode.BadBinding;
 92
 093        private bool IsClientError(NegotiateInternalSecurityStatusErrorCode error) => error == NegotiateInternalSecurity
 094                error == NegotiateInternalSecurityStatusErrorCode.CannotPack ||
 095                error == NegotiateInternalSecurityStatusErrorCode.QopNotSupported ||
 096                error == NegotiateInternalSecurityStatusErrorCode.NoCredentials ||
 097                error == NegotiateInternalSecurityStatusErrorCode.MessageAltered ||
 098                error == NegotiateInternalSecurityStatusErrorCode.OutOfSequence ||
 099                error == NegotiateInternalSecurityStatusErrorCode.IncompleteMessage ||
 0100                error == NegotiateInternalSecurityStatusErrorCode.IncompleteCredentials ||
 0101                error == NegotiateInternalSecurityStatusErrorCode.WrongPrincipal ||
 0102                error == NegotiateInternalSecurityStatusErrorCode.TimeSkew ||
 0103                error == NegotiateInternalSecurityStatusErrorCode.IllegalMessage ||
 0104                error == NegotiateInternalSecurityStatusErrorCode.CertUnknown ||
 0105                error == NegotiateInternalSecurityStatusErrorCode.AlgorithmMismatch ||
 0106                error == NegotiateInternalSecurityStatusErrorCode.SecurityQosFailed ||
 0107                error == NegotiateInternalSecurityStatusErrorCode.UnsupportedPreauth;
 108    }
 109}