Merge branch 'sg/httpd-test-unflake'
authorJunio C Hamano <gitster@pobox.com>
Thu, 2 Aug 2018 22:30:39 +0000 (15:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Aug 2018 22:30:39 +0000 (15:30 -0700)
httpd tests saw occasional breakage due to the way its access log
gets inspected by the tests, which has been updated to make them
less flaky.

* sg/httpd-test-unflake:
t/lib-httpd: avoid occasional failures when checking access.log
t/lib-httpd: add the strip_access_log() helper function
t5541: clean up truncating access log

1  2 
t/lib-httpd.sh
t/t5541-http-push-smart.sh
t/t5551-http-fetch-smart.sh
t/t5561-http-backend.sh
diff --combined t/lib-httpd.sh
index ed41b155af9a38a471a2518fc42d7c9a1f110da1,7f060aebd0ced74e37241ab10da87e4b3fcd794c..a8729f82325ee7fb9350c42553e11205e6720928
@@@ -132,7 -132,6 +132,7 @@@ prepare_httpd() 
        cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
        install_script broken-smart-http.sh
        install_script error.sh
 +      install_script apply-one-time-sed.sh
  
        ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
  
@@@ -288,3 -287,24 +288,24 @@@ expect_askpass() 
        test_cmp "$TRASH_DIRECTORY/askpass-expect" \
                 "$TRASH_DIRECTORY/askpass-query"
  }
+ strip_access_log() {
+       sed -e "
+               s/^.* \"//
+               s/\"//
+               s/ [1-9][0-9]*\$//
+               s/^GET /GET  /
+       " "$HTTPD_ROOT_PATH"/access.log
+ }
+ # Requires one argument: the name of a file containing the expected stripped
+ # access log entries.
+ check_access_log() {
+       sort "$1" >"$1".sorted &&
+       strip_access_log >access.log.stripped &&
+       sort access.log.stripped >access.log.sorted &&
+       if ! test_cmp "$1".sorted access.log.sorted
+       then
+               test_cmp "$1" access.log.stripped
+       fi
+ }
index a2af693068fa455838c97df1fefe38bd630ceb2e,918822868ea593caad2a11bf909c629211d04866..a0fc4005e059723dbafb26606548a074554bc961
@@@ -38,25 -38,16 +38,16 @@@ GET  /smart/test_repo.git/info/refs?ser
  POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
  EOF
  test_expect_success 'no empty path components' '
+       # Clear the log, so that it does not affect the "used receive-pack
+       # service" test which reads the log too.
+       test_when_finished ">\"\$HTTPD_ROOT_PATH\"/access.log" &&
        # In the URL, add a trailing slash, and see if git appends yet another
        # slash.
        cd "$ROOT_PATH" &&
        git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
  
-       sed -e "
-               s/^.* \"//
-               s/\"//
-               s/ [1-9][0-9]*\$//
-               s/^GET /GET  /
-       " >act <"$HTTPD_ROOT_PATH"/access.log &&
-       # Clear the log, so that it does not affect the "used receive-pack
-       # service" test which reads the log too.
-       #
-       # We do this before the actual comparison to ensure the log is cleared.
-       echo > "$HTTPD_ROOT_PATH"/access.log &&
-       test_cmp exp act
+       check_access_log exp
  '
  
  test_expect_success 'clone remote repository' '
@@@ -124,7 -115,6 +115,6 @@@ test_expect_success 'rejected update pr
  rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
  
  cat >exp <<EOF
  GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
  GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
@@@ -138,13 -128,7 +128,7 @@@ GET  /smart/test_repo.git/info/refs?ser
  POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
  EOF
  test_expect_success 'used receive-pack service' '
-       sed -e "
-               s/^.* \"//
-               s/\"//
-               s/ [1-9][0-9]*\$//
-               s/^GET /GET  /
-       " >act <"$HTTPD_ROOT_PATH"/access.log &&
-       test_cmp exp act
+       check_access_log exp
  '
  
  test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
@@@ -234,7 -218,7 +218,7 @@@ test_expect_success TTY 'push --no-prog
        test_commit no-progress &&
        test_terminal git push --no-progress >output 2>&1 &&
        test_i18ngrep "^To http" output &&
 -      test_i18ngrep ! "^Writing objects"
 +      test_i18ngrep ! "^Writing objects" output
  '
  
  test_expect_success 'push --progress shows progress to non-tty' '
@@@ -377,17 -361,5 +361,17 @@@ test_expect_success 'push status outpu
        grep "^To $HTTPD_URL/smart/test_repo.git" status
  '
  
 +test_expect_success 'colorize errors/hints' '
 +      cd "$ROOT_PATH"/test_repo_clone &&
 +      test_must_fail git -c color.transport=always -c color.advice=always \
 +              -c color.push=always \
 +              push origin origin/master^:master 2>act &&
 +      test_decode_color <act >decoded &&
 +      test_i18ngrep "<RED>.*rejected.*<RESET>" decoded &&
 +      test_i18ngrep "<RED>error: failed to push some refs" decoded &&
 +      test_i18ngrep "<YELLOW>hint: " decoded &&
 +      test_i18ngrep ! "^hint: " decoded
 +'
 +
  stop_httpd
  test_done
index 913089b14452976144878415c05a9a2c743d22bf,f0b03e5190a6ddf8f5c7c6ec202409d8e22b5442..3aab44bdcbbc8939c0f80c84f7d44f50bc3ede16
@@@ -26,14 -26,14 +26,14 @@@ setup_askpass_helpe
  cat >exp <<EOF
  > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
  > Accept: */*
 -> Accept-Encoding: gzip
 +> Accept-Encoding: ENCODINGS
  > Pragma: no-cache
  < HTTP/1.1 200 OK
  < Pragma: no-cache
  < Cache-Control: no-cache, max-age=0, must-revalidate
  < Content-Type: application/x-git-upload-pack-advertisement
  > POST /smart/repo.git/git-upload-pack HTTP/1.1
 -> Accept-Encoding: gzip
 +> Accept-Encoding: ENCODINGS
  > Content-Type: application/x-git-upload-pack-request
  > Accept: application/x-git-upload-pack-result
  > Content-Length: xxx
@@@ -79,13 -79,8 +79,13 @@@ test_expect_success 'clone http reposit
                /^< Date: /d
                /^< Content-Length: /d
                /^< Transfer-Encoding: /d
 -      " >act &&
 -      test_cmp exp act
 +      " >actual &&
 +      sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
 +                      actual >actual.smudged &&
 +      test_cmp exp actual.smudged &&
 +
 +      grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
 +      test_line_count = 2 actual.gzip
  '
  
  test_expect_success 'fetch changes via http' '
@@@ -103,13 -98,7 +103,7 @@@ GET  /smart/repo.git/info/refs?service=
  POST /smart/repo.git/git-upload-pack HTTP/1.1 200
  EOF
  test_expect_success 'used upload-pack service' '
-       sed -e "
-               s/^.* \"//
-               s/\"//
-               s/ [1-9][0-9]*\$//
-               s/^GET /GET  /
-       " >act <"$HTTPD_ROOT_PATH"/access.log &&
-       test_cmp exp act
+       check_access_log exp
  '
  
  test_expect_success 'follow redirects (301)' '
@@@ -369,38 -358,5 +363,38 @@@ test_expect_success 'custom http header
                submodule update sub
  '
  
 +test_expect_success 'GIT_REDACT_COOKIES redacts cookies' '
 +      rm -rf clone &&
 +      echo "Set-Cookie: Foo=1" >cookies &&
 +      echo "Set-Cookie: Bar=2" >>cookies &&
 +      GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Bar,Baz \
 +              git -c "http.cookieFile=$(pwd)/cookies" clone \
 +              $HTTPD_URL/smart/repo.git clone 2>err &&
 +      grep "Cookie:.*Foo=1" err &&
 +      grep "Cookie:.*Bar=<redacted>" err &&
 +      ! grep "Cookie:.*Bar=2" err
 +'
 +
 +test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
 +      rm -rf clone &&
 +      echo "Set-Cookie: Foo=" >cookies &&
 +      GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Foo \
 +              git -c "http.cookieFile=$(pwd)/cookies" clone \
 +              $HTTPD_URL/smart/repo.git clone 2>err &&
 +      grep "Cookie:.*Foo=<redacted>" err
 +'
 +
 +test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
 +      rm -rf clone &&
 +      GIT_TRACE_CURL=true \
 +              git clone $HTTPD_URL/smart/repo.git clone 2>err &&
 +      grep "=> Send data" err &&
 +
 +      rm -rf clone &&
 +      GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
 +              git clone $HTTPD_URL/smart/repo.git clone 2>err &&
 +      ! grep "=> Send data" err
 +'
 +
  stop_httpd
  test_done
diff --combined t/t5561-http-backend.sh
index 84a955770a017e68d0cc1e928929e5a043d64e86,28c74b80a82ccbbd03c84179fc258b3f471b27b7..1c49054595c23564cf762ac01ea0a1667a59f2f9
@@@ -3,16 -3,10 +3,16 @@@
  test_description='test git-http-backend'
  . ./test-lib.sh
  . "$TEST_DIRECTORY"/lib-httpd.sh
 +
 +if ! test_have_prereq CURL; then
 +      skip_all='skipping raw http-backend tests, curl not available'
 +      test_done
 +fi
 +
  start_httpd
  
  GET() {
 -      curl --include "$HTTPD_URL/$SMART/repo.git/$1" >out 2>/dev/null &&
 +      curl --include "$HTTPD_URL/$SMART/repo.git/$1" >out &&
        tr '\015' Q <out |
        sed '
                s/Q$//
@@@ -25,7 -19,7 +25,7 @@@
  POST() {
        curl --include --data "$2" \
        --header "Content-Type: application/x-$1-request" \
 -      "$HTTPD_URL/smart/repo.git/$1" >out 2>/dev/null &&
 +      "$HTTPD_URL/smart/repo.git/$1" >out &&
        tr '\015' Q <out |
        sed '
                s/Q$//
@@@ -129,13 -123,7 +129,7 @@@ GET  /smart/repo.git/info/refs?service=
  POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
  EOF
  test_expect_success 'server request log matches test results' '
-       sed -e "
-               s/^.* \"//
-               s/\"//
-               s/ [1-9][0-9]*\$//
-               s/^GET /GET  /
-       " >act <"$HTTPD_ROOT_PATH"/access.log &&
-       test_cmp exp act
+       check_access_log exp
  '
  
  stop_httpd