Skip to content

Commit

Permalink
added funtest
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tsebastiani committed May 8, 2024
1 parent 804b38e commit 4a98cc4
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 14 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,30 @@ jobs:
kubectl create namespace namespace-scenario
kubectl apply -f CI/templates/time_pod.yaml
kubectl wait --for=condition=ready pod -l scenario=time-skew --timeout=300s
kubectl apply -f CI/templates/service_hijacking.yaml
kubectl wait --for=condition=ready pod -l "app.kubernetes.io/name=proxy" --timeout=300s
- name: Get Kind nodes
run: |
kubectl get nodes --show-labels=true
# Pull request only steps
- name: Run unit tests
if: github.event_name == 'pull_request'
run: python -m coverage run -a -m unittest discover -s tests -v

- name: Setup Pull Request Functional Tests
if: github.event_name == 'pull_request'
run: |
yq -i '.kraken.port="8081"' CI/config/common_test_config.yaml
yq -i '.kraken.signal_address="0.0.0.0"' CI/config/common_test_config.yaml
yq -i '.kraken.performance_monitoring="localhost:9090"' CI/config/common_test_config.yaml
echo "test_app_outages" > ./CI/tests/functional_tests
echo "test_container" >> ./CI/tests/functional_tests
echo "test_namespace" >> ./CI/tests/functional_tests
echo "test_net_chaos" >> ./CI/tests/functional_tests
echo "test_time" >> ./CI/tests/functional_tests
echo "test_arca_cpu_hog" >> ./CI/tests/functional_tests
echo "test_arca_memory_hog" >> ./CI/tests/functional_tests
echo "test_arca_io_hog" >> ./CI/tests/functional_tests
# echo "test_app_outages" > ./CI/tests/functional_tests
# echo "test_container" >> ./CI/tests/functional_tests
# echo "test_namespace" >> ./CI/tests/functional_tests
# echo "test_net_chaos" >> ./CI/tests/functional_tests
# echo "test_time" >> ./CI/tests/functional_tests
# echo "test_arca_cpu_hog" >> ./CI/tests/functional_tests
# echo "test_arca_memory_hog" >> ./CI/tests/functional_tests
# echo "test_arca_io_hog" >> ./CI/tests/functional_tests
echo "test_service_hijacking" > ./CI/tests/functional_tests

# Push on main only steps
- name: Configure AWS Credentials
Expand Down
29 changes: 29 additions & 0 deletions CI/templates/service_hijacking.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app.kubernetes.io/name: proxy
spec:
containers:
- name: nginx
image: nginx:stable
ports:
- containerPort: 80
name: http-web-svc

---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app.kubernetes.io/name: proxy
type: NodePort
ports:
- name: name-of-service-port
protocol: TCP
port: 80
targetPort: http-web-svc
nodePort: 30036
93 changes: 93 additions & 0 deletions CI/tests/test_service_hijacking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
set -xeEo pipefail

source CI/tests/common.sh

trap error ERR
trap finish EXIT
# port mapping has been configured in kind-config.yml
SERVICE_URL=http://localhost:8888
PAYLOAD_GET_1="{ \
\"status\":\"internal server error\" \
}"
STATUS_CODE_GET_1=500

PAYLOAD_PATCH_1="resource patched"
STATUS_CODE_PATCH_1=201

PAYLOAD_POST_1="{ \
\"status\": \"unauthorized\" \
}"
STATUS_CODE_POST_1=401

PAYLOAD_GET_2="{ \
\"status\":\"resource created\" \
}"
STATUS_CODE_GET_2=201

PAYLOAD_PATCH_2="bad request"
STATUS_CODE_PATCH_2=400

PAYLOAD_POST_2="not found"
STATUS_CODE_POST_2=404

JSON_MIME="application/json"
TEXT_MIME="text/plain"

function functional_test_service_hijacking {

export scenario_type="service_hijacking"
export scenario_file="scenarios/kube/service_hijacking.yaml"
export post_config=""
envsubst < CI/config/common_test_config.yaml > CI/config/service_hijacking.yaml
python3 -m coverage run -a run_kraken.py -c CI/config/service_hijacking.yaml > /dev/null 2>&1 &
PID=$!
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;
OUT_GET="`curl -X GET -s $SERVICE_URL/list/index.php`"
OUT_CONTENT=`curl -X GET -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php`
OUT_STATUS_CODE=`curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php`
[ "${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)
[ "$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)
[ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 1 GET MIME OK" || (echo " Step 1 GET MIME did not match. Test failed." && exit 1)

OUT_POST="`curl -s -X POST $SERVICE_URL/list/index.php`"
OUT_STATUS_CODE=`curl -X POST -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php`
OUT_CONTENT=`curl -X POST -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php`
[ "${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)
[ "$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)
[ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 1 POST MIME OK" || (echo " Step 1 POST MIME did not match. Test failed." && exit 1)

OUT_PATCH="`curl -s -X PATCH $SERVICE_URL/patch`"
OUT_STATUS_CODE=`curl -X PATCH -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/patch`
OUT_CONTENT=`curl -X PATCH -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/patch`
[ "${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)
[ "$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)
[ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 1 PATCH MIME OK" || (echo " Step 1 PATCH MIME did not match. Test failed." && exit 1)
# wait for the next step
sleep 16

OUT_GET="`curl -X GET -s $SERVICE_URL/list/index.php`"
OUT_CONTENT=`curl -X GET -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php`
OUT_STATUS_CODE=`curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php`
[ "${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)
[ "$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)
[ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 2 GET MIME OK" || (echo " Step 2 GET MIME did not match. Test failed." && exit 1)

OUT_POST="`curl -s -X POST $SERVICE_URL/list/index.php`"
OUT_CONTENT=`curl -X POST -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php`
OUT_STATUS_CODE=`curl -X POST -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php`
[ "${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)
[ "$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)
[ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 2 POST MIME OK" || (echo " Step 2 POST MIME did not match. Test failed." && exit 1)

OUT_PATCH="`curl -s -X PATCH $SERVICE_URL/patch`"
OUT_CONTENT=`curl -X PATCH -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/patch`
OUT_STATUS_CODE=`curl -X PATCH -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/patch`
[ "${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)
[ "$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)
[ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 2 PATCH MIME OK" || (echo " Step 2 PATCH MIME did not match. Test failed." && exit 1)
wait $PID
echo "Service Hijacking Chaos test: Success"
}


functional_test_service_hijacking
3 changes: 3 additions & 0 deletions kind-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30036
hostPort: 8888
- role: control-plane
- role: control-plane
- role: worker
Expand Down
10 changes: 5 additions & 5 deletions scenarios/kube/service_hijacking.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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)
service_name: nginx-service # name of the service to be hijacked
service_namespace: default # namespace of the service to be hijacked
image: quay.io/redhat-chaos/krkn-service-hijacking:v0.1.0 # krkn workload image that will be deployed and will receive the traffic
image: quay.io/krkn-chaos/krkn-service-hijacking:v0.1.2 # krkn workload image that will be deployed and will receive the traffic
chaos_duration: 30 # duration of the chaos scenario in seconds
plan:
- resource: "/list/index.php" # resource that will respond to the scenario. Can be a resource or a path. in case of a path
Expand Down Expand Up @@ -34,26 +34,26 @@ plan:
"status":"resource created"
}
POST:
- duration: 7
- duration: 15
status: 401
mime_type: "application/json"
payload: |
{
"status": "unauthorized"
}
- duration: 1
- duration: 15
status: 404
mime_type: "text/plain"
payload: "not found"

- resource: "/patch"
steps:
PATCH:
- duration: 3
- duration: 15
status: 201
mime_type: "text/plain"
payload: "resource patched"
- duration: 2
- duration: 15
status: 400
mime_type: "text/plain"
payload: "bad request"

0 comments on commit 4a98cc4

Please sign in to comment.