Add ability to skip the error when only a password is provided.

This is intended to enable testing only.
This commit is contained in:
Neil Macneale IV
2023-06-15 13:01:10 -07:00
parent b427a61d85
commit cc94161010
3 changed files with 18 additions and 0 deletions
+8
View File
@@ -27,6 +27,7 @@ type UserPassword struct {
}
const DOLT_ENV_PWD = "DOLT_CLI_PASSWORD"
const DOLT_SILENCE_USER_REQ_FOR_TESTING = "DOLT_SILENCE_USER_REQ_FOR_TESTING"
// BuildUserPasswordPrompt builds a UserPassword struct from the parsed args. The user is prompted for a password if one
// is not provided. If a username is not provided, the default is "root" (which will not be allowed is a password is
@@ -81,5 +82,12 @@ func BuildUserPasswordPrompt(parsedArgs *argparser.ArgParseResults) (newParsedAr
return newParsedArgs, &UserPassword{Username: userId, Password: password}, nil
}
testOverride, hasTestOverride := os.LookupEnv(DOLT_SILENCE_USER_REQ_FOR_TESTING)
if hasTestOverride && testOverride == "Y" {
// Used for BATS testing only. Typical usage will not hit this path, but we have many legacy tests which
// do not provide a user, and the DOLT_ENV_PWD is set to avoid the prompt.
return newParsedArgs, &UserPassword{Username: "root", Password: password}, nil
}
return nil, nil, fmt.Errorf("When a password is provided, a user must also be provided. Use the --user flag to provide a username")
}
@@ -60,7 +60,16 @@ setup_no_dolt_init() {
export BATS_TEST_RETRIES="$DOLT_TEST_RETRIES"
fi
# Our tests use a mix of root and dolt users, and the CLI
# commands which authenticate will block for user input if we don't
# set DOLT_CLI_PASSWORD - so we set it to the empty string by default.
# The DOLT_SILENCE_USER_REQ_FOR_TESTING environment variable is to skip
# a check which errors out if a password is presented but no user is specified.
# The combination of these two flags allows us to avoid altering hundreds
# of existing tests which predate the authentication restrictions added
# during the cli -> sql migration.
export DOLT_CLI_PASSWORD=""
export DOLT_SILENCE_USER_REQ_FOR_TESTING="Y"
}
assert_feature_version() {
@@ -29,6 +29,7 @@ setup() {
fi
setup_no_dolt_init
unset DOLT_CLI_PASSWORD
unset DOLT_SILENCE_USER_REQ_FOR_TESTING
make_repo defaultDB
make_repo altDB
}