Skip to content

Commit 0aeb2d9

Browse files
Fix flaky test (#570)
* Fix flaky test Try and fix flaky Apple provider test by not validating token lifetimes and increasing the delay slightly. * Make the asserts easier to read Swap the order so the asserts make more sense if the test fails. * Wait longer before expiry The macOS machines seem to be a bit "slow" so it seems that the two initial generations where they should be the same end up different because it takes too long to complete. If this doesn't work, I'll just disable the test as it's redundant for the v6 release anyway.
1 parent 0d5b1d4 commit 0aeb2d9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test/AspNet.Security.OAuth.Providers.Tests/Apple/AppleClientSecretGeneratorTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@ await GenerateTokenAsync(Configure, async (context) =>
117117
public async Task GenerateAsync_Varies_Key_By_Options()
118118
{
119119
// Arrange
120-
var clientSecretExpiresAfter = TimeSpan.FromSeconds(2);
120+
var clientSecretExpiresAfter = TimeSpan.FromSeconds(3);
121121

122122
void ConfigureA(AppleAuthenticationOptions options)
123123
{
124124
options.ClientId = "my-client-id";
125125
options.ClientSecretExpiresAfter = clientSecretExpiresAfter;
126+
options.JwtSecurityTokenHandler = new FrozenJwtSecurityTokenHandler();
126127
options.KeyId = "my-key-id";
127128
options.TeamId = "my-team-id";
128129
options.PrivateKeyBytes = (_) => TestKeys.GetPrivateKeyBytesAsync();
@@ -132,7 +133,7 @@ void ConfigureA(AppleAuthenticationOptions options)
132133
{
133134
ClientId = "my-other-client-id",
134135
ClientSecretExpiresAfter = clientSecretExpiresAfter,
135-
JwtSecurityTokenHandler = new JwtSecurityTokenHandler(),
136+
JwtSecurityTokenHandler = new FrozenJwtSecurityTokenHandler(),
136137
KeyId = "my-other-key-id",
137138
TeamId = "my-other-team-id",
138139
PrivateKeyBytes = (_) => TestKeys.GetPrivateKeyBytesAsync(),
@@ -155,13 +156,13 @@ await GenerateTokenAsync(ConfigureA, async (contextA) =>
155156

156157
// Assert
157158
tokenA1.ShouldNotBeNullOrWhiteSpace();
158-
tokenA1.ShouldBe(tokenA2);
159+
tokenA2.ShouldBe(tokenA1);
159160
tokenB1.ShouldNotBeNullOrWhiteSpace();
160-
tokenB1.ShouldBe(tokenB2);
161-
tokenA1.ShouldNotBe(tokenB1);
161+
tokenB2.ShouldBe(tokenB1);
162+
tokenB1.ShouldNotBe(tokenA1);
162163

163164
// Act
164-
await Task.Delay(clientSecretExpiresAfter * 2);
165+
await Task.Delay(clientSecretExpiresAfter * 3);
165166

166167
string tokenA3 = await generator.GenerateAsync(contextA);
167168
string tokenB3 = await generator.GenerateAsync(contextB);

0 commit comments

Comments
 (0)