colnod-connector/bugs/getTokensDeleted.sh
2019-11-05 11:48:12 +01:00

36 lines
2.5 KiB
Bash

#!/bin/bash
# Saving login token
TOKEN=$(curl -k --user "spaceti:E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" -d '{"password":"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0","username":"spaceti"}' -H "Content-Type: application/json" https://192.168.1.3:8443/AaaManager/authSession 2>/dev/null | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["id"]')
# Saving current time and timestamp
DATE=`date +"%Y-%m-%d %H:%M:%S"`
TIMESTAMP=`date +%s%N | cut -b1-13`
echo
echo "I'm going to add and delete test token,"
echo "then ask for deleted tokens with time before deleting"
echo "and with time after deleting."
echo "It should return token deleted with time before,"
echo "but should NOT with time after."
echo "===================================================================="
echo "Current time: $DATE / timestamp: $TIMESTAMP"
echo "===================================================================="
echo "Creating test token with id = 235c4a3c-7e20-4f2a-8ed2-2fe36cc87907"
curl -k -u "$TOKEN:" -d '{"items":[{"id":"235c4a3c-7e20-4f2a-8ed2-2fe36cc87907","name":"bug test","description":"mobile","tokenType":"Token","tokenBits":32,"tokenData":"7B9D32","timeToLive":255,"authErrors":255,"flags":["Enabled","NoValidity"],"subjectId":"72b37f7e-5761-4e6c-8e87-20c0bed0d904"}]}' -H "Content-Type: application/json" -X POST https://192.168.1.3:8443/TokenManager/setTokens
echo
echo "Deleting test token..."
curl -k -u "$TOKEN:" -d '{"items":["235c4a3c-7e20-4f2a-8ed2-2fe36cc87907"]}' -H "Content-Type: application/json" -X POST https://192.168.1.3:8443/TokenManager/deleteTokens
echo
echo
echo "getTokensDeleted with time (before deleting): $DATE"
echo "Expect only one token which has been deleted"
curl -k -u "$TOKEN:" -d "{\"timestamp\":$TIMESTAMP}" -H "Content-Type: application/json" -X POST https://192.168.1.3:8443/TokenManager/getTokensDeleted
echo
echo "===================================================================="
echo "Waiting 5 secs, so we can ask again after deleting"
echo "===================================================================="
sleep 5
echo "getTokensDeleted with time (after deleting): $DATE + 2 sec"
echo "Expect no tokens returned, because token has been deleted before more than 5 secs"
((TIMESTAMP=TIMESTAMP+2000))
curl -k -u "$TOKEN:" -d "{\"timestamp\":$TIMESTAMP}" -H "Content-Type: application/json" -X POST https://192.168.1.3:8443/TokenManager/getTokensDeleted
echo
exit