< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.UpnEndpointIdentity
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/UpnEndpointIdentity.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 34
Coverable lines: 34
Total lines: 94
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
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(...)0%440%
WriteContentsTo(...)0%220%
GetUpnSid()0%880%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/UpnEndpointIdentity.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.Security.Principal;
 6using System.Xml;
 7using CoreWCF.IdentityModel.Claims;
 8using CoreWCF.Runtime;
 9
 10namespace CoreWCF
 11{
 12    public class UpnEndpointIdentity : EndpointIdentity
 13    {
 14        private SecurityIdentifier _upnSid;
 15        private bool _hasUpnSidBeenComputed;
 016        private readonly object _thisLock = new object();
 17
 018        public UpnEndpointIdentity(string upnName)
 19        {
 020            if (upnName == null)
 21            {
 022                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(upnName));
 23            }
 24
 025            Initialize(Claim.CreateUpnClaim(upnName));
 026            _hasUpnSidBeenComputed = false;
 027        }
 28
 029        public UpnEndpointIdentity(Claim identity)
 30        {
 031            if (identity == null)
 32            {
 033                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(identity));
 34            }
 35
 036            if (!identity.ClaimType.Equals(ClaimTypes.Upn))
 37            {
 038                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.Format(SR.UnrecognizedClaimTypeForIdenti
 39            }
 40
 041            Initialize(identity);
 042        }
 43
 44        internal override void WriteContentsTo(XmlDictionaryWriter writer)
 45        {
 046            if (writer == null)
 47            {
 048                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 49            }
 50
 051            writer.WriteElementString(XD.AddressingDictionary.Upn, XD.AddressingDictionary.IdentityExtensionNamespace, (
 052        }
 53
 54        internal SecurityIdentifier GetUpnSid()
 55        {
 56            Fx.Assert(ClaimTypes.Upn.Equals(IdentityClaim.ClaimType), "");
 057            if (!_hasUpnSidBeenComputed)
 58            {
 059                lock (_thisLock)
 60                {
 061                    string upn = (string)IdentityClaim.Resource;
 062                    if (!_hasUpnSidBeenComputed)
 63                    {
 64                        try
 65                        {
 066                            var userAccount = new NTAccount(upn);
 067                            _upnSid = userAccount.Translate(typeof(SecurityIdentifier)) as SecurityIdentifier;
 068                        }
 69                        catch (Exception e)
 70                        {
 71                            // Always immediately rethrow fatal exceptions.
 072                            if (Fx.IsFatal(e))
 73                            {
 074                                throw;
 75                            }
 76
 077                            if (e is NullReferenceException)
 78                            {
 079                                throw;
 80                            }
 81
 82                            //SecurityTraceRecordHelper.TraceSpnToSidMappingFailure(upn, e);
 083                        }
 84                        finally
 85                        {
 086                            _hasUpnSidBeenComputed = true;
 087                        }
 88                    }
 089                }
 90            }
 091            return _upnSid;
 92        }
 93    }
 94}