-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delay and consolidate coercion and validation of
PasswordlessOptions
(
#143)
- Loading branch information
Showing
8 changed files
with
124 additions
and
53 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Passwordless.Tests.Infra; | ||
|
||
public record PasswordlessApplication(string Name, string ApiUrl, string ApiSecret, string ApiKey) | ||
{ | ||
public IPasswordlessClient CreateClient() => | ||
// Initialize using a service container to cover more code paths in tests | ||
new ServiceCollection().AddPasswordlessSdk(o => | ||
{ | ||
o.ApiUrl = ApiUrl; | ||
o.ApiKey = ApiKey; | ||
o.ApiSecret = ApiSecret; | ||
}).BuildServiceProvider().GetRequiredService<IPasswordlessClient>(); | ||
public IPasswordlessClient CreateClient() => new PasswordlessClient(new PasswordlessOptions | ||
{ | ||
ApiUrl = ApiUrl, | ||
ApiSecret = ApiSecret, | ||
ApiKey = ApiKey | ||
}); | ||
} |
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 |
---|---|---|
|
@@ -16,7 +16,12 @@ public async Task I_can_send_a_magic_link_with_a_specified_time_to_live() | |
{ | ||
// Arrange | ||
var passwordless = await Api.CreateClientAsync(); | ||
var request = new SendMagicLinkRequest("[email protected]", "https://www.example.com?token=$TOKEN", "user", new TimeSpan(0, 15, 0)); | ||
|
||
var request = new SendMagicLinkRequest( | ||
"[email protected]", | ||
"https://www.example.com?token=$TOKEN", "user", | ||
new TimeSpan(0, 15, 0) | ||
); | ||
|
||
// Act | ||
var action = async () => await passwordless.SendMagicLinkAsync(request, CancellationToken.None); | ||
|
@@ -30,7 +35,12 @@ public async Task I_can_send_a_magic_link_without_a_time_to_live() | |
{ | ||
// Arrange | ||
var passwordless = await Api.CreateClientAsync(); | ||
var request = new SendMagicLinkRequest("[email protected]", "https://www.example.com?token=$TOKEN", "user", null); | ||
|
||
var request = new SendMagicLinkRequest( | ||
"[email protected]", | ||
"https://www.example.com?token=$TOKEN", "user", | ||
null | ||
); | ||
|
||
// Act | ||
var action = async () => await passwordless.SendMagicLinkAsync(request, CancellationToken.None); | ||
|
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,29 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Passwordless.Tests; | ||
|
||
public class ServiceRegistrationTests | ||
{ | ||
[Fact] | ||
public async Task I_can_register_a_client_with_invalid_credentials_and_not_receive_an_error_until_it_is_used() | ||
{ | ||
// Arrange | ||
var services = new ServiceCollection() | ||
.AddPasswordlessSdk(o => | ||
{ | ||
o.ApiSecret = ""; | ||
o.ApiKey = ""; | ||
}) | ||
.BuildServiceProvider(); | ||
|
||
var passwordless = services.GetRequiredService<IPasswordlessClient>(); | ||
|
||
// Act & assert | ||
await Assert.ThrowsAnyAsync<InvalidOperationException>(async () => | ||
await passwordless.CreateRegisterTokenAsync(new RegisterOptions("user123", "User")) | ||
); | ||
} | ||
} |