-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add possibility to use different passwords for Sentinel and Redis host (#1698) #3140
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
base: main
Are you sure you want to change the base?
Changes from all commits
0a0e9fe
262b459
b88180e
f5f9530
982095e
f05f5aa
42ff65c
96dcc8a
b151f99
12e3d37
4030837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #nullable enable | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should all just be in PublicAPI.Unshipped.txt - it isn't feature-specific |
||
| StackExchange.Redis.ConfigurationOptions.SentinelUser.get -> string? | ||
| StackExchange.Redis.ConfigurationOptions.SentinelUser.set -> void | ||
| StackExchange.Redis.ConfigurationOptions.SentinelPassword.get -> string? | ||
| StackExchange.Redis.ConfigurationOptions.SentinelPassword.set -> void | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -957,13 +957,15 @@ private async Task HandshakeAsync(PhysicalConnection connection, ILogger? log) | |
| Multiplexer.Trace("No connection!?"); | ||
| return; | ||
| } | ||
|
|
||
| Message msg; | ||
| // Note that we need "" (not null) for password in the case of 'nopass' logins | ||
| var config = Multiplexer.RawConfig; | ||
| string? user = config.User; | ||
| string password = config.Password ?? ""; | ||
| var isSentinelConnection = Multiplexer.ServerSelectionStrategy.ServerType == ServerType.Sentinel; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this not be checking something like is fine, without the explicit |
||
| var user = isSentinelConnection ? config.SentinelUser : config.User; | ||
| // Note that we need "" (not null) for password in the case of 'nopass' logins | ||
| var password = (isSentinelConnection ? config.SentinelPassword : config.Password) ?? ""; | ||
| var clientName = Multiplexer.ClientName; | ||
|
|
||
| string clientName = Multiplexer.ClientName; | ||
| if (!string.IsNullOrWhiteSpace(clientName)) | ||
| { | ||
| clientName = nameSanitizer.Replace(clientName, ""); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| using System; | ||
| using Xunit; | ||
|
|
||
| namespace StackExchange.Redis.Tests; | ||
|
|
||
| public class SentinelConfigTests | ||
| { | ||
| [Fact] | ||
| public void Parse_SentinelCredentials_FromConnectionString() | ||
| { | ||
| var cs = "localhost:26379,serviceName=myprimary,sentinelUser=su,sentinelPassword=sp"; | ||
| var options = ConfigurationOptions.Parse(cs); | ||
|
|
||
| Assert.Equal("su", options.SentinelUser); | ||
| Assert.Equal("sp", options.SentinelPassword); | ||
| Assert.Equal("myprimary", options.ServiceName); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToString_Masks_SentinelPassword_WhenExcluded() | ||
| { | ||
| var options = new ConfigurationOptions(); | ||
| options.EndPoints.Add("localhost", 26379); | ||
| options.ServiceName = "myprimary"; | ||
| options.SentinelUser = "su"; | ||
| options.SentinelPassword = "secret"; | ||
|
|
||
| var repr = options.ToString(includePassword: false); | ||
|
|
||
| Assert.Contains("sentinelUser=su", repr); | ||
| Assert.Contains("sentinelPassword=*****", repr); | ||
| Assert.DoesNotContain("secret", repr); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Clone_Preserves_SentinelCredentials() | ||
| { | ||
| var options = new ConfigurationOptions(); | ||
| options.SentinelUser = "su"; | ||
| options.SentinelPassword = "sp"; | ||
|
|
||
| var clone = options.Clone(); | ||
|
|
||
| Assert.Equal(options.SentinelUser, clone.SentinelUser); | ||
| Assert.Equal(options.SentinelPassword, clone.SentinelPassword); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.