• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

me-viper / OpaDotNet / 11762631757

08 Nov 2024 01:44PM UTC coverage: 84.369%. Remained the same
11762631757

push

github

me-viper
chore: Apply formatting rules

1820 of 2364 branches covered (76.99%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 3 files covered. (100.0%)

82 existing lines in 15 files now uncovered.

3815 of 4315 relevant lines covered (88.41%)

1719.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/Extensions.AspNetCore/src/OpaPolicyRequirement.cs
1
namespace OpaDotNet.Extensions.AspNetCore;
2

3
/// <summary>
4
/// Represents OPA policy requirement.
5
/// </summary>
6
public record OpaPolicyRequirement : IAuthorizationRequirement
7
{
8
    [PublicAPI]
9
    public OpaPolicyRequirement(string entrypoint)
40,042✔
10
    {
11
        ArgumentException.ThrowIfNullOrEmpty(entrypoint);
40,042✔
12

13
        Entrypoint = entrypoint;
40,042✔
14
    }
40,042✔
15

16
    /// <summary>
17
    /// OPA policy entrypoint.
18
    /// </summary>
19
    public string Entrypoint { get; }
180,130✔
20

21
    /// <summary>
22
    /// Tries to build <see cref="OpaPolicyRequirement"/> from policy name.
23
    /// </summary>
24
    /// <param name="policyName">OPA policy name in format Opa/[module]/?[entrypoint]</param>
25
    /// <param name="result">Parsed OPA policy requirement</param>
26
    /// <returns><c>true</c> if <see cref="policyName"/> represents OPA policy, otherwise <c>false</c></returns>
27
    internal static bool TryParse(string policyName, [MaybeNullWhen(false)] out OpaPolicyRequirement result)
28
    {
29
        result = null;
40,052✔
30

31
        if (string.IsNullOrWhiteSpace(policyName))
40,052!
UNCOV
32
            return false;
×
33

34
        policyName = policyName.TrimEnd('/');
40,052✔
35

36
        var prefixIndex = policyName.IndexOf(OpaPolicyAuthorizeAttribute.PolicyPrefix, StringComparison.OrdinalIgnoreCase);
40,052✔
37

38
        if (prefixIndex < 0)
40,052✔
39
            return false;
6✔
40

41
        prefixIndex += OpaPolicyAuthorizeAttribute.PolicyPrefix.Length + 1;
40,046✔
42

43
        if (prefixIndex > policyName.Length)
40,046✔
44
            return false;
4✔
45

46
        var ep = policyName[prefixIndex..];
40,042✔
47

48
        if (string.IsNullOrWhiteSpace(ep))
40,042!
UNCOV
49
            return false;
×
50

51
        result = new OpaPolicyRequirement(ep);
40,042✔
52

53
        return true;
40,042✔
54
    }
55

56
    [ExcludeFromCodeCoverage]
57
    public override string ToString()
58
    {
59
        return $"OPA: {Entrypoint}";
60
    }
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc