From 97448df9f2ac5287d3cd6d8bb4840a1a9c8d709d Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:10:38 +0200 Subject: [PATCH 1/2] asd --- tests/Passwordless.Tests/TokenTests.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/Passwordless.Tests/TokenTests.cs b/tests/Passwordless.Tests/TokenTests.cs index 59140e2..087f2b8 100644 --- a/tests/Passwordless.Tests/TokenTests.cs +++ b/tests/Passwordless.Tests/TokenTests.cs @@ -36,19 +36,28 @@ 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")] + [Fact] public async Task I_can_try_to_verify_an_invalid_signin_token_and_get_a_null_response() { // Arrange var passwordless = await Api.CreateClientAsync(); // Act - var response = await passwordless.VerifyTokenAsync("verify_foobar"); + var response = await passwordless.VerifyTokenAsync( + "verify_" + + "k8Qg4kXVl8D2aunn__jMT7td5endUueS9zEG8zIsu0lqQjfFAQXcABPX_wlDNbBlTNiB2SQ5MjQ0ZmUzYS0wOGExLTRlMTctOTMwZS1i" + + "YWZhNmM0OWJiOGWucGFzc2tleV9zaWduaW7AwMDAwMDA2SQ3NGUxMzFjOS0yNDZhLTRmNzYtYjIxMS1jNzBkZWQ1Mjg2YzLX_wlDJIBl" + + "TNgJv2FkbWluY29uc29sZTAxLmxlc3NwYXNzd29yZC5kZXbZJ2h0dHBzOi8vYWRtaW5jb25zb2xlMDEubGVzc3Bhc3N3b3JkLmRldsOy" + + "Q2hyb21lLCBXaW5kb3dzIDEwolVBqXRlc3Rlc3RzZcQghR4WgXh0HvbrT27GvP0Pkk4HmfL2b0ucVVSRlDElp_fOeb02NQ" + ); // Assert response.Should().BeNull(); From 4db33d54bf4508db5a59507df4474cfcf634764f Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:52:04 +0200 Subject: [PATCH 2/2] Add a few more tests --- src/Passwordless/IPasswordlessClient.cs | 16 +++++------ src/Passwordless/Models/VerifiedUser.cs | 1 + tests/Passwordless.Tests/TokenTests.cs | 37 ++++++++++++++++++------- 3 files changed, 36 insertions(+), 18 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 087f2b8..5f06008 100644 --- a/tests/Passwordless.Tests/TokenTests.cs +++ b/tests/Passwordless.Tests/TokenTests.cs @@ -45,21 +45,38 @@ await passwordless.VerifyTokenAsync("invalid") } [Fact] - public async Task I_can_try_to_verify_an_invalid_signin_token_and_get_a_null_response() + 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_" + - "k8Qg4kXVl8D2aunn__jMT7td5endUueS9zEG8zIsu0lqQjfFAQXcABPX_wlDNbBlTNiB2SQ5MjQ0ZmUzYS0wOGExLTRlMTctOTMwZS1i" + - "YWZhNmM0OWJiOGWucGFzc2tleV9zaWduaW7AwMDAwMDA2SQ3NGUxMzFjOS0yNDZhLTRmNzYtYjIxMS1jNzBkZWQ1Mjg2YzLX_wlDJIBl" + - "TNgJv2FkbWluY29uc29sZTAxLmxlc3NwYXNzd29yZC5kZXbZJ2h0dHBzOi8vYWRtaW5jb25zb2xlMDEubGVzc3Bhc3N3b3JkLmRldsOy" + - "Q2hyb21lLCBXaW5kb3dzIDEwolVBqXRlc3Rlc3RzZcQghR4WgXh0HvbrT27GvP0Pkk4HmfL2b0ucVVSRlDElp_fOeb02NQ" + // 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