< Summary

Information
Class: AsiBackbone.Core.Classification.DlpFailurePolicyOptions
Assembly: AsiBackbone.Core
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Classification/DlpFailurePolicyOptions.cs
Line coverage
91%
Covered lines: 22
Uncovered lines: 2
Coverable lines: 24
Total lines: 80
Line coverage: 91.6%
Branch coverage
81%
Covered branches: 9
Total branches: 11
Branch coverage: 81.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
GetBehavior(...)71.43%7786.67%
ValidateBehavior(...)100%44100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.Core/Classification/DlpFailurePolicyOptions.cs

#LineLine coverage
 1namespace AsiBackbone.Core.Classification;
 2
 3/// <summary>
 4/// Defines provider-neutral policy options for resolving DLP or classification failure behavior.
 5/// </summary>
 6public sealed class DlpFailurePolicyOptions
 7{
 8    /// <summary>
 9    /// Gets or sets the default behavior for low-risk intents.
 10    /// </summary>
 11    public DlpFailureBehavior LowRiskBehavior { get; set; } = DlpFailureBehavior.WarnAndAllow;
 12
 13    /// <summary>
 14    /// Gets or sets the default behavior for medium-risk intents.
 15    /// </summary>
 16    public DlpFailureBehavior MediumRiskBehavior { get; set; } = DlpFailureBehavior.RequireAcknowledgment;
 17
 18    /// <summary>
 19    /// Gets or sets the default behavior for high-risk or regulated intents.
 20    /// </summary>
 21    public DlpFailureBehavior HighRiskBehavior { get; set; } = DlpFailureBehavior.Deny;
 22
 23    /// <summary>
 24    /// Gets risk- and failure-specific behavior overrides.
 25    /// </summary>
 26    public IDictionary<DlpFailurePolicyKey, DlpFailureBehavior> BehaviorOverrides { get; } =
 3027        new Dictionary<DlpFailurePolicyKey, DlpFailureBehavior>();
 28
 29    /// <summary>
 30    /// Resolves the configured behavior for the supplied failure context.
 31    /// </summary>
 32    /// <param name="context">The DLP failure policy context.</param>
 33    /// <returns>The configured behavior.</returns>
 34    public DlpFailureBehavior GetBehavior(DlpFailurePolicyContext context)
 35    {
 3036        ArgumentNullException.ThrowIfNull(context);
 37
 2838        var key = new DlpFailurePolicyKey(context.RiskLevel, context.FailureKind);
 39
 2840        if (BehaviorOverrides.TryGetValue(key, out DlpFailureBehavior overrideBehavior))
 41        {
 742            return ValidateBehavior(overrideBehavior, nameof(BehaviorOverrides));
 43        }
 44
 2145        DlpFailureBehavior behavior = context.RiskLevel switch
 2146        {
 1047            DlpIntentRiskLevel.Low => LowRiskBehavior,
 648            DlpIntentRiskLevel.Medium => MediumRiskBehavior,
 549            DlpIntentRiskLevel.High => HighRiskBehavior,
 2150            // DlpFailurePolicyContext rejects an unspecified risk level at construction, so this arm is unreachable thr
 2151            // a validly constructed context. It stays explicit so an unassigned tier can never fall through to a defaul
 052            DlpIntentRiskLevel.Unspecified => throw new ArgumentOutOfRangeException(nameof(context), context.RiskLevel, 
 053            _ => throw new ArgumentOutOfRangeException(nameof(context), context.RiskLevel, "DLP intent risk level must b
 2154        };
 55
 2156        return ValidateBehavior(behavior, nameof(context));
 57    }
 58
 59    /// <summary>
 60    /// Validates a resolved or configured failure behavior.
 61    /// </summary>
 62    /// <remarks>
 63    /// This is the single choke point for both the risk-tier properties and <see cref="BehaviorOverrides" />, so reject
 64    /// <see cref="DlpFailureBehavior.Unspecified" /> here keeps a partially configured policy from resolving a screenin
 65    /// failure into an allow. An incomplete policy raises instead of quietly proceeding.
 66    /// </remarks>
 67    private static DlpFailureBehavior ValidateBehavior(
 68        DlpFailureBehavior behavior,
 69        string parameterName)
 70    {
 2871        return !Enum.IsDefined(behavior)
 2872            ? throw new ArgumentOutOfRangeException(parameterName, behavior, "DLP failure behavior must be defined.")
 2873            : behavior == DlpFailureBehavior.Unspecified
 2874                ? throw new ArgumentOutOfRangeException(
 2875                    parameterName,
 2876                    behavior,
 2877                    "DLP failure behavior must be configured. Set an explicit behavior rather than leaving it unspecifie
 2878                : behavior;
 79    }
 80}