Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2362: Set FailureType to AuthenticationFailure for auth exceptions #2367

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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