Skip to content

Commit b140a36

Browse files
committed
Issue #218 Address PR comments with minot updates to XUnit usage and log message formats
1 parent ff53cd2 commit b140a36

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/shared/Atlassian.Bitbucket.Tests/BitbucketHostProviderTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ public async Task BitbucketHostProvider_StoreCredentialAsync(string protocol, st
361361

362362
var provider = new BitbucketHostProvider(context, bitbucketAuthentication.Object, bitbucketApi.Object);
363363

364-
Assert.Equal(context.CredentialStore.Count, 0);
364+
Assert.Equal(0, context.CredentialStore.Count);
365365

366366
await provider.StoreCredentialAsync(input);
367367

368-
Assert.Equal(context.CredentialStore.Count, 1);
368+
Assert.Equal(1, context.CredentialStore.Count);
369369
}
370370

371371
[Theory]
@@ -380,11 +380,11 @@ public async Task BitbucketHostProvider_EraseCredentialAsync(string protocol, st
380380

381381
var provider = new BitbucketHostProvider(context, bitbucketAuthentication.Object, bitbucketApi.Object);
382382

383-
Assert.Equal(context.CredentialStore.Count, 1);
383+
Assert.Equal(1, context.CredentialStore.Count);
384384

385385
await provider.EraseCredentialAsync(input);
386386

387-
Assert.Equal(context.CredentialStore.Count, 0);
387+
Assert.Equal(0, context.CredentialStore.Count);
388388
}
389389

390390
#endregion

src/shared/Atlassian.Bitbucket.Tests/BitbucketOauth2ClientTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private void VerifyOAuth2TokenResult(OAuth2TokenResult result)
7979
Assert.Equal(refresh_token, result.RefreshToken);
8080
IEnumerable<char> tokenType = null;
8181
Assert.Equal(tokenType, result.TokenType);
82-
Assert.Equal(null, result.Scopes);
82+
Assert.Null(result.Scopes);
8383
}
8484

8585
private void VerifyAuthorizationCodeResult(OAuth2AuthorizationCodeResult result)

src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public bool IsSupported(HttpResponseMessage response)
6565
}
6666

6767
// Identify Bitbucket on-prem instances from the HTTP response using the Atlassian specific header X-AREQUESTID
68-
var supported = response.Headers.Contains("X-AREQUESTID");
68+
var supported = response.Headers.Contains("X-AREQUESTID");
6969

7070
_context.Trace.WriteLine($"Host is{(supported ? null : "n't")} supported as Bitbucket");
7171

@@ -94,8 +94,8 @@ private static void ValidateTargetUri(InputArguments input)
9494

9595
private async Task<ICredential> GetStoredCredentials(InputArguments input)
9696
{
97-
if (_context.Settings.TryGetSetting(BitbucketConstants.EnvironmentVariables.AlwaysRefreshCredentials,
98-
Constants.GitConfiguration.Credential.SectionName, BitbucketConstants.GitConfiguration.Credential.AlwaysRefreshCredentials,
97+
if (_context.Settings.TryGetSetting(BitbucketConstants.EnvironmentVariables.AlwaysRefreshCredentials,
98+
Constants.GitConfiguration.Credential.SectionName, BitbucketConstants.GitConfiguration.Credential.AlwaysRefreshCredentials,
9999
out string alwaysRefreshCredentials) && alwaysRefreshCredentials.ToBooleanyOrDefault(false))
100100
{
101101
_context.Trace.WriteLine($"Ignore stored credentials");
@@ -110,14 +110,15 @@ private async Task<ICredential> GetStoredCredentials(InputArguments input)
110110

111111
if (credentials == null)
112112
{
113-
_context.Trace.WriteLine($" Found none");
113+
_context.Trace.WriteLine($"No stored credentials found");
114114
return null;
115115
}
116116

117-
_context.Trace.WriteLineSecrets($" Found credentials: {credentials.Account}/{{0}}", new object[] {credentials.Password});
118-
119-
//check credentials are still valid
120-
if (!await ValidateCredentialsWork(input, credentials, GetSupportedAuthenticationModes(targetUri))) {
117+
_context.Trace.WriteLineSecrets($"Found stored credentials: {credentials.Account}/{{0}}", new object[] { credentials.Password });
118+
119+
// Check credentials are still valid
120+
if (!await ValidateCredentialsWork(input, credentials, GetSupportedAuthenticationModes(targetUri)))
121+
{
121122
return null;
122123
}
123124

@@ -139,7 +140,7 @@ private async Task<ICredential> GetRefreshedCredentials(InputArguments input)
139140
ICredential refreshToken = SupportsOAuth(authModes) ? _context.CredentialStore.Get(refreshTokenService, input.UserName) : null;
140141
if (refreshToken is null)
141142
{
142-
_context.Trace.WriteLine($" Found none");
143+
_context.Trace.WriteLine($"No stored refresh token found");
143144
// There is no refresh token either because this is a non-2FA enabled account (where OAuth is not
144145
// required), or because we previously erased the RT.
145146

@@ -156,7 +157,7 @@ private async Task<ICredential> GetRefreshedCredentials(InputArguments input)
156157
{
157158
return basicCredentials;
158159
}
159-
160+
160161
// Fall through to the start of the interactive OAuth authentication flow
161162
}
162163

@@ -178,7 +179,7 @@ private async Task<ICredential> GetRefreshedCredentials(InputArguments input)
178179
}
179180
else
180181
{
181-
_context.Trace.WriteLine($" Found refresh token: {refreshToken} ");
182+
_context.Trace.WriteLineSecrets($"Found stored refresh token: {{0}}", new object[] { refreshToken });
182183

183184
// It's very likely that any access token expired between the last time we used/stored it.
184185
// To ensure the AT is as 'fresh' as it can be, always first try to use the refresh token
@@ -379,7 +380,7 @@ private async Task<string> ResolveBasicAuthUserNameAsync(string username, string
379380

380381
private async Task<bool> RequiresTwoFactorAuthenticationAsync(ICredential credentials, AuthenticationModes authModes)
381382
{
382-
_context.Trace.WriteLineSecrets($"Check if 2FA si required for credentials ({credentials.Account}/{{0}}) {authModes} ...", new object[] {credentials.Password});
383+
_context.Trace.WriteLineSecrets($"Check if 2FA si required for credentials ({credentials.Account}/{{0}}) {authModes} ...", new object[] { credentials.Password });
383384

384385
if (!SupportsOAuth(authModes))
385386
{
@@ -407,7 +408,7 @@ private async Task<bool> RequiresTwoFactorAuthenticationAsync(ICredential creden
407408
}
408409
}
409410

410-
private async Task<bool> ValidateCredentialsWork(InputArguments input, ICredential credentials, AuthenticationModes authModes)
411+
private async Task<bool> ValidateCredentialsWork(InputArguments input, ICredential credentials, AuthenticationModes authModes)
411412
{
412413
if (credentials == null)
413414
{
@@ -419,7 +420,7 @@ private async Task<bool> ValidateCredentialsWork(InputArguments input, ICredenti
419420
// This would be more efficient than having to make REST API calls to check.
420421

421422
var targetUri = input.GetRemoteUri();
422-
_context.Trace.WriteLineSecrets($"Validate credentials ({credentials.Account}/{{0}}) are fresh for {targetUri} ...", new object[] {credentials.Password});
423+
_context.Trace.WriteLineSecrets($"Validate credentials ({credentials.Account}/{{0}}) are fresh for {targetUri} ...", new object[] { credentials.Password });
423424

424425
if (!IsBitbucketOrg(targetUri))
425426
{
@@ -440,7 +441,7 @@ private async Task<bool> ValidateCredentialsWork(InputArguments input, ICredenti
440441
_context.Trace.WriteLine("Validated existing credentials using OAuth");
441442
return true;
442443
}
443-
catch(Exception)
444+
catch (Exception)
444445
{
445446
_context.Trace.WriteLine("Failed to validate existing credentials using OAuth");
446447
}
@@ -454,7 +455,7 @@ private async Task<bool> ValidateCredentialsWork(InputArguments input, ICredenti
454455
_context.Trace.WriteLine("Validated existing credentials using BasicAuth");
455456
return true;
456457
}
457-
catch(Exception)
458+
catch (Exception)
458459
{
459460
_context.Trace.WriteLine("Failed to validate existing credentials using Basic Auth");
460461
return false;
@@ -475,7 +476,7 @@ private static string GetRefreshTokenServiceName(InputArguments input)
475476

476477
// The refresh token key never includes the path component.
477478
// Instead we use the path component to specify this is the "refresh_token".
478-
Uri uri = new UriBuilder(baseUri) {Path = "/refresh_token"}.Uri;
479+
Uri uri = new UriBuilder(baseUri) { Path = "/refresh_token" }.Uri;
479480

480481
return uri.AbsoluteUri.TrimEnd('/');
481482
}

0 commit comments

Comments
 (0)