@@ -19,7 +19,11 @@ temp_log_file=$(mktemp)
19
19
function test_interceptor {
20
20
# Run the interceptor and print logs to temporary log file
21
21
CAD_PD_TOKEN=$( echo $pd_test_token ) CAD_SILENT_POLICY=$( echo $pd_test_silence_policy ) ./../bin/interceptor > $temp_log_file 2>&1 &
22
-
22
+ 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 "
26
+
23
27
# Store the PID of the interceptor process
24
28
INTERCEPTOR_PID=$!
25
29
@@ -32,8 +36,8 @@ function test_interceptor {
32
36
# Send an interceptor request to localhost:8080
33
37
# See https://pkg.go.dev/github.com/tektoncd/triggers/pkg/apis/triggers/v1alpha1#InterceptorRequest
34
38
CURL_EXITCODE=0
35
- CURL_OUTPUT=$( curl -s -X POST -H " Content-Type: application/json" \
36
- -d " { \" body \" : \" { \\\" __pd_metadata \\\" :{ \\\" incident \\\" :{ \\\" id \\\" : \\\" $incident_id \\\" }}} \" , \" header \" :{ \" Content-Type \" :[ \" application/json \" ]}, \" extensions \" :{}, \" interceptor_params \" :{}, \" context \" :null} " \
39
+ CURL_OUTPUT=$( curl -s -X POST -H " X-PagerDuty-Signature:v1= ${SIGN} " -H " Content-Type: application/json" \
40
+ -d " $PAYLOAD " \
37
41
http://localhost:8080) || CURL_EXITCODE=$?
38
42
39
43
# Check if the curl output matches the expected response
@@ -69,5 +73,9 @@ echo "Test 1: alert with existing handling returns a 'continue: true' response"
69
73
test_interceptor " Q12WO44XJLR3H3" " $EXPECTED_RESPONSE_CONTINUE "
70
74
71
75
# Test for an alert we don't handle (alert called unhandled)
72
- echo " Test 1 : unhandled alerts returns a 'continue: false' response"
76
+ echo " Test 2 : unhandled alerts returns a 'continue: false' response"
73
77
test_interceptor " Q3722KGCG12ZWD" " $EXPECTED_RESPONSE_STOP "
78
+
79
+ echo " Test 3: expected failure due to invalid signature"
80
+ PD_SIGNATURE=" invalid-signature"
81
+ test_interceptor " Q12WO44XJLR3H3" " $EXPECTED_RESPONSE_STOP "
0 commit comments