MCPcopy
hub / github.com/go-sql-driver/mysql / TestAuthFastCachingSHA256PasswordFullRSAWithKey

Function TestAuthFastCachingSHA256PasswordFullRSAWithKey

auth_test.go:220–271  ·  auth_test.go::TestAuthFastCachingSHA256PasswordFullRSAWithKey
(t *testing.T)

Source from the content-addressed store, hash-verified

218}
219
220func TestAuthFastCachingSHA256PasswordFullRSAWithKey(t *testing.T) {
221 conn, mc := newRWMockConn(1)
222 mc.cfg.User = "root"
223 mc.cfg.Passwd = "secret"
224 mc.cfg.pubKey = testPubKeyRSA
225
226 authData := []byte{6, 81, 96, 114, 14, 42, 50, 30, 76, 47, 1, 95, 126, 81,
227 62, 94, 83, 80, 52, 85}
228 plugin := "caching_sha2_password"
229
230 // Send Client Authentication Packet
231 authResp, err := mc.auth(authData, plugin)
232 if err != nil {
233 t.Fatal(err)
234 }
235 err = mc.writeHandshakeResponsePacket(authResp, plugin)
236 if err != nil {
237 t.Fatal(err)
238 }
239
240 // check written auth response
241 authRespStart := 4 + 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1
242 authRespEnd := authRespStart + 1 + len(authResp)
243 writtenAuthRespLen := conn.written[authRespStart]
244 writtenAuthResp := conn.written[authRespStart+1 : authRespEnd]
245 expectedAuthResp := []byte{171, 201, 138, 146, 89, 159, 11, 170, 0, 67, 165,
246 49, 175, 94, 218, 68, 177, 109, 110, 86, 34, 33, 44, 190, 67, 240, 70,
247 110, 40, 139, 124, 41}
248 if writtenAuthRespLen != 32 || !bytes.Equal(writtenAuthResp, expectedAuthResp) {
249 t.Fatalf("unexpected written auth response (%d bytes): %v", writtenAuthRespLen, writtenAuthResp)
250 }
251 conn.written = nil
252
253 // auth response
254 conn.data = []byte{
255 2, 0, 0, 2, 1, 4, // Perform Full Authentication
256 }
257 conn.queuedReplies = [][]byte{
258 // OK
259 {7, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0},
260 }
261 conn.maxReads = 2
262
263 // Handle response to auth packet
264 if err := mc.handleAuthResult(authData, plugin); err != nil {
265 t.Errorf("got error: %v", err)
266 }
267
268 if !bytes.HasPrefix(conn.written, []byte{0, 1, 0, 3}) {
269 t.Errorf("unexpected written data: %v", conn.written)
270 }
271}
272
273func TestAuthFastCachingSHA256PasswordFullSecure(t *testing.T) {
274 conn, mc := newRWMockConn(1)

Callers

nothing calls this directly

Calls 4

newRWMockConnFunction · 0.85
authMethod · 0.80
handleAuthResultMethod · 0.80

Tested by

no test coverage detected