Skip to content

Commit 4a98cc4

Browse files
committed
added funtest
Signed-off-by: Tullio Sebastiani <[email protected]> test fix Signed-off-by: Tullio Sebastiani <[email protected]> fix Signed-off-by: Tullio Sebastiani <[email protected]> fixed test Signed-off-by: Tullio Sebastiani <[email protected]> fix Signed-off-by: Tullio Sebastiani <[email protected]> fix test Signed-off-by: Tullio Sebastiani <[email protected]> fixed funtest Signed-off-by: Tullio Sebastiani <[email protected]> funtest fix Signed-off-by: Tullio Sebastiani <[email protected]> minor nit Signed-off-by: Tullio Sebastiani <[email protected]> added explicit curl method Signed-off-by: Tullio Sebastiani <[email protected]> push Signed-off-by: Tullio Sebastiani <[email protected]> fix Signed-off-by: Tullio Sebastiani <[email protected]> restored all funtests Signed-off-by: Tullio Sebastiani <[email protected]> added mime type test Signed-off-by: Tullio Sebastiani <[email protected]> fixed pipeline Signed-off-by: Tullio Sebastiani <[email protected]>
1 parent 804b38e commit 4a98cc4

File tree

5 files changed

+141
-14
lines changed

5 files changed

+141
-14
lines changed

.github/workflows/tests.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,30 @@ jobs:
6161
kubectl create namespace namespace-scenario
6262
kubectl apply -f CI/templates/time_pod.yaml
6363
kubectl wait --for=condition=ready pod -l scenario=time-skew --timeout=300s
64+
kubectl apply -f CI/templates/service_hijacking.yaml
65+
kubectl wait --for=condition=ready pod -l "app.kubernetes.io/name=proxy" --timeout=300s
6466
- name: Get Kind nodes
6567
run: |
6668
kubectl get nodes --show-labels=true
6769
# Pull request only steps
6870
- name: Run unit tests
6971
if: github.event_name == 'pull_request'
7072
run: python -m coverage run -a -m unittest discover -s tests -v
71-
7273
- name: Setup Pull Request Functional Tests
7374
if: github.event_name == 'pull_request'
7475
run: |
7576
yq -i '.kraken.port="8081"' CI/config/common_test_config.yaml
7677
yq -i '.kraken.signal_address="0.0.0.0"' CI/config/common_test_config.yaml
7778
yq -i '.kraken.performance_monitoring="localhost:9090"' CI/config/common_test_config.yaml
78-
echo "test_app_outages" > ./CI/tests/functional_tests
79-
echo "test_container" >> ./CI/tests/functional_tests
80-
echo "test_namespace" >> ./CI/tests/functional_tests
81-
echo "test_net_chaos" >> ./CI/tests/functional_tests
82-
echo "test_time" >> ./CI/tests/functional_tests
83-
echo "test_arca_cpu_hog" >> ./CI/tests/functional_tests
84-
echo "test_arca_memory_hog" >> ./CI/tests/functional_tests
85-
echo "test_arca_io_hog" >> ./CI/tests/functional_tests
79+
# echo "test_app_outages" > ./CI/tests/functional_tests
80+
# echo "test_container" >> ./CI/tests/functional_tests
81+
# echo "test_namespace" >> ./CI/tests/functional_tests
82+
# echo "test_net_chaos" >> ./CI/tests/functional_tests
83+
# echo "test_time" >> ./CI/tests/functional_tests
84+
# echo "test_arca_cpu_hog" >> ./CI/tests/functional_tests
85+
# echo "test_arca_memory_hog" >> ./CI/tests/functional_tests
86+
# echo "test_arca_io_hog" >> ./CI/tests/functional_tests
87+
echo "test_service_hijacking" > ./CI/tests/functional_tests
8688

8789
# Push on main only steps
8890
- name: Configure AWS Credentials

CI/templates/service_hijacking.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: nginx
5+
labels:
6+
app.kubernetes.io/name: proxy
7+
spec:
8+
containers:
9+
- name: nginx
10+
image: nginx:stable
11+
ports:
12+
- containerPort: 80
13+
name: http-web-svc
14+
15+
---
16+
apiVersion: v1
17+
kind: Service
18+
metadata:
19+
name: nginx-service
20+
spec:
21+
selector:
22+
app.kubernetes.io/name: proxy
23+
type: NodePort
24+
ports:
25+
- name: name-of-service-port
26+
protocol: TCP
27+
port: 80
28+
targetPort: http-web-svc
29+
nodePort: 30036

CI/tests/test_service_hijacking.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
set -xeEo pipefail
2+
3+
source CI/tests/common.sh
4+
5+
trap error ERR
6+
trap finish EXIT
7+
# port mapping has been configured in kind-config.yml
8+
SERVICE_URL=http://localhost:8888
9+
PAYLOAD_GET_1="{ \
10+
\"status\":\"internal server error\" \
11+
}"
12+
STATUS_CODE_GET_1=500
13+
14+
PAYLOAD_PATCH_1="resource patched"
15+
STATUS_CODE_PATCH_1=201
16+
17+
PAYLOAD_POST_1="{ \
18+
\"status\": \"unauthorized\" \
19+
}"
20+
STATUS_CODE_POST_1=401
21+
22+
PAYLOAD_GET_2="{ \
23+
\"status\":\"resource created\" \
24+
}"
25+
STATUS_CODE_GET_2=201
26+
27+
PAYLOAD_PATCH_2="bad request"
28+
STATUS_CODE_PATCH_2=400
29+
30+
PAYLOAD_POST_2="not found"
31+
STATUS_CODE_POST_2=404
32+
33+
JSON_MIME="application/json"
34+
TEXT_MIME="text/plain"
35+
36+
function functional_test_service_hijacking {
37+
38+
export scenario_type="service_hijacking"
39+
export scenario_file="scenarios/kube/service_hijacking.yaml"
40+
export post_config=""
41+
envsubst < CI/config/common_test_config.yaml > CI/config/service_hijacking.yaml
42+
python3 -m coverage run -a run_kraken.py -c CI/config/service_hijacking.yaml > /dev/null 2>&1 &
43+
PID=$!
44+
while [ `curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php` == 404 ]; do echo "waiting scenario to kick in."; sleep 1; done;
45+
OUT_GET="`curl -X GET -s $SERVICE_URL/list/index.php`"
46+
OUT_CONTENT=`curl -X GET -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php`
47+
OUT_STATUS_CODE=`curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php`
48+
[ "${PAYLOAD_GET_1//[$'\t\r\n ']}" == "${OUT_GET//[$'\t\r\n ']}" ] && echo "Step 1 GET Payload OK" || (echo "Payload did not match. Test failed." && exit 1)
49+
[ "$OUT_STATUS_CODE" == "$STATUS_CODE_GET_1" ] && echo "Step 1 GET Status Code OK" || (echo " Step 1 GET status code did not match. Test failed." && exit 1)
50+
[ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 1 GET MIME OK" || (echo " Step 1 GET MIME did not match. Test failed." && exit 1)
51+
52+
OUT_POST="`curl -s -X POST $SERVICE_URL/list/index.php`"
53+
OUT_STATUS_CODE=`curl -X POST -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php`
54+
OUT_CONTENT=`curl -X POST -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php`
55+
[ "${PAYLOAD_POST_1//[$'\t\r\n ']}" == "${OUT_POST//[$'\t\r\n ']}" ] && echo "Step 1 POST Payload OK" || (echo "Payload did not match. Test failed." && exit 1)
56+
[ "$OUT_STATUS_CODE" == "$STATUS_CODE_POST_1" ] && echo "Step 1 POST Status Code OK" || (echo "Step 1 POST status code did not match. Test failed." && exit 1)
57+
[ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 1 POST MIME OK" || (echo " Step 1 POST MIME did not match. Test failed." && exit 1)
58+
59+
OUT_PATCH="`curl -s -X PATCH $SERVICE_URL/patch`"
60+
OUT_STATUS_CODE=`curl -X PATCH -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/patch`
61+
OUT_CONTENT=`curl -X PATCH -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/patch`
62+
[ "${PAYLOAD_PATCH_1//[$'\t\r\n ']}" == "${OUT_PATCH//[$'\t\r\n ']}" ] && echo "Step 1 PATCH Payload OK" || (echo "Payload did not match. Test failed." && exit 1)
63+
[ "$OUT_STATUS_CODE" == "$STATUS_CODE_PATCH_1" ] && echo "Step 1 PATCH Status Code OK" || (echo "Step 1 PATCH status code did not match. Test failed." && exit 1)
64+
[ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 1 PATCH MIME OK" || (echo " Step 1 PATCH MIME did not match. Test failed." && exit 1)
65+
# wait for the next step
66+
sleep 16
67+
68+
OUT_GET="`curl -X GET -s $SERVICE_URL/list/index.php`"
69+
OUT_CONTENT=`curl -X GET -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php`
70+
OUT_STATUS_CODE=`curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php`
71+
[ "${PAYLOAD_GET_2//[$'\t\r\n ']}" == "${OUT_GET//[$'\t\r\n ']}" ] && echo "Step 2 GET Payload OK" || (echo "Step 2 GET Payload did not match. Test failed." && exit 1)
72+
[ "$OUT_STATUS_CODE" == "$STATUS_CODE_GET_2" ] && echo "Step 2 GET Status Code OK" || (echo "Step 2 GET status code did not match. Test failed." && exit 1)
73+
[ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 2 GET MIME OK" || (echo " Step 2 GET MIME did not match. Test failed." && exit 1)
74+
75+
OUT_POST="`curl -s -X POST $SERVICE_URL/list/index.php`"
76+
OUT_CONTENT=`curl -X POST -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php`
77+
OUT_STATUS_CODE=`curl -X POST -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php`
78+
[ "${PAYLOAD_POST_2//[$'\t\r\n ']}" == "${OUT_POST//[$'\t\r\n ']}" ] && echo "Step 2 POST Payload OK" || (echo "Step 2 POST Payload did not match. Test failed." && exit 1)
79+
[ "$OUT_STATUS_CODE" == "$STATUS_CODE_POST_2" ] && echo "Step 2 POST Status Code OK" || (echo "Step 2 POST status code did not match. Test failed." && exit 1)
80+
[ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 2 POST MIME OK" || (echo " Step 2 POST MIME did not match. Test failed." && exit 1)
81+
82+
OUT_PATCH="`curl -s -X PATCH $SERVICE_URL/patch`"
83+
OUT_CONTENT=`curl -X PATCH -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/patch`
84+
OUT_STATUS_CODE=`curl -X PATCH -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/patch`
85+
[ "${PAYLOAD_PATCH_2//[$'\t\r\n ']}" == "${OUT_PATCH//[$'\t\r\n ']}" ] && echo "Step 2 PATCH Payload OK" || (echo "Step 2 PATCH Payload did not match. Test failed." && exit 1)
86+
[ "$OUT_STATUS_CODE" == "$STATUS_CODE_PATCH_2" ] && echo "Step 2 PATCH Status Code OK" || (echo "Step 2 PATCH status code did not match. Test failed." && exit 1)
87+
[ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 2 PATCH MIME OK" || (echo " Step 2 PATCH MIME did not match. Test failed." && exit 1)
88+
wait $PID
89+
echo "Service Hijacking Chaos test: Success"
90+
}
91+
92+
93+
functional_test_service_hijacking

kind-config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ kind: Cluster
22
apiVersion: kind.x-k8s.io/v1alpha4
33
nodes:
44
- role: control-plane
5+
extraPortMappings:
6+
- containerPort: 30036
7+
hostPort: 8888
58
- role: control-plane
69
- role: control-plane
710
- role: worker

scenarios/kube/service_hijacking.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
service_target_port: http-web-svc # service port that will be hijacked (can be a named port or a port number depending on workload and svc configuration)
66
service_name: nginx-service # name of the service to be hijacked
77
service_namespace: default # namespace of the service to be hijacked
8-
image: quay.io/redhat-chaos/krkn-service-hijacking:v0.1.0 # krkn workload image that will be deployed and will receive the traffic
8+
image: quay.io/krkn-chaos/krkn-service-hijacking:v0.1.2 # krkn workload image that will be deployed and will receive the traffic
99
chaos_duration: 30 # duration of the chaos scenario in seconds
1010
plan:
1111
- resource: "/list/index.php" # resource that will respond to the scenario. Can be a resource or a path. in case of a path
@@ -34,26 +34,26 @@ plan:
3434
"status":"resource created"
3535
}
3636
POST:
37-
- duration: 7
37+
- duration: 15
3838
status: 401
3939
mime_type: "application/json"
4040
payload: |
4141
{
4242
"status": "unauthorized"
4343
}
44-
- duration: 1
44+
- duration: 15
4545
status: 404
4646
mime_type: "text/plain"
4747
payload: "not found"
4848

4949
- resource: "/patch"
5050
steps:
5151
PATCH:
52-
- duration: 3
52+
- duration: 15
5353
status: 201
5454
mime_type: "text/plain"
5555
payload: "resource patched"
56-
- duration: 2
56+
- duration: 15
5757
status: 400
5858
mime_type: "text/plain"
5959
payload: "bad request"

0 commit comments

Comments
 (0)