From 23540b9d94a1a522f2cdef623798d7888f5d78df Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Tue, 14 Jun 2022 13:57:48 -0700 Subject: [PATCH] Beef up askpass_url support * Don't need to get the password at startup (it happens in the sync loop anyway) * Add tests for bad password and flaky URL --- askpass_git.sh | 2 +- test_e2e.sh | 105 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 98 insertions(+), 9 deletions(-) diff --git a/askpass_git.sh b/askpass_git.sh index c6230f0..cac75eb 100755 --- a/askpass_git.sh +++ b/askpass_git.sh @@ -24,7 +24,7 @@ touch "${XDG_CONFIG_HOME}/git/config" # outside the e2e test environment. See https://git-scm.com/docs/git-credential-store touch "${XDG_CONFIG_HOME}/git/credentials" -if [ "$1" != "clone" ]; then +if [ "$1" != "clone" -a "$1" != "ls-remote" -a "$1" != "fetch" ]; then git "$@" exit $? fi diff --git a/test_e2e.sh b/test_e2e.sh index 6161a16..8bafb5e 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -1052,14 +1052,14 @@ function e2e::password_correct_password() { } ############################################## -# Test askpass-url +# Test askpass-url with bad password ############################################## -function e2e::askpass_url() { - echo "$FUNCNAME 1" > "$REPO"/file - git -C "$REPO" commit -qam "$FUNCNAME 1" - +function e2e::askpass_url_wrong_password() { # run the askpass_url service with wrong password + HITLOG="$WORK/hitlog" + cat /dev/null > "$HITLOG" CTR=$(docker_run \ + -v "$HITLOG":/var/log/hits \ e2e/test/test-ncsvr \ 80 ' echo "HTTP/1.1 200 OK" @@ -1082,10 +1082,17 @@ function e2e::askpass_url() { # check for failure assert_file_absent "$ROOT"/link/file +} +############################################## +# Test askpass-url +############################################## +function e2e::askpass_url() { # run with askpass_url service with correct password - docker_kill "$CTR" + HITLOG="$WORK/hitlog" + cat /dev/null > "$HITLOG" CTR=$(docker_run \ + -v "$HITLOG":/var/log/hits \ e2e/test/test-ncsvr \ 80 ' echo "HTTP/1.1 200 OK" @@ -1095,16 +1102,98 @@ function e2e::askpass_url() { ') IP=$(docker_ip "$CTR") + # First sync + echo "$FUNCNAME 1" > "$REPO"/file + git -C "$REPO" commit -qam "$FUNCNAME 1" + GIT_SYNC \ --git="$ASKPASS_GIT" \ --askpass-url="http://$IP/git_askpass" \ - --one-time \ + --period=100ms \ --repo="file://$REPO" \ --branch="$MAIN_BRANCH" \ --rev=HEAD \ --root="$ROOT" \ --link="link" \ - >> "$1" 2>&1 + >> "$1" 2>&1 & + sleep 3 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" + + # Move HEAD forward + echo "$FUNCNAME 2" > "$REPO"/file + git -C "$REPO" commit -qam "$FUNCNAME 2" + sleep 3 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 2" + + # Move HEAD backward + git -C "$REPO" reset -q --hard HEAD^ + sleep 3 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" +} + +############################################## +# Test askpass-url where the URL is flaky +############################################## +function e2e::askpass_url_flaky() { + # run with askpass_url service which alternates good/bad replies. + HITLOG="$WORK/hitlog" + cat /dev/null > "$HITLOG" + CTR=$(docker_run \ + -v "$HITLOG":/var/log/hits \ + e2e/test/test-ncsvr \ + 80 ' + echo "HTTP/1.1 200 OK" + echo + if [ -f /tmp/flag ]; then + echo "username=my-username" + echo "password=my-password" + rm /tmp/flag + else + echo "username=my-username" + echo "password=wrong" + touch /tmp/flag + fi + ') + IP=$(docker_ip "$CTR") + + # First sync + echo "$FUNCNAME 1" > "$REPO"/file + git -C "$REPO" commit -qam "$FUNCNAME 1" + + GIT_SYNC \ + --git="$ASKPASS_GIT" \ + --askpass-url="http://$IP/git_askpass" \ + --max-sync-failures=2 \ + --period=100ms \ + --repo="file://$REPO" \ + --branch="$MAIN_BRANCH" \ + --rev=HEAD \ + --root="$ROOT" \ + --link="link" \ + >> "$1" 2>&1 & + sleep 3 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 1" + + # Move HEAD forward + echo "$FUNCNAME 2" > "$REPO"/file + git -C "$REPO" commit -qam "$FUNCNAME 2" + sleep 3 + assert_link_exists "$ROOT"/link + assert_file_exists "$ROOT"/link/file + assert_file_eq "$ROOT"/link/file "$FUNCNAME 2" + + # Move HEAD backward + git -C "$REPO" reset -q --hard HEAD^ + sleep 3 + assert_link_exists "$ROOT"/link assert_file_exists "$ROOT"/link/file assert_file_eq "$ROOT"/link/file "$FUNCNAME 1"