Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/3315 New Integration test facility & add integration tests for auth #3344

Merged
merged 76 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
7419393
launch service using Dockerode
t83714 Apr 5, 2022
f40e6e9
- move integration tests to a seperate module
t83714 Apr 6, 2022
21853c7
add es to authServiceRunner
t83714 Apr 7, 2022
0308be1
only create /data when it doesn't exist
t83714 Apr 7, 2022
57e9524
- add opa support
t83714 Apr 7, 2022
62b3b04
add db migrator
t83714 Apr 7, 2022
a8c8b13
turn off elasticsearch by default
t83714 Apr 7, 2022
e7299f3
auto remove containers for migrator
t83714 Apr 7, 2022
9894094
add auth api to authServiceRunner
t83714 Apr 7, 2022
94cd37f
renamed to service runner
t83714 Apr 8, 2022
830b2e8
move test cases to tests folder
t83714 Apr 8, 2022
d9888fc
Add run-service CLI tool
t83714 Apr 8, 2022
252aee5
add registry api & aspect migrator
t83714 Apr 8, 2022
4827cb0
- refactor auth api
t83714 Apr 8, 2022
24c9a30
- refactor user related type definition
t83714 Apr 9, 2022
a9a5d70
add more registry test case
t83714 Apr 11, 2022
d57d9e1
- make user related api also available at /public/user as well (to be…
t83714 Apr 11, 2022
009d85e
- not support draft datasets without "publishing.state" set to "draft…
t83714 Apr 11, 2022
36c2144
fix test cases
t83714 Apr 11, 2022
26cd0e6
adjust CI pipeline
t83714 Apr 11, 2022
06dd9f7
- remove legacy int-tests
t83714 Apr 11, 2022
d7566db
update cache key
t83714 Apr 11, 2022
476b76b
increase default wait service live time to 5 mins
t83714 Apr 11, 2022
4d1da71
auto pull migrator image
t83714 Apr 11, 2022
8c0488a
auto setup port-forwarding
t83714 Apr 11, 2022
079059c
fix: should run `setDockerServiceForwardHost` in ServiceRunner constr…
t83714 Apr 12, 2022
897b991
fix incorrect quote in port-forward command
t83714 Apr 12, 2022
c19abc2
port-forward should not wait for process exit
t83714 Apr 12, 2022
a132361
adjust how sbt task is run
t83714 Apr 12, 2022
606bcff
should build magda-migrator-registry-aspects before run integration t…
t83714 Apr 12, 2022
33ee51a
correct scala db connection string
t83714 Apr 12, 2022
862cc4a
- remove getUserPublic from authApiClient (as getUser will use public…
t83714 Apr 12, 2022
83b056e
- refactor update node method
t83714 Apr 12, 2022
721be0c
update test cases
t83714 Apr 12, 2022
884ae47
refactor test cases
t83714 Apr 12, 2022
7c9ee99
add test cases for anonymous users
t83714 Apr 12, 2022
383964d
fix authApiClient test cases
t83714 Apr 12, 2022
4b78c96
fix create new user endpoint
t83714 Apr 13, 2022
83a01c6
- ownership constraint related policy changes: a resource doesn't hav…
t83714 Apr 13, 2022
dec4750
- add patchRecord method to registry client
t83714 Apr 13, 2022
9ffc567
update test cases as we now allow authApiClient to act as an anonymou…
t83714 Apr 13, 2022
5ad66b4
fix test case
t83714 Apr 13, 2022
62fbf2a
add test cases for distributions
t83714 Apr 13, 2022
78500b2
- add get by uri api to resource & operation api endpoint
t83714 Apr 13, 2022
c858be1
fix mockAuth
t83714 Apr 13, 2022
63d1058
fix test cases error due to registryApiClient refactoring
t83714 Apr 13, 2022
94be21f
fix gateway test case due to authApiClient refactoring
t83714 Apr 13, 2022
d4ad404
make minio & storage api lauch via serviceRunner
t83714 Apr 14, 2022
216c346
rename test case name
t83714 Apr 14, 2022
9b0bd0a
refactor registry auth test cases
t83714 Apr 14, 2022
8f3229c
- better minio service readiness checker
t83714 Apr 15, 2022
b6179d1
add fetch based http request utiliies to magda-typescript-common to o…
t83714 Apr 15, 2022
9d1163f
add storage api test case
t83714 Apr 17, 2022
552d666
add more test cases
t83714 Apr 17, 2022
6487481
complete storage api test cases
t83714 Apr 18, 2022
6a63cf1
use original docker compose file to launach elasticsearch
t83714 Apr 18, 2022
1c7520b
- add `allowAutoCrawlOnStartingUp` option to indexer
t83714 Apr 18, 2022
8f50561
fix indexer test case
t83714 Apr 18, 2022
172b89f
move status endpoint of indexer to /v0/status/x
t83714 Apr 19, 2022
ca448ca
add search api service to service runner
t83714 Apr 19, 2022
a4b375f
#3345 Add dataset index / delete API endpoints to indexer
t83714 Apr 19, 2022
527ae03
reformat code
t83714 Apr 20, 2022
e8d9aa8
make indexer auto-exit unless user explicitly requests the service
t83714 Apr 20, 2022
3fd9315
indexer api client
t83714 Apr 20, 2022
12240a9
Indexer index & delete endpoint will auto refresh index
t83714 Apr 20, 2022
f77fcdf
fix: search api should be able to locate dataset by dataset id
t83714 Apr 20, 2022
1cdd015
add debug mode to search api
t83714 Apr 20, 2022
721e92d
bug fixes
t83714 Apr 20, 2022
2c790a7
add more search api auth test cases
t83714 Apr 20, 2022
a046897
reformat code
t83714 Apr 20, 2022
1390e27
fix MockIndexer
t83714 Apr 20, 2022
7d460d1
make registry db migrator run first
t83714 Apr 20, 2022
b84433c
increase max timeout
t83714 Apr 20, 2022
7c14058
update docs
t83714 Apr 21, 2022
0be38a2
mark integration test job as "heavy" job
t83714 Apr 21, 2022
e3657fb
wait for 5 seconds and let destroy commands flow through
t83714 Apr 21, 2022
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
142 changes: 61 additions & 81 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variables:
-Dsbt.ivy.home=$CI_PROJECT_DIR/sbt-cache/ivy
# If you changed dependencies (especially for scala), you might want to prevent your branch from using old cache by increase the version blew
# gitlab actually use the same technique when you click the `Clear Cache Button`
CACHE_VERSION: ts-12-scala-7
CACHE_VERSION: ts-13-scala-7
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
Expand All @@ -31,7 +31,7 @@ stages:

yarn-install:
stage: builders
image: data61/magda-builder-docker:buildx
image: data61/magda-builder-docker:master
retry: 1
needs: []
cache:
Expand All @@ -50,7 +50,7 @@ yarn-install:

build-builder-image:
stage: builders
image: data61/magda-builder-docker:buildx
image: data61/magda-builder-docker:master
retry: 1
needs: []
before_script:
Expand Down Expand Up @@ -465,6 +465,57 @@ buildtest:storage-api:
- "*/dist"
expire_in: 7 days

buildtest:integration-tests:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/data61/magda-builder-scala:$BUILDER_IMG_TAG
retry: 1
needs:
- yarn-install
- build-builder-image
- registry-typescript-api
- sbt-prebuild
- dockerize:dockerExtensions
before_script:
- |
if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
export DOCKER_HOST='tcp://localhost:2375'
fi
- docker info
- docker-compose --version
# we can remove socat installation in future once the change is merged into master as it's installed in base image
- apk add socat
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- "$CI_PROJECT_DIR/pip-cache"
services:
- docker:dind
variables:
POSTGRES_URL: "jdbc:postgresql://localhost/postgres"
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: "password"
tags:
- heavy
script:
- cd magda-authorization-api && yarn build
- cd ..
- cd magda-storage-api && yarn build
- cd ..
- cd magda-migrator-registry-aspects && yarn build
- cd ..
- cd magda-int-test-ts
- yarn test
artifacts:
paths:
- "target"
- "project/target"
- "project/project/target"
- "*/target"
- "*/project/target"
- "*/project/project/target"
expire_in: 7 days

buildtest:opa-policies:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/data61/magda-builder-docker:$BUILDER_IMG_TAG
Expand Down Expand Up @@ -629,7 +680,7 @@ dockerize:opa:
- yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64

dockerize:dockerExtensions:
stage: buildtest
stage: prebuild
image: registry.gitlab.com/magda-data/magda/data61/magda-builder-docker:$BUILDER_IMG_TAG
retry: 2
needs:
Expand All @@ -646,83 +697,6 @@ dockerize:dockerExtensions:
- cd $CI_PROJECT_DIR/magda-elastic-search && yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
- cd $CI_PROJECT_DIR/magda-postgres && yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG

inttest:registryAuth:
# https://github.com/kind-ci/examples/blob/master/.gitlab-ci.yml
stage: preview
retry: 1
image: registry.gitlab.com/magda-data/magda/data61/magda-builder-scala:$BUILDER_IMG_TAG
allow_failure: true
tags:
- heavy
needs:
- yarn-install
- sbt-prebuild
- buildtest:registry
- buildtest:helm-charts
- dockerize:dockerExtensions
services:
- docker:dind
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- /usr/local/bin/kind
- /usr/local/bin/kubectl
- /usr/local/bin/helm
variables:
KUBECTL: v1.19.14
KIND: v0.11.1
before_script:
- echo "Waiting for docker cli to respond before continuing build..."
- |
for i in $(seq 1 30); do
if ! docker info &> /dev/null; then
echo "Docker not responding yet. Sleeping for 2s..." && sleep 2s
else
echo "Docker ready. Continuing build..."
break
fi
done
script: |
apk add --update postgresql-client sed curl pwgen
curl -Lo /usr/local/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND}/kind-$(uname)-amd64 -C -
chmod +x /usr/local/bin/kind
curl -Lo /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL}/bin/linux/amd64/kubectl -C -
chmod +x /usr/local/bin/kubectl
curl -L https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz -C - | tar -xzO linux-amd64/helm > /usr/local/bin/helm
chmod +x /usr/local/bin/helm

# create k8s cluster
kind create cluster --config=./kind-config.yaml --wait 20m --image kindest/node:v1.16.15@sha256:83067ed51bf2a3395b24687094e283a7c7c865ccc12a8b1d7aa673ba0c5e8861

# Set up KUBECONFIG that links to kind - we use sed to edit it so it's pointing to gitlab's docker host
kind get kubeconfig | sed -E -e 's/localhost|0\.0\.0\.0/docker/g' > ./kubeconfig

export KUBECONFIG="$(pwd)/kubeconfig"
export JWT_SECRET=udIsbcYaKs1G4n6AdiMSIvPx5KpxQAy8FA2aIcD46iCipNAZvds4jeXFLZKhVvSJZvhYb5Pvgvmtonk7UFfhGnYcd3DXM7KzHG7gBmGO8PCsOZ4t7icqZoJbpdDqYWMmd9XnrVXtJhR6HVFBmEmbk9AmFJ1Gz9ipYPGYLoFcavPs9iZ63KPXgdt4aBdWQcmICkGPYiY8CQOvqOoiU7hUhKDTkJgRRTSaax6UQDOveTQvQnd5uyXuV4os0tlahzRX
kubectl create ns test2
echo "{ \"apiVersion\": \"v1\", \"kind\": \"Secret\", \"metadata\": {\"name\": \"auth-secrets\"}, \"type\": \"Opaque\", \"data\": {\"jwt-secret\": \"dWRJc2JjWWFLczFHNG42QWRpTVNJdlB4NUtweFFBeThGQTJhSWNENDZpQ2lwTkFadmRzNGplWEZMWktoVnZTSlp2aFliNVB2Z3ZtdG9uazdVRmZoR25ZY2QzRFhNN0t6SEc3Z0JtR084UENzT1o0dDdpY3Fab0picGREcVlXTW1kOVhuclZYdEpoUjZIVkZCbUVtYms5QW1GSjFHejlpcFlQR1lMb0ZjYXZQczlpWjYzS1BYZ2R0NGFCZFdRY21JQ2tHUFlpWThDUU92cU9vaVU3aFVoS0RUa0pnUlJUU2FheDZVUURPdmVUUXZRbmQ1dXlYdVY0b3MwdGxhaHpSWA==\"}}" | kubectl apply --namespace test2 -f -
echo "{ \"apiVersion\": \"v1\", \"kind\": \"Secret\", \"metadata\": {\"name\": \"regcred\"}, \"type\": \"kubernetes.io/dockerconfigjson\", \"data\": { \".dockerconfigjson\": \"$DOCKERCONFIGJSON\" }}" | kubectl apply --namespace test2 -f -

# Create DB password secret
export PGPASSWORD="${DB_PASSWORD:-$(pwgen 16 1)}"
kubectl create secret generic db-main-account-secret --from-literal=postgresql-password=$PGPASSWORD --namespace test2

helm upgrade test2 deploy/helm/local-auth-test-deployment --debug --namespace test2 --install --timeout 1200s --set global.image.tag=$CI_COMMIT_REF_SLUG,magda-core.combined-db.magda-postgres.postgresql.image.tag=$CI_COMMIT_REF_SLUG

# Forward local ports to kind
kubectl port-forward combined-db-postgresql-0 5432 --namespace test2 >/dev/null 2>&1 < /dev/null &
kubectl port-forward deployment/authorization-api 6104:80 --namespace test2 >/dev/null 2>&1 < /dev/null &
# Wait for port forwarding to start
timeout 22 sh -c 'until nc -z $0 $1; do sleep 1; done' localhost 5432
timeout 22 sh -c 'until nc -z $0 $1; do sleep 1; done' localhost 6104
# Set up some values
psql -h localhost -p 5432 -U postgres -d auth -f magda-registry-api/src/test/resources/data/organizations.sql
psql -h localhost -p 5432 -U postgres -d auth -f magda-registry-api/src/test/resources/data/users.sql
# Test!
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=$PGPASSWORD
sbt "registryApi/testOnly au.csiro.data61.magda.opa.*"

(Full) Run As Preview: &runAsPreview
stage: preview
when: manual
Expand Down Expand Up @@ -834,6 +808,7 @@ Deploy Master To Dev:
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
image:
name: dtzar/helm-kubectl:3.5.2
retry: 1
Expand Down Expand Up @@ -882,6 +857,7 @@ Release-to-Docker-Hub:
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
cache: {}
image: registry.gitlab.com/magda-data/magda/data61/magda-builder-docker:$BUILDER_IMG_TAG
retry: 1
Expand All @@ -906,6 +882,7 @@ Release-Master-Tag-to-Docker-Hub:
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
cache: {}
image: registry.gitlab.com/magda-data/magda/data61/magda-builder-docker:$BUILDER_IMG_TAG
retry: 1
Expand Down Expand Up @@ -936,6 +913,7 @@ Release-Latest-Tag-to-Docker-Hub:
- dockerize:migrators
- dockerize:dockerExtensions
- Release-to-Docker-Hub
- buildtest:integration-tests
cache: {}
image: registry.gitlab.com/magda-data/magda/data61/magda-builder-docker:$BUILDER_IMG_TAG
retry: 1
Expand Down Expand Up @@ -964,6 +942,7 @@ Publish NPM Packages:
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
image:
name: registry.gitlab.com/magda-data/magda/data61/magda-builder-nodejs:$BUILDER_IMG_TAG
cache: {}
Expand Down Expand Up @@ -991,6 +970,7 @@ Publish Helm Chart:
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
image:
name: dtzar/helm-kubectl:3.5.2
cache:
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
- #3340 OPA AST parser takes too long to evaluate large response
- Increase registry default request timeout to 60s (from 30s)
- Bump Dataset index version to 49 & publishers index version to 7
- Fixed registry API generated ts client patchRecord API response type
- add `allowAutoCrawlOnStartingUp` option to indexer
- add `/v0/status/live` & `/v0/status/ready` endpoint to indexer
- Related to #3315, introduce `ServiceRunner` to launch an integrated test & dev environment
- #3315 rewrite auth related integration tests and execute tests using `ServiceRunner` rather than mini k8s cluster `kind`
- #3345 Add dataset index / delete API endpoints to indexer
- Add `debug` switch to registry API, search API & Auth API

## 1.2.1

Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/internal-charts/indexer/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ spec:
"-Dregistry.webhookUrl=http://indexer/v0/registry-hook",
"-Dregistry.baseUrl=http://registry-api",
"-Dregistry.readOnlyBaseUrl=http://registry-api-read-only",
"-DauthApi.baseUrl=http://authorization-api",
"-Dopa.baseUrl=http://authorization-api/v0/opa/",
"-Dindexer.readSnapshots={{ .Values.readSnapshots }}",
"-Dindexer.makeSnapshots={{ .Values.makeSnapshots }}",
"-Dakka.loglevel={{ .Values.global.logLevel }}",
Expand Down
1 change: 1 addition & 0 deletions deploy/helm/internal-charts/search-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Kubernetes: `>= 1.14.0-0`
| autoscaler.minReplicas | int | `1` | |
| autoscaler.targetCPUUtilizationPercentage | int | `80` | |
| datasetsIndexVersion | string | `nil` | Manually set dataset index version. If not specify, default version will be used. you want to manually set this setting when upgrade to a Magda version that involves dataset index version changes. As it takes time to rebuild the index, you could use this setting to make search API query existing old version index before the new version index is built. |
| debug | bool | `false` | when set to true, search API will print verbose debug info (e.g. ES DSL query) to log |
| defaultImage.pullPolicy | string | `"IfNotPresent"` | |
| defaultImage.pullSecrets | bool | `false` | |
| defaultImage.repository | string | `"docker.io/data61"` | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ spec:
- "-DauthApi.baseUrl=http://authorization-api"
- "-Dopa.baseUrl=http://authorization-api/v0/opa/"
- "-DelasticSearch.serverUrl=elasticsearch://elasticsearch:9200"
{{- if .Values.debug }}
- "-DsearchApi.debug=true"
{{- end }}
{{- if .Values.datasetsIndexVersion }}
- "-DelasticSearch.indices.datasets.version={{ .Values.datasetsIndexVersion }}"
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions deploy/helm/internal-charts/search-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ resources:
limits:
cpu: 200m

# -- when set to true, search API will print verbose debug info (e.g. ES DSL query) to log
debug: false

# -- Manually set dataset index version.
# If not specify, default version will be used.
# you want to manually set this setting when upgrade to a Magda version that involves dataset index version changes.
Expand Down
6 changes: 4 additions & 2 deletions magda-authorization-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
},
"dependencies": {
"@magda/typescript-common": "^2.0.0-alpha.0",
"uuid": "^8.2.0",
"bcrypt": "^5.0.0",
"body-parser": "^1.18.3",
"express": "^4.17.1",
"is-uuid": "^1.0.2",
"jsonwebtoken": "^8.4.0",
"lodash": "^4.17.4",
"object-path": "^0.11.4",
"pg": "^6.4.0",
"pg": "^7.18.2",
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
"sql-syntax": "^1.1.3",
Expand All @@ -42,13 +43,14 @@
"@types/mocha": "^2.2.47",
"@types/nock": "^9.1.2",
"@types/object-path": "^0.11.0",
"@types/pg": "^6.1.41",
"@types/pg": "^7.14.4",
"@types/recursive-readdir": "^2.2.0",
"@types/request": "^2.48.1",
"@types/request-promise-native": "^1.0.16",
"@types/sinon": "^7.0.11",
"@types/supertest": "^2.0.4",
"@types/yargs": "^12.0.8",
"@types/uuid": "^8.0.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"fs-extra": "^8.0.1",
Expand Down
Loading