-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 use of user identity in SHOW GRANTS + error messages #30294
Changes from all commits
c871648
8ae35ed
83645fc
688bb8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,6 +372,35 @@ func TestShowGrants(t *testing.T) { | |
require.Len(t, gs, 3) | ||
} | ||
|
||
// TestErrorMessage checks that the identity in error messages matches the mysql.user table one. | ||
// MySQL is inconsistent in its error messages, as some match the loginHost and others the | ||
// identity from mysql.user. In TiDB we now use the identity from mysql.user in error messages | ||
// for consistency. | ||
func TestErrorMessage(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Manually testing this with v5.3.0 and master @ 13d0deb show the same error messages as in this test. Are you sure this test fails without your fix?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this for future checking. The case where it currently fails prior to this is the Column name in |
||
t.Parallel() | ||
store, clean := newStore(t) | ||
defer clean() | ||
|
||
rootSe := newSession(t, store, dbName) | ||
mustExec(t, rootSe, `CREATE USER wildcard`) | ||
mustExec(t, rootSe, `CREATE USER [email protected]`) | ||
mustExec(t, rootSe, `GRANT SELECT on test.* TO wildcard`) | ||
mustExec(t, rootSe, `GRANT SELECT on test.* TO [email protected]`) | ||
|
||
wildSe := newSession(t, store, dbName) | ||
|
||
// The session.Auth() func will populate the AuthUsername and AuthHostname fields. | ||
// We don't have to explicitly specify them. | ||
require.True(t, wildSe.Auth(&auth.UserIdentity{Username: "wildcard", Hostname: "192.168.1.1"}, nil, nil)) | ||
_, err := wildSe.ExecuteInternal(context.Background(), "use mysql;") | ||
require.Equal(t, "[executor:1044]Access denied for user 'wildcard'@'%' to database 'mysql'", err.Error()) | ||
|
||
specificSe := newSession(t, store, dbName) | ||
require.True(t, specificSe.Auth(&auth.UserIdentity{Username: "specifichost", Hostname: "192.168.1.1"}, nil, nil)) | ||
_, err = specificSe.ExecuteInternal(context.Background(), "use mysql;") | ||
require.Equal(t, "[executor:1044]Access denied for user 'specifichost'@'192.168.1.1' to database 'mysql'", err.Error()) | ||
} | ||
|
||
func TestShowColumnGrants(t *testing.T) { | ||
t.Parallel() | ||
store, clean := newStore(t) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: This totally change the semantic of the old API, and all the code referencing of the old API might be affected.
I can't say the new API is better or necessay (Go also discourage public API change), but as long as it fix more cases and do not introduce regression, it looks good to me.