Skip to content

Commit b94a8cf

Browse files
authored
Fix #2362: Set FailureType to AuthenticationFailure for auth exceptions (#2367)
1 parent d8aa7f8 commit b94a8cf

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Current package versions:
99
## Unreleased
1010

1111
- 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))
12+
- 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))
1213

1314
## 2.6.90
1415

src/StackExchange.Redis/ExceptionFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,12 @@ internal static Exception UnableToConnect(ConnectionMultiplexer muxer, string? f
386386
{
387387
var sb = new StringBuilder("It was not possible to connect to the redis server(s).");
388388
Exception? inner = null;
389+
var failureType = ConnectionFailureType.UnableToConnect;
389390
if (muxer is not null)
390391
{
391392
if (muxer.AuthException is Exception aex)
392393
{
394+
failureType = ConnectionFailureType.AuthenticationFailure;
393395
sb.Append(" There was an authentication failure; check that passwords (or client certificates) are configured correctly: (").Append(aex.GetType().Name).Append(") ").Append(aex.Message);
394396
inner = aex;
395397
if (aex is AuthenticationException && aex.InnerException is Exception iaex)
@@ -407,7 +409,7 @@ internal static Exception UnableToConnect(ConnectionMultiplexer muxer, string? f
407409
sb.Append(' ').Append(failureMessage.Trim());
408410
}
409411

410-
return new RedisConnectionException(ConnectionFailureType.UnableToConnect, sb.ToString(), inner);
412+
return new RedisConnectionException(failureType, sb.ToString(), inner);
411413
}
412414

413415
internal static Exception BeganProfilingWithDuplicateContext(object forContext)

tests/StackExchange.Redis.Tests/SecureTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public async Task ConnectWithWrongPassword(string password, string exepctedMessa
7676

7777
conn.GetDatabase().Ping();
7878
}).ConfigureAwait(false);
79-
Log("Exception: " + ex.Message);
79+
Log($"Exception ({ex.FailureType}): {ex.Message}");
80+
Assert.Equal(ConnectionFailureType.AuthenticationFailure, ex.FailureType);
8081
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);
8182

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

0 commit comments

Comments
 (0)