From 4f6cd6577c300d38ec98eba3019e525abe857c27 Mon Sep 17 00:00:00 2001 From: arpit551 Date: Sat, 4 Jul 2020 16:47:27 +0530 Subject: [PATCH] http_headers: Substitute Nginx version based on OS. success-http-headers-bionic.txt and success-http-headers-focal.txt differ only in the nginx version so this substitution will allow us to have single file for both of them. Also this change helps to avoid CI failure if Nginx version is updated in the OS. --- .circleci/config.yml | 3 +- tools/ci/production-build | 3 +- tools/ci/production-verify | 13 ++++----- tools/ci/success-http-headers-focal.txt | 28 ------------------- ....txt => success-http-headers.template.txt} | 4 +-- tools/linter_lib/custom_check.py | 2 +- 6 files changed, 10 insertions(+), 43 deletions(-) delete mode 100644 tools/ci/success-http-headers-focal.txt rename tools/ci/{success-http-headers-bionic.txt => success-http-headers.template.txt} (92%) diff --git a/.circleci/config.yml b/.circleci/config.yml index ef178c668f..ff75b97bd3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -299,8 +299,7 @@ jobs: # Must be relative path from root paths: - zulip-server-test.tar.gz - - success-http-headers-bionic.txt - - success-http-headers-focal.txt + - success-http-headers.template.txt - production-install - production-verify - production-upgrade-pg diff --git a/tools/ci/production-build b/tools/ci/production-build index e08f263468..d9eb426e8c 100755 --- a/tools/ci/production-build +++ b/tools/ci/production-build @@ -32,8 +32,7 @@ fi # .circleci/config.yml mv /tmp/tmp.*/zulip-server-test.tar.gz /tmp/ cp -a \ - tools/ci/success-http-headers-bionic.txt \ - tools/ci/success-http-headers-focal.txt \ + tools/ci/success-http-headers.template.txt \ tools/ci/production-install \ tools/ci/production-verify \ tools/ci/production-upgrade-pg \ diff --git a/tools/ci/production-verify b/tools/ci/production-verify index 0625fd65ab..f3b474e040 100755 --- a/tools/ci/production-verify +++ b/tools/ci/production-verify @@ -5,11 +5,6 @@ set -e set -x -if [ -f /etc/os-release ]; then - os_info="$(. /etc/os-release; printf '%s\n' "$VERSION_CODENAME")" - { read -r os_version_codename || true; } <<< "$os_info" -fi - cat >>/etc/zulip/settings.py < /tmp/wget-output || true # || true so we see errors.log if this 500s grep -vi '\(Vary\|Content-Language\|expires\|issued by\|modified\|saved\|[.][.][.]\|Date\|[-][-]\)' /tmp/wget-output > /tmp/http-headers-processed +nginx_version="$(nginx -v 2>&1 | awk '{print $3, $4}')" + # Simplify the diff by getting replacing 4-5 digit length numbers with . sed -i 's|Length: [0-9]\+\( [(][0-9]\+[.][0-9]K[)]\)\?|Length: |' /tmp/http-headers-processed -sed -i 's|Length: [0-9]\+\( [(][0-9]\+[.][0-9]K[)]\)\?|Length: |' /tmp/success-http-headers-"$os_version_codename".txt -if ! diff -ur /tmp/http-headers-processed /tmp/success-http-headers-"$os_version_codename".txt; then +sed -i -e 's|Length: [0-9]\+\( [(][0-9]\+[.][0-9]K[)]\)\?|Length: |' -e "s|{nginx_version_string}|$nginx_version|g" /tmp/success-http-headers.template.txt +if ! diff -ur /tmp/http-headers-processed /tmp/success-http-headers.template.txt; then set +x echo - echo "FAILURE: The HTTP Headers returned from loading the homepage on the server do not match the contents of tools/ci/success-http-headers.txt. Typically, this means that the server threw a 500 when trying to load the homepage." + echo "FAILURE: The HTTP Headers returned from loading the homepage on the server do not match the contents of tools/ci/success-http-headers.template.txt. Typically, this means that the server threw a 500 when trying to load the homepage." echo "Displaying the contents of the server's error log:" echo cat /var/log/zulip/errors.log diff --git a/tools/ci/success-http-headers-focal.txt b/tools/ci/success-http-headers-focal.txt deleted file mode 100644 index 8fa7d47206..0000000000 --- a/tools/ci/success-http-headers-focal.txt +++ /dev/null @@ -1,28 +0,0 @@ - Self-signed certificate encountered. - WARNING: certificate common name ‘127.0.0.1’ doesn't match requested host name ‘localhost’. - HTTP/1.1 302 Found - Server: nginx/1.18.0 (Ubuntu) - Content-Type: text/html; charset=utf-8 - Content-Length: 0 - Connection: keep-alive - Location: /login/ - Strict-Transport-Security: max-age=15768000 - X-Frame-Options: DENY - X-Content-Type-Options: nosniff - X-XSS-Protection: 1; mode=block -Location: /login/ [following] -Reusing existing connection to localhost:443. - HTTP/1.1 200 OK - Server: nginx/1.18.0 (Ubuntu) - Content-Type: text/html; charset=utf-8 - Content-Length: 6361 - Connection: keep-alive - Strict-Transport-Security: max-age=15768000 - X-Frame-Options: DENY - X-Content-Type-Options: nosniff - X-XSS-Protection: 1; mode=block -Length: 6361 (6.2K) [text/html] -Saving to: ‘/tmp/index.html’ - - - diff --git a/tools/ci/success-http-headers-bionic.txt b/tools/ci/success-http-headers.template.txt similarity index 92% rename from tools/ci/success-http-headers-bionic.txt rename to tools/ci/success-http-headers.template.txt index 20c863ed5b..113cb9da65 100644 --- a/tools/ci/success-http-headers-bionic.txt +++ b/tools/ci/success-http-headers.template.txt @@ -1,7 +1,7 @@ Self-signed certificate encountered. WARNING: certificate common name ‘127.0.0.1’ doesn't match requested host name ‘localhost’. HTTP/1.1 302 Found - Server: nginx/1.14.0 (Ubuntu) + Server: {nginx_version_string} Content-Type: text/html; charset=utf-8 Content-Length: 0 Connection: keep-alive @@ -13,7 +13,7 @@ Location: /login/ [following] Reusing existing connection to localhost:443. HTTP/1.1 200 OK - Server: nginx/1.14.0 (Ubuntu) + Server: {nginx_version_string} Content-Type: text/html; charset=utf-8 Content-Length: 6361 Connection: keep-alive diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index a7a9392df8..2bf7b76b58 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -65,7 +65,7 @@ whitespace_rules: List["Rule"] = [ }, {'pattern': '\t', 'strip': '\n', - 'exclude': {'tools/ci/success-http-headers-bionic.txt', 'tools/ci/success-http-headers-focal.txt'}, + 'exclude': {'tools/ci/success-http-headers.template.txt'}, 'description': 'Fix tab-based whitespace'}, ] comma_whitespace_rule: List["Rule"] = [