< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.Tokens.SupportingTokenParameters
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/Tokens/SupportingTokenParameters.cs
Line coverage
39%
Covered lines: 24
Uncovered lines: 37
Coverable lines: 61
Total lines: 185
Line coverage: 39.3%
Branch coverage
25%
Covered branches: 12
Total branches: 48
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)80%101083.33%
.ctor()100%11100%
SetKeyDerivation(...)50%8855.55%
IsSetKeyDerivation(...)0%880%
ToString()0%16160%
Clone()100%11100%
CloneCore()100%11100%
IsEmpty()0%660%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Security/Tokens/SupportingTokenParameters.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.Collections.ObjectModel;
 6using System.Globalization;
 7using System.Text;
 8
 9namespace CoreWCF.Security.Tokens
 10{
 11    public class SupportingTokenParameters
 12    {
 278413        private SupportingTokenParameters(SupportingTokenParameters other)
 14        {
 278415            if (other == null)
 16            {
 017                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(other));
 18            }
 19
 570420            foreach (SecurityTokenParameters p in other.Signed)
 21            {
 6822                Signed.Add((SecurityTokenParameters)p.Clone());
 23            }
 24
 650625            foreach (SecurityTokenParameters p in other.SignedEncrypted)
 26            {
 46927                SignedEncrypted.Add((SecurityTokenParameters)p.Clone());
 28            }
 29
 719030            foreach (SecurityTokenParameters p in other.Endorsing)
 31            {
 81132                Endorsing.Add((SecurityTokenParameters)p.Clone());
 33            }
 34
 556835            foreach (SecurityTokenParameters p in other.SignedEndorsing)
 36            {
 037                SignedEndorsing.Add((SecurityTokenParameters)p.Clone());
 38            }
 278439        }
 40
 76641        public SupportingTokenParameters()
 42        {
 43            // empty
 76644        }
 45
 825846        public Collection<SecurityTokenParameters> Endorsing { get; } = new Collection<SecurityTokenParameters>();
 47
 700448        public Collection<SecurityTokenParameters> SignedEndorsing { get; } = new Collection<SecurityTokenParameters>();
 49
 678350        public Collection<SecurityTokenParameters> Signed { get; } = new Collection<SecurityTokenParameters>();
 51
 756552        public Collection<SecurityTokenParameters> SignedEncrypted { get; } = new Collection<SecurityTokenParameters>();
 53
 54        public void SetKeyDerivation(bool requireDerivedKeys)
 55        {
 28656            foreach (SecurityTokenParameters t in Endorsing)
 57            {
 158                if (t.HasAsymmetricKey)
 59                {
 060                    t.RequireDerivedKeys = false;
 61                }
 62                else
 63                {
 164                    t.RequireDerivedKeys = requireDerivedKeys;
 65                }
 66            }
 28467            foreach (SecurityTokenParameters t in SignedEndorsing)
 68            {
 069                if (t.HasAsymmetricKey)
 70                {
 071                    t.RequireDerivedKeys = false;
 72                }
 73                else
 74                {
 075                    t.RequireDerivedKeys = requireDerivedKeys;
 76                }
 77            }
 14278        }
 79
 80        internal bool IsSetKeyDerivation(bool requireDerivedKeys)
 81        {
 082            foreach (SecurityTokenParameters t in Endorsing)
 83            {
 084                if (t.RequireDerivedKeys != requireDerivedKeys)
 85                {
 086                    return false;
 87                }
 88            }
 89
 090            foreach (SecurityTokenParameters t in SignedEndorsing)
 91            {
 092                if (t.RequireDerivedKeys != requireDerivedKeys)
 93                {
 094                    return false;
 95                }
 96            }
 97
 098            return true;
 099        }
 100
 101        public override string ToString()
 102        {
 0103            StringBuilder sb = new StringBuilder();
 104            int k;
 105
 0106            if (Endorsing.Count == 0)
 107            {
 0108                sb.AppendLine("No endorsing tokens.");
 109            }
 110            else
 111            {
 0112                for (k = 0; k < Endorsing.Count; k++)
 113                {
 0114                    sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "Endorsing[{0}]", k.ToString(CultureInfo.I
 0115                    sb.AppendLine("  " + Endorsing[k].ToString().Trim().Replace("\n", "\n  "));
 116                }
 117            }
 118
 0119            if (Signed.Count == 0)
 120            {
 0121                sb.AppendLine("No signed tokens.");
 122            }
 123            else
 124            {
 0125                for (k = 0; k < Signed.Count; k++)
 126                {
 0127                    sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "Signed[{0}]", k.ToString(CultureInfo.Inva
 0128                    sb.AppendLine("  " + Signed[k].ToString().Trim().Replace("\n", "\n  "));
 129                }
 130            }
 131
 0132            if (SignedEncrypted.Count == 0)
 133            {
 0134                sb.AppendLine("No signed encrypted tokens.");
 135            }
 136            else
 137            {
 0138                for (k = 0; k < SignedEncrypted.Count; k++)
 139                {
 0140                    sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "SignedEncrypted[{0}]", k.ToString(Culture
 0141                    sb.AppendLine("  " + SignedEncrypted[k].ToString().Trim().Replace("\n", "\n  "));
 142                }
 143            }
 144
 0145            if (SignedEndorsing.Count == 0)
 146            {
 0147                sb.AppendLine("No signed endorsing tokens.");
 148            }
 149            else
 150            {
 0151                for (k = 0; k < SignedEndorsing.Count; k++)
 152                {
 0153                    sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "SignedEndorsing[{0}]", k.ToString(Culture
 0154                    sb.AppendLine("  " + SignedEndorsing[k].ToString().Trim().Replace("\n", "\n  "));
 155                }
 156            }
 157
 0158            return sb.ToString().Trim();
 159        }
 160
 161        public SupportingTokenParameters Clone()
 162        {
 2784163            SupportingTokenParameters parameters = CloneCore();
 164            /* if (parameters == null || parameters.GetType() != this.GetType())
 165             {
 166                 TraceUtility.TraceEvent(
 167                     TraceEventType.Error,
 168                     TraceCode.Security,
 169                     SR.GetString(SR.CloneNotImplementedCorrectly, new object[] { this.GetType(), (parameters != null) ?
 170             }*/
 171
 2784172            return parameters;
 173        }
 174
 175        protected virtual SupportingTokenParameters CloneCore()
 176        {
 2784177            return new SupportingTokenParameters(this);
 178        }
 179
 180        internal bool IsEmpty()
 181        {
 0182            return Signed.Count == 0 && SignedEncrypted.Count == 0 && Endorsing.Count == 0 && SignedEndorsing.Count == 0
 183        }
 184    }
 185}