fix: Validate that all application names are valid domain names

Invalid application names will need to be manually cleaned up by the user, and as such this is a bc-break.

Closes #3054
This commit is contained in:
Jose Diaz-Gonzalez committed 2018-02-17 17:26:06 -05:00
1 parent a80bd92f40
commit 16b8f2682b
3 files changed
+21 -9

No files matched your search

+4 -4
View File
@@ -5,10 +5,10 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions"
apps_create() { apps_create() {
declare desc="verifies app name and creates an app" declare desc="verifies app name and creates an app"
[[ -z $1 ]] && dokku_log_fail "Please specify an app to run the command on" declare APP="$1"
[[ ! "$1" =~ ^[a-z].* && ! "$1" =~ ^[0-9].* ]] && dokku_log_fail "App name must begin with lowercase alphanumeric character" is_valid_app_name "$APP"
[[ -d "$DOKKU_ROOT/$1" ]] && dokku_log_fail "Name is already taken"
local APP="$1" [[ -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "Name is already taken"
mkdir -p "$DOKKU_ROOT/$APP" mkdir -p "$DOKKU_ROOT/$APP"
echo "Creating $APP... done" echo "Creating $APP... done"
+7 -4
View File
@@ -141,11 +141,14 @@ is_valid_app_name() {
declare desc="verify app name format" declare desc="verify app name format"
local APP="$1" local APP="$1"
[[ ! -n "$APP" ]] && dokku_log_fail "APP must not be null" [[ ! -n "$APP" ]] && dokku_log_fail "APP must not be null"
if [[ ! "$APP" =~ ^[a-z].* && ! "$APP" =~ ^[0-9].* ]]; then if [[ "$APP" =~ ^[a-z].* ]] || [[ "$APP" =~ ^[0-9].* ]]; then
[[ -d "$DOKKU_ROOT/$APP" ]] && rm -rf "${DOKKU_ROOT:?}/$APP" if [[ ! $APP =~ [A-Z] ]] && [[ ! $APP =~ [:] ]]; then
dokku_log_fail "App name must begin with lowercase alphanumeric character" return 0
fi
fi fi
return 0
[[ -d "$DOKKU_ROOT/$APP" ]] && rm -rf "${DOKKU_ROOT:?}/$APP"
dokku_log_fail "App name must begin with lowercase alphanumeric character"
} }
verify_app_name() { verify_app_name() {
+10 -1
View File
@@ -25,7 +25,16 @@ teardown () {
echo "output: "$output echo "output: "$output
echo "status: "$status echo "status: "$status
assert_success assert_success
dokku --force apps:destroy 1994testapp
run dokku apps:create testapp:latest
echo "output: "$output
echo "status: "$status
assert_failure
run dokku apps:create testApp:latest
echo "output: "$output
echo "status: "$status
assert_failure
run dokku apps:create TestApp run dokku apps:create TestApp
echo "output: "$output echo "output: "$output