Add script to test PUSH token

This commit is contained in:
Benoit Marty 2020-10-02 11:55:41 +02:00
parent cb33b9f158
commit 3133cbcc3e
2 changed files with 99 additions and 0 deletions

46
tools/tests/test_push.sh Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env bash
# Some doc
# https://firebase.google.com/docs/cloud-messaging/android/first-message
# http://bulkpush.com/pushnotification/guidedetail/s-4/android-gcm-api-configuration
# http://www.feelzdroid.com/2016/02/android-google-cloud-messaging-push-notifications-gcm-tutorial.html
# Ask for parameter
read -p "Enter the server API key: " SERVER_KEY
echo
echo "Check validity of API key, InvalidRegistration error is OK"
# https://developers.google.com/cloud-messaging/http
curl -H "Authorization: key=$SERVER_KEY" \
-H Content-Type:"application/json" \
-d "{\"registration_ids\":[\"ABC\"]}" \
-s \
https://fcm.googleapis.com/fcm/send \
| python -m json.tool
# should obtain something like this:
# {"multicast_id":5978845027639121780,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
read -p "Enter the FCM token: " FCM_TOKEN
# content of the notification
DATA="{\"message\":\"Message of PUSH!\"}"
echo
echo
echo "Send a push, you should see success:1..."
curl -H "Authorization: key=$SERVER_KEY" \
-H Content-Type:"application/json" \
-d "{ \"data\" : $DATA, \"to\":\"$FCM_TOKEN\" }" \
-s \
https://fcm.googleapis.com/fcm/send \
| python -m json.tool
echo
echo
# should obtain something like this:
# {"multicast_id":7967233883611790812,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1472636210339069%84ac25d9f9fd7ecd"}]}

53
tools/tests/test_push_unsafe.sh Executable file
View file

@ -0,0 +1,53 @@
#!/usr/bin/env bash
# Copy and adaptation of ./test_push.sh, which takes 2 params: server key and fcm token.
# It's unsafe to use it because it takes server key as parameter, that will remain in the terminal history.
# Some doc
# https://firebase.google.com/docs/cloud-messaging/android/first-message
# http://bulkpush.com/pushnotification/guidedetail/s-4/android-gcm-api-configuration
# http://www.feelzdroid.com/2016/02/android-google-cloud-messaging-push-notifications-gcm-tutorial.html
if [[ "$#" -ne 2 ]]; then
echo "Usage: $0 SERVER_KEY FCM_TOKEN" >&2
exit 1
fi
# Get the command line parameters
SERVER_KEY=$1
FCM_TOKEN=$2
echo
echo "Check validity of API key, InvalidRegistration error is OK"
# https://developers.google.com/cloud-messaging/http
curl -H "Authorization: key=$SERVER_KEY" \
-H Content-Type:"application/json" \
-d "{\"registration_ids\":[\"ABC\"]}" \
-s \
https://fcm.googleapis.com/fcm/send \
| python -m json.tool
# should obtain something like this:
# {"multicast_id":5978845027639121780,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
# content of the notification
DATA="{\"message\":\"Message of PUSH!\"}"
echo
echo
echo "Send a push, you should see success:1..."
curl -H "Authorization: key=$SERVER_KEY" \
-H Content-Type:"application/json" \
-d "{ \"data\" : $DATA, \"to\":\"$FCM_TOKEN\" }" \
-s \
https://fcm.googleapis.com/fcm/send \
| python -m json.tool
echo
echo
# should obtain something like this:
# {"multicast_id":7967233883611790812,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1472636210339069%84ac25d9f9fd7ecd"}]}