-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-sigstore.sh
executable file
·53 lines (45 loc) · 1.38 KB
/
test-sigstore.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -euo pipefail
# Test configuration
HOST=${HOST:-"localhost:8080"}
TEST_IMAGE=${SIGSTORE_PATH:-""}
EXPECTED_URL="https://access.redhat.com/webassets/docker/content/sigstore/${TEST_IMAGE}"
echo "Testing sigstore endpoint redirection..."
echo "Using host: ${HOST}"
echo "Test image: ${TEST_IMAGE}"
# Use curl to make the request and capture headers
# -s: silent
# -I: headers only
response=$(curl -s -I "https://${HOST}/containers/sigstore/${TEST_IMAGE}")
if [ -z "$response" ]; then
echo -e "Test failed: No response"
exit 1
fi
# Extract the Location header
redirect_url=$(echo "$response" | grep -i "location:" | head -n1 | awk '{print $2}' | tr -d '\r')
if [ -z "$redirect_url" ]; then
echo -e "Test failed: No redirect URL"
echo "Response:"
echo "$response"
exit 1
fi
# Check if we got a redirect (301)
if ! echo "$response" | grep -E "HTTP/1.1 301|HTTP/2 301"; then
echo -e "Test failed: Expected 301 redirect status code"
echo "Response:"
echo "$response"
exit 1
fi
# Check if redirect URL matches expected URL
if [ "$redirect_url" = "$EXPECTED_URL" ]; then
echo -e "Test passed: Redirect URL matches expected URL"
echo "$response"
exit 0
else
echo -e "Test failed: Redirect URL doesn't match expected URL"
echo "Expected: $EXPECTED_URL"
echo "Got: $redirect_url"
echo "Response:"
echo "$response"
exit 1
fi