From d8d9ff72b8bc705ecb99cbb38271bbcf805eec45 Mon Sep 17 00:00:00 2001 From: Chuanying Du Date: Wed, 18 Dec 2019 21:07:01 -0800 Subject: [PATCH] add e2e test for askpasswd_url --- docs/askpass-url.md | 9 ++------- test_e2e.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/docs/askpass-url.md b/docs/askpass-url.md index 841cc47..e75f6a4 100644 --- a/docs/askpass-url.md +++ b/docs/askpass-url.md @@ -6,7 +6,7 @@ The GIT ASKPASS Service is exposed via HTTP and provide the answer to GIT_ASKPAS Example of the service's output, see more at -```json +``` username=xxx@example.com password=ya29.mysecret ``` @@ -18,12 +18,7 @@ In your git-sync container configuration, specify the GIT_ASKPASS_URL The credentials will pass in plain text, make sure the connection between git-sync and GIT ASKPASS Service are secure. -The recommended situation are: - -* ASKPASS Service running within the same pod as git-sync. -* ASKPASS Service rely on [GCE metadata](https://cloud.google.com/compute/docs/storing-retrieving-metadata) to get service account's credential to access Google Cloud Source Repo. - -See as a full example. +See askpass_url e2e test as an example. ```yaml name: "git-sync" diff --git a/test_e2e.sh b/test_e2e.sh index d3ae055..3c90db9 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -666,6 +666,51 @@ assert_file_eq "$ROOT"/link/file "$TESTCASE 1" # Wrap up pass +############################################## +# Test askpass_url +############################################## +testcase "askpass_url" +echo "$TESTCASE 1" > "$REPO"/file +NCPORT=8888 +git -C "$REPO" commit -qam "$TESTCASE 1" +# run the askpass_url service with wrong password +# Need to run it twice one for setup another for real clone +{ (for i in 1 2; do echo -e 'HTTP/1.1 200 OK\r\n\r\nusername=you@example.com\npassword=dummypw' | nc -N -l $NCPORT > /dev/null; done) &} +GIT_SYNC \ + --git=$ASKPASS_GIT \ + --askpass-url="http://localhost:$NCPORT/git_askpass" \ + --logtostderr \ + --v=5 \ + --one-time \ + --repo="file://$REPO" \ + --branch=master \ + --rev=HEAD \ + --root="$ROOT" \ + --dest="link" \ + > "$DIR"/log."$TESTCASE" 2>&1 || true +# check for failure +assert_file_absent "$ROOT"/link/file +# run with askpass_url service with correct password +# Need to run it twice one for setup another for real clone +{ (for i in 1 2; do echo -e 'HTTP/1.1 200 OK\r\n\r\nusername=you@example.com\npassword=Lov3!k0os' | nc -N -l $NCPORT > /dev/null; done) &} +GIT_SYNC \ + --git=$ASKPASS_GIT \ + --askpass-url="http://localhost:$NCPORT/git_askpass" \ + --logtostderr \ + --v=5 \ + --one-time \ + --repo="file://$REPO" \ + --branch=master \ + --rev=HEAD \ + --root="$ROOT" \ + --dest="link" \ + > "$DIR"/log."$TESTCASE" 2>&1 +assert_link_exists "$ROOT"/link +assert_file_exists "$ROOT"/link/file +assert_file_eq "$ROOT"/link/file "$TESTCASE 1" +# Wrap up +pass + ############################################## # Test webhook ##############################################