Skip to content

Commit

Permalink
Add test for authSha
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Jan 30, 2023
1 parent fc2b446 commit b84d496
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions server/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1806,3 +1806,48 @@ func TestExtensionChangeUser(t *testing.T) {
require.Equal(t, expectedConnInfo.Error, logInfo.Error)
require.Equal(t, *(expectedConnInfo.ConnectionInfo), *(logInfo.ConnectionInfo))
}

func TestAuthSha(t *testing.T) {
store := testkit.CreateMockStore(t)

var outBuffer bytes.Buffer
tidbdrv := NewTiDBDriver(store)
cfg := newTestConfig()
cfg.Port, cfg.Status.StatusPort = 0, 0
cfg.Status.ReportStatus = false
server, err := NewServer(cfg, tidbdrv)
require.NoError(t, err)
defer server.Close()

cc := &clientConn{
connectionID: 1,
salt: []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14},
server: server,
pkt: &packetIO{
bufWriter: bufio.NewWriter(&outBuffer),
},
collation: mysql.DefaultCollationID,
peerHost: "localhost",
alloc: arena.NewAllocator(512),
chunkAlloc: chunk.NewAllocator(),
capability: mysql.ClientProtocol41,
}

tk := testkit.NewTestKit(t, store)
ctx := &TiDBContext{Session: tk.Session()}
cc.setCtx(ctx)

resp := handshakeResponse41{
Capability: mysql.ClientProtocol41 | mysql.ClientPluginAuth,
AuthPlugin: mysql.AuthCachingSha2Password,
Auth: []byte{}, // No password
}

authData, err := cc.authSha(context.Background(), resp)
require.NoError(t, err)

// If no password is specified authSha() should return an empty byte slice
// which differs from when a password is specified as that should trigger
// fastAuthFail and the rest of the auth process.
require.Equal(t, authData, []byte{})
}

0 comments on commit b84d496

Please sign in to comment.