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

Function TestAuthFastCachingSHA256PasswordCached

auth_test.go:78–121  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

76}
77
78func TestAuthFastCachingSHA256PasswordCached(t *testing.T) {
79 conn, mc := newRWMockConn(1)
80 mc.cfg.User = "root"
81 mc.cfg.Passwd = "secret"
82
83 authData := []byte{90, 105, 74, 126, 30, 48, 37, 56, 3, 23, 115, 127, 69,
84 22, 41, 84, 32, 123, 43, 118}
85 plugin := "caching_sha2_password"
86
87 // Send Client Authentication Packet
88 authResp, err := mc.auth(authData, plugin)
89 if err != nil {
90 t.Fatal(err)
91 }
92 err = mc.writeHandshakeResponsePacket(authResp, plugin)
93 if err != nil {
94 t.Fatal(err)
95 }
96
97 // check written auth response
98 authRespStart := 4 + 4 + 4 + 1 + 23 + len(mc.cfg.User) + 1
99 authRespEnd := authRespStart + 1 + len(authResp)
100 writtenAuthRespLen := conn.written[authRespStart]
101 writtenAuthResp := conn.written[authRespStart+1 : authRespEnd]
102 expectedAuthResp := []byte{102, 32, 5, 35, 143, 161, 140, 241, 171, 232, 56,
103 139, 43, 14, 107, 196, 249, 170, 147, 60, 220, 204, 120, 178, 214, 15,
104 184, 150, 26, 61, 57, 235}
105 if writtenAuthRespLen != 32 || !bytes.Equal(writtenAuthResp, expectedAuthResp) {
106 t.Fatalf("unexpected written auth response (%d bytes): %v", writtenAuthRespLen, writtenAuthResp)
107 }
108 conn.written = nil
109
110 // auth response
111 conn.data = []byte{
112 2, 0, 0, 2, 1, 3, // Fast Auth Success
113 7, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, // OK
114 }
115 conn.maxReads = 1
116
117 // Handle response to auth packet
118 if err := mc.handleAuthResult(authData, plugin); err != nil {
119 t.Errorf("got error: %v", err)
120 }
121}
122
123func TestAuthFastCachingSHA256PasswordEmpty(t *testing.T) {
124 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