feat: implement git:auth command

Refs #4364
This commit is contained in:
Jose Diaz-Gonzalez
2021-02-21 03:31:05 -05:00
parent 4d13e0c2f6
commit 7a710005a1
10 changed files with 155 additions and 16 deletions

View File

@@ -20,6 +20,12 @@ install_dependencies() {
curl -L "https://packagecloud.io/dokku/dokku/packages/ubuntu/bionic/herokuish_${HEROKUISH_VERSION}_amd64.deb/download.deb" -o "$ROOT_DIR/build/${HEROKUISH_PACKAGE_NAME}"
fi
NETRC_VERSION=$(grep NETRC_VERSION "${ROOT_DIR}/Makefile" | head -n1 | cut -d' ' -f3)
NETRC_PACKAGE_NAME="netrc_${NETRC_VERSION}_amd64.deb"
if [[ ! -f "$ROOT_DIR/build/${NETRC_PACKAGE_NAME}" ]]; then
curl -L "https://packagecloud.io/dokku/dokku/packages/ubuntu/bionic/netrc_${NETRC_VERSION}_amd64.deb/download.deb" -o "$ROOT_DIR/build/${NETRC_PACKAGE_NAME}"
fi
PLUGN_VERSION=$(grep PLUGN_VERSION "${ROOT_DIR}/Makefile" | head -n1 | cut -d' ' -f3)
PLUGN_PACKAGE_NAME="plugn_${PLUGN_VERSION}_amd64.deb"
if [[ ! -f "$ROOT_DIR/build/${PLUGN_PACKAGE_NAME}" ]]; then
@@ -52,6 +58,7 @@ install_dependencies() {
sudo dpkg -i \
"${ROOT_DIR}/build/$DOCKER_IMAGE_LABELER_PACKAGE_NAME" \
"${ROOT_DIR}/build/$HEROKUISH_PACKAGE_NAME" \
"${ROOT_DIR}/build/$NETRC_PACKAGE_NAME" \
"${ROOT_DIR}/build/$PLUGN_PACKAGE_NAME" \
"${ROOT_DIR}/build/$PROCFILE_UTIL_PACKAGE_NAME" \
"${ROOT_DIR}/build/$SIGIL_PACKAGE_NAME" \

View File

@@ -5,12 +5,16 @@ load test_helper
setup() {
global_setup
create_app
[[ -f "$DOKKU_ROOT/.netrc" ]] && cp -fp "$DOKKU_ROOT/.netrc" "$DOKKU_ROOT/.netrc.bak"
touch /home/dokku/.netrc
chown dokku:dokku /home/dokku/.netrc
touch /home/dokku/.ssh/known_hosts
chown dokku:dokku /home/dokku/.ssh/known_hosts
}
teardown() {
rm -f /home/dokku/.ssh/id_rsa.pub || true
[[ -f "$DOKKU_ROOT/.netrc.bak" ]] && mv "$DOKKU_ROOT/.netrc.bak" "$DOKKU_ROOT/.netrc" && chown dokku:dokku "$DOKKU_ROOT/.netrc"
destroy_app
global_teardown
}
@@ -60,6 +64,31 @@ teardown() {
assert_equal "$output" "$((start_lines + 2))"
}
@test "(git) git:auth" {
run /bin/bash -c "dokku git:auth"
echo "output: $output"
echo "status: $status"
assert_failure
run /bin/bash -c "dokku git:auth github.com"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Removing netrc auth entry for host github.com"
run /bin/bash -c "dokku git:auth github.com username"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "Missing password for netrc auth entry"
run /bin/bash -c "dokku git:auth github.com username password"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Setting netrc auth entry for host github.com"
}
@test "(git) git:sync new [errors]" {
run /bin/bash -c "dokku git:sync"
echo "output: $output"
@@ -274,11 +303,40 @@ teardown() {
assert_output_contains "Application deployed"
}
@test "(git) git:sync private" {
if [[ -z "$SYNC_GITHUB_USERNAME" ]] || [[ -z "$SYNC_GITHUB_PASSWORD" ]]; then
skip "skipping due to missing github credentials SYNC_GITHUB_USERNAME:SYNC_GITHUB_PASSWORD"
fi
run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app-private.git"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "fatal: could not read Username for"
run /bin/bash -c "dokku git:auth github.com $SYNC_GITHUB_USERNAME $SYNC_GITHUB_PASSWORD"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "cat /home/dokku/.netrc"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:sync $TEST_APP https://github.com/dokku/smoke-test-app-private.git"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(git) git:public-key" {
run /bin/bash -c "dokku git:public-key"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "There is no deploy key associated with the dokku user."
run /bin/bash -c "cp /root/.ssh/dokku_test_rsa.pub /home/dokku/.ssh/id_rsa.pub"
echo "output: $output"