| | | 1 | | using ArturRios.Heimdall.Shared.Messages; |
| | | 2 | | using FluentValidation; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Heimdall.Command.Input.Validation; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Shape validation for <see cref="EnableTwoFactorAuthCommand" /> (UC-36, AF-36c): at least one |
| | | 8 | | /// of <c>"App"</c>/<c>"Email"</c> must be selected, and nothing else. Eligibility (AF-36b) and |
| | | 9 | | /// the already-active check (AF-36a) are enforced by the handler, since both need a database |
| | | 10 | | /// read the validator has no business making. |
| | | 11 | | /// </summary> |
| | | 12 | | public class EnableTwoFactorAuthCommandValidator : AbstractValidator<EnableTwoFactorAuthCommand> |
| | | 13 | | { |
| | 2 | 14 | | private static readonly string[] KnownMethods = ["App", "Email"]; |
| | | 15 | | |
| | 51 | 16 | | public EnableTwoFactorAuthCommandValidator() |
| | | 17 | | { |
| | 51 | 18 | | RuleFor(command => command.Methods) |
| | 51 | 19 | | .Must(methods => methods is { Count: > 0 } && |
| | 108 | 20 | | methods.All(method => KnownMethods.Contains(method, StringComparer.OrdinalIgnoreCase))) |
| | 51 | 21 | | .WithMessage(TwoFactorMessages.NoMethodSelected); |
| | 51 | 22 | | } |
| | | 23 | | } |