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