-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from GSA/develop
Release
- Loading branch information
Showing
10 changed files
with
248 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM bats/bats | ||
|
||
RUN apk add curl jq | ||
|
||
COPY tests/ /tests/ | ||
|
||
# bats/bats uses bats as the entrypoint | ||
CMD ["-r", "/tests"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: '3' | ||
services: | ||
app: | ||
command: /opt/inventory-app/start.sh seed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: '3' | ||
services: | ||
test: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.test | ||
depends_on: | ||
- app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#!/bin/bash | ||
|
||
# Can optionally specify an api key if the user is already created. Add as second argument to command. | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
# The app takes quite a while to startup (solr initialization and | ||
# migrations), close to a minute. Make sure to give it enough time before | ||
# starting the tests. | ||
|
||
hostname="localhost" | ||
port="5000" | ||
retries=20 | ||
while ! nc -z -w 30 "$hostname" "$port" ; do | ||
if [ "$retries" -le 0 ]; then | ||
return 1 | ||
fi | ||
|
||
retries=$(( $retries - 1 )) | ||
echo 'retrying...' | ||
sleep 5 | ||
done | ||
|
||
#If api_key is passed, utilize; if not, create new user | ||
if [ "${1-}" == "" ]; then | ||
echo creating user admin | ||
#Setup various users, organizations, and datasets | ||
if /usr/lib/ckan/bin/paster --plugin=ckan user add admin password=admin email=fake@fake.com -c /etc/ckan/production.ini > /tmp/user_temp.txt ; then | ||
/usr/lib/ckan/bin/paster --plugin=ckan sysadmin add admin -c /etc/ckan/production.ini | ||
api_key=$(grep -oP "apikey.: u.\K.+" /tmp/user_temp.txt | cut -d "'" -f1) | ||
else | ||
api_key=$(/usr/lib/ckan/bin/paster --plugin=ckan user admin -c /etc/ckan/production.ini | grep -oP "apikey=\K.+ " | cut -d " " -f1) | ||
fi | ||
|
||
else | ||
api_key="$1" | ||
fi | ||
|
||
# Adding organization | ||
curl -X POST \ | ||
http://localhost:5000/api/3/action/organization_create \ | ||
-H "authorization: $api_key" \ | ||
-H "cache-control: no-cache" \ | ||
-d '{"description": "Test organization","title": "Test Organization","approval_status": "approved","state": "active","name": "test-organization"}' | ||
|
||
echo '' | ||
|
||
# Adding dataset(s) via API | ||
curl -X POST \ | ||
http://localhost:5000/api/3/action/package_create \ | ||
-H "authorization: $api_key" \ | ||
-H 'cache-control: no-cache' \ | ||
-H 'content-type: application/json' \ | ||
-d ' | ||
{ | ||
"license_title": "License not specified", | ||
"maintainer": null, | ||
"relationships_as_object": [], | ||
"private": true, | ||
"maintainer_email": null, | ||
"num_tags": 1, | ||
"metadata_created": "2019-12-18T19:01:33.429530", | ||
"metadata_modified": "2019-12-18T19:02:54.841495", | ||
"author": null, | ||
"author_email": null, | ||
"state": "active", | ||
"version": null, | ||
"type": "dataset", | ||
"resources": [ | ||
{ | ||
"conformsTo": "", | ||
"cache_last_updated": null, | ||
"describedByType": "", | ||
"labels": { | ||
"accessURL new": "Access URL", | ||
"conformsTo": "Conforms To", | ||
"describedBy": "Described By", | ||
"describedByType": "Described By Type", | ||
"format": "Media Type", | ||
"formatReadable": "Format", | ||
"created": "Created" | ||
}, | ||
"webstore_last_updated": null, | ||
"clear_upload": "", | ||
"state": "active", | ||
"size": null, | ||
"describedBy": "", | ||
"hash": "", | ||
"description": "", | ||
"format": "CSV", | ||
"mimetype_inner": null, | ||
"url_type": null, | ||
"formatReadable": "", | ||
"mimetype": null, | ||
"cache_url": null, | ||
"name": "Test Resource", | ||
"created": "2019-12-18T19:02:54.448285", | ||
"url": "https://www.bia.gov/tribal-leaders-csv", | ||
"upload": "", | ||
"webstore_url": null, | ||
"last_modified": null, | ||
"position": 0, | ||
"resource_type": "file" | ||
} | ||
], | ||
"num_resources": 1, | ||
"tags": [ | ||
{ | ||
"vocabulary_id": null, | ||
"state": "active", | ||
"display_name": "test", | ||
"id": "65c76784-e271-4eb1-9778-a738622a1a3d", | ||
"name": "test" | ||
} | ||
], | ||
"tag_string": "test", | ||
"groups": [], | ||
"license_id": "notspecified", | ||
"relationships_as_subject": [], | ||
"organization": "test-organization", | ||
"isopen": false, | ||
"url": null, | ||
"notes": "The description of the test dataset", | ||
"owner_org": "test-organization", | ||
"bureau_code": "010:00", | ||
"contact_email": "tester@fake.com", | ||
"contact_name": "Tester", | ||
"modified": "2019-12-18", | ||
"public_access_level": "public", | ||
"publisher": "Department of the Interior", | ||
"unique_id": "doi-123456789", | ||
"title": "Test Dataset 1", | ||
"name": "test-dataset-1", | ||
"program_code": "010:001" | ||
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bats | ||
|
||
function wait_for () { | ||
# The app takes quite a while to startup (solr initialization and | ||
# migrations), close to a minute. Make sure to give it enough time before | ||
# starting the tests. | ||
|
||
local hostname=$1 | ||
local port=$2 | ||
local retries=10 | ||
while ! nc -z -w 30 "$hostname" "$port" ; do | ||
if [ "$retries" -le 0 ]; then | ||
return 1 | ||
fi | ||
|
||
retries=$(( $retries - 1 )) | ||
sleep 5 | ||
done | ||
} | ||
|
||
function test_login_and_datasets () { | ||
sleep 15 # Validate that the seed file has time to implement | ||
curl --silent --fail 'http://app:5000/login_generic?came_from=/user/logged_in' --compressed -H 'Content-Type: application/x-www-form-urlencoded' -H 'Origin: http://app:5000' -H 'Referer: http://app:5000/user/login' --data 'login=admin&password=admin' --cookie-jar ./cookie-jar | ||
|
||
dataset_success=$(curl --fail --location --request GET 'http://app:5000/api/3/action/package_show?id=test-dataset-1' --cookie ./cookie-jar | grep -o '"success": true') | ||
|
||
if [ "$dataset_success" = '"success": true' ]; then | ||
return 0; | ||
else | ||
return 1; | ||
fi | ||
} | ||
|
||
@test "app container is up" { | ||
wait_for app 5000 | ||
} | ||
|
||
@test "/user/login is up" { | ||
curl --silent --fail http://app:5000/user/login | ||
} | ||
|
||
@test "data is accessible for user" { | ||
test_login_and_datasets | ||
} | ||
|
||
@test "data is inaccessible to public" { | ||
run curl --fail --location --request GET 'http://app:5000/api/3/action/package_show?id=test-dataset-1' | ||
# Validate output is 22, curl response for 403 (Forbidden) | ||
[ "$status" -eq 22 ] | ||
} |