-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9766e5e
commit 759fe7b
Showing
14 changed files
with
130 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http.Json; | ||
using System.Threading.Tasks; | ||
using HintKeep.Services; | ||
using HintKeep.Storage; | ||
using HintKeep.Storage.Entities; | ||
using Microsoft.Azure.Cosmos.Table; | ||
using Moq; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace HintKeep.Tests.Integration.Users | ||
|
@@ -63,16 +64,16 @@ public async Task Post_WhenUserDoesNotExist_ReturnsCreated() | |
.WithEmailService(out var emailService) | ||
.CreateClient(); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
securityService | ||
.Setup(securityService => securityService.GeneratePasswordSalt()) | ||
.GeneratePasswordSalt() | ||
.Returns("#password-salt"); | ||
securityService | ||
.Setup(securityService => securityService.ComputePasswordHash("#password-salt", "#Test-Password1")) | ||
.ComputePasswordHash("#password-salt", "#Test-Password1") | ||
.Returns("#password-hash"); | ||
securityService | ||
.Setup(securityService => securityService.GenerateConfirmationToken()) | ||
.GenerateConfirmationToken() | ||
.Returns(new ConfirmationToken("#confirmation-token", TimeSpan.FromHours(1))); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users", new { email = "#[email protected]", hint = "#Test-Hint", password = "#Test-Password1" }); | ||
|
@@ -103,8 +104,10 @@ public async Task Post_WhenUserDoesNotExist_ReturnsCreated() | |
Assert.True(DateTimeOffset.UtcNow.AddMinutes(55) < expiration); | ||
Assert.True(expiration < DateTimeOffset.UtcNow.AddMinutes(65)); | ||
|
||
emailService.Verify(emailService => emailService.SendAsync("#[email protected]", "Welcome to HintKeep!", It.Is<string>(body => body.Contains("#confirmation-token"))), Times.Once); | ||
emailService.VerifyNoOtherCalls(); | ||
await emailService | ||
.Received() | ||
.SendAsync("#[email protected]", "Welcome to HintKeep!", Arg.Is<string>(body => body.Contains("#confirmation-token"))); | ||
Assert.Single(emailService.ReceivedCalls()); | ||
} | ||
|
||
[Fact] | ||
|
@@ -116,10 +119,10 @@ public async Task Post_WhenUserEmailAlreadyExists_ReturnsConflict() | |
.WithEmailService(out var emailService) | ||
.CreateClient(); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
securityService | ||
.Setup(securityService => securityService.GenerateConfirmationToken()) | ||
.GenerateConfirmationToken() | ||
.Returns(new ConfirmationToken("#confirmation-token", TimeSpan.FromHours(1))); | ||
entityTables.Users.Execute(TableOperation.Insert(new TableEntity { PartitionKey = "#email-hash".ToEncodedKeyProperty(), RowKey = "details" })); | ||
|
||
|
@@ -133,7 +136,7 @@ public async Task Post_WhenUserEmailAlreadyExists_ReturnsConflict() | |
Assert.Equal("#email-hash".ToEncodedKeyProperty(), userEntity.PartitionKey); | ||
Assert.Equal("details", userEntity.RowKey); | ||
|
||
emailService.VerifyNoOtherCalls(); | ||
Assert.Empty(emailService.ReceivedCalls()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using HintKeep.Storage; | ||
using HintKeep.Storage.Entities; | ||
using Microsoft.Azure.Cosmos.Table; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace HintKeep.Tests.Integration.UsersConfirmations | ||
|
@@ -59,7 +60,7 @@ public async Task Post_WhenValidTokenExist_ReturnsCreated() | |
} | ||
); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/confirmations", new { token = "#test-token" }); | ||
|
@@ -109,7 +110,7 @@ public async Task Post_WhenExpiredTokenExist_ReturnsNotFound() | |
Expiration = DateTimeOffset.UtcNow.AddDays(-1) | ||
})); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/confirmations", new { token = "#token" }); | ||
|
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
using HintKeep.Storage; | ||
using HintKeep.Storage.Entities; | ||
using Microsoft.Azure.Cosmos.Table; | ||
using Moq; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace HintKeep.Tests.Integration.UsersHintsNotifications | ||
|
@@ -51,7 +51,7 @@ public async Task Post_WhenActiveUserExists_ReturnsCreated() | |
} | ||
); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/hints/notifications", new { email = "#[email protected]" }); | ||
|
@@ -60,8 +60,10 @@ public async Task Post_WhenActiveUserExists_ReturnsCreated() | |
Assert.Empty(await response.Content.ReadAsStringAsync()); | ||
Assert.Equal(new Uri("/api/users/sessions", UriKind.Relative), response.Headers.Location); | ||
|
||
emailService.Verify(emailService => emailService.SendAsync("#[email protected]", "HintKeep - Account Hint", It.IsRegex("#hint")), Times.Once); | ||
emailService.VerifyNoOtherCalls(); | ||
await emailService | ||
.Received() | ||
.SendAsync("#[email protected]", "HintKeep - Account Hint", Arg.Is<string>(body => body.Contains("#hint"))); | ||
Assert.Single(emailService.ReceivedCalls()); | ||
} | ||
|
||
[Fact] | ||
|
@@ -72,7 +74,7 @@ public async Task Post_WhenUserDoesNotExist_ReturnsNotFound() | |
.WithSecurityService(out var securityService) | ||
.CreateClient(); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/hints/notifications", new { email = "#[email protected]" }); | ||
|
@@ -101,7 +103,7 @@ public async Task Post_WhenInactiveUserExists_ReturnsNotFound() | |
} | ||
); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/hints/notifications", new { email = "#[email protected]" }); | ||
|
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 |
---|---|---|
|
@@ -2,11 +2,10 @@ | |
using System.Net; | ||
using System.Net.Http.Json; | ||
using System.Threading.Tasks; | ||
using HintKeep.Services; | ||
using HintKeep.Storage; | ||
using HintKeep.Storage.Entities; | ||
using Microsoft.Azure.Cosmos.Table; | ||
using Moq; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace HintKeep.Tests.Integration.UsersPasswords | ||
|
@@ -45,7 +44,7 @@ public async Task Post_WhenTokenDoesNotExist_ReturnsNotFound() | |
Expiration = DateTimeOffset.UtcNow.AddDays(-1) | ||
})); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/passwords", new { email = "#[email protected]", token = "#token", password = "passWORD$123" }); | ||
|
@@ -69,7 +68,7 @@ public async Task Post_WhenUserDoesNotExist_ReturnsNotFound() | |
Expiration = DateTimeOffset.UtcNow.AddDays(1) | ||
})); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/passwords", new { email = "#[email protected]", token = "#token", password = "passWORD$123" }); | ||
|
@@ -108,13 +107,13 @@ public async Task Post_WhenValidTokenExist_ReturnsCreated() | |
}) | ||
}); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
securityService | ||
.Setup(securityService => securityService.GeneratePasswordSalt()) | ||
.GeneratePasswordSalt() | ||
.Returns("#password-salt"); | ||
securityService | ||
.Setup(securityService => securityService.ComputePasswordHash("#password-salt", "passWORD$123")) | ||
.ComputePasswordHash("#password-salt", "passWORD$123") | ||
.Returns("#password-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/passwords", new { email = "#[email protected]", token = "#token", password = "passWORD$123" }); | ||
|
@@ -134,8 +133,10 @@ public async Task Post_WhenValidTokenExist_ReturnsCreated() | |
Assert.Equal("#password-hash", userEntity.Properties[nameof(UserEntity.PasswordHash)].StringValue); | ||
Assert.True(userEntity.Properties[nameof(UserEntity.IsActive)].BooleanValue); | ||
|
||
emailService.Verify(emailService => emailService.SendAsync("#[email protected]", "HintKeep - Password Reset", It.IsAny<string>()), Times.Once); | ||
emailService.VerifyNoOtherCalls(); | ||
await emailService | ||
.Received() | ||
.SendAsync("#[email protected]", "HintKeep - Password Reset", Arg.Any<string>()); | ||
Assert.Single(emailService.ReceivedCalls()); | ||
} | ||
|
||
[Fact] | ||
|
@@ -167,7 +168,7 @@ public async Task Post_WhenInactiveUserExists_ReturnsNotFound() | |
}) | ||
}); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/passwords", new { email = "#[email protected]", token = "#token", password = "passWORD$123" }); | ||
|
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
using HintKeep.Storage; | ||
using HintKeep.Storage.Entities; | ||
using Microsoft.Azure.Cosmos.Table; | ||
using Moq; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace HintKeep.Tests.Integration.UsersPasswordsResets | ||
|
@@ -51,10 +51,10 @@ public async Task Post_WhenActiveUserExists_ReturnsCreated() | |
} | ||
); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
securityService | ||
.Setup(securityService => securityService.GenerateConfirmationToken()) | ||
.GenerateConfirmationToken() | ||
.Returns(new ConfirmationToken("#confirmation-token", TimeSpan.FromHours(1))); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/passwords/resets", new { email = "#[email protected]" }); | ||
|
@@ -73,8 +73,10 @@ public async Task Post_WhenActiveUserExists_ReturnsCreated() | |
Assert.True(DateTimeOffset.UtcNow.AddMinutes(55) < expiration); | ||
Assert.True(expiration < DateTimeOffset.UtcNow.AddMinutes(65)); | ||
|
||
emailService.Verify(emailService => emailService.SendAsync("#[email protected]", "HintKeep - Password Reset", It.Is<string>(body => body.Contains("#confirmation-token"))), Times.Once); | ||
emailService.VerifyNoOtherCalls(); | ||
await emailService | ||
.Received() | ||
.SendAsync("#[email protected]", "HintKeep - Password Reset", Arg.Is<string>(body => body.Contains("#confirmation-token"))); | ||
Assert.Single(emailService.ReceivedCalls()); | ||
} | ||
|
||
[Fact] | ||
|
@@ -85,7 +87,7 @@ public async Task Post_WhenUserDoesNotExist_ReturnsNotFound() | |
.WithSecurityService(out var securityService) | ||
.CreateClient(); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/passwords/resets", new { email = "#[email protected]" }); | ||
|
@@ -114,7 +116,7 @@ public async Task Post_WhenInactiveUserExists_ReturnsNotFound() | |
} | ||
); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/passwords/resets", new { email = "#[email protected]" }); | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using HintKeep.Storage; | ||
using HintKeep.Storage.Entities; | ||
using Microsoft.Azure.Cosmos.Table; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace HintKeep.Tests.Integration.UsersSessions | ||
|
@@ -54,7 +55,7 @@ public async Task Post_WhenInactiveUserExists_ReturnsNotFound() | |
IsActive = false | ||
})); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/sessions", new { email = "#[email protected]", password = "#test-password" }); | ||
|
@@ -70,7 +71,7 @@ public async Task Post_WhenActiveUserExistButPasswordsDoNotMatch_ReturnsUnproces | |
.WithSecurityService(out var securityService) | ||
.CreateClient(); | ||
securityService | ||
.Setup(securityService => securityService.ComputePasswordHash("#password-salt", "#test-password")) | ||
.ComputePasswordHash("#password-salt", "#test-password") | ||
.Returns("#password-hash-not-matching"); | ||
entityTables.Users.Execute(TableOperation.Insert(new UserEntity | ||
{ | ||
|
@@ -81,10 +82,10 @@ public async Task Post_WhenActiveUserExistButPasswordsDoNotMatch_ReturnsUnproces | |
IsActive = true | ||
})); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
securityService | ||
.Setup(securityService => securityService.ComputePasswordHash("#password-salt", "#test-password")) | ||
.ComputePasswordHash("#password-salt", "#test-password") | ||
.Returns("#password-hash-not-matching"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/sessions", new { email = "#[email protected]", password = "#test-password" }); | ||
|
@@ -111,10 +112,10 @@ public async Task Post_WhenActiveUserExsitsWithMatchingPassword_ReturnsCreated() | |
IsActive = true | ||
})); | ||
securityService | ||
.Setup(securityService => securityService.ComputeHash("#[email protected]")) | ||
.ComputeHash("#[email protected]") | ||
.Returns("#email-hash"); | ||
securityService | ||
.Setup(securityService => securityService.ComputePasswordHash("#password-salt", "#test-password")) | ||
.ComputePasswordHash("#password-salt", "#test-password") | ||
.Returns("#password-hash"); | ||
|
||
var response = await client.PostAsJsonAsync("/api/users/sessions", new { email = "#[email protected]", password = "#test-password" }); | ||
|
Oops, something went wrong.