@@ -129,63 +129,56 @@ def test_sentinel_failover_prioritize_healthy_sentinel
129
129
end
130
130
131
131
def test_sentinel_with_non_sentinel_options
132
- sentinels = [ { :host => "127.0.0.1" , :port => 26381 } ]
133
-
134
- commands = {
135
- :s1 => [ ] ,
136
- :m1 => [ ]
137
- }
132
+ commands = { s1 : [ ] , m1 : [ ] }
138
133
139
134
sentinel = lambda do |port |
140
135
{
141
- : auth => lambda do |pass |
142
- commands [ :s1 ] << [ " auth" , pass ]
136
+ auth : lambda do |pass |
137
+ commands [ :s1 ] << [ ' auth' , pass ]
143
138
'+OK'
144
139
end ,
145
- : select => lambda do |db |
146
- commands [ :s1 ] << [ " select" , db ]
140
+ select : lambda do |db |
141
+ commands [ :s1 ] << [ ' select' , db ]
147
142
"-ERR unknown command 'select'"
148
143
end ,
149
- : sentinel => lambda do |command , *args |
144
+ sentinel : lambda do |command , *args |
150
145
commands [ :s1 ] << [ command , *args ]
151
- [ " 127.0.0.1" , port . to_s ]
146
+ [ ' 127.0.0.1' , port . to_s ]
152
147
end
153
148
}
154
149
end
155
150
156
151
master = {
157
- : auth => lambda do |pass |
158
- commands [ :m1 ] << [ " auth" , pass ]
159
- " +OK"
152
+ auth : lambda do |pass |
153
+ commands [ :m1 ] << [ ' auth' , pass ]
154
+ ' +OK'
160
155
end ,
161
- : role => lambda do
162
- commands [ :m1 ] << [ " role" ]
163
- [ " master" ]
156
+ role : lambda do
157
+ commands [ :m1 ] << [ ' role' ]
158
+ [ ' master' ]
164
159
end
165
160
}
166
161
167
162
RedisMock . start ( master ) do |master_port |
168
163
RedisMock . start ( sentinel . call ( master_port ) ) do |sen_port |
169
- sentinels [ 0 ] [ :port ] = sen_port
170
- redis = Redis . new ( :url => "redis://:foo@master1/15" , :sentinels => sentinels , :role => :master )
171
-
164
+ s = [ { host : '127.0.0.1' , port : sen_port } ]
165
+ redis = Redis . new ( url : 'redis://:foo@master1/15' , sentinels : s , role : :master )
172
166
assert redis . ping
173
167
end
174
168
end
175
169
176
- assert_equal [ %w[ auth foo ] , %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
170
+ assert_equal [ %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
177
171
assert_equal [ %w[ auth foo ] , %w[ role ] ] , commands [ :m1 ]
178
172
end
179
173
180
- def test_sentinel_authentication_in_redis_prior_to_version_five
181
- sentinels = [ { host : '127.0.0.1' , port : 26381 } ]
174
+ def test_authentication_for_sentinel
182
175
commands = { s1 : [ ] , m1 : [ ] }
183
176
184
177
sentinel = lambda do |port |
185
178
{
186
179
auth : lambda do |pass |
187
180
commands [ :s1 ] << [ 'auth' , pass ]
188
- '-ERR unknown command `auth` '
181
+ '+OK '
189
182
end ,
190
183
select : lambda do |db |
191
184
commands [ :s1 ] << [ 'select' , db ]
@@ -201,7 +194,7 @@ def test_sentinel_authentication_in_redis_prior_to_version_five
201
194
master = {
202
195
auth : lambda do |pass |
203
196
commands [ :m1 ] << [ 'auth' , pass ]
204
- '+OK '
197
+ '-ERR Client sent AUTH, but no password is set '
205
198
end ,
206
199
role : lambda do
207
200
commands [ :m1 ] << [ 'role' ]
@@ -211,18 +204,57 @@ def test_sentinel_authentication_in_redis_prior_to_version_five
211
204
212
205
RedisMock . start ( master ) do |master_port |
213
206
RedisMock . start ( sentinel . call ( master_port ) ) do |sen_port |
214
- sentinels [ 0 ] [ :port ] = sen_port
215
- redis = Redis . new ( url : 'redis:// master1' ,
216
- sentinels : sentinels ,
217
- role : :master ,
218
- password : 'foo' )
207
+ s = [ { host : '127.0.0.1' , port : sen_port , password : 'foo' } ]
208
+ r = Redis . new ( host : 'master1' , sentinels : s , role : :master )
209
+ assert r . ping
210
+ end
211
+ end
219
212
220
- assert redis . ping
213
+ assert_equal [ %w[ auth foo ] , %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
214
+ assert_equal [ %w[ role ] ] , commands [ :m1 ]
215
+ end
216
+
217
+ def test_authentication_for_sentinel_and_redis
218
+ commands = { s1 : [ ] , m1 : [ ] }
219
+
220
+ sentinel = lambda do |port |
221
+ {
222
+ auth : lambda do |pass |
223
+ commands [ :s1 ] << [ 'auth' , pass ]
224
+ '+OK'
225
+ end ,
226
+ select : lambda do |db |
227
+ commands [ :s1 ] << [ 'select' , db ]
228
+ '-ERR unknown command `select`'
229
+ end ,
230
+ sentinel : lambda do |command , *args |
231
+ commands [ :s1 ] << [ command , *args ]
232
+ [ '127.0.0.1' , port . to_s ]
233
+ end
234
+ }
235
+ end
236
+
237
+ master = {
238
+ auth : lambda do |pass |
239
+ commands [ :m1 ] << [ 'auth' , pass ]
240
+ '+OK'
241
+ end ,
242
+ role : lambda do
243
+ commands [ :m1 ] << [ 'role' ]
244
+ [ 'master' ]
245
+ end
246
+ }
247
+
248
+ RedisMock . start ( master ) do |master_port |
249
+ RedisMock . start ( sentinel . call ( master_port ) ) do |sen_port |
250
+ s = [ { host : '127.0.0.1' , port : sen_port , password : 'foo' } ]
251
+ r = Redis . new ( host : 'master1' , sentinels : s , role : :master , password : 'bar' )
252
+ assert r . ping
221
253
end
222
254
end
223
255
224
256
assert_equal [ %w[ auth foo ] , %w[ get-master-addr-by-name master1 ] ] , commands [ :s1 ]
225
- assert_equal [ %w[ auth foo ] , %w[ role ] ] , commands [ :m1 ]
257
+ assert_equal [ %w[ auth bar ] , %w[ role ] ] , commands [ :m1 ]
226
258
end
227
259
228
260
def test_sentinel_role_mismatch
0 commit comments