Skip to content

Commit

Permalink
chore(cd): add http2 smoke test (#10454)
Browse files Browse the repository at this point in the history
This PR adds a simple smoke test to check if the HTTP/2 listening port can respond with valid response data.

KAG-854
  • Loading branch information
windmgc authored Mar 9, 2023
1 parent bed7133 commit 40c572d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,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 +508,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 +531,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
18 changes: 18 additions & 0 deletions build/tests/03-http2-admin-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/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
err_exit " local cURL does not support HTTP/2"
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"
}

1 comment on commit 40c572d

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:40c572dc5b734ab4d2000cbd9f3f71456b60a626
Artifacts available https://github.com/Kong/kong/actions/runs/4371158787

Please sign in to comment.