@@ -9,35 +9,40 @@ NC='\033[0m'
9
9
# Load pd token from vault - needed by interceptor
10
10
export VAULT_ADDR=" https://vault.devshift.net"
11
11
export VAULT_TOKEN=" $( vault login -method=oidc -token-only) "
12
- for v in $( vault kv get -format=json osd-sre/configuration-anomaly-detection/cad-testing | jq -r " .data.data|to_entries|map(\" \(.key)=\(.value|tostring)\" )|.[]" ) ; do export $v ; done
12
+ for v in $( vault kv get -format=json osd-sre/configuration-anomaly-detection/cad-testing | jq -r " .data.data|to_entries|map(\" \(.key)=\(.value|tostring)\" )|.[]" ) ; do export $v ; done
13
13
unset VAULT_ADDR VAULT_TOKEN
14
- echo
14
+ echo
15
15
16
16
temp_log_file=$( mktemp)
17
17
18
18
# Function to send an interceptor request and check the response
19
19
function test_interceptor {
20
+
21
+ local incident_id=$1
22
+ local expected_response=$2
23
+
20
24
# Run the interceptor and print logs to temporary log file
21
25
CAD_PD_TOKEN=$( echo $pd_test_token ) CAD_SILENT_POLICY=$( echo $pd_test_silence_policy ) ./../bin/interceptor > $temp_log_file 2>&1 &
22
26
PD_SIGNATURE=" test"
23
- PAYLOAD =" {\" body \" : \" { \\\" __pd_metadata\\\" :{\\\" incident\\\" :{\\\" id\\\" :\\\" $incident_id \\\" }}} \" , \" header \" :{ \" Content-Type \" :[ \" application/json \" ]}, \" extensions \" :{}, \" interceptor_params \" :{}, \" context \" :null }"
24
- SIGN= $( echo -n " $PAYLOAD " | sha256hmac -K $PD_SIGNATURE | tr -d " [:space:]- " )
25
- echo " Sign: $SIGN "
27
+ PAYLOAD_BODY =" {\\\" __pd_metadata\\\" :{\\\" incident\\\" :{\\\" id\\\" :\\\" $incident_id \\\" }}}"
28
+ PAYLOAD_BODY_FORMATTED= ' {"__pd_metadata":{"incident":{"id":" ' $incident_id ' "}}} '
29
+ SIGN= $( echo -n " $PAYLOAD_BODY_FORMATTED " | sha256hmac -K $PD_SIGNATURE | tr -d " [:space:]- " )
26
30
27
31
# Store the PID of the interceptor process
28
32
INTERCEPTOR_PID=$!
29
33
34
+ # Wrap the webhook originating payload (this is the expected format of the payload sent to the interceptor)
35
+ WRAPPED_PAYLOAD=" {\" header\" :{\" Content-Type\" :[\" application/json\" ],\" X-PagerDuty-Signature\" :[\" v1=$SIGN \" ]},\" body\" :\" $PAYLOAD_BODY \" }"
36
+
30
37
# Wait for 1 second to allow the interceptor to start up
31
38
sleep 5
32
39
33
- local incident_id=$1
34
- local expected_response=$2
35
40
36
41
# Send an interceptor request to localhost:8080
37
42
# See https://pkg.go.dev/github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1#InterceptorRequest
38
43
CURL_EXITCODE=0
39
44
CURL_OUTPUT=$( curl -s -X POST -H " X-PagerDuty-Signature:v1=${SIGN} " -H " Content-Type: application/json" \
40
- -d " $PAYLOAD " \
45
+ -d " $WRAPPED_PAYLOAD " \
41
46
http://localhost:8080) || CURL_EXITCODE=$?
42
47
43
48
# Check if the curl output matches the expected response
@@ -66,6 +71,7 @@ function test_interceptor {
66
71
# See https://github.com/tektoncd/triggers/blob/v0.27.0/pkg/apis/triggers/v1alpha1/interceptor_types.go#L134
67
72
EXPECTED_RESPONSE_CONTINUE=' {"continue":true,"status":{}}'
68
73
EXPECTED_RESPONSE_STOP=' {"continue":false,"status":{}}'
74
+ EXPECTED_RESPONSE_SIGNATURE_ERROR=' failed to verify signature: invalid webhook signature'
69
75
70
76
echo " ========= TESTS ============="
71
77
# Test for a pre-existing alert we handle (ClusterProvisioningDelay)
@@ -76,6 +82,7 @@ test_interceptor "Q12WO44XJLR3H3" "$EXPECTED_RESPONSE_CONTINUE"
76
82
echo " Test 2: unhandled alerts returns a 'continue: false' response"
77
83
test_interceptor " Q3722KGCG12ZWD" " $EXPECTED_RESPONSE_STOP "
78
84
85
+ # Test for an alert with invalid signature
79
86
echo " Test 3: expected failure due to invalid signature"
80
87
PD_SIGNATURE=" invalid-signature"
81
- test_interceptor " Q12WO44XJLR3H3" " $EXPECTED_RESPONSE_STOP "
88
+ test_interceptor " Q12WO44XJLR3H3" " $EXPECTED_RESPONSE_SIGNATURE_ERROR "
0 commit comments