< Summary

Information
Class: Chronicis.Shared.Admin.SysAdminChecker
Assembly: Chronicis.Shared
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Shared/Admin/SysAdminChecker.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 36
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%44100%
IsSysAdmin(...)100%88100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Shared/Admin/SysAdminChecker.cs

#LineLine coverage
 1namespace Chronicis.Shared.Admin;
 2
 3/// <summary>
 4/// Evaluates system administrator status by checking a user's Auth0 ID or email
 5/// against the configured <see cref="SysAdminOptions"/>.
 6/// </summary>
 7public class SysAdminChecker : ISysAdminChecker
 8{
 9    private readonly HashSet<string> _auth0UserIds;
 10    private readonly HashSet<string> _emails;
 11
 12    public SysAdminChecker(SysAdminOptions options)
 13    {
 1414        ArgumentNullException.ThrowIfNull(options);
 15
 1316        _auth0UserIds = new HashSet<string>(
 1317            options.Auth0UserIds ?? [],
 1318            StringComparer.OrdinalIgnoreCase);
 19
 1320        _emails = new HashSet<string>(
 1321            options.Emails ?? [],
 1322            StringComparer.OrdinalIgnoreCase);
 1323    }
 24
 25    /// <inheritdoc/>
 26    public bool IsSysAdmin(string auth0UserId, string? email)
 27    {
 1328        if (!string.IsNullOrEmpty(auth0UserId) && _auth0UserIds.Contains(auth0UserId))
 329            return true;
 30
 1031        if (!string.IsNullOrEmpty(email) && _emails.Contains(email))
 232            return true;
 33
 834        return false;
 35    }
 36}