From a38588850716cd9c195c0ac87eb7adf3af7635f5 Mon Sep 17 00:00:00 2001 From: Prateek Jain Date: Thu, 18 Jun 2020 00:10:08 +0530 Subject: [PATCH] Add functional test for admin panel --- .../functional/journalist_navigation_steps.py | 19 +++++++++++++++++++ .../tests/functional/test_admin_interface.py | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/securedrop/tests/functional/journalist_navigation_steps.py b/securedrop/tests/functional/journalist_navigation_steps.py index 3f066e647dc..f04f1e6192b 100644 --- a/securedrop/tests/functional/journalist_navigation_steps.py +++ b/securedrop/tests/functional/journalist_navigation_steps.py @@ -322,6 +322,25 @@ def _add_user(self, username, first_name="", last_name="", is_admin=False, hotp= self.wait_for(lambda: self.driver.find_element_by_id("check-token")) + def _admin_adds_a_user_with_invalid_username(self): + self.safe_click_by_id("add-user") + + self.wait_for(lambda: self.driver.find_element_by_id("username")) + + if not hasattr(self, "accept_languages"): + # The add user page has a form with an "ADD USER" button + btns = self.driver.find_elements_by_tag_name("button") + assert "ADD USER" in [el.text for el in btns] + + invalid_username = 'deleted' + + self.safe_send_keys_by_css_selector('input[name="username"]', invalid_username) + + self.safe_click_by_css_selector("button[type=submit]") + + error_msg = self.driver.find_element_by_css_selector(".form-validation-error") + assert "Invalid username '{}'".format(invalid_username) in error_msg.text + def _admin_adds_a_user(self, is_admin=False, new_username=""): self.safe_click_by_id("add-user") diff --git a/securedrop/tests/functional/test_admin_interface.py b/securedrop/tests/functional/test_admin_interface.py index 027aeed705b..8d3fb7ae7c7 100644 --- a/securedrop/tests/functional/test_admin_interface.py +++ b/securedrop/tests/functional/test_admin_interface.py @@ -56,6 +56,12 @@ def test_ossec_alert_button(self): self._admin_visits_system_config_page() self._admin_can_send_test_alert() + def test_admin_adds_user_with_invalid_username(self): + self._admin_logs_in() + self._admin_visits_admin_interface() + # Add an user with invalid username + self._admin_adds_a_user_with_invalid_username() + def test_admin_adds_admin_user(self): self._admin_logs_in() self._admin_visits_admin_interface()