Skip to content

Commit 966b943

Browse files
author
Prasad, Hari
committed
fixing review commnets, adding tests
1 parent 344b168 commit 966b943

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

out

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ if [[ ${disable} == "true" ]]; then
2424
exit 0
2525
fi
2626

27-
webhook_url="$( jq --raw-output '.source.url // "https://slack.com/api/chat.postMessage"' < "${payload}")"
28-
oauth_token="$( jq --raw-output '.source.token' < "${payload}")"
27+
webhook_url="$( jq --raw-output '.source.url // "https://slack.com/api/chat.postMessage"' <<< "${payload}")"
28+
oauth_token="$( jq --raw-output '.source.token' <<< "${payload}")"
2929
allow_insecure=$(jq --raw-output '.source.insecure // "false"' <<< "${payload}")
3030
raw_ca_certs=$( jq '.source.ca_certs // []' <<< "${payload}")
3131

@@ -176,9 +176,9 @@ EOF
176176
elif [[ "${silent}" == "true" ]]; then
177177
echo "INFO: using silent output"
178178
if [[ -n ${oauth_token} ]]; then
179-
curl -s -X POST -H 'Content-type: application/json' \
180-
-H "Authorization: Bearer ${oauth_token}" \
181-
-T /tmp/compact_body.json ${CURL_OPTION} "${webhook_url}"
179+
curl --silent -X POST --header 'Content-type: application/json' \
180+
--header "Authorization: Bearer ${oauth_token}" \
181+
--data-raw "${compact_body}" ${CURL_OPTIONS[@]} "${webhook_url}"
182182
else
183183
curl --silent --fail --show-error --location "${CURL_OPTIONS[@]}" \
184184
--request "POST" --url "${webhook_url}" \
@@ -190,10 +190,10 @@ EOF
190190
sed -Ee 's,https?://[^/]*(/[^?&#]*).*,\1,' <<< "${webhook_url}"
191191
)
192192
if [[ -n ${oauth_token} ]]; then
193-
curl -v -X POST -H 'Content-type: application/json' \
194-
-H "Authorization: Bearer ${oauth_token}" \
195-
-T /tmp/compact_body.json \
196-
${CURL_OPTION} "${webhook_url}" 2>&1 | sed -e "s#${url_path}#***WEBHOOK URL REDACTED***#g"
193+
curl -v -X POST --header 'Content-type: application/json' \
194+
--header "Authorization: Bearer ${oauth_token}" \
195+
--data-raw "${compact_body}" \
196+
${CURL_OPTIONS[@]} "${webhook_url}" 2>&1 | sed -e "s#${url_path}#***OAUTH TOKEN REDACTED***#g"
197197
else
198198
curl --verbose --silent --fail --show-error --location "${CURL_OPTIONS[@]}" \
199199
--request "POST" --url "${webhook_url}" \
@@ -203,10 +203,10 @@ EOF
203203
curl_errors=$(( ${curl_errors} + ${PIPESTATUS[0]} ))
204204
else
205205
if [[ -n ${oauth_token} ]]; then
206-
curl -v -X POST -H 'Content-type: application/json' \
207-
-H "Authorization: Bearer ${oauth_token}" \
208-
-T /tmp/compact_body.json \
209-
${CURL_OPTION} "${webhook_url}" | sed -e "s#${url_path}#***WEBHOOK URL REDACTED***#g"
206+
curl -v -X POST --header 'Content-type: application/json' \
207+
--header "Authorization: Bearer ${oauth_token}" \
208+
--data-raw "${compact_body}" \
209+
${CURL_OPTIONS[@]} "${webhook_url}" | sed -e "s#${url_path}#***OAUTH TOKEN REDACTED***#g"
210210
else
211211
curl --verbose --silent --fail --show-error --location "${CURL_OPTIONS[@]}" \
212212
--request "POST" --url "${webhook_url}" \

test/all.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,18 @@ test env_file | jq -e "
254254
.body.attachments[1].text == \"<something> - ./path/to/*.jar\" and
255255
( .body.attachments | length == 2 )"
256256

257+
oauth_token_test() {
258+
payload='{ "source": { "token": "test-oauth-token" }, "params": { "text": "Test message" } }'
259+
result=$(echo "$payload" | ${cmd})
260+
expected='{"version":{"timestamp":"$(date +%s)"}}'
261+
if [[ "$result" == *"version"* ]]; then
262+
echo "OAuth token test passed"
263+
else
264+
echo "OAuth token test failed: expected $expected but got $result"
265+
fi
266+
}
267+
268+
# Call the oauth_token_test function
269+
oauth_token_test
270+
257271
echo -e '\e[32;1m'"All tests passed!"'\e[0m'

0 commit comments

Comments
 (0)