2020-10-30 16:47:05 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# generate certs for testing
|
|
|
|
|
|
|
|
generateCert() {
|
2023-03-28 06:08:01 +00:00
|
|
|
local DOMAIN="$1"
|
2020-10-30 16:47:05 +00:00
|
|
|
if [[ ! -d certs/"$DOMAIN" ]] ; then
|
|
|
|
mkdir -p certs/"$DOMAIN"
|
|
|
|
cd certs/"$DOMAIN"
|
|
|
|
openssl req -x509 -newkey rsa:4096 -keyout privkey.pem -out fullchain.pem -days 365 -subj "/CN=$DOMAIN" -nodes
|
|
|
|
chmod 777 *.pem
|
|
|
|
cd ../../
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-05-07 12:06:29 +00:00
|
|
|
registerTestUser() {
|
|
|
|
local userName="$1"
|
|
|
|
local containerName="$2"
|
2023-02-23 15:22:36 +00:00
|
|
|
echo "Registering TestUser '$userName' in container '$containerName'"
|
2024-11-19 14:09:13 +00:00
|
|
|
sudo docker compose exec "$containerName" /bin/bash -c "prosodyctl register $userName example.com 12345678"
|
2021-05-07 12:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
registerTestUsers() {
|
|
|
|
local containerName="$1"
|
|
|
|
registerTestUser admin "$containerName"
|
|
|
|
registerTestUser user1 "$containerName"
|
|
|
|
registerTestUser user2 "$containerName"
|
|
|
|
registerTestUser user3 "$containerName"
|
|
|
|
}
|
|
|
|
|
|
|
|
runTests() {
|
|
|
|
local containerName="$1"
|
|
|
|
python --version \
|
|
|
|
&& python3 --version \
|
|
|
|
&& python3 -m venv venv \
|
|
|
|
&& source venv/bin/activate \
|
|
|
|
&& python --version \
|
|
|
|
&& pip --version \
|
|
|
|
&& pip install -r requirements.txt \
|
|
|
|
&& pytest \
|
|
|
|
&& deactivate \
|
|
|
|
&& sleep 5 \
|
2024-11-19 14:09:13 +00:00
|
|
|
&& sudo docker compose logs "$containerName" \
|
2021-05-07 12:06:29 +00:00
|
|
|
&& export batsContainerName="$containerName" \
|
|
|
|
&& ./bats/bats-core/bin/bats tests.bats \
|
|
|
|
&& ./bats/bats-core/bin/bats tests-"$containerName".bats
|
|
|
|
}
|
|
|
|
|
2023-03-28 06:08:01 +00:00
|
|
|
generateCert "example.com"
|
|
|
|
generateCert "conference.example.com"
|
|
|
|
generateCert "proxy.example.com"
|
|
|
|
generateCert "pubsub.example.com"
|
|
|
|
generateCert "upload.example.com"
|
2020-10-30 16:47:05 +00:00
|
|
|
|
2021-05-07 12:06:29 +00:00
|
|
|
# Run tests for first container with postgres
|
|
|
|
# Start postgres first and wait for 10 seconds before starting prosody.
|
2024-11-19 14:09:13 +00:00
|
|
|
sudo docker compose down
|
|
|
|
sudo docker compose up -d postgres
|
2023-03-28 06:08:01 +00:00
|
|
|
sleep 10
|
2024-11-19 14:09:13 +00:00
|
|
|
sudo docker compose up -d prosody_postgres
|
2021-05-07 12:06:29 +00:00
|
|
|
|
2022-05-05 16:25:19 +00:00
|
|
|
registerTestUsers prosody_postgres
|
2021-05-07 12:06:29 +00:00
|
|
|
runTests prosody_postgres
|
2024-11-19 14:09:13 +00:00
|
|
|
sudo docker compose down
|
2020-10-30 16:47:05 +00:00
|
|
|
|
2021-05-07 12:06:29 +00:00
|
|
|
# Run tests for second container with SQLite
|
2024-11-19 14:09:13 +00:00
|
|
|
sudo docker compose up -d prosody
|
2022-05-05 16:25:19 +00:00
|
|
|
registerTestUsers prosody
|
2021-05-07 12:06:29 +00:00
|
|
|
runTests prosody
|
2024-11-19 14:09:13 +00:00
|
|
|
sudo docker compose down
|
2023-03-28 06:08:01 +00:00
|
|
|
|
|
|
|
# Run tests for prosody with ldap
|
2024-11-19 14:09:13 +00:00
|
|
|
sudo docker compose up -d prosody_ldap
|
2023-03-28 06:08:01 +00:00
|
|
|
runTests prosody_ldap
|
2024-11-19 14:09:13 +00:00
|
|
|
sudo docker compose down
|