Skip to content

Commit

Permalink
test: add tests for basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 2, 2017
1 parent ab8fffd commit 94cab58
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
22 changes: 22 additions & 0 deletions script/foo-bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"consumer": {
"name": "Foo"
},
"provider": {
"name": "Bar"
},
"interactions": [
{
"description" : "a request for something",
"providerState": null,
"request": {
"method": "get",
"path" : "/something"
},
"response": {
"status": 200,
"body" : "something"
}
}
]
}
15 changes: 15 additions & 0 deletions script/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# set -x

if [ -z "$1" ]; then
BASE_URL="http://localhost"
else
BASE_URL="$1"
fi

BODY=$(ruby -e "require 'json'; j = JSON.parse(File.read('script/foo-bar.json')); j['interactions'][0]['providerState'] = 'it is ' + Time.now.to_s; puts j.to_json")
echo ${BODY} >> tmp.json
curl -v -XPUT -u foo:bar \-H "Content-Type: application/json" \
[email protected] \
${BASE_URL}/pacts/provider/Bar/consumer/Foo/version/1.1.0
rm tmp.json
echo ""
32 changes: 25 additions & 7 deletions script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,34 @@ echo "Checking that server accepts and return HTML from outside"
curl -H "Accept:text/html" --user ${PACT_BROKER_BASIC_AUTH_USERNAME}:${PACT_BROKER_BASIC_AUTH_PASSWORD} -s "http://${test_ip}:${EXTERN_BROKER_PORT}"
echo ""
echo "Checking for specific HTML content from outside: '0 pacts'"
curl -H "Accept:text/html" --user ${PACT_BROKER_BASIC_AUTH_USERNAME}:${PACT_BROKER_BASIC_AUTH_PASSWORD} -s "http://${test_ip}:${EXTERN_BROKER_PORT}" | grep "0 pacts"
echo "Checking for specific HTML content from outside: 'Pacts'"
curl -H "Accept:text/html" --user ${PACT_BROKER_BASIC_AUTH_USERNAME}:${PACT_BROKER_BASIC_AUTH_PASSWORD} -s "http://${test_ip}:${EXTERN_BROKER_PORT}" | grep "Pacts"
echo ""
echo "Checking that server accepts and responds with status 200"
response_code=$(curl -s -o /dev/null -w "%{http_code}" --user ${PACT_BROKER_BASIC_AUTH_USERNAME}:${PACT_BROKER_BASIC_AUTH_PASSWORD} http://${test_ip}:${EXTERN_BROKER_PORT})
if [[ "${response_code}" == '200' ]]; then
if [[ "${response_code}" -ne '200' ]]; then
die "Expected response code to be 200, but was ${response_code}"
fi
if [[ ! -z "${PACT_BROKER_BASIC_AUTH_USERNAME}" ]]; then
echo ""
echo "SUCCESS: All tests passed!"
else
die "While checking HTML response status 200"
echo "Checking that basic auth is configured"
response_code=$(curl -s -o /dev/null -w "%{http_code}" http://${test_ip}:${EXTERN_BROKER_PORT})
if [[ "${response_code}" -ne '401' ]]; then
die "Expected response code to be 401, but was ${response_code}"
fi
fi
script/publish.sh "http://${test_ip}:${EXTERN_BROKER_PORT}"
echo ""
echo "Checking that badges can be accessed without basic auth"
response_code=$(curl -s -o /dev/null -w "%{http_code}" http://${test_ip}:${EXTERN_BROKER_PORT}/pacts/provider/Bar/consumer/Foo/latest/badge.svg)
if [[ "${response_code}" -ne '200' ]]; then
die "Expected response code to be 200, but was ${response_code}"
fi
echo "SUCCESS: All tests passed!"

0 comments on commit 94cab58

Please sign in to comment.