Software Engineer

I am a Software Engineer. I have a Bachelor (Honours) of Science in Information Technology from the University of Sunderland - Class of 2003. I have been developing software since 2001 when I was offered a role at CERN as part of their Technical Student Programme.

By 2016 I had grown really tired of the software industry and by the end of 2019 Apple killed whatever excitement I had left. I am not sure what the next 10 years will bring. What I do know is that my apettite to do work that is impactful has only grown bigger and stronger. Great people make me tick more than anything.

I am also tired.

Primitive testing of a REST API in bash

I have been developing the Windmill REST API using JAX-RS and wanted a very basic, lightweight way to ensure the API hasn’t regressed.

I have been using curl to quickly check the API anyway so I thought I’d take it a step further.

#!/bin/bash

set -e

function assertTrue()
{
if [ ${1} -eq ${2} ]; then
echo *SUCCESS*
else
echo "*FAILURE* expected: ${1} actual: ${2}"
exit 1
fi
}


echo "Given valid subscription access; Assert GET exports 200 OK"
HTTP_CODE=$(set -x;curl -s -o /dev/null -w "%{http_code}" https://api.windmill.io/account/qnoid/exports -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpc1ZhbGlkIn0.rqED0v7meSp72MBaeQtyXce3S_dJoh_eo6iIV2Rpt3s")

set +x;assertTrue 200 "${HTTP_CODE}"

echo "Given invalid subscription access; Assert GET exports 401 Unauthorized"
HTTP_CODE=$(set -x;curl -s -o /dev/null -w "%{http_code}" https://api.windmill.io/account/qnoid/exports -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpc1ZhbGlkIn0.3zjr4euU206esZpd0w6Au4o5qYk4ydiuAKXE6SClUaw")

set +x;assertTrue 401 "${HTTP_CODE}"

Which gives the following output

Given valid subscription access; Assert GET exports 200 OK
++ curl -s -o /dev/null -w "%{http_code}" https://api.windmill.io/account/qnoid/exports -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpc1ZhbGlkIn0.rqED0v7meSp72MBaeQtyXce3S_dJoh_eo6iIV2Rpt3s'
*SUCCESS*

Given invalid subscription access; Assert GET exports 401 Unauthorized
++ curl -s -o /dev/null -w "%{http_code}" https://api.windmill.io/account/qnoid/exports -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpc1ZhbGlkIn0.3zjr4euU206esZpd0w6Au4o5qYk4ydiuAKXE6SClUaw'
*SUCCESS*

In case of a failure, execution stops right away with the following output

Given valid subscription access; Assert GET exports 200 OK
++ curl -s -o /dev/null -w "%{http_code}" https://api.windmill.io/account/qnoid/exports -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpc1ZhbGlkIn0.rqED0v7meSp72MBaeQtyXce3S_dJoh_eo6iIV2Rpt3s'
*FAILURE* expected: 200 actual: 401

It’s very primitive and not hardened but it should work in the meantime.-