Skip to content

Commit

Permalink
server/user-create: Warn if user already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
leonklingele committed May 18, 2018
1 parent a507b08 commit f7cead1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/git-shell-commands/user-create
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ if [ -z "$NEW_USER" ]; then
exit 1
fi

# TODO(leon): DRY
# Regex is not an issue here, .* is not allowed in user names :)
MATCH="^environment=\"GIT_USER=$NEW_USER\".*$"
if grep -xq "$MATCH" "$FILE_PATH_AUTHORIZED_KEYS"; then
echo "User '$NEW_USER' already exists"
exit 1
fi

if [ -z "$PUBLIC_KEY" ]; then
echo "No public key specified"
exit 1
Expand Down
2 changes: 2 additions & 0 deletions tests/02-user.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ users_list_count_must_equal "3"
user_create "invalid-ssh" "invalid-ssh" "$INVALID_SSH_KEY_ERROR_MSG"
user_create "invalid-ssh" "ssh" "$INVALID_SSH_KEY_ERROR_MSG"
users_list_count_must_equal "3"
user_create "test" "ssh-rsa" "Error! User 'test' already exists"
users_list_count_must_equal "3"

# Test user deletion
user_delete "test2"
Expand Down

0 comments on commit f7cead1

Please sign in to comment.