218 lines
5.9 KiB
Bash
Executable File
218 lines
5.9 KiB
Bash
Executable File
readonly SERVER_PID_FILE=./tmp/server.pid
|
|
is_ci(){
|
|
if [ -z ${CI+x} ];
|
|
then
|
|
return 1
|
|
else
|
|
return 0
|
|
fi
|
|
}
|
|
|
|
if is_ci
|
|
then
|
|
MAILDEV_URL="http://smtp:1080"
|
|
FORGEJO_URL="http://forgejo:3000"
|
|
FORGEJO_SSH_URL="ssh://git@forgejo:22"
|
|
else
|
|
MAILDEV_URL="http://localhost:1080"
|
|
FORGEJO_URL="http://localhost:3000"
|
|
FORGEJO_SSH_URL="ssh://git@localhost:22"
|
|
fi
|
|
|
|
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-forgejo
|
|
|
|
readonly FORGEJO_ROOT_USERNAME=root
|
|
readonly FORGEJO_ROOT_EMAIL="$FORGEJO_ROOT_USERNAME@example.org"
|
|
readonly FORGEJO_ROOT_PASSOWRD=supercomplicatedpassword
|
|
readonly FORGEJO_HOSTEA_SSO_NAME=hostea-sso
|
|
readonly FORGEJO_OIDC_CALLBACK="$FORGEJO_URL/user/oauth2/$FORGEJO_HOSTEA_SSO_NAME/callback"
|
|
readonly FORGEJO_HOSTEA_FLEET_DEPLOY_KEY="$(realpath tests/fleet-deploy-key.pub)"
|
|
readonly FORGEJO_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE="$(realpath tests/fleet-deploy-key)"
|
|
|
|
readonly FORGEJO_HOSTEA_USERNAME=hostea
|
|
readonly FORGEJO_HOSTEA_PASSWORD=supercomplicatedpassword
|
|
readonly FORGEJO_HOSTEA_EMAIL="$FORGEJO_HOSTEA_USERNAME@example.org"
|
|
readonly FORGEJO_HOSTEA_SUPPORT_REPO="support"
|
|
readonly FORGEJO_HOSTEA_FLEET_REPO="fleet"
|
|
readonly FORGEJO_HOSTEA_FLEET_REPO_REMOTE="$FORGEJO_SSH_URL/$FORGEJO_HOSTEA_USERNAME/$FORGEJO_HOSTEA_FLEET_REPO.git"
|
|
|
|
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 $FORGEJO_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 \
|
|
$FORGEJO_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 Forgejo to simulate Hoste admin and integrate SSO
|
|
forgejo_root(){
|
|
python -m integration \
|
|
forgejo install \
|
|
$FORGEJO_ROOT_USERNAME $FORGEJO_ROOT_PASSOWRD \
|
|
$FORGEJO_ROOT_EMAIL \
|
|
$FORGEJO_URL
|
|
python -m integration \
|
|
forgejo register \
|
|
$FORGEJO_ROOT_USERNAME $FORGEJO_ROOT_PASSOWRD \
|
|
$FORGEJO_ROOT_EMAIL \
|
|
$FORGEJO_URL
|
|
python -m integration \
|
|
forgejo login \
|
|
$FORGEJO_ROOT_USERNAME $FORGEJO_ROOT_PASSOWRD \
|
|
$FORGEJO_ROOT_EMAIL \
|
|
$FORGEJO_URL
|
|
# python -m integration \
|
|
# forgejo install_sso \
|
|
# $FORGEJO_ROOT_USERNAME $FORGEJO_ROOT_PASSOWRD \
|
|
# $FORGEJO_ROOT_EMAIL \
|
|
# $FORGEJO_URL \
|
|
# $FORGEJO_HOSTEA_SSO_NAME \
|
|
# $OIDC_CLIENT_ID $OIDC_CLIENT_SECRET \
|
|
# $DASHBOARD_OIDC_DISCOVERY_URL
|
|
}
|
|
|
|
|
|
# register user "Hostea" on Forgejo and create support repository
|
|
support_repo_init() {
|
|
python -m integration \
|
|
forgejo register \
|
|
$FORGEJO_HOSTEA_USERNAME $FORGEJO_HOSTEA_PASSWORD \
|
|
$FORGEJO_HOSTEA_EMAIL \
|
|
$FORGEJO_URL
|
|
python -m integration \
|
|
forgejo login \
|
|
$FORGEJO_HOSTEA_USERNAME $FORGEJO_HOSTEA_PASSWORD \
|
|
$FORGEJO_HOSTEA_EMAIL \
|
|
$FORGEJO_URL
|
|
python -m integration \
|
|
forgejo create_repo \
|
|
$FORGEJO_HOSTEA_USERNAME $FORGEJO_HOSTEA_PASSWORD \
|
|
$FORGEJO_HOSTEA_EMAIL \
|
|
$FORGEJO_URL \
|
|
$FORGEJO_HOSTEA_SUPPORT_REPO
|
|
}
|
|
|
|
new_fleet_repo_init() {
|
|
python -m integration \
|
|
forgejo create_repo \
|
|
$FORGEJO_HOSTEA_USERNAME $FORGEJO_HOSTEA_PASSWORD \
|
|
$FORGEJO_HOSTEA_EMAIL \
|
|
$FORGEJO_URL \
|
|
$1
|
|
|
|
python -m integration \
|
|
forgejo add_deploy_key \
|
|
$FORGEJO_HOSTEA_USERNAME $FORGEJO_HOSTEA_PASSWORD \
|
|
$FORGEJO_HOSTEA_EMAIL \
|
|
$FORGEJO_URL \
|
|
$1 \
|
|
$FORGEJO_HOSTEA_FLEET_DEPLOY_KEY
|
|
|
|
tmp_dir=$(mktemp -d)
|
|
pushd $tmp_dir
|
|
echo "init" >> README
|
|
git init
|
|
if is_ci
|
|
then
|
|
git config user.email "hostea-dashobard-test@example.org"
|
|
git config user.name "hoste-dashobard-test"
|
|
chmod 600 $FORGEJO_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE
|
|
fi
|
|
git add README
|
|
git commit -m "init"
|
|
REMOTE="$FORGEJO_SSH_URL/$FORGEJO_HOSTEA_USERNAME/$1.git"
|
|
git remote add origin $REMOTE
|
|
GIT_SSH_COMMAND="/usr/bin/ssh -oStrictHostKeyChecking=no -i $FORGEJO_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE" \
|
|
git push --set-upstream origin master
|
|
popd
|
|
rm -rf $tmp_dir
|
|
|
|
}
|
|
|
|
|
|
# register user "Hostea" on Forgejo and create support repository
|
|
fleet_repo_init() {
|
|
python -m integration \
|
|
forgejo register \
|
|
$FORGEJO_HOSTEA_USERNAME $FORGEJO_HOSTEA_PASSWORD \
|
|
$FORGEJO_HOSTEA_EMAIL \
|
|
$FORGEJO_URL || true
|
|
python -m integration \
|
|
forgejo login \
|
|
$FORGEJO_HOSTEA_USERNAME $FORGEJO_HOSTEA_PASSWORD \
|
|
$FORGEJO_HOSTEA_EMAIL \
|
|
$FORGEJO_URL
|
|
|
|
new_fleet_repo_init $FORGEJO_HOSTEA_FLEET_REPO
|
|
|
|
}
|
|
|
|
# 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 \
|
|
$FORGEJO_URL \
|
|
$FORGEJO_HOSTEA_USERNAME $FORGEJO_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)
|
|
}
|
|
|
|
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
|
|
}
|