2022-06-25 23:21:15 +00:00
|
|
|
readonly SERVER_PID_FILE=./tmp/server.pid
|
2022-06-26 23:00:25 +00:00
|
|
|
is_ci(){
|
|
|
|
if [ -z ${CI+x} ];
|
|
|
|
then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if is_ci
|
|
|
|
then
|
|
|
|
MAILDEV_URL="http://smtp:1080"
|
|
|
|
GITEA_URL="http://gitea:3000"
|
2022-06-26 23:10:41 +00:00
|
|
|
GITEA_SSH_URL="ssh://git@gitea:22"
|
2022-06-26 23:00:25 +00:00
|
|
|
else
|
|
|
|
MAILDEV_URL="http://localhost:1080"
|
|
|
|
GITEA_URL="http://localhost:3000"
|
|
|
|
GITEA_SSH_URL="ssh://git@localhost:22"
|
|
|
|
fi
|
2022-06-25 22:32:18 +00:00
|
|
|
|
|
|
|
readonly DASHBOARD_URL="http://localhost:8000"
|
|
|
|
|
|
|
|
|
|
|
|
readonly DASHBOARD_OIDC_DISCOVERY_URL="$DASHBOARD_URL/o/.well-known/openid-configuration/"
|
|
|
|
|
|
|
|
readonly DASHBOARD_ADMIN_USERNAME=root
|
|
|
|
readonly DASHBOARD_ADMIN_PASSWORD=supercomplicatedpassword
|
|
|
|
readonly DASHBOARD_ADMIN_EMAIL="$DASHBOARD_ADMIN_USERNAME@dash.example.org"
|
|
|
|
readonly DASHBOARD_OIDC_APP_NAME=hostea-gitea
|
|
|
|
|
|
|
|
readonly GITEA_ROOT_USERNAME=root
|
|
|
|
readonly GITEA_ROOT_EMAIL="$GITEA_ROOT_USERNAME@example.org"
|
|
|
|
readonly GITEA_ROOT_PASSOWRD=supercomplicatedpassword
|
|
|
|
readonly GITEA_HOSTEA_SSO_NAME=hostea-sso
|
|
|
|
readonly GITEA_OIDC_CALLBACK="$GITEA_URL/user/oauth2/$GITEA_HOSTEA_SSO_NAME/callback"
|
2022-06-26 23:00:25 +00:00
|
|
|
readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY="$(realpath tests/fleet-deploy-key.pub)"
|
|
|
|
readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE="$(realpath tests/fleet-deploy-key)"
|
2022-06-25 22:32:18 +00:00
|
|
|
|
|
|
|
readonly GITEA_HOSTEA_USERNAME=hostea
|
|
|
|
readonly GITEA_HOSTEA_PASSWORD=supercomplicatedpassword
|
|
|
|
readonly GITEA_HOSTEA_EMAIL="$GITEA_HOSTEA_USERNAME@example.org"
|
|
|
|
readonly GITEA_HOSTEA_SUPPORT_REPO="support"
|
2022-06-25 23:21:15 +00:00
|
|
|
readonly GITEA_HOSTEA_FLEET_REPO="fleet"
|
2022-06-26 23:00:25 +00:00
|
|
|
readonly GITEA_HOSTEA_FLEET_REPO_REMOTE="$GITEA_SSH_URL/$GITEA_HOSTEA_USERNAME/$GITEA_HOSTEA_FLEET_REPO.git"
|
2022-06-25 22:32:18 +00:00
|
|
|
|
|
|
|
readonly HOSTEA_CUSTOMER_USERNAME=batman
|
|
|
|
readonly HOSTEA_CUSTOMER_PASSWORD=supercomplicatedpassword
|
|
|
|
readonly HOSTEA_CUSTOMER_EMAIL="$HOSTEA_CUSTOMER_USERNAME@example.org"
|
|
|
|
|
|
|
|
OIDC_CLIENT_ID=""
|
|
|
|
OIDC_CLIENT_SECRET=""
|
|
|
|
|
|
|
|
wait_for_env() {
|
|
|
|
python -m integration \
|
|
|
|
check_env $GITEA_URL $DASHBOARD_URL $MAILDEV_URL
|
|
|
|
}
|
|
|
|
|
|
|
|
# create OIDC app on Hostea Dashboard
|
|
|
|
oidc_dashboard_init() {
|
|
|
|
python -m integration \
|
|
|
|
hostea register \
|
|
|
|
$DASHBOARD_ADMIN_USERNAME $DASHBOARD_ADMIN_PASSWORD \
|
|
|
|
$DASHBOARD_ADMIN_EMAIL \
|
|
|
|
$DASHBOARD_URL \
|
|
|
|
$MAILDEV_URL
|
|
|
|
|
|
|
|
resp=$(python manage.py create_oidc \
|
|
|
|
$DASHBOARD_OIDC_APP_NAME $DASHBOARD_ADMIN_USERNAME \
|
|
|
|
$GITEA_OIDC_CALLBACK)
|
|
|
|
OIDC_CLIENT_ID=$(echo $resp | cut -d ":" -f 2 | cut -d " " -f 2)
|
|
|
|
OIDC_CLIENT_SECRET=$(echo $resp | cut -d ":" -f 3 | cut -d " " -f 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
# register root user on Gitea to simulate Hoste admin and integrate SSO
|
|
|
|
gitea_root(){
|
|
|
|
python -m integration \
|
|
|
|
gitea install \
|
|
|
|
$GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
|
|
|
$GITEA_ROOT_EMAIL \
|
|
|
|
$GITEA_URL
|
|
|
|
python -m integration \
|
|
|
|
gitea register \
|
|
|
|
$GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
|
|
|
$GITEA_ROOT_EMAIL \
|
|
|
|
$GITEA_URL
|
|
|
|
python -m integration \
|
|
|
|
gitea login \
|
|
|
|
$GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
|
|
|
$GITEA_ROOT_EMAIL \
|
|
|
|
$GITEA_URL
|
2022-06-25 23:21:15 +00:00
|
|
|
# python -m integration \
|
|
|
|
# gitea install_sso \
|
|
|
|
# $GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
|
|
|
# $GITEA_ROOT_EMAIL \
|
|
|
|
# $GITEA_URL \
|
|
|
|
# $GITEA_HOSTEA_SSO_NAME \
|
|
|
|
# $OIDC_CLIENT_ID $OIDC_CLIENT_SECRET \
|
|
|
|
# $DASHBOARD_OIDC_DISCOVERY_URL
|
2022-06-25 22:32:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# register user "Hostea" on Gitea and create support repository
|
|
|
|
support_repo_init() {
|
|
|
|
python -m integration \
|
|
|
|
gitea register \
|
|
|
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
|
|
|
$GITEA_HOSTEA_EMAIL \
|
|
|
|
$GITEA_URL
|
|
|
|
python -m integration \
|
|
|
|
gitea login \
|
|
|
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
|
|
|
$GITEA_HOSTEA_EMAIL \
|
|
|
|
$GITEA_URL
|
|
|
|
python -m integration \
|
|
|
|
gitea create_repo \
|
|
|
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
|
|
|
$GITEA_HOSTEA_EMAIL \
|
|
|
|
$GITEA_URL \
|
|
|
|
$GITEA_HOSTEA_SUPPORT_REPO
|
|
|
|
}
|
|
|
|
|
2022-07-01 14:22:10 +00:00
|
|
|
new_fleet_repo_init() {
|
2022-06-25 23:21:15 +00:00
|
|
|
python -m integration \
|
|
|
|
gitea create_repo \
|
|
|
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
|
|
|
$GITEA_HOSTEA_EMAIL \
|
|
|
|
$GITEA_URL \
|
2022-07-01 14:22:10 +00:00
|
|
|
$1
|
2022-06-25 23:21:15 +00:00
|
|
|
|
|
|
|
python -m integration \
|
|
|
|
gitea add_deploy_key \
|
|
|
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
|
|
|
$GITEA_HOSTEA_EMAIL \
|
|
|
|
$GITEA_URL \
|
2022-07-01 14:22:10 +00:00
|
|
|
$1 \
|
2022-06-25 23:21:15 +00:00
|
|
|
$GITEA_HOSTEA_FLEET_DEPLOY_KEY
|
2022-06-26 23:00:25 +00:00
|
|
|
|
|
|
|
tmp_dir=$(mktemp -d)
|
|
|
|
pushd $tmp_dir
|
|
|
|
echo "init" >> README
|
2022-07-08 12:26:59 +00:00
|
|
|
git init
|
2022-06-26 23:00:25 +00:00
|
|
|
if is_ci
|
|
|
|
then
|
2022-07-08 14:21:06 +00:00
|
|
|
git config user.email "hostea-dashobard-test@example.org"
|
|
|
|
git config user.name "hoste-dashobard-test"
|
2022-06-26 23:13:28 +00:00
|
|
|
chmod 600 $GITEA_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE
|
2022-06-26 23:00:25 +00:00
|
|
|
fi
|
|
|
|
git add README
|
|
|
|
git commit -m "init"
|
2022-07-01 14:22:10 +00:00
|
|
|
REMOTE="$GITEA_SSH_URL/$GITEA_HOSTEA_USERNAME/$1.git"
|
|
|
|
git remote add origin $REMOTE
|
2022-06-26 23:00:25 +00:00
|
|
|
GIT_SSH_COMMAND="/usr/bin/ssh -oStrictHostKeyChecking=no -i $GITEA_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE" \
|
|
|
|
git push --set-upstream origin master
|
|
|
|
popd
|
|
|
|
rm -rf $tmp_dir
|
|
|
|
|
2022-06-25 23:21:15 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 14:22:10 +00:00
|
|
|
|
|
|
|
# register user "Hostea" on Gitea and create support repository
|
|
|
|
fleet_repo_init() {
|
|
|
|
python -m integration \
|
|
|
|
gitea register \
|
|
|
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
|
|
|
$GITEA_HOSTEA_EMAIL \
|
|
|
|
$GITEA_URL || true
|
|
|
|
python -m integration \
|
|
|
|
gitea login \
|
|
|
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
|
|
|
$GITEA_HOSTEA_EMAIL \
|
|
|
|
$GITEA_URL
|
|
|
|
|
|
|
|
new_fleet_repo_init $GITEA_HOSTEA_FLEET_REPO
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-25 22:32:18 +00:00
|
|
|
# Create user on Hostea to simulate a Hostea customer
|
|
|
|
hostea_customer_simulation() {
|
|
|
|
python -m integration \
|
|
|
|
hostea register \
|
|
|
|
$HOSTEA_CUSTOMER_USERNAME $HOSTEA_CUSTOMER_PASSWORD \
|
|
|
|
$HOSTEA_CUSTOMER_EMAIL \
|
|
|
|
$DASHBOARD_URL \
|
|
|
|
$MAILDEV_URL
|
|
|
|
python -m integration \
|
|
|
|
hostea login \
|
|
|
|
$HOSTEA_CUSTOMER_USERNAME $HOSTEA_CUSTOMER_PASSWORD \
|
|
|
|
$HOSTEA_CUSTOMER_EMAIL $DASHBOARD_URL
|
|
|
|
python -m integration \
|
|
|
|
hostea support \
|
|
|
|
$HOSTEA_CUSTOMER_USERNAME $HOSTEA_CUSTOMER_PASSWORD \
|
|
|
|
$HOSTEA_CUSTOMER_EMAIL \
|
|
|
|
$DASHBOARD_URL \
|
|
|
|
$GITEA_URL \
|
|
|
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_SUPPORT_REPO
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_env() {
|
|
|
|
mkdir tmp/ || true
|
|
|
|
nohup python manage.py runserver > /dev/null 2>&1 &
|
|
|
|
SERVER_PID=$!
|
|
|
|
echo $SERVER_PID > $SERVER_PID_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown_env() {
|
|
|
|
kill $(cat $SERVER_PID_FILE)
|
|
|
|
}
|
2022-06-25 23:21:15 +00:00
|
|
|
|
|
|
|
docker_compose_up() {
|
|
|
|
docker-compose -f docker-compose-dev-deps.yml up -d
|
|
|
|
}
|
|
|
|
|
|
|
|
docker_compose_down() {
|
|
|
|
docker-compose -f docker-compose-dev-deps.yml down
|
|
|
|
docker-compose -f docker-compose-dev-deps.yml down --remove-orphans
|
|
|
|
}
|