< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.X509CertificateInitiatorServiceCredential
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/X509CertificateInitiatorServiceCredential.cs
Line coverage
32%
Covered lines: 9
Uncovered lines: 19
Coverable lines: 28
Total lines: 77
Line coverage: 32.1%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
.ctor(...)100%11100%
SetCertificate(...)0%220%
SetCertificate(...)0%220%
MakeReadOnly()100%110%
ThrowIfImmutable()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/X509CertificateInitiatorServiceCredential.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.Cryptography.X509Certificates;
 6
 7namespace CoreWCF.Security
 8{
 9    public sealed class X509CertificateInitiatorServiceCredential
 10    {
 11        internal const StoreLocation DefaultStoreLocation = StoreLocation.LocalMachine;
 12        internal const StoreName DefaultStoreName = StoreName.My;
 13        internal const X509FindType DefaultFindType = X509FindType.FindBySubjectDistinguishedName;
 14        private X509Certificate2 _certificate;
 15        private bool _isReadOnly;
 16
 5217        internal X509CertificateInitiatorServiceCredential()
 18        {
 5219            Authentication = new X509ClientCertificateAuthentication();
 5220        }
 21
 6622        internal X509CertificateInitiatorServiceCredential(X509CertificateInitiatorServiceCredential other)
 23        {
 6624            _certificate = other._certificate;
 6625            Authentication = new X509ClientCertificateAuthentication(other.Authentication);
 6626            _isReadOnly = other._isReadOnly;
 6627        }
 28
 29        public X509Certificate2 Certificate
 30        {
 31            get
 32            {
 033                return _certificate;
 34            }
 35            set
 36            {
 037                ThrowIfImmutable();
 038                _certificate = value;
 039            }
 40        }
 41
 9342        public X509ClientCertificateAuthentication Authentication { get; }
 43
 44        public void SetCertificate(string subjectName, StoreLocation storeLocation, StoreName storeName)
 45        {
 046            if (subjectName == null)
 47            {
 048                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(subjectName));
 49            }
 050            SetCertificate(storeLocation, storeName, DefaultFindType, subjectName);
 051        }
 52
 53        public void SetCertificate(StoreLocation storeLocation, StoreName storeName, X509FindType findType, object findV
 54        {
 055            if (findValue == null)
 56            {
 057                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(findValue));
 58            }
 059            ThrowIfImmutable();
 060            _certificate = SecurityUtils.GetCertificateFromStore(storeName, storeLocation, findType, findValue, null);
 061        }
 62
 63        internal void MakeReadOnly()
 64        {
 065            _isReadOnly = true;
 066            Authentication.MakeReadOnly();
 067        }
 68
 69        private void ThrowIfImmutable()
 70        {
 071            if (_isReadOnly)
 72            {
 073                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.ObjectIsReadO
 74            }
 075        }
 76    }
 77}