< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Command.Input.Validation.SetScopeEmailLinksCommandValidator
Assembly: ArturRios.Heimdall.Command
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Command/Input/Validation/SetScopeEmailLinksCommandValidator.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 33
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
BeUsableLink(...)100%88100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Command/Input/Validation/SetScopeEmailLinksCommandValidator.cs

#LineLine coverage
 1using ArturRios.Heimdall.Shared.Messages;
 2using FluentValidation;
 3
 4namespace ArturRios.Heimdall.Command.Input.Validation;
 5
 6/// <summary>
 7///     Shape validation for <see cref="SetScopeEmailLinksCommand" />: each link, when present, is an
 8///     absolute http or https URL that fits its column. An absent or blank one is a clear, not an error.
 9/// </summary>
 10public class SetScopeEmailLinksCommandValidator : AbstractValidator<SetScopeEmailLinksCommand>
 11{
 12    private const int MaxLength = 2048;
 13
 3914    public SetScopeEmailLinksCommandValidator()
 15    {
 3916        RuleFor(command => command.EmailVerificationUrl)
 3917            .Must(BeUsableLink)
 3918            .WithMessage(ScopeMessages.EmailLinkInvalid);
 19
 3920        RuleFor(command => command.PasswordResetUrl)
 3921            .Must(BeUsableLink)
 3922            .WithMessage(ScopeMessages.EmailLinkInvalid);
 3923    }
 24
 25    // The scheme is checked, not just absoluteness, for the reason UpdateScopeCommandValidator gives
 26    // for the privacy notice URI: on Unix, Uri.TryCreate parses "/some/path" as an absolute file://
 27    // URI, so an absoluteness check alone accepts a local filesystem path as an emailed link.
 28    private static bool BeUsableLink(string? url) =>
 7829        string.IsNullOrWhiteSpace(url) ||
 7830        (url.Length <= MaxLength
 7831         && Uri.TryCreate(url, UriKind.Absolute, out var parsed)
 7832         && (parsed.Scheme == Uri.UriSchemeHttps || parsed.Scheme == Uri.UriSchemeHttp));
 33}