Skip to content

Commit

Permalink
Fix #2362: Set FailureType to AuthenticationFailure for auth exceptio…
Browse files Browse the repository at this point in the history
…ns (#2367)
  • Loading branch information
NickCraver authored Feb 8, 2023
1 parent d8aa7f8 commit b94a8cf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Current package versions:
## Unreleased

- Fix [#2350](https://github.com/StackExchange/StackExchange.Redis/issues/2350): Properly parse lua script paramters in all cultures ([#2351 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2351))
- Fix [#2362](https://github.com/StackExchange/StackExchange.Redis/issues/2362): Set `RedisConnectionException.FailureType` to `AuthenticationFailure` on all authentication scenarios for better handling ([#2367 by NickCraver](https://github.com/StackExchange/StackExchange.Redis/pull/2367))

## 2.6.90

Expand Down
4 changes: 3 additions & 1 deletion src/StackExchange.Redis/ExceptionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,12 @@ internal static Exception UnableToConnect(ConnectionMultiplexer muxer, string? f
{
var sb = new StringBuilder("It was not possible to connect to the redis server(s).");
Exception? inner = null;
var failureType = ConnectionFailureType.UnableToConnect;
if (muxer is not null)
{
if (muxer.AuthException is Exception aex)
{
failureType = ConnectionFailureType.AuthenticationFailure;
sb.Append(" There was an authentication failure; check that passwords (or client certificates) are configured correctly: (").Append(aex.GetType().Name).Append(") ").Append(aex.Message);
inner = aex;
if (aex is AuthenticationException && aex.InnerException is Exception iaex)
Expand All @@ -407,7 +409,7 @@ internal static Exception UnableToConnect(ConnectionMultiplexer muxer, string? f
sb.Append(' ').Append(failureMessage.Trim());
}

return new RedisConnectionException(ConnectionFailureType.UnableToConnect, sb.ToString(), inner);
return new RedisConnectionException(failureType, sb.ToString(), inner);
}

internal static Exception BeganProfilingWithDuplicateContext(object forContext)
Expand Down
3 changes: 2 additions & 1 deletion tests/StackExchange.Redis.Tests/SecureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public async Task ConnectWithWrongPassword(string password, string exepctedMessa

conn.GetDatabase().Ping();
}).ConfigureAwait(false);
Log("Exception: " + ex.Message);
Log($"Exception ({ex.FailureType}): {ex.Message}");
Assert.Equal(ConnectionFailureType.AuthenticationFailure, ex.FailureType);
Assert.StartsWith("It was not possible to connect to the redis server(s). There was an authentication failure; check that passwords (or client certificates) are configured correctly: (RedisServerException) ", ex.Message);

// This changed in some version...not sure which. For our purposes, splitting on v3 vs v6+
Expand Down

0 comments on commit b94a8cf

Please sign in to comment.