@@ -83,6 +83,60 @@ public function testUnexpectedAuthPluginShouldEmitErrorOnAuthenticateCommandAndC
83
83
$ stream ->write ("\x43\0\0\0\x0a\x38\x2e\x34\x2e\x35\0\x5e\0\0\0\x08\x0c\x41\x44\x12\x5e\x69\x59\0\xff\xff\xff\x02\0\xff\xdf\x15\0\0\0\0\0\0\0\0\0\0\x3c\x2c\x5e\x54\x06\x04\x01\x61\x01\x20\x79\x1b\0\x73\x68\x61\x32\x35\x36\x5f\x70\x61\x73\x73\x77\x6f\x72\x64\0" );
84
84
}
85
85
86
+ public function testParseAuthSwitchRequestWillSendAuthSwitchResponsePacket ()
87
+ {
88
+ $ stream = new ThroughStream ();
89
+ $ stream ->on ('close ' , $ this ->expectCallableNever ());
90
+
91
+ $ outgoing = new ThroughStream ();
92
+ $ outgoing ->on ('data ' , $ this ->expectCallableOnceWith ("\x09\0\0\x01" . "encrypted " ));
93
+
94
+ $ executor = new Executor ();
95
+
96
+ $ command = $ this ->getMockBuilder ('React\Mysql\Commands\AuthenticateCommand ' )->disableOriginalConstructor ()->getMock ();
97
+ $ command ->expects ($ this ->once ())->method ('authResponse ' )->with ('scramble ' , 'caching_sha2_password ' )->willReturn ('encrypted ' );
98
+
99
+ $ parser = new Parser (new CompositeStream ($ stream , $ outgoing ), $ executor );
100
+ $ parser ->start ();
101
+
102
+ $ ref = new \ReflectionProperty ($ parser , 'phase ' );
103
+ $ ref ->setAccessible (true );
104
+ $ ref ->setValue ($ parser , Parser::PHASE_AUTH_SENT );
105
+
106
+ $ ref = new \ReflectionProperty ($ parser , 'currCommand ' );
107
+ $ ref ->setAccessible (true );
108
+ $ ref ->setValue ($ parser , $ command );
109
+
110
+ $ stream ->write ("\x20\0\0\0" . "\xfe" . "caching_sha2_password " . "\0" . "scramble " . "\0" );
111
+ }
112
+
113
+ public function testParseAuthSwitchRequestWithUnexpectedAuthPluginWillEmitErrorAndCloseConnection ()
114
+ {
115
+ $ stream = new ThroughStream ();
116
+ $ stream ->on ('close ' , $ this ->expectCallableOnce ());
117
+
118
+ $ outgoing = new ThroughStream ();
119
+ $ outgoing ->on ('data ' , $ this ->expectCallableNever ());
120
+
121
+ $ command = new AuthenticateCommand ('root ' , '' , 'test ' , 'utf8mb4 ' );
122
+ $ command ->on ('error ' , $ this ->expectCallableOnceWith (new \UnexpectedValueException ('Unknown authentication plugin "sha256_password" requested by server ' )));
123
+
124
+ $ executor = new Executor ();
125
+
126
+ $ parser = new Parser (new CompositeStream ($ stream , $ outgoing ), $ executor );
127
+ $ parser ->start ();
128
+
129
+ $ ref = new \ReflectionProperty ($ parser , 'phase ' );
130
+ $ ref ->setAccessible (true );
131
+ $ ref ->setValue ($ parser , Parser::PHASE_AUTH_SENT );
132
+
133
+ $ ref = new \ReflectionProperty ($ parser , 'currCommand ' );
134
+ $ ref ->setAccessible (true );
135
+ $ ref ->setValue ($ parser , $ command );
136
+
137
+ $ stream ->write ("\x19\0\0\0" . "\xfe" . "sha256_password " . "\0" . "scramble " . "\0" );
138
+ }
139
+
86
140
public function testParseAuthMoreDataWithFastAuthSuccessWillPrintDebugLogAndWaitForOkPacketWithoutSendingPacket ()
87
141
{
88
142
$ stream = new ThroughStream ();
@@ -167,7 +221,7 @@ public function testParseAuthMoreDataWithCertificateWillSendEncryptedPassword()
167
221
$ stream ->write ("\x04\0\0\0" . "\x01--- " );
168
222
}
169
223
170
- public function testAuthMoreDataWithCertificateWillEmitErrorAndCloseConnectionWhenEncryptingPasswordThrows ()
224
+ public function testParseAuthMoreDataWithCertificateWillEmitErrorAndCloseConnectionWhenEncryptingPasswordThrows ()
171
225
{
172
226
$ stream = new ThroughStream ();
173
227
$ stream ->on ('close ' , $ this ->expectCallableOnce ());
0 commit comments