Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix can't connect to MySQL 8.0 with long password #914

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ func (c *Conn) readInitialHandshake() error {
// the first packet *must* have at least 20 bytes of a scramble.
// if a plugin provided less, we pad it to 20 with zeros
rest := int(authPluginDataLen) - 8
if max := 12 + 1; rest < max {
rest = max
if rest < 13 {
rest = 13
}

authPluginDataPart2 := data[pos : pos+rest]
authPluginDataPart2 := data[pos : pos+rest-1]
pos += rest

c.salt = append(c.salt, authPluginDataPart2...)
Expand Down
13 changes: 13 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,16 @@ INSERT INTO field_value_test VALUES (
require.Equal(s.T(), expected[i], v.String())
}
}

func (s *clientTestSuite) TestLongPassword() {
_, err := s.c.Execute("DROP USER IF EXISTS 'test_long_password'@'%'")
require.NoError(s.T(), err)
_, err = s.c.Execute("CREATE USER 'test_long_password'@'%' IDENTIFIED BY '12345678901234567890'")
require.NoError(s.T(), err)

addr := fmt.Sprintf("%s:%s", *test_util.MysqlHost, s.port)
c, err := Connect(addr, "test_long_password", "12345678901234567890", "")
require.NoError(s.T(), err)
err = c.Close()
require.NoError(s.T(), err)
}