From 57767cdb1b78845fa7b8b62a9d8be0f0397a5a9c Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Fri, 10 Nov 2023 01:53:20 +0200 Subject: [PATCH] Add more tests (#71) --- src/Passwordless/IPasswordlessClient.cs | 16 +++++----- src/Passwordless/Models/VerifiedUser.cs | 1 + tests/Passwordless.Tests/TokenTests.cs | 40 ++++++++++++++++++++----- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/Passwordless/IPasswordlessClient.cs b/src/Passwordless/IPasswordlessClient.cs index 70eb7df..57d4b9a 100644 --- a/src/Passwordless/IPasswordlessClient.cs +++ b/src/Passwordless/IPasswordlessClient.cs @@ -22,7 +22,7 @@ public interface IPasswordlessClient /// The that will be used to configure your token. /// /// A task object representing the asynchronous operation containing the . - /// An exception containing details abaout the reason for failure. + /// An exception containing details about the reason for failure. Task CreateRegisterTokenAsync(RegisterOptions registerOptions, CancellationToken cancellationToken = default); /// @@ -31,7 +31,7 @@ public interface IPasswordlessClient /// The id of a credential representing as a Base64 URL encoded . /// /// A task object representing the asynchronous operation. - /// An exception containing details abaout the reason for failure. + /// An exception containing details about the reason for failure. Task DeleteCredentialAsync(string id, CancellationToken cancellationToken = default); /// @@ -40,7 +40,7 @@ public interface IPasswordlessClient /// The id of a credential representing as a Base64 URL encoded . /// /// A task object representing the asynchronous operation. - /// An exception containing details abaout the reason for failure. + /// An exception containing details about the reason for failure. Task DeleteCredentialAsync(byte[] id, CancellationToken cancellationToken = default); /// @@ -54,7 +54,7 @@ public interface IPasswordlessClient /// The userId of the user for which the aliases will be returned. /// /// A task object representing the asynchronous operation containing the . - /// An exception containing details abaout the reason for failure. + /// An exception containing details about the reason for failure. Task> ListAliasesAsync(string userId, CancellationToken cancellationToken = default); /// @@ -63,7 +63,7 @@ public interface IPasswordlessClient /// The userId of the user for which the credentials will be returned. /// /// A task object representing the asynchronous operation containing the . - /// An exception containing details abaout the reason for failure. + /// An exception containing details about the reason for failure. Task> ListCredentialsAsync(string userId, CancellationToken cancellationToken = default); /// @@ -71,7 +71,7 @@ public interface IPasswordlessClient /// /// /// A task object representing the asynchronous operation containing the . - /// An exception containing details abaout the reason for failure. + /// An exception containing details about the reason for failure. Task> ListUsersAsync(CancellationToken cancellationToken = default); /// @@ -81,7 +81,7 @@ public interface IPasswordlessClient /// The token to verify. /// /// A task object representing the asynchronous operation containing the . - /// An exception containing details abaout the reason for failure. + /// An exception containing details about the reason for failure. Task VerifyTokenAsync(string verifyToken, CancellationToken cancellationToken = default); /// @@ -90,6 +90,6 @@ public interface IPasswordlessClient /// The id of the user that should be deleted. /// /// A task object representing the asynchronous operation. - /// An exception containing details abaout the reason for failure. + /// An exception containing details about the reason for failure. Task DeleteUserAsync(string userId, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Passwordless/Models/VerifiedUser.cs b/src/Passwordless/Models/VerifiedUser.cs index 7a784d1..a0428a7 100644 --- a/src/Passwordless/Models/VerifiedUser.cs +++ b/src/Passwordless/Models/VerifiedUser.cs @@ -20,6 +20,7 @@ public VerifiedUser(string userId, byte[] credentialId, bool success, TokenId = tokenId; Type = type; } + public string UserId { get; } public byte[] CredentialId { get; } public bool Success { get; } diff --git a/tests/Passwordless.Tests/TokenTests.cs b/tests/Passwordless.Tests/TokenTests.cs index 59140e2..5f06008 100644 --- a/tests/Passwordless.Tests/TokenTests.cs +++ b/tests/Passwordless.Tests/TokenTests.cs @@ -36,21 +36,47 @@ public async Task I_can_try_to_verify_a_poorly_formatted_signin_token_and_get_an var passwordless = await Api.CreateClientAsync(); // Act & assert - await Assert.ThrowsAnyAsync(async () => + var ex = await Assert.ThrowsAnyAsync(async () => await passwordless.VerifyTokenAsync("invalid") ); + + ex.Details.Status.Should().Be(400); + ex.Details.Title.Should().NotBeNullOrWhiteSpace(); } - [Fact(Skip = "Need to figure out a syntactically correct token that is invalid")] - public async Task I_can_try_to_verify_an_invalid_signin_token_and_get_a_null_response() + [Fact] + public async Task I_can_try_to_verify_a_tampered_signin_token_and_get_an_error() { // Arrange var passwordless = await Api.CreateClientAsync(); - // Act - var response = await passwordless.VerifyTokenAsync("verify_foobar"); + // Act & assert + var ex = await Assert.ThrowsAnyAsync(async () => + await passwordless.VerifyTokenAsync("verify_something_that_looks_like_a_token_but_is_not") + ); - // Assert - response.Should().BeNull(); + ex.Details.Status.Should().Be(400); + ex.Details.Title.Should().NotBeNullOrWhiteSpace(); + } + + [Fact] + public async Task I_can_try_to_verify_an_invalid_signin_token_and_get_an_error() + { + // Arrange + var passwordless = await Api.CreateClientAsync(); + + // Act & assert + var ex = await Assert.ThrowsAnyAsync(async () => + await passwordless.VerifyTokenAsync( + "verify_" + + "k8Qg4kXVl8D2aunn__jMT7td5endUueS9zEG8zIsu0lqQjfFAQXcABPX_wlDNbBlTNiB2SQ5MjQ0ZmUzYS0wOGExLTRlMTctOTMwZS1i" + + "YWZhNmM0OWJiOGWucGFzc2tleV9zaWduaW7AwMDAwMDA2SQ3NGUxMzFjOS0yNDZhLTRmNzYtYjIxMS1jNzBkZWQ1Mjg2YzLX_wlDJIBl" + + "TNgJv2FkbWluY29uc29sZTAxLmxlc3NwYXNzd29yZC5kZXbZJ2h0dHBzOi8vYWRtaW5jb25zb2xlMDEubGVzc3Bhc3N3b3JkLmRldsOy" + + "Q2hyb21lLCBXaW5kb3dzIDEwolVBqXRlc3Rlc3RzZcQghR4WgXh0HvbrT27GvP0Pkk4HmfL2b0ucVVSRlDElp_fOeb02NQ" + ) + ); + + ex.Details.Status.Should().Be(400); + ex.Details.Title.Should().NotBeNullOrWhiteSpace(); } } \ No newline at end of file