fix and tests

This commit is contained in:
James Cor
2022-08-16 15:06:46 -07:00
parent c32cc936da
commit cf1ca904af
4 changed files with 15 additions and 14 deletions

View File

@@ -126,6 +126,11 @@ func Serve(
} else if sErr != nil {
return sErr, nil
}
// TODO: move this to GMS
serverHost := serverConfig.Host()
if serverHost == "" || serverHost == "0.0.0.0" {
serverHost = "%"
}
// Create SQL Engine with users
config := &engine.SqlEngineConfig{
@@ -135,7 +140,7 @@ func Serve(
DoltCfgDirPath: serverConfig.CfgDir(),
ServerUser: serverConfig.User(),
ServerPass: serverConfig.Password(),
ServerHost: serverConfig.Host(),
ServerHost: serverHost,
Autocommit: serverConfig.AutoCommit(),
JwksConfig: serverConfig.JwksConfig(),
}
@@ -150,13 +155,6 @@ func Serve(
}
defer sqlEngine.Close()
// TODO: move this to GMS
// set host to "%" if empty string or 0.0.0.0
serverHost := config.ServerHost
if serverHost == "" || serverHost == "0.0.0.0" {
serverHost = "%"
}
// Add superuser if specified user exists; add root superuser if no user specified and no existing privileges
userSpecified := config.ServerUser != ""
privsExist := sqlEngine.GetUnderlyingEngine().Analyzer.Catalog.MySQLDb.UserTable().Data().Count() != 0
@@ -166,7 +164,7 @@ func Serve(
sqlEngine.GetUnderlyingEngine().Analyzer.Catalog.MySQLDb.AddSuperUser(config.ServerUser, serverHost, config.ServerPass)
}
} else if !privsExist {
sqlEngine.GetUnderlyingEngine().Analyzer.Catalog.MySQLDb.AddSuperUser(defaultUser, defaultHost, defaultPass)
sqlEngine.GetUnderlyingEngine().Analyzer.Catalog.MySQLDb.AddSuperUser(defaultUser, "%", defaultPass)
}
labels := serverConfig.MetricsLabels()

View File

@@ -37,7 +37,7 @@ const (
)
const (
defaultHost = "localhost"
defaultHost = "0.0.0.0"
defaultPort = 3306
defaultUser = "root"
defaultPass = ""

View File

@@ -310,10 +310,6 @@ func getCommandLineServerConfig(dEnv *env.DoltEnv, apr *argparser.ArgParseResult
serverConfig.WithSocket(sock)
}
if host, ok := apr.GetValue(hostFlag); ok {
serverConfig.WithHost(host)
}
if port, ok := apr.GetInt(portFlag); ok {
serverConfig.WithPort(port)
}

View File

@@ -183,6 +183,13 @@ teardown() {
[[ "$output" =~ "privileges.db" ]] || false
}
@test "sql-privs: host option doesn't affect user" {
make_test_repo
start_sql_server_with_args --host 127.0.0.1 --user=dolt
server_query test_db 1 "select user, host from mysql.user order by user" "User,Host\ndolt,%"
}
@test "sql-privs: multiple doltcfg directories causes error" {
# setup repo
rm -rf test_db