From 58395147c96a3bf804d9e38122145d6d58f4b454 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 30 Mar 2021 13:13:26 +0200 Subject: [PATCH] Replace PasswdVirtualUserBackend with RoundcubeIdentityController --- .../mailboxes/tests/functional_tests/tests.py | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/orchestra/contrib/mailboxes/tests/functional_tests/tests.py b/orchestra/contrib/mailboxes/tests/functional_tests/tests.py index fb37208f..ccfb1c22 100644 --- a/orchestra/contrib/mailboxes/tests/functional_tests/tests.py +++ b/orchestra/contrib/mailboxes/tests/functional_tests/tests.py @@ -29,21 +29,21 @@ class MailboxMixin(object): 'orchestra.contrib.mails', 'orchestra.contrib.resources', ) - + def setUp(self): super(MailboxMixin, self).setUp() self.add_route() # clean resource relation from other tests apps.get_app_config('resources').reload_relations() djsettings.DEBUG = True - + def add_route(self): server = Server.objects.create(name=self.MASTER_SERVER) - backend = backends.PasswdVirtualUserBackend.get_name() + backend = backends.RoundcubeIdentityController.get_name() Route.objects.create(backend=backend, match=True, host=server) backend = backends.PostfixAddressController.get_name() Route.objects.create(backend=backend, match=True, host=server) - + def add_quota_resource(self): Resource.objects.create( name='disk', @@ -55,38 +55,38 @@ class MailboxMixin(object): on_demand=False, default_allocation=2000 ) - + def save(self): raise NotImplementedError - + def add(self): raise NotImplementedError - + def delete(self): raise NotImplementedError - + def update(self): raise NotImplementedError - + def disable(self): raise NotImplementedError - + def add_group(self, username, groupname): raise NotImplementedError - + def login_imap(self, username, password): mail = imaplib.IMAP4_SSL(self.MASTER_SERVER) status, msg = mail.login(username, password) self.assertEqual('OK', status) self.assertEqual(['Logged in'], msg) return mail - + def login_pop3(self, username, password): pop = poplib.POP3(self.MASTER_SERVER) pop.user(username) pop.pass_(password) return pop - + def send_email(self, to, token): msg = MIMEText(token) msg['To'] = to @@ -100,14 +100,14 @@ class MailboxMixin(object): server.sendmail(msg['From'], msg['To'], msg.as_string()) finally: server.quit() - + def validate_mailbox(self, username): sshrun(self.MASTER_SERVER, "doveadm search -u %s ALL" % username, display=False) - + def validate_email(self, username, token): home = Mailbox.objects.get(name=username).get_home() sshrun(self.MASTER_SERVER, "grep '%s' %s/Maildir/new/*" % (token, home), display=False) - + def test_add(self): username = '%s_mailbox' % random_ascii(10) password = '@!?%spppP001' % random_ascii(5) @@ -115,7 +115,7 @@ class MailboxMixin(object): self.addCleanup(self.delete, username) imap = self.login_imap(username, password) self.validate_mailbox(username) - + def test_change_password(self): username = '%s_systemuser' % random_ascii(10) password = '@!?%spppP001' % random_ascii(5) @@ -125,7 +125,7 @@ class MailboxMixin(object): new_password = '@!?%spppP001' % random_ascii(5) self.change_password(username, new_password) imap = self.login_imap(username, new_password) - + def test_quota(self): username = '%s_mailbox' % random_ascii(10) password = '@!?%spppP001' % random_ascii(5) @@ -139,7 +139,7 @@ class MailboxMixin(object): imap = self.login_imap(username, password) imap_quota = int(imap.getquotaroot("INBOX")[1][1][0].split(' ')[-1].split(')')[0]) self.assertEqual(quota*1024, imap_quota) - + def test_send_email(self): username = '%s_mailbox' % random_ascii(10) password = '@!?%spppP001' % random_ascii(5) @@ -155,7 +155,7 @@ class MailboxMixin(object): server.sendmail(msg['From'], msg['To'], msg.as_string()) finally: server.quit() - + def test_address(self): username = '%s_mailbox' % random_ascii(10) password = '@!?%spppP001' % random_ascii(5) @@ -168,7 +168,7 @@ class MailboxMixin(object): token = random_ascii(100) self.send_email("%s@%s" % (name, domain), token) self.validate_email(username, token) - + def test_disable(self): username = '%s_systemuser' % random_ascii(10) password = '@!?%spppP001' % random_ascii(5) @@ -178,7 +178,7 @@ class MailboxMixin(object): imap = self.login_imap(username, password) self.disable(username) self.assertRaises(imap.error, self.login_imap, username, password) - + def test_delete(self): username = '%s_systemuser' % random_ascii(10) password = '@!?%sppppP001' % random_ascii(5) @@ -193,7 +193,7 @@ class MailboxMixin(object): self.assertRaises(imap.error, self.login_imap, username, password) self.assertRaises(CommandError, sshrun, self.MASTER_SERVER, 'ls %s' % home, display=False) - + def test_delete_address(self): username = '%s_mailbox' % random_ascii(10) password = '@!?%spppP001' % random_ascii(5) @@ -209,14 +209,14 @@ class MailboxMixin(object): self.delete_address(username) self.send_email("%s@%s" % (name, domain), token) self.validate_email(username, token) - + def test_custom_filtering(self): username = '%s_mailbox' % random_ascii(10) password = '@!?%spppP001' % random_ascii(5) folder = random_ascii(5) filtering = textwrap.dedent(""" require "fileinto"; - if true { + if true { fileinto "%s"; stop; }""" % folder) @@ -239,7 +239,7 @@ class RESTMailboxMixin(MailboxMixin): def setUp(self): super(RESTMailboxMixin, self).setUp() self.rest_login() - + @save_response_on_error def add(self, username, password, quota=None, filtering=None): extra = {} @@ -258,28 +258,28 @@ class RESTMailboxMixin(MailboxMixin): 'custom_filtering': filtering, }) self.rest.mailboxes.create(name=username, password=password, **extra) - + @save_response_on_error def delete(self, username): mailbox = self.rest.mailboxes.retrieve(name=username).get() mailbox.delete() - + @save_response_on_error def change_password(self, username, password): mailbox = self.rest.mailboxes.retrieve(name=username).get() mailbox.change_password(password) - + @save_response_on_error def add_address(self, username, name, domain): mailbox = self.rest.mailboxes.retrieve(name=username).get() domain = self.rest.domains.retrieve(name=domain.name).get() self.rest.addresses.create(name=name, domain=domain, mailboxes=[mailbox]) - + @save_response_on_error def delete_address(self, username): mailbox = self.rest.mailboxes.retrieve(name=username).get() self.rest.addresses.delete() - + @save_response_on_error def disable(self, username): mailbox = self.rest.mailboxes.retrieve(name=username).get() @@ -290,30 +290,30 @@ class AdminMailboxMixin(MailboxMixin): def setUp(self): super(AdminMailboxMixin, self).setUp() self.admin_login() - + @snapshot_on_error def add(self, username, password, quota=None, filtering=None): url = self.live_server_url + reverse('admin:mailboxes_mailbox_add') self.selenium.get(url) - + # account_input = self.selenium.find_element_by_id('id_account') # account_select = Select(account_input) # account_select.select_by_value(str(self.account.pk)) - + name_field = self.selenium.find_element_by_id('id_name') name_field.send_keys(username) - + password_field = self.selenium.find_element_by_id('id_password1') password_field.send_keys(password) password_field = self.selenium.find_element_by_id('id_password2') password_field.send_keys(password) - + if quota is not None: quota_id = 'id_resources-resourcedata-content_type-object_id-0-allocated' quota_field = self.selenium.find_element_by_id(quota_id) quota_field.clear() quota_field.send_keys(quota) - + if filtering is not None: filtering_input = self.selenium.find_element_by_id('id_filtering') filtering_select = Select(filtering_input) @@ -323,45 +323,45 @@ class AdminMailboxMixin(MailboxMixin): time.sleep(0.5) filtering_field = self.selenium.find_element_by_id('id_custom_filtering') filtering_field.send_keys(filtering) - + name_field.submit() self.assertNotEqual(url, self.selenium.current_url) - + @snapshot_on_error def delete(self, username): mailbox = Mailbox.objects.get(name=username) self.admin_delete(mailbox) - + @snapshot_on_error def change_password(self, username, password): mailbox = Mailbox.objects.get(name=username) self.admin_change_password(mailbox, password) - + @snapshot_on_error def add_address(self, username, name, domain): url = self.live_server_url + reverse('admin:mailboxes_address_add') self.selenium.get(url) - + name_field = self.selenium.find_element_by_id('id_name') name_field.send_keys(name) - + domain_input = self.selenium.find_element_by_id('id_domain') domain_select = Select(domain_input) domain_select.select_by_value(str(domain.pk)) - + mailboxes = self.selenium.find_element_by_id('id_mailboxes_add_all_link') mailboxes.click() time.sleep(0.5) name_field.submit() - + self.assertNotEqual(url, self.selenium.current_url) - + @snapshot_on_error def delete_address(self, username): mailbox = Mailbox.objects.get(name=username) address = mailbox.addresses.get() self.admin_delete(address) - + @snapshot_on_error def disable(self, username): mailbox = Mailbox.objects.get(name=username)