File tree Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Expand file tree Collapse file tree 3 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -134,12 +134,13 @@ $factory->createClient('redis://localhost:6379');
134
134
135
135
Redis supports password-based authentication (` AUTH ` command). Note that Redis'
136
136
authentication mechanism does not employ a username, so you can pass the
137
- password "secret" as part of the URI like this:
137
+ password ` h@llo ` URL-encoded (percent-encoded) as part of the URI like this:
138
138
139
139
``` php
140
- // both forms are equivalent
141
- $factory->createClient('redis://ignored:secret@localhost');
142
- $factory->createClient('redis://localhost?password=secret');
140
+ // all forms are equivalent
141
+ $factory->createClient('redis://:h%40llo@localhost');
142
+ $factory->createClient('redis://ignored:h%40llo@localhost');
143
+ $factory->createClient('redis://localhost?password=h%40llo');
143
144
```
144
145
145
146
> Legacy notice: The ` redis:// ` scheme is defined and preferred as of ` v1.2.0 ` .
Original file line number Diff line number Diff line change @@ -123,10 +123,10 @@ private function parseUrl($target)
123
123
124
124
$ auth = null ;
125
125
if (isset ($ parts ['user ' ]) && $ parts ['scheme ' ] === 'tcp ' ) {
126
- $ auth = $ parts ['user ' ];
126
+ $ auth = rawurldecode ( $ parts ['user ' ]) ;
127
127
}
128
128
if (isset ($ parts ['pass ' ])) {
129
- $ auth .= ($ parts ['scheme ' ] === 'tcp ' ? ': ' : '' ) . $ parts ['pass ' ];
129
+ $ auth .= ($ parts ['scheme ' ] === 'tcp ' ? ': ' : '' ) . rawurldecode ( $ parts ['pass ' ]) ;
130
130
}
131
131
if ($ auth !== null ) {
132
132
$ parts ['auth ' ] = $ auth ;
Original file line number Diff line number Diff line change @@ -86,6 +86,15 @@ public function testWillWriteAuthCommandIfRedisUriContainsUserInfo()
86
86
$ this ->
factory ->
createClient (
'redis://hello:[email protected] ' );
87
87
}
88
88
89
+ public function testWillWriteAuthCommandIfRedisUriContainsEncodedUserInfo ()
90
+ {
91
+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
92
+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nh@llo \r\n" );
93
+
94
+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (Promise \resolve ($ stream ));
95
+ $ this ->
factory ->
createClient (
'redis://:h%[email protected] ' );
96
+ }
97
+
89
98
public function testWillWriteAuthCommandIfTargetContainsPasswordQueryParameter ()
90
99
{
91
100
$ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
@@ -95,6 +104,15 @@ public function testWillWriteAuthCommandIfTargetContainsPasswordQueryParameter()
95
104
$ this ->factory ->createClient ('redis://example.com?password=secret ' );
96
105
}
97
106
107
+ public function testWillWriteAuthCommandIfTargetContainsEncodedPasswordQueryParameter ()
108
+ {
109
+ $ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
110
+ $ stream ->expects ($ this ->once ())->method ('write ' )->with ("*2 \r\n$4 \r\nauth \r\n$5 \r\nh@llo \r\n" );
111
+
112
+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('example.com:6379 ' )->willReturn (Promise \resolve ($ stream ));
113
+ $ this ->factory ->createClient ('redis://example.com?password=h%40llo ' );
114
+ }
115
+
98
116
public function testWillWriteAuthCommandIfRedissUriContainsUserInfo ()
99
117
{
100
118
$ stream = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
You can’t perform that action at this time.
0 commit comments