(t *testing.T)
| 163 | } |
| 164 | |
| 165 | func TestAuthFastCachingSHA256PasswordFullRSA(t *testing.T) { |
| 166 | conn, mc := newRWMockConn(1) |
| 167 | mc.cfg.User = "root" |
| 168 | mc.cfg.Passwd = "secret" |
| 169 | |
| 170 | authData := []byte{6, 81, 96, 114, 14, 42, 50, 30, 76, 47, 1, 95, 126, 81, |
| 171 | 62, 94, 83, 80, 52, 85} |
| 172 | plugin := "caching_sha2_password" |
| 173 | |
| 174 | // Send Client Authentication Packet |
| 175 | authResp, err := mc.auth(authData, plugin) |
| 176 | if err != nil { |
| 177 | t.Fatal(err) |
| 178 | } |
| 179 | err = mc.writeHandshakeResponsePacket(authResp, plugin) |
| 180 | if err != nil { |
| 181 | t.Fatal(err) |
| 182 | } |
| 183 | |
| 184 | // check written auth response |
| 185 | authRespStart := 4 + 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1 |
| 186 | authRespEnd := authRespStart + 1 + len(authResp) |
| 187 | writtenAuthRespLen := conn.written[authRespStart] |
| 188 | writtenAuthResp := conn.written[authRespStart+1 : authRespEnd] |
| 189 | expectedAuthResp := []byte{171, 201, 138, 146, 89, 159, 11, 170, 0, 67, 165, |
| 190 | 49, 175, 94, 218, 68, 177, 109, 110, 86, 34, 33, 44, 190, 67, 240, 70, |
| 191 | 110, 40, 139, 124, 41} |
| 192 | if writtenAuthRespLen != 32 || !bytes.Equal(writtenAuthResp, expectedAuthResp) { |
| 193 | t.Fatalf("unexpected written auth response (%d bytes): %v", writtenAuthRespLen, writtenAuthResp) |
| 194 | } |
| 195 | conn.written = nil |
| 196 | |
| 197 | // auth response |
| 198 | conn.data = []byte{ |
| 199 | 2, 0, 0, 2, 1, 4, // Perform Full Authentication |
| 200 | } |
| 201 | conn.queuedReplies = [][]byte{ |
| 202 | // pub key response |
| 203 | append([]byte{byte(1 + len(testPubKey)), 1, 0, 4, 1}, testPubKey...), |
| 204 | |
| 205 | // OK |
| 206 | {7, 0, 0, 6, 0, 0, 0, 2, 0, 0, 0}, |
| 207 | } |
| 208 | conn.maxReads = 3 |
| 209 | |
| 210 | // Handle response to auth packet |
| 211 | if err := mc.handleAuthResult(authData, plugin); err != nil { |
| 212 | t.Errorf("got error: %v", err) |
| 213 | } |
| 214 | |
| 215 | if !bytes.HasPrefix(conn.written, []byte{1, 0, 0, 3, 2, 0, 1, 0, 5}) { |
| 216 | t.Errorf("unexpected written data: %v", conn.written) |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | func TestAuthFastCachingSHA256PasswordFullRSAWithKey(t *testing.T) { |
| 221 | conn, mc := newRWMockConn(1) |
nothing calls this directly
no test coverage detected