From 6c5d334cefa95f51b415b52472cd46f2ea7a0575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sara=20Aim=C3=A9e=20Smiseth?= <51710585+SaraSmiseth@users.noreply.github.com> Date: Fri, 7 May 2021 11:00:17 +0200 Subject: [PATCH] Run tests for prosody with postgres and also for prosody with sqlite. TODO Add tests that check if postgres or sqlite is used. --- tests/test.bash | 23 ++++++++++++++++++----- tests/tests.bats | 30 +++++++++++++++--------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/tests/test.bash b/tests/test.bash index 6e5bd0d..34c0f71 100755 --- a/tests/test.bash +++ b/tests/test.bash @@ -15,12 +15,18 @@ generateCert() { fi } +registerTestUser() { + local userName="$1" + local containerName="$2" + sudo docker exec "$containerName" /bin/bash -c "/entrypoint.bash register $userName localhost 12345678" +} + registerTestUsers() { local containerName="$1" - sudo docker exec "$containerName" /bin/bash -c "/entrypoint.bash register admin localhost 12345678" \ - && sudo docker exec "$containerName" /bin/bash -c "/entrypoint.bash register user1 localhost 12345678" \ - && sudo docker exec "$containerName" /bin/bash -c "/entrypoint.bash register user2 localhost 12345678" \ - && sudo docker exec "$containerName" /bin/bash -c "/entrypoint.bash register user3 localhost 12345678" + registerTestUser admin "$containerName" + registerTestUser user1 "$containerName" + registerTestUser user2 "$containerName" + registerTestUser user3 "$containerName" } runTests() { @@ -36,6 +42,7 @@ runTests() { && deactivate \ && sleep 5 \ && sudo docker-compose logs "$containerName" \ + && export batsContainerName="$containerName" \ && ./bats/bats-core/bin/bats tests.bats } @@ -45,6 +52,7 @@ generateCert "proxy.localhost" generateCert "pubsub.localhost" generateCert "upload.localhost" +# Run tests for first container with postgres # Start postgres first and wait for 10 seconds before starting prosody. sudo docker-compose down \ && sudo docker-compose up -d postgres \ @@ -53,5 +61,10 @@ sudo docker-compose down \ registerTestUsers tests_prosody_postgres_1 runTests prosody_postgres - +sudo docker-compose down + +# Run tests for second container with SQLite +sudo docker-compose up -d prosody +registerTestUsers tests_prosody_1 +runTests prosody sudo docker-compose down diff --git a/tests/tests.bats b/tests/tests.bats index f9f8df2..31dac1e 100644 --- a/tests/tests.bats +++ b/tests/tests.bats @@ -5,91 +5,91 @@ load 'bats/bats-assert/load' # group alternation in regex because the xml properties switch around. sometimes 'type=...' comes after 'to=...' and sometimes before @test "Should send 5 messages" { - run bash -c "sudo docker-compose logs | grep -E \"Received\[c2s\]: \" | wc -l" + run bash -c "sudo docker-compose logs $batsContainerName | grep -E \"Received\[c2s\]: \" | wc -l" assert_success assert_output "5" } @test "Should select certificate for localhost" { - run bash -c "sudo docker-compose logs | grep \"Selecting certificate /usr/local/etc/prosody/certs/localhost/fullchain.pem with key /usr/local/etc/prosody/certs/localhost/privkey.pem for localhost\" | wc -l" + run bash -c "sudo docker-compose logs $batsContainerName | grep \"Selecting certificate /usr/local/etc/prosody/certs/localhost/fullchain.pem with key /usr/local/etc/prosody/certs/localhost/privkey.pem for localhost\" | wc -l" assert_success assert_output "3" } @test "Should select certificate for conference.localhost" { - run bash -c "sudo docker-compose logs | grep \"Selecting certificate /usr/local/etc/prosody/certs/conference.localhost/fullchain.pem with key /usr/local/etc/prosody/certs/conference.localhost/privkey.pem for conference.localhost\" | wc -l" + run bash -c "sudo docker-compose logs $batsContainerName | grep \"Selecting certificate /usr/local/etc/prosody/certs/conference.localhost/fullchain.pem with key /usr/local/etc/prosody/certs/conference.localhost/privkey.pem for conference.localhost\" | wc -l" assert_success assert_output "3" } @test "Should select certificate for proxy.localhost" { - run bash -c "sudo docker-compose logs | grep \"Selecting certificate /usr/local/etc/prosody/certs/proxy.localhost/fullchain.pem with key /usr/local/etc/prosody/certs/proxy.localhost/privkey.pem for proxy.localhost\" | wc -l" + run bash -c "sudo docker-compose logs $batsContainerName | grep \"Selecting certificate /usr/local/etc/prosody/certs/proxy.localhost/fullchain.pem with key /usr/local/etc/prosody/certs/proxy.localhost/privkey.pem for proxy.localhost\" | wc -l" assert_success assert_output "3" } @test "Should select certificate for pubsub.localhost" { - run bash -c "sudo docker-compose logs | grep \"Selecting certificate /usr/local/etc/prosody/certs/pubsub.localhost/fullchain.pem with key /usr/local/etc/prosody/certs/pubsub.localhost/privkey.pem for pubsub.localhost\" | wc -l" + run bash -c "sudo docker-compose logs $batsContainerName | grep \"Selecting certificate /usr/local/etc/prosody/certs/pubsub.localhost/fullchain.pem with key /usr/local/etc/prosody/certs/pubsub.localhost/privkey.pem for pubsub.localhost\" | wc -l" assert_success assert_output "3" } @test "Should select certificate for upload.localhost" { - run bash -c "sudo docker-compose logs | grep \"Selecting certificate /usr/local/etc/prosody/certs/upload.localhost/fullchain.pem with key /usr/local/etc/prosody/certs/upload.localhost/privkey.pem for upload.localhost\" | wc -l" + run bash -c "sudo docker-compose logs $batsContainerName | grep \"Selecting certificate /usr/local/etc/prosody/certs/upload.localhost/fullchain.pem with key /usr/local/etc/prosody/certs/upload.localhost/privkey.pem for upload.localhost\" | wc -l" assert_success assert_output "3" } @test "Should log error for user with wrong password" { - run bash -c "sudo docker-compose logs | grep \"Session closed by remote with error: undefined-condition (user intervention: authentication failed: authentication aborted by user)\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep \"Session closed by remote with error: undefined-condition (user intervention: authentication failed: authentication aborted by user)\"" assert_success assert_output } @test "Should activate s2s" { - run bash -c "sudo docker-compose logs | grep -E \"Activated service 's2s' on (\[::\]:5269|\[\*\]:5269), (\[::\]:5269|\[\*\]:5269)\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep -E \"Activated service 's2s' on (\[::\]:5269|\[\*\]:5269), (\[::\]:5269|\[\*\]:5269)\"" assert_success assert_output } @test "Should activate c2s" { - run bash -c "sudo docker-compose logs | grep -E \"Activated service 'c2s' on (\[::\]:5222|\[\*\]:5222), (\[::\]:5222|\[\*\]:5222)\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep -E \"Activated service 'c2s' on (\[::\]:5222|\[\*\]:5222), (\[::\]:5222|\[\*\]:5222)\"" assert_success assert_output } @test "Should activate legacy_ssl" { - run bash -c "sudo docker-compose logs | grep -E \"Activated service 'legacy_ssl' on (\[::\]:5223|\[\*\]:5223), (\[::\]:5223|\[\*\]:5223)\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep -E \"Activated service 'legacy_ssl' on (\[::\]:5223|\[\*\]:5223), (\[::\]:5223|\[\*\]:5223)\"" assert_success assert_output } @test "Should activate proxy65" { - run bash -c "sudo docker-compose logs | grep -E \"Activated service 'proxy65' on (\[::\]:5000|\[\*\]:5000), (\[::\]:5000|\[\*\]:5000)\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep -E \"Activated service 'proxy65' on (\[::\]:5000|\[\*\]:5000), (\[::\]:5000|\[\*\]:5000)\"" assert_success assert_output } @test "Should activate http" { - run bash -c "sudo docker-compose logs | grep -E \"Activated service 'http' on (\[::\]:5280|\[\*\]:5280), (\[::\]:5280|\[\*\]:5280)\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep -E \"Activated service 'http' on (\[::\]:5280|\[\*\]:5280), (\[::\]:5280|\[\*\]:5280)\"" assert_success assert_output } @test "Should activate https" { - run bash -c "sudo docker-compose logs | grep -E \"Activated service 'https' on (\[::\]:5281|\[\*\]:5281), (\[::\]:5281|\[\*\]:5281)\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep -E \"Activated service 'https' on (\[::\]:5281|\[\*\]:5281), (\[::\]:5281|\[\*\]:5281)\"" assert_success assert_output } @test "Should load module cloud_notify" { - run bash -c "sudo docker-compose logs | grep \"localhost:cloud_notify.*info.*Module loaded\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep \"localhost:cloud_notify.*info.*Module loaded\"" assert_success assert_output } @test "Should show upload URL" { - run bash -c "sudo docker-compose logs | grep \"URL: - Ensure this can be reached by users\"" + run bash -c "sudo docker-compose logs $batsContainerName | grep \"URL: - Ensure this can be reached by users\"" assert_success assert_output }