-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from AdrianJSClark/130-accept-pre-hashed-pass…
…word Accept Pre-Hashed Password
- Loading branch information
Showing
6 changed files
with
117 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,22 @@ | |
|
||
namespace Aydsko.iRacingData.UnitTests; | ||
|
||
public class LoginViaOptionsTests : MockedHttpTestBase | ||
public class PasswordEncodingTests : MockedHttpTestBase | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
BaseSetUp(); | ||
} | ||
|
||
[Test] | ||
public async Task GivenOptionsWithUsernameAndPasswordWhenAMethodIsCalledThenItWillSucceedAsync() | ||
[TestCaseSource(nameof(GetTestCases))] | ||
public async Task ValidateLoginRequestViaOptions(string username, string password, bool passwordIsEncoded, string expectedEncodedPassword) | ||
{ | ||
var options = new iRacingDataClientOptions | ||
{ | ||
Username = "[email protected]", | ||
Password = "SuperSecretPassword", | ||
Username = username, | ||
Password = password, | ||
PasswordIsEncoded = passwordIsEncoded, | ||
RestoreCookies = null, | ||
SaveCookies = null, | ||
}; | ||
|
@@ -43,51 +44,105 @@ public async Task GivenOptionsWithUsernameAndPasswordWhenAMethodIsCalledThenItWi | |
var loginDto = await JsonSerializer.DeserializeAsync<TestLoginDto>(requestContentStream).ConfigureAwait(false); | ||
Assert.That(loginDto, Is.Not.Null); | ||
|
||
Assert.That(loginDto!.Email, Is.EqualTo("[email protected]")); | ||
Assert.That(loginDto!.Password, Is.EqualTo("nXmEFCdpHheD1R3XBVkm6VQavR7ZLbW7SRmzo/MfFso=")); | ||
Assert.That(loginDto!.Email, Is.EqualTo(username)); | ||
Assert.That(loginDto!.Password, Is.EqualTo(expectedEncodedPassword)); | ||
|
||
Assert.That(sut.IsLoggedIn, Is.True); | ||
Assert.That(lookups, Is.Not.Null); | ||
Assert.That(lookups.Data, Is.Not.Null.Or.Empty); | ||
} | ||
|
||
[Test] | ||
public async Task GivenOptionsWithUsernameAndPasswordAndGiven22S3ModeWhenAMethodIsCalledThenItWillSucceedAsync() | ||
[TestCaseSource(nameof(GetTestCases))] | ||
public async Task ValidateLoginRequestViaMethodWithPasswordIsEncodedParam(string username, string password, bool passwordIsEncoded, string expectedEncodedPassword) | ||
{ | ||
var options = new iRacingDataClientOptions | ||
{ | ||
Username = "[email protected]", | ||
Password = "MyPassWord", | ||
RestoreCookies = null, | ||
SaveCookies = null, | ||
}; | ||
|
||
await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync)).ConfigureAwait(false); | ||
|
||
var sut = new DataClient(HttpClient, | ||
new TestLogger<DataClient>(), | ||
options, | ||
CookieContainer); | ||
|
||
sut.UseUsernameAndPassword(username, password, passwordIsEncoded); | ||
|
||
var lookups = await sut.GetLookupsAsync(CancellationToken.None).ConfigureAwait(false); | ||
|
||
var loginRequest = MessageHandler.Requests.Peek(); | ||
Assert.That(loginRequest, Is.Not.Null); | ||
|
||
var contentStreamTask = loginRequest.Content?.ReadAsStreamAsync() ?? Task.FromResult(Stream.Null); | ||
using var requestContentStream = await contentStreamTask.ConfigureAwait(false); | ||
Assert.That(requestContentStream, Is.Not.Null.Or.Empty); | ||
|
||
var loginDto = await JsonSerializer.DeserializeAsync<TestLoginDto>(requestContentStream).ConfigureAwait(false); | ||
Assert.That(loginDto, Is.Not.Null); | ||
|
||
Assert.That(loginDto!.Email, Is.EqualTo(username)); | ||
Assert.That(loginDto!.Password, Is.EqualTo(expectedEncodedPassword)); | ||
|
||
Assert.That(sut.IsLoggedIn, Is.True); | ||
Assert.That(lookups, Is.Not.Null); | ||
Assert.That(lookups.Data, Is.Not.Null.Or.Empty); | ||
} | ||
|
||
[TestCaseSource(nameof(GetTestCasesWithUnencodedPasswords))] | ||
public async Task ValidateLoginRequestViaMethod(string username, string password, string expectedEncodedPassword) | ||
{ | ||
var options = new iRacingDataClientOptions | ||
{ | ||
RestoreCookies = null, | ||
SaveCookies = null, | ||
}; | ||
|
||
await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync)).ConfigureAwait(false); | ||
|
||
var sut = new DataClient(HttpClient, | ||
new TestLogger<DataClient>(), | ||
options, | ||
CookieContainer); | ||
|
||
sut.UseUsernameAndPassword(username, password); | ||
|
||
var lookups = await sut.GetLookupsAsync(CancellationToken.None).ConfigureAwait(false); | ||
|
||
var loginRequest = MessageHandler.Requests.Peek(); | ||
Assert.That(loginRequest, Is.Not.Null); | ||
|
||
var contentStreamTask = loginRequest.Content?.ReadAsStreamAsync() ?? Task.FromResult(Stream.Null); | ||
using var requestContentStream = await contentStreamTask.ConfigureAwait(false); | ||
Assert.That(requestContentStream, Is.Not.Null); | ||
Assert.That(requestContentStream, Is.Not.Null.Or.Empty); | ||
|
||
var loginDto = await JsonSerializer.DeserializeAsync<TestLoginDto>(requestContentStream).ConfigureAwait(false); | ||
Assert.That(loginDto, Is.Not.Null); | ||
|
||
Assert.That(loginDto!.Email, Is.EqualTo("[email protected]")); | ||
Assert.That(loginDto!.Password, Is.EqualTo("xGKecAR27ALXNuMLsGaG0v5Q9pSs2tZTZRKNgmHMg+Q=")); | ||
Assert.That(loginDto!.Email, Is.EqualTo(username)); | ||
Assert.That(loginDto!.Password, Is.EqualTo(expectedEncodedPassword)); | ||
|
||
Assert.That(sut.IsLoggedIn, Is.True); | ||
Assert.That(lookups, Is.Not.Null); | ||
Assert.That(lookups.Data, Is.Not.Null.Or.Empty); | ||
} | ||
|
||
public static IEnumerable<TestCaseData> GetTestCases() | ||
{ | ||
yield return new("[email protected]", "SuperSecretPassword", false, "nXmEFCdpHheD1R3XBVkm6VQavR7ZLbW7SRmzo/MfFso="); | ||
yield return new("[email protected]", "MyPassWord", false, "xGKecAR27ALXNuMLsGaG0v5Q9pSs2tZTZRKNgmHMg+Q="); | ||
|
||
yield return new("[email protected]", "nXmEFCdpHheD1R3XBVkm6VQavR7ZLbW7SRmzo/MfFso=", true, "nXmEFCdpHheD1R3XBVkm6VQavR7ZLbW7SRmzo/MfFso="); | ||
yield return new("[email protected]", "xGKecAR27ALXNuMLsGaG0v5Q9pSs2tZTZRKNgmHMg+Q=", true, "xGKecAR27ALXNuMLsGaG0v5Q9pSs2tZTZRKNgmHMg+Q="); | ||
} | ||
|
||
public static IEnumerable<TestCaseData> GetTestCasesWithUnencodedPasswords() | ||
{ | ||
yield return new("[email protected]", "SuperSecretPassword", "nXmEFCdpHheD1R3XBVkm6VQavR7ZLbW7SRmzo/MfFso="); | ||
yield return new("[email protected]", "MyPassWord", "xGKecAR27ALXNuMLsGaG0v5Q9pSs2tZTZRKNgmHMg+Q="); | ||
} | ||
|
||
private class TestLoginDto | ||
{ | ||
[JsonPropertyName("email")] | ||
|
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,11 +1,6 @@ | ||
Fixes / Changes: | ||
|
||
- TODO | ||
|
||
|
||
|
||
Contributions: | ||
|
||
- TODO | ||
- Accept Pre-Hashed Password (Issue #130) | ||
- Allow a user of the library the ability of using a pre-encoded password rather than the plain text. | ||
|
||
Thanks for helping out with pull requests to the library! |
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