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

executor: support creating user with no password. #1841

Merged
merged 1 commit into from Oct 18, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions executor/executor_simple.go
Expand Up @@ -322,10 +322,12 @@ func (e *SimpleExec) executeCreateUser(s *ast.CreateUserStmt) error {
continue
}
pwd := ""
if spec.AuthOpt.ByAuthString {
pwd = util.EncodePassword(spec.AuthOpt.AuthString)
} else {
pwd = util.EncodePassword(spec.AuthOpt.HashString)
if spec.AuthOpt != nil {
if spec.AuthOpt.ByAuthString {
pwd = util.EncodePassword(spec.AuthOpt.AuthString)
} else {
pwd = util.EncodePassword(spec.AuthOpt.HashString)
}
}
user := fmt.Sprintf(`("%s", "%s", "%s")`, host, userName, pwd)
users = append(users, user)
Expand Down
12 changes: 12 additions & 0 deletions executor/executor_simple_test.go
Expand Up @@ -192,6 +192,18 @@ func (s *testSuite) TestCreateUser(c *C) {
c.Check(err, NotNil)
}

func (s *testSuite) TestCreateUserWithNoPassword(c *C) {
defer testleak.AfterTest(c)()
tk := testkit.NewTestKit(c, s.store)
// Create user test.
createUserSQL := `CREATE USER 'test1'@'localhost';`
tk.MustExec(createUserSQL)
// Make sure user test in mysql.User.
result := tk.MustQuery(`SELECT Password FROM mysql.User WHERE User="test1" and Host="localhost"`)
rowStr := fmt.Sprintf("%v", []byte(util.EncodePassword("")))
result.Check(testkit.Rows(rowStr))
}

func (s *testSuite) TestSetPwd(c *C) {
defer testleak.AfterTest(c)()
tk := testkit.NewTestKit(c, s.store)
Expand Down