Skip to content

Commit 74b7f87

Browse files
authored
Merge pull request #292 from TykTechnologies/streams-kafka-test
Streams kafka test
2 parents e0212b5 + 6046c65 commit 74b7f87

File tree

15 files changed

+102
-18
lines changed

15 files changed

+102
-18
lines changed

deployments/healthcheck-blackbox/bootstrap.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ deployment="Health Check - Blackbox Exporter"
66

77
log_start_deployment
88

9-
# This deployment does not require any bootstrap steps.
9+
log_message "Wait for services to be ready, as tests as based on health checks"
10+
wait_for_liveness
1011
bootstrap_progress
1112

1213
log_end_deployment
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# Variables
4+
POST_URL="http://tyk-gateway.localhost:8080/streams-authentication/post"
5+
GET_URL="http://tyk-gateway.localhost:8080/streams-authentication/get/stream"
6+
DATA="test-message-$(date +%s)"
7+
TIMEOUT=10
8+
RESPONSE_FILE=$(mktemp)
9+
AUTH_HEADER="Authorization: streams_authentication"
10+
11+
# Function to clean up background listener
12+
cleanup() {
13+
if [[ -n "$listener_pid" ]]; then
14+
kill "$listener_pid" 2>/dev/null || true
15+
disown "$listener_pid" 2>/dev/null || true # Suppress shell termination messages
16+
fi
17+
rm -f "$RESPONSE_FILE"
18+
}
19+
trap cleanup EXIT
20+
21+
# Test unauthenticated request
22+
echo "Testing unauthenticated request..."
23+
if curl -s -o /dev/null -w "%{http_code}" -X POST "$POST_URL" -H "Content-Type: text/plain" -d "$DATA" | grep -q "401"; then
24+
echo "Unauthenticated request correctly rejected."
25+
else
26+
echo "Unauthenticated request was not rejected."
27+
exit 1
28+
fi
29+
30+
# Start listening for the message in the background
31+
curl -N "$GET_URL" -H "$AUTH_HEADER" > "$RESPONSE_FILE" 2>&1 & listener_pid=$!
32+
33+
# Send the authenticated message
34+
echo "Testing authenticated request..."
35+
if ! curl -s -X POST "$POST_URL" -H "Content-Type: text/plain" -H "$AUTH_HEADER" -d "$DATA" >/dev/null; then
36+
echo "Failed to send authenticated message."
37+
exit 1
38+
fi
39+
40+
# Poll the response file for the expected message
41+
end_time=$((SECONDS + TIMEOUT))
42+
while [[ $SECONDS -lt $end_time ]]; do
43+
if grep -q "$DATA" "$RESPONSE_FILE"; then
44+
echo "Authenticated message received: $DATA"
45+
exit 0
46+
fi
47+
sleep 1
48+
done
49+
50+
echo "Authenticated message not received within timeout period."
51+
exit 1

deployments/tyk/scripts/examples/streams/Kafka/README.md renamed to deployments/tyk/scripts/examples/streams/kafka/README.md

File renamed without changes.

deployments/tyk/scripts/examples/streams/Kafka/listen_cli.sh renamed to deployments/tyk/scripts/examples/streams/kafka/listen_cli.sh

File renamed without changes.

deployments/tyk/scripts/examples/streams/Kafka/listen_sse.sh renamed to deployments/tyk/scripts/examples/streams/kafka/listen_sse.sh

File renamed without changes.

deployments/tyk/scripts/examples/streams/Kafka/post_data.sh renamed to deployments/tyk/scripts/examples/streams/kafka/post_data.sh

File renamed without changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Variables
4+
POST_URL="http://tyk-gateway.localhost:8080/streams-kafka/post"
5+
GET_URL="http://tyk-gateway.localhost:8080/streams-kafka/get/stream"
6+
DATA="test-message-$(date +%s)"
7+
TIMEOUT=10
8+
RESPONSE_FILE=$(mktemp)
9+
10+
# Function to clean up background listener
11+
cleanup() {
12+
if [[ -n "$listener_pid" ]]; then
13+
kill "$listener_pid" 2>/dev/null || true
14+
disown "$listener_pid" 2>/dev/null || true # Suppress shell termination messages
15+
fi
16+
rm -f "$RESPONSE_FILE"
17+
}
18+
trap cleanup EXIT
19+
20+
# Start listening for the message in the background
21+
curl -N "$GET_URL" > "$RESPONSE_FILE" 2>&1 & listener_pid=$!
22+
23+
# Send the message
24+
if ! curl -s -X POST "$POST_URL" -H "Content-Type: text/plain" -d "$DATA" >/dev/null; then
25+
echo "Failed to send message."
26+
exit 1
27+
fi
28+
29+
# Poll the response file for the expected message
30+
end_time=$((SECONDS + TIMEOUT))
31+
while [[ $SECONDS -lt $end_time ]]; do
32+
if grep -q "$DATA" "$RESPONSE_FILE"; then
33+
echo "Message received: $DATA"
34+
exit 0
35+
fi
36+
sleep 1
37+
done
38+
39+
echo "Message not received within timeout period."
40+
exit 1

deployments/tyk/scripts/examples/streams/SSE/README.md renamed to deployments/tyk/scripts/examples/streams/sse/README.md

File renamed without changes.

deployments/tyk/scripts/examples/streams/SSE/listen_sse.sh renamed to deployments/tyk/scripts/examples/streams/sse/listen_sse.sh

File renamed without changes.

deployments/tyk/scripts/examples/streams/SSE/post_data.sh renamed to deployments/tyk/scripts/examples/streams/sse/post_data.sh

File renamed without changes.

0 commit comments

Comments
 (0)