< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.KafkaSecurity
Assembly: CoreWCF.Kafka
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Kafka/src/CoreWCF/Channels/KafkaSecurity.cs
Line coverage
75%
Covered lines: 21
Uncovered lines: 7
Coverable lines: 28
Total lines: 88
Line coverage: 75%
Branch coverage
62%
Covered branches: 15
Total branches: 24
Branch coverage: 62.5%
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(...)50%6685.71%
CreateMessageSecurity()100%11100%
ApplySecurity(...)90%1010100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Kafka/src/CoreWCF/Channels/KafkaSecurity.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.Runtime;
 7
 8namespace CoreWCF.Channels;
 9
 10public sealed class KafkaSecurity
 11{
 12    internal const KafkaSecurityMode DefaultMode = KafkaSecurityMode.None;
 13    private KafkaSecurityMode _mode;
 14    private KafkaTransportSecurity _transportSecurity;
 15    private KafkaMessageSecurity _messageSecurity;
 16
 17    public KafkaSecurity()
 5218        : this(DefaultMode, new KafkaTransportSecurity(), new KafkaMessageSecurity())
 19    {
 5220    }
 21
 5222    private KafkaSecurity(KafkaSecurityMode mode, KafkaTransportSecurity transportSecurity, KafkaMessageSecurity message
 23    {
 24        Fx.Assert(KafkaSecurityModeHelper.IsDefined(mode), $"Invalid SecurityMode value: {mode.ToString()}.");
 25
 5226        if (!KafkaSecurityModeHelper.IsSupported(mode))
 27        {
 028            throw new NotSupportedException(SR.SecurityModeNotSupportedYet);
 29        }
 30
 5231        _mode = mode;
 5232        _transportSecurity = transportSecurity ?? new KafkaTransportSecurity();
 5233        _messageSecurity = messageSecurity ?? new KafkaMessageSecurity();
 5234    }
 35
 36    [DefaultValue(DefaultMode)]
 37    public KafkaSecurityMode Mode
 38    {
 039        get { return _mode; }
 40        set
 41        {
 842            if (!KafkaSecurityModeHelper.IsDefined(value))
 43            {
 044                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(value))
 45            }
 46
 847            if (!KafkaSecurityModeHelper.IsSupported(value))
 48            {
 049                throw new NotSupportedException(SR.SecurityModeNotSupportedYet);
 50            }
 51
 852            _mode = value;
 853        }
 54    }
 55
 56    public KafkaTransportSecurity Transport
 57    {
 058        get => _transportSecurity;
 859        set => _transportSecurity = value ?? throw new ArgumentNullException(nameof(value));
 60    }
 61
 62    public KafkaMessageSecurity Message
 63    {
 064        get => _messageSecurity;
 065        set => _messageSecurity = value ?? throw new ArgumentNullException(nameof(value));
 66    }
 67
 68    internal SecurityBindingElement CreateMessageSecurity()
 69    {
 88270        return null;
 71    }
 72
 73    internal void ApplySecurity(KafkaTransportBindingElement element)
 74    {
 88275        if (_mode == KafkaSecurityMode.Transport || _mode == KafkaSecurityMode.TransportWithMessageCredential)
 76        {
 7877            _transportSecurity.ConfigureTransportSecurityWithClientAuthentication(element);
 78        }
 80479        else if (_mode == KafkaSecurityMode.TransportCredentialOnly)
 80        {
 2681            _transportSecurity.ConfigureClientAuthenticationOnly(element);
 82        }
 77883        else if (_mode == KafkaSecurityMode.None || _mode == KafkaSecurityMode.Message)
 84        {
 77885            _transportSecurity.ConfigureNoTransportSecurity(element);
 86        }
 77887    }
 88}