Skip to content

Commit

Permalink
Merge pull request #195 from AdrianJSClark/185-auth-concurrency-issues
Browse files Browse the repository at this point in the history
Implement Locking for Authentication
  • Loading branch information
AdrianJSClark authored Nov 27, 2023
2 parents 9684ffa + de92896 commit da1e5cf
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1369,4 +1369,13 @@ public async Task GetSpectatorSubsessionIdentifiersAsync()
.And.Property(nameof(SpectatorSubsessionIds.Success)).EqualTo(true)
.And.Property(nameof(SpectatorSubsessionIds.SubsessionIdentifiers)).Length.EqualTo(192));
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
sut?.Dispose();
}
base.Dispose(disposing);
}
}
24 changes: 12 additions & 12 deletions src/Aydsko.iRacingData.UnitTests/CookiePersistenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public async Task GivenOptionsWithNullDelegateValuesWhenAMethodIsCalledThenItWil
Password = "obviously.fake.password.value",
};

var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);
using var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);

await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync)).ConfigureAwait(false);
await sut.GetLookupsAsync(CancellationToken.None).ConfigureAwait(false);
Expand All @@ -47,10 +47,10 @@ public async Task GivenOptionsWithASaveActionTheSaveActionIsCalledWithTheCookies
Password = "obviously.fake.password.value",
};

var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);
using var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);

await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync)).ConfigureAwait(false);
await sut.GetLookupsAsync(CancellationToken.None).ConfigureAwait(false);
Expand Down Expand Up @@ -79,10 +79,10 @@ public async Task GivenOptionsWithARestoreFuncTheFuncIsCalledToGetTheCookiesAsyn
SaveCookies = null,
};

var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);
using var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);

await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync)).ConfigureAwait(false);
await sut.GetLookupsAsync(CancellationToken.None).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@ public async Task GivenSuzukaTrack_ThenGetTrackAssetScreenshotUrisReturnsCorrect
Assert.That(suzukaResults, Contains.Item(new Uri("https://dqfp1ltauszrc.cloudfront.net/public/track-maps-screenshots/114_screenshots/04.jpg")));
});
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
sut?.Dispose();
}
base.Dispose(disposing);
}
}
32 changes: 16 additions & 16 deletions src/Aydsko.iRacingData.UnitTests/LoginViaOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public async Task ValidateLoginRequestViaOptionsAsync(string username, string pa
SaveCookies = null,
};

var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);
using var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);

await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync)).ConfigureAwait(false);
var lookups = await sut.GetLookupsAsync(CancellationToken.None).ConfigureAwait(false);
Expand Down Expand Up @@ -64,10 +64,10 @@ public async Task ValidateLoginRequestViaMethodWithPasswordIsEncodedParamAsync(s

await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync)).ConfigureAwait(false);

var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);
using var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);

sut.UseUsernameAndPassword(username, password, passwordIsEncoded);

Expand Down Expand Up @@ -100,10 +100,10 @@ public async Task ValidateLoginRequestViaMethodAsync(string username, string pas

await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync)).ConfigureAwait(false);

var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);
using var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);

sut.UseUsernameAndPassword(username, password);

Expand Down Expand Up @@ -153,10 +153,10 @@ public async Task LoginIsNotCalledIfCookiesAreSuccessfullyRestoredAsync(string u

await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetLookupsSuccessfulAsync), false).ConfigureAwait(false);

var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);
using var sut = new DataClient(HttpClient,
new TestLogger<DataClient>(),
options,
CookieContainer);

sut.UseUsernameAndPassword(username, password);

Expand Down
28 changes: 19 additions & 9 deletions src/Aydsko.iRacingData.UnitTests/TrackScreenshotServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ namespace Aydsko.iRacingData.UnitTests;
internal sealed class TrackScreenshotServiceTests : MockedHttpTestBase
{
// NUnit will ensure that "SetUp" runs before each test so these can all be forced to "null".
private DataClient dataClient = null!;
private TrackScreenshotService sut = null!;

[SetUp]
public async Task SetUpAsync()
{
BaseSetUp();
var dataClient = new DataClient(HttpClient,
new TestLogger<DataClient>(),
new iRacingDataClientOptions()
{
Username = "[email protected]",
Password = "SuperSecretPassword",
CurrentDateTimeSource = () => new DateTimeOffset(2022, 04, 05, 0, 0, 0, TimeSpan.Zero)
},
new System.Net.CookieContainer());
dataClient = new DataClient(HttpClient,
new TestLogger<DataClient>(),
new iRacingDataClientOptions()
{
Username = "[email protected]",
Password = "SuperSecretPassword",
CurrentDateTimeSource = () => new DateTimeOffset(2022, 04, 05, 0, 0, 0, TimeSpan.Zero)
},
new System.Net.CookieContainer());

// Make use of our captured responses.
await MessageHandler.QueueResponsesAsync(nameof(CapturedResponseValidationTests.GetTracksSuccessfulAsync)).ConfigureAwait(false);
Expand Down Expand Up @@ -67,5 +68,14 @@ public async Task GivenSuzukaTrackId_ThenGetScreenshotsByTrackIdReturnsCorrectRe
Assert.That(suzukaResults, Contains.Item(new Uri("https://dqfp1ltauszrc.cloudfront.net/public/track-maps-screenshots/114_screenshots/04.jpg")));
});
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
dataClient?.Dispose();
}
base.Dispose(disposing);
}
}
#pragma warning restore CS0618 // Type or member is obsolete
Loading

0 comments on commit da1e5cf

Please sign in to comment.