-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MfaOptions to PasswordCredential. #52
- Loading branch information
1 parent
94a79bb
commit c1dea5c
Showing
16 changed files
with
457 additions
and
73 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Domain.Events.Shared/Identities/PasswordCredentials/MfaOptionsChanged.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Domain.Common; | ||
using Domain.Common.ValueObjects; | ||
using Domain.Shared.Identities; | ||
using JetBrains.Annotations; | ||
|
||
namespace Domain.Events.Shared.Identities.PasswordCredentials; | ||
|
||
public sealed class MfaOptionsChanged : DomainEvent | ||
{ | ||
public MfaOptionsChanged(Identifier id) : base(id) | ||
{ | ||
} | ||
|
||
[UsedImplicitly] | ||
public MfaOptionsChanged() | ||
{ | ||
} | ||
|
||
public required bool MfaCanBeDisabled { get; set; } | ||
|
||
public required bool IsMfaEnabled { get; set; } | ||
|
||
public required MfaAuthenticators MfaTypes { get; set; } | ||
|
||
public required string UserId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Domain.Shared.Identities; | ||
|
||
[Flags] | ||
public enum MfaAuthenticators | ||
{ | ||
None = 0, // No Authenticator is required | ||
OobSms = 2, // Code is sent "Out of Band" in an SMS message | ||
OobEmail = 4, // Code is sent "Out of Band" in an email message | ||
TotpAuthenticator = 8 // "Time-based One Time Password" is generated by a supported authenticator App | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using Common; | ||
using Domain.Shared.Identities; | ||
using FluentAssertions; | ||
using UnitTesting.Common; | ||
using Xunit; | ||
|
||
namespace IdentityDomain.UnitTests; | ||
|
||
[Trait("Category", "Unit")] | ||
public class MfaOptionsSpec | ||
{ | ||
[Fact] | ||
public void WhenCreateAndEnabledButNoAuthenticators_ThenReturnsError() | ||
{ | ||
var result = MfaOptions.Create(true, true, MfaAuthenticators.None); | ||
|
||
result.Should().BeError(ErrorCode.Validation, Resources.MfaOptions_NoAuthenticators); | ||
} | ||
|
||
[Fact] | ||
public void WhenCreate_ThenCreates() | ||
{ | ||
var result = MfaOptions.Create(true, true, MfaAuthenticators.TotpAuthenticator); | ||
|
||
result.Should().BeSuccess(); | ||
result.Value.IsEnabled.Should().BeTrue(); | ||
result.Value.CanBeDisabled.Should().BeTrue(); | ||
result.Value.Types.Should().Be(MfaAuthenticators.TotpAuthenticator); | ||
} | ||
|
||
[Fact] | ||
public void WhenChangeAndEnabledAndCannotBeDisabled_ThenReturnsError() | ||
{ | ||
var options = MfaOptions.Create(true, false, MfaAuthenticators.TotpAuthenticator).Value; | ||
|
||
var result = options.Change(MfaOptions.Create(false, false, MfaAuthenticators.TotpAuthenticator).Value); | ||
|
||
result.Should().BeError(ErrorCode.RuleViolation, Resources.MfaOptions_Change_CannotBeDisabled); | ||
} | ||
|
||
[Fact] | ||
public void WhenChangeAndDisabledAndCannotBeDisabled_ThenReturnsError() | ||
{ | ||
var options = MfaOptions.Create(false, false, MfaAuthenticators.None).Value; | ||
|
||
var result = options.Change(MfaOptions.Create(true, false, MfaAuthenticators.TotpAuthenticator).Value); | ||
|
||
result.Should().BeError(ErrorCode.RuleViolation, Resources.MfaOptions_Change_CannotBeEnabled); | ||
} | ||
|
||
[Fact] | ||
public void WhenChangeAndCanBeDisabledAndTryToChangeCanBeDisabled_ThenReturnsError() | ||
{ | ||
var options = MfaOptions.Create(true, true, MfaAuthenticators.TotpAuthenticator).Value; | ||
|
||
var result = options.Change(MfaOptions.Create(true, false, MfaAuthenticators.TotpAuthenticator).Value); | ||
|
||
result.Should().BeError(ErrorCode.RuleViolation, Resources.MfaOptions_CannotChangeCanBeDisabled); | ||
} | ||
|
||
[Fact] | ||
public void WhenChangeAndCannotBeDisabledAndTryToChangeCanBeDisabled_ThenReturnsError() | ||
{ | ||
var options = MfaOptions.Create(true, false, MfaAuthenticators.TotpAuthenticator).Value; | ||
|
||
var result = options.Change(MfaOptions.Create(true, true, MfaAuthenticators.TotpAuthenticator).Value); | ||
|
||
result.Should().BeError(ErrorCode.RuleViolation, Resources.MfaOptions_CannotChangeCanBeDisabled); | ||
} | ||
|
||
[Fact] | ||
public void WhenChange_ThenReturnsChanged() | ||
{ | ||
var options = MfaOptions.Create(false, true, MfaAuthenticators.None).Value; | ||
|
||
var result = | ||
options.Change(MfaOptions.Create(true, true, MfaAuthenticators.TotpAuthenticator).Value); | ||
|
||
result.Should().BeSuccess(); | ||
result.Value.IsEnabled.Should().BeTrue(); | ||
result.Value.CanBeDisabled.Should().BeTrue(); | ||
result.Value.Types.Should().Be(MfaAuthenticators.TotpAuthenticator); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.