< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.ServiceModel.Channels.KafkaSecurity
Assembly: CoreWCF.Kafka.Client
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Kafka.Client/src/CoreWCF/ServiceModel/Channels/KafkaSecurity.cs
Line coverage
88%
Covered lines: 24
Uncovered lines: 3
Coverable lines: 27
Total lines: 83
Line coverage: 88.8%
Branch coverage
66%
Covered branches: 12
Total branches: 18
Branch coverage: 66.6%
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%
CreateMessageSecurity()100%11100%
ApplySecurity(...)90%1010100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Kafka.Client/src/CoreWCF/ServiceModel/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 System.ServiceModel.Channels;
 7
 8namespace CoreWCF.ServiceModel.Channels;
 9
 10public sealed class KafkaSecurity
 11{
 12    private KafkaTransportSecurity _transportSecurity;
 13    private KafkaMessageSecurity _messageSecurity;
 14    private KafkaSecurityMode _mode;
 15    internal const KafkaSecurityMode DefaultMode = KafkaSecurityMode.None;
 16
 17    public KafkaSecurity()
 4418        : this(DefaultMode, new KafkaTransportSecurity(), new KafkaMessageSecurity())
 19    {
 20
 4421    }
 22
 4423    private KafkaSecurity(KafkaSecurityMode mode, KafkaTransportSecurity transportSecurity,
 4424        KafkaMessageSecurity messageSecurity)
 25    {
 4426        _mode = mode;
 4427        _transportSecurity = transportSecurity;
 4428        _messageSecurity = messageSecurity;
 4429    }
 30
 31    [DefaultValue(DefaultMode)]
 32    public KafkaSecurityMode Mode
 33    {
 434        get { return _mode; }
 35        set
 36        {
 537            if (!KafkaSecurityModeHelper.IsDefined(value))
 38            {
 039                throw new ArgumentOutOfRangeException(nameof(value));
 40            }
 41
 542            if (!KafkaSecurityModeHelper.IsSupported(value))
 43            {
 044                throw new NotSupportedException(SR.SecurityModeNotSupportedYet);
 45            }
 46
 547            _mode = value;
 548        }
 49    }
 50
 51    public KafkaTransportSecurity Transport
 52    {
 453        get => _transportSecurity;
 454        set => _transportSecurity = value ?? throw new ArgumentNullException(nameof(value));
 55    }
 56
 57    public KafkaMessageSecurity Message
 58    {
 459        get => _messageSecurity;
 060        set => _messageSecurity = value ?? throw new ArgumentNullException(nameof(value));
 61    }
 62
 63    internal SecurityBindingElement CreateMessageSecurity()
 64    {
 33165        return null;
 66    }
 67
 68    internal void ApplySecurity(KafkaTransportBindingElement bindingElement)
 69    {
 33170        if (_mode == KafkaSecurityMode.Transport || _mode == KafkaSecurityMode.TransportWithMessageCredential)
 71        {
 3072            _transportSecurity.ConfigureTransportSecurityWithClientAuthentication(bindingElement);
 73        }
 30174        else if (_mode == KafkaSecurityMode.TransportCredentialOnly)
 75        {
 1076            _transportSecurity.ConfigureClientAuthenticationOnly(bindingElement);
 77        }
 29178        else if (_mode == KafkaSecurityMode.None || _mode == KafkaSecurityMode.Message)
 79        {
 29180            _transportSecurity.ConfigureNoTransportSecurity(bindingElement);
 81        }
 29182    }
 83}