-
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.
Use Cookies Even Without "RestoreCookies"
Previously the code only checked the cookie container for relevant cookies if the "RestoreCookies" delegate was configured. This means that if the cookie container was populated some other way then the login process would be called again. Move the check for cookies which might be existing, valid authentication outside the check for "RestoreCookies" delegate to take advantage of any data the collection already contains.
- Loading branch information
1 parent
c476296
commit 0d873a6
Showing
2 changed files
with
38 additions
and
7 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 |
---|---|---|
|
@@ -97,4 +97,35 @@ public async Task GivenOptionsWithARestoreFuncTheFuncIsCalledToGetTheCookiesAsyn | |
Assert.That(cookies, Has.One.Property(nameof(Cookie.Name)).EqualTo("irsso_members")); | ||
Assert.That(cookies, Has.One.Property(nameof(Cookie.Name)).EqualTo("authtoken_members")); | ||
} | ||
|
||
[Test] | ||
public async Task GivenACookieContainerWithCookiesAndNoRestoreOrSaveFunctionsThenTheCookiesAreUsed() | ||
{ | ||
CookieContainer.Add(new Cookie("irsso_members", "one", "/", "members-ng.iracing.com")); | ||
CookieContainer.Add(new Cookie("authtoken_members", "two", "/", "members-ng.iracing.com")); | ||
|
||
var options = new iRacingDataClientOptions | ||
{ | ||
Username = "[email protected]", | ||
Password = "SuperSecretPassword", | ||
RestoreCookies = null, | ||
SaveCookies = null, | ||
}; | ||
|
||
using var sut = new DataClient(HttpClient, | ||
new TestLogger<DataClient>(), | ||
options, | ||
CookieContainer); | ||
|
||
await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync), false).ConfigureAwait(false); | ||
await sut.GetLookupsAsync(CancellationToken.None).ConfigureAwait(false); | ||
|
||
Assert.That(sut.IsLoggedIn, Is.True); | ||
|
||
var cookies = CookieContainer.GetAllCookies(); | ||
|
||
Assert.That(cookies, Has.Count.EqualTo(2)); | ||
Assert.That(cookies, Has.One.Property(nameof(Cookie.Name)).EqualTo("irsso_members")); | ||
Assert.That(cookies, Has.One.Property(nameof(Cookie.Name)).EqualTo("authtoken_members")); | ||
} | ||
} |
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