Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Add provider side of Auth contract tests. #711

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
3577ca1
Add contract tests.
pmacik Nov 14, 2018
f0d6e62
contract-tests: Update comments in make file.
pmacik Nov 15, 2018
6db5236
Use master version of loginusers-go
pmacik Nov 16, 2018
924613b
contract-tests: Consumer part moved to consumer repo.
pmacik Jan 11, 2019
8b6cb81
contract-tests: Create directory for downloaded and filtered pact files.
pmacik Jan 14, 2019
e6edcec
contract-tests: Simplify name of consumer and provider.
pmacik Jan 14, 2019
95077fc
contract-tests: Fix golangci issues.
pmacik Jan 14, 2019
7aae932
contract-tests: Add OSIO cluster parameter.
pmacik Jan 16, 2019
21604e9
contract-tests: Add CICO run script.
pmacik Jan 17, 2019
560978f
contract-tests: Add archiving test artifacts
pmacik Jan 17, 2019
28d9168
contract-tests: Rename provider to match github project.
pmacik Jan 21, 2019
cf73072
Merge branch 'master' into contract-tests
pmacik Feb 5, 2019
6043c53
Merge branch 'master' into contract-tests
pmacik Feb 8, 2019
ac31338
contract-tests: Add type to the request for creating user.
pmacik Feb 12, 2019
7497180
contract-tests: Add local cluster service instance.
pmacik Feb 12, 2019
df33a4a
contract-tests: Optionally disable cico_setup function.
pmacik Feb 12, 2019
02da64e
Merge branch 'master' into contract-tests
pmacik Feb 13, 2019
e9a4850
contract-tests: Add pact broker response code checks.
pmacik Feb 13, 2019
73b61cd
contract-tests: Move sources under *_test package.
pmacik Feb 13, 2019
36447db
contract-test: Implement Dipak's suggestions.
pmacik Feb 14, 2019
e195363
Merge branch 'master' into contract-tests
pmacik Feb 25, 2019
10cb81c
contract-tests: Fix conflicts.
pmacik Feb 25, 2019
962bcd3
contract-tests: Fix Gopkg.toml.
pmacik Feb 25, 2019
438e044
Merge branch 'master' into contract-tests
pmacik Feb 26, 2019
c63b025
Merge branch 'master' into contract-tests
pmacik Feb 28, 2019
9b26878
contract-tests: Implement timeout and response code checks to provide…
pmacik Feb 28, 2019
8e9c9e7
Merge branch 'master' into contract-tests
pmacik Mar 4, 2019
1cdae7f
contract-tests: Use common version of getting service account token.
pmacik Mar 4, 2019
f2f8d99
contract-tests: Fix user structure in registration.
pmacik Mar 7, 2019
041bef8
contract-tests: Delete useless file.
pmacik Mar 7, 2019
6e07d80
contract-tests: Prepare environment for cico run.
pmacik Mar 8, 2019
cf8dfe8
contract-tests: Prepare environment for cico run.
pmacik Mar 8, 2019
bf61ea2
contract-tests: Make install less verbose.
pmacik Mar 8, 2019
7544992
contract-tests: Fix cluster service github url.
pmacik Mar 8, 2019
34ee2be
Merge branch 'master' into contract-tests
pmacik Mar 14, 2019
8585528
contract-tests: Disable errexit for pact-mock-service check.
pmacik Mar 14, 2019
960467f
contract-tests: Enable archiving artifacts..
pmacik Mar 18, 2019
761a385
contract-tests: Fix archiving artifacts.
pmacik Mar 18, 2019
52f15ce
contract-tests: Load Jenkins env vars.
pmacik Mar 18, 2019
1352e4e
contract-tests: Fix artifacts key path.
pmacik Mar 18, 2019
1a4aedf
contract-tests: Fix artifacts key path.
pmacik Mar 18, 2019
213cced
contract-tests: Check for artifacts.key
pmacik Mar 18, 2019
173b1d0
contract-tests: Check for artifacts.key
pmacik Mar 18, 2019
f5f3f5a
contract-tests: Check for artifacts.key
pmacik Mar 18, 2019
2b84027
contract-tests: Check for artifacts.key
pmacik Mar 18, 2019
67b7541
contract-tests: Check for artifacts.key
pmacik Mar 18, 2019
be9ee4a
contract-tests: Include JOB_NAME env variable.
pmacik Mar 18, 2019
895b143
contract-tests: Set artifacts key aside.
pmacik Mar 18, 2019
214278a
contract-tests: Fix artifacts key path.
pmacik Mar 18, 2019
144fbb8
contract-tests: Get docker image before start.
pmacik Mar 18, 2019
d1a9c95
contract-tests: Aviod 'to many open files' error
pmacik Mar 18, 2019
f8da88b
contract-tests: Avoid 'to many open files' error.
pmacik Mar 18, 2019
adb5406
contract-tests: Load more Jenkins env vars.
pmacik Mar 18, 2019
50b1604
contract-tests: Load correct Jenkins env vars.
pmacik Mar 18, 2019
d956f74
Merge branch 'master' into contract-tests
pmacik Mar 20, 2019
5485869
contract-tests: Move archiving of artifacts to the CICO only run.
pmacik Mar 20, 2019
2c15f59
contract-tests: Fix conflicts in Gopkg.lock.
pmacik Mar 20, 2019
ae4f45f
contract-tests: Update pact CLI version.
pmacik Mar 20, 2019
573aed1
contract-tests: Clean any running auth/cluster contaiers first.
pmacik Mar 20, 2019
af3409b
contract-tests: Include cluster URL.
pmacik Mar 20, 2019
e72e3a5
Merge branch 'master' into contract-tests
pmacik Mar 20, 2019
d9d38be
Merge branch 'master' into contract-tests
pmacik Mar 21, 2019
401c1a7
contract-tests: Process artifacts.key only when ARCHIVE_ARTIFACTS is …
pmacik Mar 21, 2019
2ba9dfb
contract-tests: Handle artifacts.key after env is loaded.
pmacik Mar 21, 2019
005ae7b
Merge branch 'master' into contract-tests
pmacik Apr 8, 2019
154e642
contract-tests: Set test verbosity flag.
pmacik Apr 8, 2019
db77367
Merge branch 'master' into contract-tests
pmacik Apr 15, 2019
157c527
Merge branch 'master' into contract-tests
pmacik Apr 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,35 @@ test-integration-benchmark: prebuild-check migrate-database $(SOURCES)
$(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN)))
AUTH_DEVELOPER_MODE_ENABLED=1 AUTH_LOG_LEVEL=error AUTH_RESOURCE_DATABASE=1 AUTH_RESOURCE_UNIT_TEST=0 F8_LOG_LEVEL=$(F8_LOG_LEVEL) go test $(GO_TEST_INTEGRATION_FLAG) -vet off -run=^$$ -bench=. -cpu 1,2,4 -test.benchmem $(GO_TEST_VERBOSITY_FLAG) $(TEST_PACKAGES)

.PHONY: test-contracts-provider-no-coverage
## Runs the contract tests WITHOUT producing coverage files for each package.
## Make sure you ran "make dev" before you run this target.
## The Chrome or Chromium browser with headless feature
## as well as the [chromedriver](http://chromedriver.chromium.org/) is required
## to be installed for the user login part of the tests.
## The following env variables needs to be set in environment:
## - Pact consumer for whom the contract is verified as provider
## PACT_CONSUMER
## - Pact broker for storing pact files
## PACT_BROKER_URL
## PACT_BROKER_USERNAME
## PACT_BROKER_PASSWORD
## - RHD account credentials:
## OSIO_USERNAME
## OSIO_PASSWORD
## OSIO_CLUSTER_URL
## - Service account credentials (according to https://github.com/fabric8-services/fabric8-auth/blob/master/configuration/conf-files/service-account-secrets.conf#L30)
## ONLINE_REGISTRATION_SERVICE_ACCOUNT_CLIENT_ID
## ONLINE_REGISTRATION_SERVICE_ACCOUNT_CLIENT_SERCRET
test-contracts-provider-no-coverage: prebuild-check migrate-database $(SOURCES)
$(call log-info,"Running test: $@")
$(eval TEST_PACKAGES:=$(shell go list ./... | grep 'contracts/provider'))
$(eval PACT_VERSION?=latest)
PACT_DIR=$(TMP_PATH)/test/contracts/pacts \
PACT_VERSION=$(PACT_VERSION) \
PACT_PROVIDER_BASE_URL=http://localhost:8089 \
go test -count=1 $(GO_TEST_VERBOSITY_FLAG) $(TEST_PACKAGES)

.PHONY: test-remote-with-coverage
## Runs the remote tests and produces coverage files for each package.
test-remote-with-coverage: prebuild-check clean-coverage-remote $(COV_PATH_REMOTE)
Expand Down
34 changes: 34 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ required = [
"github.com/jstemmer/go-junit-report",
"github.com/wadey/gocovmerge",
"github.com/pilu/fresh",
"github.com/gojuno/minimock/cmd/minimock"
"github.com/gojuno/minimock/cmd/minimock",
"github.com/pact-foundation/pact-go",
"github.com/tebeka/selenium",
"github.com/pmacik/loginusers-go",
]

[[constraint]]
Expand Down Expand Up @@ -128,4 +131,16 @@ required = [

[prune]
go-tests = true
unused-packages = true
unused-packages = true

[[constraint]]
name = "github.com/pact-foundation/pact-go"
revision = "v1.0.0-beta.3"

[[constraint]]
name = "github.com/tebeka/selenium"
revision = "master"

[[constraint]]
name = "github.com/pmacik/loginusers-go"
revision = "master"
211 changes: 209 additions & 2 deletions cico_run_contract_tests_provider.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,211 @@
#!/bin/bash

echo "This is the provider side of the contract testing."
echo "The script will be filled when https://github.com/fabric8-services/fabric8-auth/pull/711 is merged."
. cico_setup.sh

CICO_RUN="${CICO_RUN:-true}"
if [ "$CICO_RUN" == "true" ]; then
load_jenkins_vars;
if [ -e "jenkins-env.json" ]; then
regex="PACT_*\
|ARCHIVE_ARTIFACTS\
|JOB_NAME\
|BUILD_NUMBER\
|OSIO_USERNAME\
|OSIO_PASSWORD\
|OSIO_CLUSTER_URL\
|ONLINE_REGISTRATION_SERVICE_ACCOUNT_CLIENT_ID\
|ONLINE_REGISTRATION_SERVICE_ACCOUNT_CLIENT_SECRET"
eval "$(./env-toolkit load -f jenkins-env.json --regex $regex)"
export OSIO_CLUSTER_URL="${OSIO_CLUSTER_URL:-https://api.starter-us-east-2a.openshift.com/}"
fi
if [ "$ARCHIVE_ARTIFACTS" == "true" ]; then
artifacts_key="$(readlink -f ./artifacts.key)"
artifacts_key_path="/tmp/artifacts.key"
echo "Checking for $artifacts_key file..."
if [ -f $artifacts_key ]; then
echo "$artifacts_key found - preparing for archiving artifacts."
chmod 600 "$artifacts_key"
chown root:root "$artifacts_key"
mv -vf "$artifacts_key" "$artifacts_key_path"
else
echo "$artifacts_key does not found!"
exit 1
fi
fi
install_deps;
YUM_OPTS="-y -d1"
yum $YUM_OPTS install epel-release;
yum $YUM_OPTS --enablerepo=centosplus --enablerepo=epel install \
chromium \
chromium-headless \
chromedriver \
docker-compose \
golang \
make;

# Aviod "to many open files" error
ulimit -Hn 999999
ulimit -Sn 999999
sysctl fs.inotify.max_user_watches=65536
sysctl fs.inotify.max_user_instances=2048

export GOPATH="/tmp/go"
F8_AUTH_DIR="$GOPATH/src/github.com/fabric8-services/fabric8-auth"
mkdir -p $F8_AUTH_DIR
mv * $F8_AUTH_DIR
mv .[!.]* $F8_AUTH_DIR
cd $F8_AUTH_DIR
fi

make build

TMP_PATH="$(readlink -f tmp)"
JOB_NAME="${JOB_NAME:-contract-testing-cico-job}"
BUILD_NUMBER="${BUILD_NUMBER:-0}"

ARTIFACTS_PATH="contracts/${JOB_NAME}/${BUILD_NUMBER}"
LATEST_LINK_PATH="contracts/${JOB_NAME}/latest"

OUTPUT_DIR="$TMP_PATH/test"
mkdir -p "$OUTPUT_DIR/$ARTIFACTS_PATH"

F8_CLUSTER_DIR="$GOPATH/src/github.com/fabric8-services/fabric8-cluster"
if [ ! -d $F8_CLUSTER_DIR ]; then
git clone https://github.com/fabric8-services/fabric8-cluster $F8_CLUSTER_DIR
fi

set +e

# Add Pact CLI to PATH
export PATH="$TMP_PATH/pact/bin:$PATH"

# Ensure Pact CLI is installed
pact-mock-service version &> /dev/null
test_pact_exit=$?
if [ $test_pact_exit -ne 0 ]; then
curl -L -s https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.64.0/pact-1.64.0-linux-x86_64.tar.gz -o "$TMP_PATH/pact-cli.tar.gz"
tar -xf "$TMP_PATH/pact-cli.tar.gz" --directory "$TMP_PATH"
fi

# Clean any running auth/cluster contaiers
for i in $(docker ps -f name=cluster -f name=auth -q); do
docker rm -f $i
done

# Start Auth service
AUTH_CLUSTER_URL_SHORT="http://localhost:8087" make dev &> "$OUTPUT_DIR/$ARTIFACTS_PATH/test-auth.log" &
authpid=$!

## Wait for the Auth service to start up
wait_period=10
attempts=18

final_exit=0

echo "Starting local Auth service"
sleep $wait_period
for i in $(seq 1 $attempts); do
echo "Attempt $i/$attempts..."
response_head="$(curl -LI --silent -XGET 'http://localhost:8089/api/status' | head -n 1)"
if [ -z "$response_head" ]; then
echo "Service unreachable - waiting for Auth service for ${wait_period}s ...";
sleep $wait_period;
else
response_code="$(echo $response_head | cut -d ' ' -f2)"
if [ $response_code -eq 200 ]; then
echo "The Auth service is up and running.";
break;
else
echo "Failed to start the Auth service";
echo $response_head;
kill $authpid;
final_exit=1;
fi
fi
if [ $i -eq $attempts ]; then
echo "Auth service failed to start in $attempts attempts."
kill $authpid;
final_exit=1;
fi
done

# Start Cluster service (Auth dependency)

if [ $final_exit == 0 ]; then
CUR_DIR=$(pwd)
cd $F8_CLUSTER_DIR
F8_AUTH_URL="http://localhost:8089" make dev &> "$OUTPUT_DIR/$ARTIFACTS_PATH/test-cluster.log" &
clusterpid=$!

## Wait for the Cluster service to start up
echo "Starting local Cluster service"
sleep $wait_period
for i in $(seq 1 $attempts); do
echo "Attempt $i/$attempts..."
response_head="$(curl -LI --silent -XGET 'http://localhost:8087/api/status' | head -n 1)"
if [ -z "$response_head" ]; then
echo "Service unreachable - waiting for Cluster service for ${wait_period}s ...";
sleep $wait_period;
else
response_code="$(echo $response_head | cut -d ' ' -f2)"
if [ $response_code -eq 200 ]; then
echo "The Cluster service is up and running.";
break;
else
echo "Failed to start the Cluster service";
echo $response_head;
kill $clusterpid;
kill $authpid;
final_exit=1;
fi
fi
if [ $i -eq $attempts ]; then
echo "Cluster service failed to start in $attempts attempts."
kill $clusterpid;
kill $authpid;
final_exit=1;
fi
done

cd $CUR_DIR
fi

if [ $final_exit == 0 ]; then
# Run the contract tests
GO_TEST_VERBOSITY_FLAG=-v make test-contracts-provider-no-coverage |& tee "$OUTPUT_DIR/$ARTIFACTS_PATH/test.log"
tests_exit=${PIPESTATUS[0]} #capture exit status of the make command

# Delete sensitive files
if [ "$CICO_RUN" == "true" ]; then
rm -rvf $OUTPUT_DIR/contracts/pacts
rm -rvf test/contracts/provider/log
fi
fi

set -x

# Archive the test results
if [ "$CICO_RUN" == "true" ] && [ "$ARCHIVE_ARTIFACTS" == "true" ]; then
echo
echo

echo "Archiving artifacts to http://artifacts.ci.centos.org/devtools/$ARTIFACTS_PATH"
cd $OUTPUT_DIR
ln -sfn "$BUILD_NUMBER" "$LATEST_LINK_PATH"

rsync --password-file="$artifacts_key_path" -qPHva --relative "./$ARTIFACTS_PATH" "$LATEST_LINK_PATH" [email protected]::devtools/
ARTIFACTS_UPLOAD_EXIT_CODE=$?

if [ $ARTIFACTS_UPLOAD_EXIT_CODE -eq 0 ]; then
echo "Artifacts were uploaded to http://artifacts.ci.centos.org/devtools/$ARTIFACTS_PATH"
else
echo "ERROR: Failed to upload artifacts to http://artifacts.ci.centos.org/devtools/$ARTIFACTS_PATH"
fi

echo
echo
fi

RTN_CODE=$(($tests_exit + $final_exit))

exit $RTN_CODE
3 changes: 3 additions & 0 deletions test/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider/log
pacts
output
10 changes: 10 additions & 0 deletions test/contracts/provider/model_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package provider_test

// TestJWSToken contains Base64 encoded '{"alg":"RS256","kid":"0000000000000000000000000000000000000000000","typ":"JWT"}somerandombytes'
const TestJWSToken = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJ0eXAiOiJKV1QifXNvbWVyYW5kb21ieXRlcw"

//TestUserID contains user id placeholder
const TestUserID = "00000000-0000-4000-a000-000000000000"

//TestUserName contains username placeholder
const TestUserName = "testuser00000000"
Loading