File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,17 @@ def database
161
161
end
162
162
163
163
def credentials
164
- @options [ :credentials ] || @url . userinfo &.split ( ":" )
164
+ @options [ :credentials ] || extract_userinfo ( @url . userinfo )
165
+ end
166
+
167
+ private def extract_userinfo ( userinfo )
168
+ if userinfo
169
+ credentials = userinfo . split ( ":" ) . reject ( &:empty? )
170
+
171
+ if credentials . any?
172
+ return credentials
173
+ end
174
+ end
165
175
end
166
176
167
177
def localhost?
Original file line number Diff line number Diff line change 12
12
13
13
let ( :endpoint ) { Async ::Redis . local_endpoint }
14
14
15
+ with '#credentials' do
16
+ it "can parse a url with username and password" do
17
+ endpoint = Async ::Redis ::Endpoint . parse ( "redis://testuser:testpassword@localhost" )
18
+ expect ( endpoint . credentials ) . to be == [ "testuser" , "testpassword" ]
19
+ end
20
+
21
+ it "can parse a url with a blank username and password" do
22
+ endpoint = Async ::Redis ::Endpoint . parse ( "redis://:testpassword@localhost" )
23
+ expect ( endpoint . credentials ) . to be == [ "testpassword" ]
24
+ end
25
+
26
+ it "can parse a url with a password only" do
27
+ endpoint = Async ::Redis ::Endpoint . parse ( "redis://testpassword@localhost" )
28
+ expect ( endpoint . credentials ) . to be == [ "testpassword" ]
29
+ end
30
+ end
31
+
15
32
with '#protocol' do
16
33
it "defaults to RESP2" do
17
34
expect ( endpoint . protocol ) . to be == Async ::Redis ::Protocol ::RESP2
You can’t perform that action at this time.
0 commit comments