Commit 6385226d authored by Swergas's avatar Swergas

use the new BELENIOS_SENDMAIL environment variable to define the location of...

use the new BELENIOS_SENDMAIL environment variable to define the location of the sendmail replacement, instead of requiring a sudoer account to replace the original binary
parent fd608371
Pipeline #50854 passed with stages
in 12 minutes and 23 seconds
......@@ -4,12 +4,10 @@ Automated tests are stored in the `tests` directory.
Technologies used to run these tests are: Python 3 in a virtual environment, `pip` (to install Python packages such as `selenium`), `selenium`, `firefox`, `geckodriver` (a firefox driver for selenium), `unittest`.
These automated tests start the Belenios demo server (`demo/run-server.sh`), and set up a fake `sendmail` executable (similar to a mock), so that the Belenios server does not return an error when trying to send emails in the test environment (that has no `sendmail` installed nor configured), and so that the fake `sendmail` executable makes it possible to verify what emails have been sent and read their content, simply by reading the log file where it redirects all its input.
These automated tests start the Belenios demo server (`demo/run-server.sh`), with the `BELENIOS_SENDMAIL` environment variable defined as the path to a fake `sendmail` executable (similar to a mock, provided in `tests/tools/sendmail_fake.sh`). This way, Belenios server does not return an error when trying to send emails in the test environment (that has no `sendmail` installed nor configured), and the fake `sendmail` executable makes it possible to verify what emails have been sent and read their content, simply by reading the log file where it redirects all its input (we use `/tmp/sendmail_fake` as location for this log file).
Note: For example, during election creation procedure, a step sends emails to voters. If at this moment, a `sendmail` binary is not properly installed and configured (or replaced by a mock), the web page displays the following error message: `Netchannels.Command_failure(WEXITED 126)`
Note: Steps `install_fake_sendmail()` and `uninstall_fake_sendmail()` of the automated test scripts imply that it is currently necessary that command `python ./tests/test_scenario_1.py` is executed as a sudoer (and for this to work properly using Continuous Integration, this sudoer must not have to write a sudo password when they execute a sudo command).
When these automated tests start running, and when they end, they clean up Belenios database: Belenios database consists in directories and files under the `_run/spool` directory, for each election. So these are deleted during test setup. Belenios demo server stores initial admin users logins and passwords in `demo/password_db.csv`. This file is not deleted during test setup, and its contents are used to log in the adminstrator during the test and have this administrator create an election.
Automated tests can be executed manually, or via Continuous Integration.
......
......@@ -16,7 +16,6 @@ from selenium.common.exceptions import StaleElementReferenceException
SERVER_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY = "demo/run-server.sh"
SERVER_URL = "http://localhost:8001"
DATABASE_FOLDER_PATH_RELATIVE_TO_GIT_REPOSITORY = "_run/spool"
SENDMAIL_EXECUTABLE_FILE_ABSOLUTE_PATH = "/usr/lib/sendmail"
FAKE_SENDMAIL_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY = "tests/tools/sendmail_fake.sh"
SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH = "/tmp/sendmail_fake"
USE_HEADLESS_BROWSER = True
......@@ -59,17 +58,12 @@ def remove_database_folder():
def wait_a_bit():
time.sleep(WAIT_TIME_BETWEEN_EACH_STEP)
def install_fake_sendmail():
# If the sendmail executable does not exist, script outputs an error like `mv: cannot stat '/usr/lib/sendmail': No such file or directory`. But this can be ignored as it does not cause any problem for the rest of the execution.
subprocess.run(["sudo", "mv", SENDMAIL_EXECUTABLE_FILE_ABSOLUTE_PATH, SENDMAIL_EXECUTABLE_FILE_ABSOLUTE_PATH + "_original"])
fake_sendmail_absolute_path = os.path.join(GIT_REPOSITORY_ABSOLUTE_PATH, FAKE_SENDMAIL_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY)
subprocess.run(["sudo", "ln", "--symbolic", fake_sendmail_absolute_path, SENDMAIL_EXECUTABLE_FILE_ABSOLUTE_PATH])
def install_fake_sendmail_log_file():
subprocess.run(["rm", "-f", SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH])
subprocess.run(["touch", SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH])
def uninstall_fake_sendmail():
subprocess.run(["sudo", "rm", SENDMAIL_EXECUTABLE_FILE_ABSOLUTE_PATH])
# If the original sendmail executable did not exist at setUp(), sendmail_original does not exist now, and the script outputs an error like `mv: cannot stat '/usr/lib/sendmail_original': No such file or directory`. But this can be ignored as it does not cause any problem for the rest of the execution.
subprocess.run(["sudo", "mv", SENDMAIL_EXECUTABLE_FILE_ABSOLUTE_PATH + "_original", SENDMAIL_EXECUTABLE_FILE_ABSOLUTE_PATH])
subprocess.run(["sudo", "rm", "-f", SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH])
def uninstall_fake_sendmail_log_file():
subprocess.run(["rm", "-f", SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH])
class element_exists_and_contains_expected_text(object):
......@@ -120,12 +114,14 @@ def wait_for_element_exists_and_contains_expected_text(browser, css_selector, ex
class BeleniosTestElectionScenario1(unittest.TestCase):
def setUp(self):
install_fake_sendmail()
install_fake_sendmail_log_file()
remove_database_folder()
server_path = os.path.join(GIT_REPOSITORY_ABSOLUTE_PATH, SERVER_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY)
self.server = subprocess.Popen([server_path], stdout=subprocess.PIPE)
fake_sendmail_absolute_path = os.path.join(GIT_REPOSITORY_ABSOLUTE_PATH, FAKE_SENDMAIL_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY)
custom_environment_variables = dict(os.environ, BELENIOS_SENDMAIL=fake_sendmail_absolute_path)
self.server = subprocess.Popen([server_path], stdout=subprocess.PIPE, env=custom_environment_variables)
if USE_HEADLESS_BROWSER:
from selenium.webdriver.firefox.options import Options
......@@ -144,7 +140,7 @@ class BeleniosTestElectionScenario1(unittest.TestCase):
remove_database_folder()
uninstall_fake_sendmail()
uninstall_fake_sendmail_log_file()
def administrator_creates_election(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment