< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Security.WSTrust
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/WSTrust.cs
Line coverage
55%
Covered lines: 32
Uncovered lines: 26
Coverable lines: 58
Total lines: 176
Line coverage: 55.1%
Branch coverage
35%
Covered branches: 5
Total branches: 14
Branch coverage: 35.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/WSTrust.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
 4namespace CoreWCF.IdentityModel.Security
 5{
 6    using System;
 7    using System.Collections.Generic;
 8    using System.Xml;
 9    using CoreWCF.IdentityModel;
 10    using CoreWCF.IdentityModel.Selectors;
 11    using CoreWCF.IdentityModel.Tokens;
 12    using CoreWCF.Security;
 13    using CoreWCF.Security.Tokens;
 14    using KeyIdentifierClauseEntry = CoreWCF.IdentityModel.Selectors.SecurityTokenSerializer.KeyIdentifierClauseEntry;
 15
 16    internal class WSTrust : SecurityTokenSerializer.SerializerEntries
 17    {
 18        private readonly KeyInfoSerializer _securityTokenSerializer;
 19
 13420        public WSTrust(KeyInfoSerializer securityTokenSerializer, TrustDictionary serializerDictionary)
 21        {
 13422            _securityTokenSerializer = securityTokenSerializer;
 13423            SerializerDictionary = serializerDictionary;
 13424        }
 25
 40326        public TrustDictionary SerializerDictionary { get; }
 27
 28        public override void PopulateTokenEntries(IList<SecurityTokenSerializer.TokenEntry> tokenEntryList)
 29        {
 13430            tokenEntryList.Add(new BinarySecretTokenEntry(this));
 13431        }
 32
 33        public override void PopulateKeyIdentifierClauseEntries(IList<SecurityTokenSerializer.KeyIdentifierClauseEntry> 
 34        {
 13435            keyIdentifierClauseEntries.Add(new BinarySecretClauseEntry(this));
 13436            keyIdentifierClauseEntries.Add(new GenericXmlSecurityKeyIdentifierClauseEntry(this));
 13437        }
 38
 39        private class BinarySecretTokenEntry : SecurityTokenSerializer.TokenEntry
 40        {
 41            private readonly WSTrust _parent;
 42
 13443            public BinarySecretTokenEntry(WSTrust parent)
 44            {
 13445                _parent = parent;
 13446            }
 47
 048            protected override XmlDictionaryString LocalName { get { return _parent.SerializerDictionary.BinarySecret; }
 049            protected override XmlDictionaryString NamespaceUri { get { return _parent.SerializerDictionary.Namespace; }
 850            protected override Type[] GetTokenTypesCore() { return new Type[] { typeof(BinarySecretSecurityToken) }; }
 1951            public override string TokenTypeUri { get { return null; } }
 052            protected override string ValueTypeUri { get { return null; } }
 53        }
 54
 55        internal class BinarySecretClauseEntry : KeyIdentifierClauseEntry
 56        {
 57            private readonly WSTrust _parent;
 58            private readonly TrustDictionary _otherDictionary = null;
 59
 13460            public BinarySecretClauseEntry(WSTrust parent)
 61            {
 13462                _parent = parent;
 63
 13464                _otherDictionary = null;
 65
 13466                if (parent.SerializerDictionary is TrustDec2005Dictionary)
 67                {
 13468                    _otherDictionary = parent._securityTokenSerializer.DictionaryManager.TrustFeb2005Dictionary;
 69                }
 70
 13471                if (parent.SerializerDictionary is TrustFeb2005Dictionary)
 72                {
 073                    _otherDictionary = parent._securityTokenSerializer.DictionaryManager.TrustDec2005Dictionary;
 74                }
 75
 76                // always set it, so we don't have to worry about null
 13477                if (_otherDictionary == null)
 78                {
 079                    _otherDictionary = _parent.SerializerDictionary;
 80                }
 13481            }
 82
 83            protected override XmlDictionaryString LocalName
 84            {
 9085                get { return _parent.SerializerDictionary.BinarySecret; }
 86            }
 87
 88            protected override XmlDictionaryString NamespaceUri
 89            {
 4590                get { return _parent.SerializerDictionary.Namespace; }
 91            }
 92
 93            public override SecurityKeyIdentifierClause ReadKeyIdentifierClauseCore(XmlDictionaryReader reader)
 94            {
 095                byte[] secret = reader.ReadElementContentAsBase64();
 096                return new BinarySecretKeyIdentifierClause(secret, false);
 97            }
 98
 99            public override bool SupportsCore(SecurityKeyIdentifierClause keyIdentifierClause)
 100            {
 20101                return keyIdentifierClause is BinarySecretKeyIdentifierClause;
 102            }
 103
 104            public override bool CanReadKeyIdentifierClauseCore(XmlDictionaryReader reader)
 105            {
 45106                return (reader.IsStartElement(LocalName, NamespaceUri) || reader.IsStartElement(LocalName, _otherDiction
 107            }
 108
 109            public override void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause ke
 110            {
 0111                BinarySecretKeyIdentifierClause skic = keyIdentifierClause as BinarySecretKeyIdentifierClause;
 0112                byte[] secret = skic.GetKeyBytes();
 0113                writer.WriteStartElement(_parent.SerializerDictionary.Prefix.Value, _parent.SerializerDictionary.BinaryS
 0114                writer.WriteBase64(secret, 0, secret.Length);
 0115                writer.WriteEndElement();
 0116            }
 117        }
 118
 119        internal class GenericXmlSecurityKeyIdentifierClauseEntry : KeyIdentifierClauseEntry
 120        {
 121            private readonly WSTrust _parent;
 122
 134123            public GenericXmlSecurityKeyIdentifierClauseEntry(WSTrust parent)
 124            {
 134125                _parent = parent;
 134126            }
 127
 128            protected override XmlDictionaryString LocalName
 129            {
 0130                get { return null; }
 131            }
 132
 133            protected override XmlDictionaryString NamespaceUri
 134            {
 0135                get { return null; }
 136            }
 137
 138            public override bool CanReadKeyIdentifierClauseCore(XmlDictionaryReader reader)
 139            {
 45140                return false;
 141            }
 142
 143            public override SecurityKeyIdentifierClause ReadKeyIdentifierClauseCore(XmlDictionaryReader reader)
 144            {
 0145                return null;
 146            }
 147
 148            public override bool SupportsCore(SecurityKeyIdentifierClause keyIdentifierClause)
 149            {
 20150                return keyIdentifierClause is GenericXmlSecurityKeyIdentifierClause;
 151            }
 152
 153            public override void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause ke
 154            {
 0155                GenericXmlSecurityKeyIdentifierClause genericXmlSecurityKeyIdentifierClause = keyIdentifierClause as Gen
 0156                genericXmlSecurityKeyIdentifierClause.ReferenceXml.WriteTo(writer);
 0157            }
 158        }
 159
 160        protected static bool CheckElement(XmlElement element, string name, string ns, out string value)
 161        {
 0162            value = null;
 0163            if (element.LocalName != name || element.NamespaceURI != ns)
 164            {
 0165                return false;
 166            }
 167
 0168            if (element.FirstChild is XmlText)
 169            {
 0170                value = ((XmlText)element.FirstChild).Value;
 0171                return true;
 172            }
 0173            return false;
 174        }
 175    }
 176}