< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.WSFederationHttpBinding
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/WSFederationHttpBinding.cs
Line coverage
32%
Covered lines: 15
Uncovered lines: 31
Coverable lines: 46
Total lines: 138
Line coverage: 32.6%
Branch coverage
25%
Covered branches: 4
Total branches: 16
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
.ctor()100%1133.33%
.ctor(...)100%110%
.ctor(...)100%11100%
.ctor(...)0%220%
CreatePrivacyPolicy()50%2250%
GetTransport()50%4466.66%
GetSecurityModeFromTransport(...)0%440%
CreateMessageSecurity()100%110%
CreateBindingElements()50%2280%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/WSFederationHttpBinding.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.ComponentModel;
 6using CoreWCF.Channels;
 7
 8namespace CoreWCF
 9{
 10    public class WSFederationHttpBinding : WSHttpBindingBase
 11    {
 012        private static readonly MessageSecurityVersion s_wSMessageSecurityVersion = MessageSecurityVersion.WSSecurity11W
 13        private Uri _privacyNoticeAt;
 14        private int _privacyNoticeVersion;
 215        private WSFederationHttpSecurity _security = new WSFederationHttpSecurity();
 16
 17        public WSFederationHttpBinding()
 018            : base()
 19        {
 020        }
 21
 22        public WSFederationHttpBinding(WSFederationHttpSecurityMode securityMode)
 023            : this(securityMode, false)
 24        {
 025        }
 26
 27        public WSFederationHttpBinding(WSFederationHttpSecurityMode securityMode, bool reliableSessionEnabled)
 228            : base(reliableSessionEnabled)
 29        {
 230            _security.Mode = securityMode;
 231        }
 32
 33
 34        internal WSFederationHttpBinding(WSFederationHttpSecurity security, PrivacyNoticeBindingElement privacy, bool re
 035            : base(reliableSessionEnabled)
 36        {
 037            _security = security;
 038            if (null != privacy)
 39            {
 040                _privacyNoticeAt = privacy.Url;
 041                _privacyNoticeVersion = privacy.Version;
 42            }
 043        }
 44
 45        [DefaultValue(null)]
 46        public Uri PrivacyNoticeAt
 47        {
 5048            get { return _privacyNoticeAt; }
 049            set { _privacyNoticeAt = value; }
 50        }
 51
 52        [DefaultValue(0)]
 53        public int PrivacyNoticeVersion
 54        {
 055            get { return _privacyNoticeVersion; }
 056            set { _privacyNoticeVersion = value; }
 57        }
 58
 59        public WSFederationHttpSecurity Security
 60        {
 5461            get { return _security; }
 62            set
 63            {
 064                if (value == null)
 065                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 066                _security = value;
 067            }
 68        }
 69
 70        private PrivacyNoticeBindingElement CreatePrivacyPolicy()
 71        {
 5072            PrivacyNoticeBindingElement privacy = null;
 73
 5074            if (PrivacyNoticeAt != null)
 75            {
 076                privacy = new PrivacyNoticeBindingElement();
 077                privacy.Url = PrivacyNoticeAt;
 078                privacy.Version = _privacyNoticeVersion;
 79            }
 80
 5081            return privacy;
 82        }
 83
 84        protected override TransportBindingElement GetTransport()
 85        {
 10786            if (_security.Mode == WSFederationHttpSecurityMode.None || _security.Mode == WSFederationHttpSecurityMode.Me
 87            {
 088                return HttpTransport;
 89            }
 90            else
 91            {
 10792                return HttpsTransport;
 93            }
 94        }
 95
 96        internal static bool GetSecurityModeFromTransport(TransportBindingElement transport, HttpTransportSecurity trans
 97        {
 098            mode = WSFederationHttpSecurityMode.None | WSFederationHttpSecurityMode.Message | WSFederationHttpSecurityMo
 099            if (transport is HttpsTransportBindingElement)
 100            {
 0101                mode = WSFederationHttpSecurityMode.TransportWithMessageCredential;
 102            }
 0103            else if (transport is HttpTransportBindingElement)
 104            {
 0105                mode = WSFederationHttpSecurityMode.None | WSFederationHttpSecurityMode.Message;
 106            }
 107            else
 108            {
 0109                return false;
 110            }
 0111            return true;
 112        }
 113
 114        protected override SecurityBindingElement CreateMessageSecurity()
 115        {
 116           // return security.CreateMessageSecurity(this.ReliableSession.Enabled, WSMessageSecurityVersion);
 117           //TODO : For reliable session
 0118            return _security.CreateMessageSecurity(false, s_wSMessageSecurityVersion);
 119        }
 120
 121        public override BindingElementCollection CreateBindingElements()
 122        {   // return collection of BindingElements
 123
 50124            BindingElementCollection bindingElements = base.CreateBindingElements();
 125            // order of BindingElements is important
 126
 50127            PrivacyNoticeBindingElement privacy = CreatePrivacyPolicy();
 50128            if (privacy != null)
 129            {
 130                // This must go first.
 0131                bindingElements.Insert(0, privacy);
 132            }
 133
 50134            return bindingElements;
 135        }
 136
 137    }
 138}