Skip to content

Commit 09a7e80

Browse files
authored
Merge pull request #2789 from dolthub/fulghum-b00987f7
[auto-bump] [no-release-notes] dependency by fulghum
2 parents 9643b85 + 29900a6 commit 09a7e80

File tree

7 files changed

+423
-52
lines changed

7 files changed

+423
-52
lines changed

enginetest/enginetests.go

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package enginetest
1616

1717
import (
1818
"context"
19+
"crypto/tls"
1920
dsql "database/sql"
2021
"fmt"
2122
"io"
@@ -2010,11 +2011,19 @@ func TestUserAuthentication(t *testing.T, h Harness) {
20102011
User: "root",
20112012
Address: "localhost",
20122013
})
2014+
2015+
tlsCert, err := tls.LoadX509KeyPair("./testdata/selfsigned_cert.pem", "./testdata/selfsigned_key.pem")
2016+
require.NoError(t, err)
2017+
tlsConfig := tls.Config{
2018+
Certificates: []tls.Certificate{tlsCert},
2019+
}
2020+
20132021
serverConfig := server.Config{
2014-
Protocol: "tcp",
2015-
Address: fmt.Sprintf("localhost:%d", port),
2016-
MaxConnections: 1000,
2017-
AllowClearTextWithoutTLS: true,
2022+
Protocol: "tcp",
2023+
Address: fmt.Sprintf("localhost:%d", port),
2024+
MaxConnections: 1000,
2025+
TLSConfig: &tlsConfig,
2026+
RequireSecureTransport: true,
20182027
}
20192028

20202029
e := mustNewEngine(t, clientHarness)
@@ -2055,24 +2064,37 @@ func TestUserAuthentication(t *testing.T, h Harness) {
20552064
}()
20562065

20572066
for _, assertion := range script.Assertions {
2058-
conn, err := dbr.Open("mysql", fmt.Sprintf("%s:%s@tcp(localhost:%d)/?allowCleartextPasswords=true",
2059-
assertion.Username, assertion.Password, port), nil)
2060-
require.NoError(t, err)
2061-
r, err := conn.Query(assertion.Query)
2062-
if assertion.ExpectedErr || len(assertion.ExpectedErrStr) > 0 || assertion.ExpectedErrKind != nil {
2063-
if !assert.Error(t, err) {
2064-
require.NoError(t, r.Close())
2065-
} else if len(assertion.ExpectedErrStr) > 0 {
2066-
assert.Equal(t, assertion.ExpectedErrStr, err.Error())
2067-
} else if assertion.ExpectedErrKind != nil {
2068-
assert.True(t, assertion.ExpectedErrKind.Is(err))
2069-
}
2070-
} else {
2071-
if assert.NoError(t, err) {
2072-
require.NoError(t, r.Close())
2067+
t.Run(assertion.Query, func(t *testing.T) {
2068+
conn, err := dbr.Open("mysql", fmt.Sprintf("%s:%s@tcp(localhost:%d)/?allowCleartextPasswords=true&tls=skip-verify",
2069+
assertion.Username, assertion.Password, port), nil)
2070+
require.NoError(t, err)
2071+
r, err := conn.Query(assertion.Query)
2072+
if assertion.ExpectedErr || len(assertion.ExpectedErrStr) > 0 || assertion.ExpectedErrKind != nil {
2073+
if !assert.Error(t, err) {
2074+
require.NoError(t, r.Close())
2075+
} else if len(assertion.ExpectedErrStr) > 0 {
2076+
assert.Equal(t, assertion.ExpectedErrStr, err.Error())
2077+
} else if assertion.ExpectedErrKind != nil {
2078+
assert.True(t, assertion.ExpectedErrKind.Is(err))
2079+
}
2080+
} else {
2081+
if assert.NoError(t, err) {
2082+
require.NoError(t, r.Close())
2083+
}
2084+
if assertion.ExpectedAuthPlugin != "" {
2085+
// NOTE: This query works as long as there is only one account configured for the current user
2086+
r, err := conn.Query("SELECT plugin FROM mysql.user WHERE user=SUBSTRING_INDEX(USER(),'@',1);")
2087+
require.NoError(t, err)
2088+
require.True(t, r.Next())
2089+
var authPlugin string
2090+
err = r.Scan(&authPlugin)
2091+
require.False(t, r.Next())
2092+
require.NoError(t, err)
2093+
require.Equal(t, assertion.ExpectedAuthPlugin, authPlugin)
2094+
}
20732095
}
2074-
}
2075-
require.NoError(t, conn.Close())
2096+
require.NoError(t, conn.Close())
2097+
})
20762098
}
20772099
})
20782100
}

enginetest/queries/priv_auth_queries.go

Lines changed: 159 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ type ServerAuthenticationTest struct {
9595

9696
// ServerAuthenticationTestAssertion is within a ServerAuthenticationTest to assert functionality.
9797
type ServerAuthenticationTestAssertion struct {
98-
Username string
99-
Password string
100-
Query string
101-
ExpectedErr bool
102-
ExpectedErrKind *errors.Kind
103-
ExpectedErrStr string
98+
Username string
99+
Password string
100+
Query string
101+
ExpectedErr bool
102+
ExpectedErrKind *errors.Kind
103+
ExpectedErrStr string
104+
ExpectedAuthPlugin string
104105
}
105106

106107
// UserPrivTests test the user and privilege systems. These tests always have the root account available, and the root
@@ -740,7 +741,37 @@ var UserPrivTests = []UserPrivilegeTest{
740741
},
741742
},
742743
},
743-
744+
{
745+
Name: "Migrate a user from mysql_native_password to caching_sha2_password",
746+
SetUpScript: []string{
747+
"CREATE USER testuser1@`127.0.0.1` identified with mysql_native_password by 'pass1';",
748+
},
749+
Assertions: []UserPrivilegeTestAssertion{
750+
{
751+
Query: "select user, host, plugin, authentication_string from mysql.user where user='testuser1';",
752+
Expected: []sql.Row{{"testuser1", "127.0.0.1", "mysql_native_password", "*22A99BA288DB55E8E230679259740873101CD636"}},
753+
},
754+
{
755+
Query: "ALTER USER testuser1@`127.0.0.1` IDENTIFIED WITH caching_sha2_password BY 'pass1';",
756+
Expected: []sql.Row{{types.NewOkResult(0)}},
757+
},
758+
{
759+
// caching_sha2_password auth uses a random salt to create the authentication
760+
// string. Since it's not a consistent value during each test run, we just sanity
761+
// check the first bytes of metadata (digest type, iterations) in the auth string.
762+
Query: "select user, host, plugin, authentication_string like '$A$005$%' from mysql.user where user='testuser1';",
763+
Expected: []sql.Row{{"testuser1", "127.0.0.1", "caching_sha2_password", true}},
764+
},
765+
{
766+
Query: "ALTER USER testuser1@`127.0.0.1` IDENTIFIED WITH caching_sha2_password;",
767+
Expected: []sql.Row{{types.NewOkResult(0)}},
768+
},
769+
{
770+
Query: "select user, host, plugin, authentication_string from mysql.user where user='testuser1';",
771+
Expected: []sql.Row{{"testuser1", "127.0.0.1", "caching_sha2_password", ""}},
772+
},
773+
},
774+
},
744775
{
745776
Name: "Dynamic privilege support",
746777
SetUpScript: []string{
@@ -2604,10 +2635,10 @@ var ServerAuthTests = []ServerAuthenticationTest{
26042635
},
26052636
Assertions: []ServerAuthenticationTestAssertion{
26062637
{
2607-
Username: "rand_user",
2608-
Password: "rand_pass",
2609-
Query: "SELECT * FROM mysql.user;",
2610-
ExpectedErr: false,
2638+
Username: "rand_user",
2639+
Password: "rand_pass",
2640+
Query: "SELECT * FROM mysql.user;",
2641+
ExpectedAuthPlugin: "mysql_native_password",
26112642
},
26122643
{
26132644
Username: "rand_user",
@@ -2630,17 +2661,17 @@ var ServerAuthTests = []ServerAuthenticationTest{
26302661
},
26312662
},
26322663
{
2633-
Name: "Create User with plugin specification",
2664+
Name: "Create User explicitly with mysql_native_password plugin",
26342665
SetUpScript: []string{
26352666
"CREATE USER ranuse@localhost IDENTIFIED WITH mysql_native_password BY 'ranpas';",
26362667
"GRANT ALL ON *.* TO ranuse@localhost WITH GRANT OPTION;",
26372668
},
26382669
Assertions: []ServerAuthenticationTestAssertion{
26392670
{
2640-
Username: "ranuse",
2641-
Password: "ranpas",
2642-
Query: "SELECT * FROM mysql.user;",
2643-
ExpectedErr: false,
2671+
Username: "ranuse",
2672+
Password: "ranpas",
2673+
Query: "SELECT * FROM mysql.user;",
2674+
ExpectedAuthPlugin: "mysql_native_password",
26442675
},
26452676
{
26462677
Username: "ranuse",
@@ -2656,6 +2687,103 @@ var ServerAuthTests = []ServerAuthenticationTest{
26562687
},
26572688
},
26582689
},
2690+
{
2691+
Name: "Create User explicitly with caching_sha2_password plugin",
2692+
SetUpScript: []string{
2693+
// testuser1 is created with a password
2694+
"CREATE USER testuser1@localhost IDENTIFIED WITH caching_sha2_password BY 'mypassword3';",
2695+
"GRANT ALL ON *.* TO testuser1@localhost WITH GRANT OPTION;",
2696+
// testuser2 is created without a password
2697+
"CREATE USER testuser2@localhost IDENTIFIED WITH caching_sha2_password;",
2698+
"GRANT ALL ON *.* TO testuser2@localhost WITH GRANT OPTION;",
2699+
},
2700+
Assertions: []ServerAuthenticationTestAssertion{
2701+
{
2702+
Username: "testuser1",
2703+
Password: "mypassword3",
2704+
Query: "SELECT * FROM mysql.user;",
2705+
ExpectedAuthPlugin: "caching_sha2_password",
2706+
},
2707+
{
2708+
Username: "testuser1",
2709+
Password: "what",
2710+
Query: "SELECT * FROM mysql.user;",
2711+
ExpectedErr: true,
2712+
ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser1'",
2713+
},
2714+
{
2715+
Username: "testuser1",
2716+
Password: "",
2717+
Query: "SELECT * FROM mysql.user;",
2718+
ExpectedErr: true,
2719+
ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser1'",
2720+
},
2721+
{
2722+
Username: "testuser2",
2723+
Password: "wrong",
2724+
Query: "SELECT * FROM mysql.user;",
2725+
ExpectedErr: true,
2726+
ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser2'",
2727+
},
2728+
{
2729+
Username: "testuser2",
2730+
Password: "",
2731+
Query: "SELECT * FROM mysql.user;",
2732+
ExpectedErr: false,
2733+
ExpectedAuthPlugin: "caching_sha2_password",
2734+
},
2735+
},
2736+
},
2737+
{
2738+
Name: "Migrate user from mysql_native_password to caching_sha2_password",
2739+
SetUpScript: []string{
2740+
// testuser1 is created with a password
2741+
"CREATE USER testuser1@localhost IDENTIFIED WITH mysql_native_password BY 'mypassword3';",
2742+
"GRANT ALL ON *.* TO testuser1@localhost WITH GRANT OPTION;",
2743+
},
2744+
Assertions: []ServerAuthenticationTestAssertion{
2745+
{
2746+
Username: "testuser1",
2747+
Password: "mypassword3",
2748+
Query: "SELECT * FROM mysql.user;",
2749+
ExpectedAuthPlugin: "mysql_native_password",
2750+
},
2751+
{
2752+
Username: "root",
2753+
Query: "ALTER USER testuser1@localhost IDENTIFIED WITH caching_sha2_password BY 'pass1';",
2754+
},
2755+
{
2756+
Username: "testuser1",
2757+
Password: "pass1",
2758+
Query: "SELECT * FROM mysql.user;",
2759+
ExpectedAuthPlugin: "caching_sha2_password",
2760+
},
2761+
{
2762+
Username: "testuser1",
2763+
Password: "wrong",
2764+
Query: "SELECT * FROM mysql.user;",
2765+
ExpectedErr: true,
2766+
ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser1'",
2767+
},
2768+
{
2769+
Username: "root",
2770+
Query: "ALTER USER testuser1@localhost IDENTIFIED WITH caching_sha2_password;",
2771+
},
2772+
{
2773+
Username: "testuser1",
2774+
Password: "",
2775+
Query: "SELECT * FROM mysql.user;",
2776+
ExpectedAuthPlugin: "caching_sha2_password",
2777+
},
2778+
{
2779+
Username: "testuser1",
2780+
Password: "wrong",
2781+
Query: "SELECT * FROM mysql.user;",
2782+
ExpectedErr: true,
2783+
ExpectedErrStr: "Error 1045 (28000): Access denied for user 'testuser1'",
2784+
},
2785+
},
2786+
},
26592787
{
26602788
Name: "Create User with jwt plugin specification",
26612789
SetUpScript: []string{
@@ -2668,22 +2796,25 @@ var ServerAuthTests = []ServerAuthenticationTest{
26682796
},
26692797
Assertions: []ServerAuthenticationTestAssertion{
26702798
{
2671-
Username: "test-user",
2672-
Password: "what",
2673-
Query: "SELECT * FROM mysql.user;",
2674-
ExpectedErr: true,
2799+
Username: "test-user",
2800+
Password: "what",
2801+
Query: "SELECT * FROM mysql.user;",
2802+
ExpectedErr: true,
2803+
ExpectedErrStr: "Error 1045 (28000): Access denied for user 'test-user'",
26752804
},
26762805
{
2677-
Username: "test-user",
2678-
Password: "",
2679-
Query: "SELECT * FROM mysql.user;",
2680-
ExpectedErr: true,
2806+
Username: "test-user",
2807+
Password: "",
2808+
Query: "SELECT * FROM mysql.user;",
2809+
ExpectedErr: true,
2810+
ExpectedErrStr: "Error 1045 (28000): Access denied for user 'test-user'",
26812811
},
26822812
{
2683-
Username: "test-user",
2684-
Password: "right-password",
2685-
Query: "SELECT * FROM mysql.user;",
2686-
ExpectedErr: false,
2813+
2814+
Username: "test-user",
2815+
Password: "right-password",
2816+
Query: "SELECT * FROM mysql.user;",
2817+
ExpectedAuthPlugin: "authentication_dolt_jwt",
26872818
},
26882819
},
26892820
},
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIErDCCApQCCQCP9IKGyBYVUDANBgkqhkiG9w0BAQsFADAYMRYwFAYDVQQKDA1E
3+
b2x0SHViLCBJbmMuMB4XDTIyMDcyMTE5NTUyN1oXDTI2MDcyMDE5NTUyN1owGDEW
4+
MBQGA1UECgwNRG9sdEh1YiwgSW5jLjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCC
5+
AgoCggIBAMRNMquL4n2bAMQmoedUFcT/zI42ThW5o9qxh9U8MhsDqKBet7JL7ruh
6+
3FRj/yaU+3ax2lGgapcTnSJHWHPUX6MzUpqkwrLzKxqMrKQYnU2F96n3GOflllsB
7+
8ISKBy0TIipLWKupndc893qk+j6HUQ9OrtFHwroZ6/Tg32h4LcJvhkwILb8EHZpI
8+
fSSzi637msnXWqln1WYmX+v4ARUVVSwl5kkPGZ4PxMDQRX3ioqy2d27GbHYSo01K
9+
tSScQvnFJeddu09l7hNTSFixRz+XU+F+jYna8xUtqHMawEpfGw8Gsu8sMV9PUfUx
10+
6WrMb1tcyWEDvHwH6RUlhNa085eCRFznHLDZNxrgBwrslII9d9xW/JaRq43d4M0q
11+
e7F+BazB3rImMo2QHFvtvq55N7mvp+LprMjoEneBboiz1I6M0rq7Sn58FxazgQvz
12+
mCZmNYIrznx+S1mlJjxtC7xgDPZn5Z/68TsmT26j5UNLou7i/yb7XFdMVY6kAnoZ
13+
BAf4+rAUEDV85OLz0kWZSJj+DdlPOl/gIhTgrgJev2Cc7THUTnuk+nGETG49DITS
14+
ySWYLsMYFHweSTm3rG6sMyN7mdbRrUSM1bqbARm46mt89+0HGsFX1QLe3v4yda67
15+
ic93J5mkfNPZ96K9Hth3SBbZt43DvB56ZqsFQlzBZeQ3hkk7ooulAgMBAAEwDQYJ
16+
KoZIhvcNAQELBQADggIBAJgopHEYmETWhH06T72EpgLr3xqckCP9QZ6/UBN8eDt0
17+
rRqMCfM5H33qpe2wojjKwFDkR8XpwF/80VflfFBt9hc1c1fuKmyQSES9gUw10uSL
18+
Z54MCPOa+c8+hslkmJR8Na0QyWN5unnozVHf4XIChsgL1/FblXcOgQLPZygzMNM2
19+
IjdT9XpEHiZTDZDp1NmM7rkRkcpgF2J8G2dcRjo/OGpnhH7wHgxm7hS6yWLW8xPP
20+
8M2/8LPYA7H6HMGYeyrYuDPeVzfaHrECTft+4cjHLu/jYnVLukMMSuI9v5FjtxtX
21+
PYtxnLv8hnbParjSnzK8cOlGdfJDRPMUw9/tvZ4bTeyTtJQYgl/jtdaU4mbdWlge
22+
XMzkZGH3kKpsV2rPZXKJuqRq3vzfr51cQhEcnbJ5H8BsDUQADS3ind37guqoKhuZ
23+
6vFUBTKLeYK5VZ4J18ztXhEynAf7kdROKP6XbE53qtH8qQujmOMWliSFQFdidYsj
24+
eItzGQ4M/ZqI84UnPRL3WPdfPkWqa0x1k6PHFRcFJPp8nhl3O5V4ZdyVC3pKhzUJ
25+
Y8sMit5RH1K8ZTYUVtEKwMX9wRMEkbfE4u/P+yItKw7QgYRdKerlDfCGZP8JY9+k
26+
wqYmF56EVGQFaJdJ1ublVEHQkAVHOBowzccwWOV/OPi1sL+cf4RxAaY7gJpuNEIk
27+
-----END CERTIFICATE-----

0 commit comments

Comments
 (0)