Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): add http2 smoke test #10454

Merged
merged 9 commits into from
Mar 9, 2023
12 changes: 12 additions & 0 deletions .github/matrix-commitly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ build-packages:
os: ubuntu-22.04
package: deb
check-manifest-file: ubuntu-22.04-amd64.txt
# Alpine
- label: alpine
os: ubuntu-22.04
package: apk
bazel_args: --platforms=//:alpine-x86_64
check-manifest-file: alpine-amd64.txt

build-images:
- label: ubuntu
base-image: ubuntu:22.04
package: deb
artifact-from: ubuntu-22.04
# Alpine
- label: alpine
base-image: alpine:3.16
package: apk
artifact-from: alpine

smoke-tests:
- label: ubuntu
- label: alpine

scan-vulnerabilities:
- label: ubuntu
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ jobs:
runs-on: ubuntu-22.04
if: |-
fromJSON(needs.metadata.outputs.matrix)['smoke-tests'] != ''
&& (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'))

# TODO: test packages
strategy:
Expand All @@ -492,6 +491,7 @@ jobs:

env:
KONG_ADMIN_URI: http://localhost:8001
KONG_ADMIN_HTTP2_URI: https://localhost:8444
KONG_PROXY_URI: http://localhost:8000

steps:
Expand All @@ -507,9 +507,9 @@ jobs:
# always pull the latest image to ensure we're testing the latest version.
run: |
docker run \
-p 8000:8000 -p 8001:8001 \
-p 8000:8000 -p 8001:8001 -p 8444:8444\
-e KONG_PG_PASSWORD=kong \
-e KONG_ADMIN_LISTEN=0.0.0.0:8001 \
-e KONG_ADMIN_LISTEN="0.0.0.0:8001, 0.0.0.0:8444 ssl http2" \
-e KONG_ANONYMOUS_REPORTS=off \
--name kong \
--restart always \
Expand All @@ -530,6 +530,11 @@ jobs:
VERBOSE: ${{ runner.debug == '1' && '1' || '' }}
run: build/tests/02-admin-api.sh

- name: Smoke Tests - HTTP2 Admin API
env:
VERBOSE: ${{ runner.debug == '1' && '1' || '' }}
run: build/tests/03-http2-admin-api.sh

release-packages:
name: Release Packages - ${{ matrix.label }} - ${{ needs.metadata.outputs.release-desc }}
needs: [metadata, build-packages, build-images, smoke-tests]
Expand Down
19 changes: 19 additions & 0 deletions build/tests/03-http2-admin-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

if [ -n "${VERBOSE:-}" ]; then
set -x
fi

source .requirements
source build/tests/util.sh

kong_ready

msg_test "Check if cURL supports HTTP/2"
if ! curl --version | grep -i "http2" > /dev/null; then
msg_yellow "local cURL does not support HTTP/2, bypass HTTP/2 tests"
exit 0
windmgc marked this conversation as resolved.
Show resolved Hide resolved
fi

msg_test "Check HTTP/2 Admin API response is valid"
admin_api_http2_validity
37 changes: 37 additions & 0 deletions build/tests/util.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

KONG_ADMIN_URI=${KONG_ADMIN_URI:-"http://localhost:8001"}
KONG_ADMIN_HTTP2_URI=${KONG_ADMIN_HTTP2_URI:-"https://localhost:8444"}
KONG_PROXY_URI=${KONG_PROXY_URI:-"http://localhost:8000"}

set_x_flag=''
Expand Down Expand Up @@ -78,6 +79,24 @@ alpine() {
_os 'alpine'
}

assert_same() {
local expected=$(echo "$1" | tr -d '[:space:]')
local actual=$(echo "$2" | tr -d '[:space:]')

if [ "$expected" != "$actual" ]; then
err_exit " expected $expected, got $actual"
fi
}

assert_contains() {
local expected=$(echo "$1" | tr -d '[:space:]')
local actual="$2"

if ! echo "$actual" | grep -q "$expected"; then
err_exit " expected $expected in $actual but not found"
fi
}

assert_response() {
local endpoint=$1
local expected_codes=$2
Expand Down Expand Up @@ -135,3 +154,21 @@ it_runs_full_enterprise() {
msg_test "workspaces are writable"
assert_response "$KONG_ADMIN_URI/workspaces -d name=$(random_string)" "201"
}

admin_api_http2_validity() {
output=$(mktemp)
header_dump=$(mktemp)
status=$(curl -ks -D "$header_dump" -o "$output" -w '%{http_code}' "$KONG_ADMIN_HTTP2_URI")

msg_test "it returns with response status code 200"
assert_same "200" "$status"

msg_test "it returns with response header content-type application/json"
assert_contains "application/json" "$(cat "$header_dump" | grep -i content-type | tr -d '[:space:]')"

msg_test "it returns a response body with correct length"
assert_same "$(wc -c < "$output")" "$(cat "$header_dump" | grep -i content-length | cut -d' ' -f2 | tr -d '[:space:]')"

msg_test "the response body is valid json and has valid json schema"
jq . "$output" > /dev/null || err_exit " response body is not valid json"
}