-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Clean up Zitadel org before running the tests
- Loading branch information
1 parent
b0d3a55
commit 32a0ef9
Showing
4 changed files
with
97 additions
and
5 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
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,70 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
# Script to wait for an ldap server to be up, clean up any existing | ||
# data and then to do some basic initialization. | ||
# | ||
# This is intended for test suite setup, don't use this in production. | ||
|
||
LDAP_HOST='ldap://ldap:1389' | ||
LDAP_BASE='dc=example,dc=org' | ||
LDAP_ADMIN='cn=admin,dc=example,dc=org' | ||
LDAP_PASSWORD='adminpassword' | ||
|
||
ZITADEL_HOST="http://zitadel:8080" | ||
|
||
# echo "Waiting for LDAP to be ready" | ||
|
||
# retries=5 | ||
|
||
# while [ $retries -gt 0 ]; do | ||
# sleep 5 | ||
# retries=$((retries - 1)) | ||
|
||
# if ldapsearch -D "${LDAP_ADMIN}" -w "${LDAP_PASSWORD}" -H "${LDAP_HOST}" -b "${LDAP_BASE}" 'objectclass=*'; then | ||
# break | ||
# fi | ||
# done | ||
|
||
echo "Authenticating to Zitadel" | ||
zitadel-tools key2jwt --audience="http://localhost" --key=/zitadel-service-user.json --output=/tmp/jwt.txt | ||
zitadel_token="$(curl \ | ||
--request POST \ | ||
--url "${ZITADEL_HOST}/oauth/v2/token" \ | ||
--header 'Content-Type: application/x-www-form-urlencoded' \ | ||
--header 'Host: localhost' \ | ||
--data grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \ | ||
--data scope=openid \ | ||
--data scope=urn:zitadel:iam:org:project:id:zitadel:aud \ | ||
--data assertion="$(cat /tmp/jwt.txt)")" | ||
zitadel_token="$(echo "${zitadel_token}" | jq --raw-output .access_token | tr -d '\n')" | ||
|
||
echo "Deleting Zitadel users" | ||
zitadel_users="$(curl \ | ||
--request POST \ | ||
--url "${ZITADEL_HOST}/management/v1/users/_search" \ | ||
--header "Authorization: Bearer ${zitadel_token}" \ | ||
--header 'Host: localhost')" | ||
|
||
echo "$zitadel_users" | ||
|
||
zitadel_users="$(echo "$zitadel_users" | jq --raw-output '.result[]? | select(.userName | startswith("zitadel-admin")) | .id')" | ||
|
||
for id in $zitadel_users; do | ||
echo "Deleting user $id" | ||
curl --request DELETE --url "${ZITADEL_HOST}/management/v1/users/$id" \ | ||
--header "Authorization: Bearer ${zitadel_token}" \ | ||
--header 'Host: localhost' | ||
done | ||
|
||
# echo "Deleting LDAP test data" | ||
# ldapdelete -D "${LDAP_ADMIN}" -w "${LDAP_PASSWORD}" -H "${LDAP_HOST}" -r 'ou=testorg,dc=example,dc=org' || true | ||
|
||
# echo "Add LDAP test organizatino" | ||
# ldapadd -D "${LDAP_ADMIN}" -w "${LDAP_PASSWORD}" -H "${LDAP_HOST}" -f /ldap/testorg.ldif | ||
|
||
# Signify that the script has completed | ||
echo "ready" > /tmp/ready | ||
|
||
sleep 5 |
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,3 @@ | ||
dn: ou=testorg,dc=example,dc=org | ||
objectClass: organizationalUnit | ||
ou: testorg |
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,11 @@ | ||
FROM bitnami/openldap:latest | ||
|
||
USER root | ||
|
||
RUN apt-get update && apt-get upgrade -y && \ | ||
apt-get install --yes curl golang-go jq && \ | ||
apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives | ||
|
||
RUN GOPATH=/ go install github.com/zitadel/zitadel-tools@latest | ||
|
||
USER 1001 |