def test_create_delete_account_alias(self): # prepare account ac_name = 'test-{}@zimbratest.example.com'.format( random.randint(0, 10**9)) ac = self.zc.create_account(ac_name, 'pass1234') alias_name = 'test-{}@zimbratest.example.com'.format( random.randint(0, 10**9)) # CREATE retval = self.zc.add_account_alias(Account(name=ac_name), alias_name) self.assertEqual(retval, None) # GET ac_got = self.zc.get_account(Account(name=ac_name)) self.assertIn(alias_name, ac_got['mail']) # DELETE self.zc.remove_account_alias(ac, alias_name) # GET ac_got = self.zc.get_account(Account(name=ac_name)) self.assertNotIn(alias_name, ac_got['mail']) self.zc.delete_account(ac)
def test_Account_admin(self): sys = Account.from_dict(self.system_account_dict['account']) norm = Account.from_dict(self.normal_account_dict['account']) adm = Account.from_dict(self.admin_account_dict['account']) self.assertEqual(sys.is_admin(), False) self.assertEqual(adm.is_admin(), True) self.assertEqual(norm.is_admin(), False)
def test_Account_admin(self): sys = Account.from_dict(self.system_account_dict["account"]) norm = Account.from_dict(self.normal_account_dict["account"]) adm = Account.from_dict(self.admin_account_dict["account"]) self.assertEqual(sys.is_admin(), False) self.assertEqual(adm.is_admin(), True) self.assertEqual(norm.is_admin(), False)
def test_get_account(self): account = self.zc.get_account(Account(name=self.LAMBDA_USER)) self.assertIsInstance(account, Account) self.assertEqual(account.name, self.LAMBDA_USER) # Now grab it by ID account_by_id = self.zc.get_account(Account(id=account.id)) self.assertIsInstance(account_by_id, Account) self.assertEqual(account_by_id.name, self.LAMBDA_USER) self.assertEqual(account_by_id.id, account.id)
def test_create_get_update_rename_delete_account(self): name = 'test-{}@zimbratest.example.com'.format(random.randint( 0, 10**9)) password = '******' ac_req = Account(name=name) with self.assertRaises(ZimbraSoapServerError): self.zc.get_account(ac_req) # CREATE ac = self.zc.create_account(name, password) self.assertIsInstance(ac, Account) self.assertEqual(ac.name, name) # GET ac_got = self.zc.get_account(ac_req) self.assertIsInstance(ac_got, Account) self.assertEqual(ac_got.name, name) # UPDATE random_name_1 = 'test-{}'.format(random.randint(0, 10**9)) self.zc.modify_account(ac_got, {'displayName': random_name_1}) ac_got = self.zc.get_account(ac_req) self.assertEqual(ac_got['displayName'], random_name_1) # MODIFY PASSWORD new_password = '******' self.zc.set_password(ac, new_password) act_zc = ZimbraAccountClient(TEST_CONF['host'], TEST_CONF['https_port']) try: act_zc.login(ac.name, new_password) except ZimbraSoapServerError: self.fail('self.zc.set_password has failed to change password') # RENAME self.zc.rename_account(ac_got, '*****@*****.**') renamed_ac_got = self.zc.get_account( Account(name='*****@*****.**')) self.assertEqual(renamed_ac_got['mail'], '*****@*****.**') # DELETE self.zc.delete_account(renamed_ac_got) with self.assertRaises(ZimbraSoapServerError): self.zc.get_account(ac)
def test_get_share_info(self): # No shares yes shares = self.zc.get_share_info() self.assertEqual(shares, []) # Create share admin_zc = ZimbraAdminClient(TEST_CONF['host'], TEST_CONF['admin_port']) admin_zc.login(TEST_CONF['admin_login'], TEST_CONF['admin_password']) mail_zc2 = ZimbraMailClient(TEST_CONF['host'], TEST_CONF['webmail_port']) mail_zc2.delegated_login(TEST_CONF['lambda_user2'], admin_zc) mail_zc2.modify_folder_grant(folder_ids=['1'], grantee_name=TEST_CONF['lambda_user'], perm='rwixd', gt='usr') shares = self.zc.get_share_info() self.assertEqual(shares[0]['ownerEmail'], TEST_CONF['lambda_user2']) # Clean mail_zc2.modify_folder_grant( folder_ids=['1'], zid=admin_zc.get_account( Account(name=TEST_CONF['lambda_user'])).id, perm='none', gt='usr')
def test_create_delete_forced_domain(self): account_mail = 'test_user@' + self.TMP_DOMAIN cal_res_mail = 'test_res@' + self.TMP_DOMAIN alias_name = self.LAMBDA_USER.split('@')[0] + '@' + self.TMP_DOMAIN dl_mail = 'test_dl@' + self.TMP_DOMAIN # CREATE self.zc.create_domain(self.TMP_DOMAIN) dom = self.zc.get_domain(Domain(name=self.TMP_DOMAIN)) self.assertIsInstance(dom, Domain) self.assertEqual(dom.name, self.TMP_DOMAIN) self.zc.create_account(account_mail, 'pass1234') self.zc.create_calendar_resource(cal_res_mail, attrs={ 'displayName': 'test display name', 'zimbraCalResType': CalendarResource.EQUIPMENT_TYPE }) self.zc.add_account_alias(Account(name=self.LAMBDA_USER), alias_name) self.zc.create_distribution_list(dl_mail) # DELETE self.zc.delete_domain_forced(dom) with self.assertRaises(ZimbraSoapServerError): self.zc.get_domain(dom)
def test_admin_get_account_authToken1(self): """ From an existing account """ authToken, lifetime = self.zc.get_account_authToken(account=Account( name=self.LAMBDA_USER)) new_zc = ZimbraAccountClient(self.HOST) new_zc.login_with_authToken(authToken, lifetime) self.assertTrue(new_zc._session.is_logged_in()) self.assertTrue(new_zc.is_session_valid())
def setUp(cls): cls.HOST = TEST_CONF['host'] cls.ADMIN_LOGIN = TEST_CONF['admin_login'] cls.ADMIN_PORT = TEST_CONF['admin_port'] # Login/connection is done at class initialization to reduce tests time cls.zc = ZimbraAdminClient(cls.HOST, TEST_CONF['admin_port']) cls.zc.login(cls.ADMIN_LOGIN, TEST_CONF['admin_password']) cls.lambda_account = Account(name=TEST_CONF['lambda_user']) domain_name = cls.lambda_account.get_domain() cls.ph_key_domain1 = cls.zc.get_domain(domain_name)['zimbraPreAuthKey']
def test_folder_grant_mount_revoke(self): admin_zc = ZimbraAdminClient(TEST_CONF['host'], TEST_CONF['admin_port']) admin_zc.login(TEST_CONF['admin_login'], TEST_CONF['admin_password']) grantee_zc = ZimbraMailClient(TEST_CONF['host']) grantee_zc.delegated_login(TEST_CONF['lambda_user2'], admin_zc) grantee_id = admin_zc.get_account( Account(name=TEST_CONF['lambda_user2']))._a_tags['zimbraId'] right = 'rwidx' self.zc.modify_folder_grant(folder_ids=['1'], perm=right, zid=grantee_id) f_gt = self.zc.get_folder_grant(path='/') self.assertEqual(f_gt['grant']['perm'], right) self.assertEqual(f_gt['grant']['d'], TEST_CONF['lambda_user2']) mount_name = 'MountedZimsoapTest' grantee_zc.create_mountpoint(name=mount_name, path='/', owner=TEST_CONF['lambda_user'], l='1') mount_path = '/' + mount_name link = grantee_zc.get_mountpoint(path=mount_path)['link'] self.assertEqual(link['name'], mount_name) self.assertEqual(link['owner'], TEST_CONF['lambda_user']) # Clean grantee grantee_zc.delete_mountpoints(folder_ids=[link['id']]) # Revoke rights self.zc.modify_folder_grant(folder_ids=['1'], perm='none', zid=grantee_id) f_gt = self.zc.get_folder_grant(path='/') self.assertEqual(f_gt, {})
def test_property(self): norm = Account.from_dict(self.normal_account_dict['account']) self.assertEqual(norm.property('zimbraFeatureSignaturesEnabled'), True)
def test_deprecated_admin_delegate_auth(self): # Cannot assertWarns before py3.2 zc_account = self.zc.delegate_auth(Account(name=self.LAMBDA_USER)) self.assertTrue(zc_account._session.is_logged_in()) self.assertTrue(zc_account.is_session_valid())
def test_mk_auth_token_fails_if_no_key(self): user = Account(name='admin@{0}'.format(self.DOMAIN2)) with self.assertRaises(DomainHasNoPreAuthKey): self.zc.mk_auth_token(user, 0)
def test_mk_auth_token_succeeds(self): user = Account(name='admin@{0}'.format(self.DOMAIN1)) tk = self.zc.mk_auth_token(user, 0) self.assertIsInstance(tk, str)
def test_get_account_cos(self): cos = self.zc.get_account_cos(Account(name=self.LAMBDA_USER)) self.assertIsInstance(cos, COS) self.assertEqual(cos.name, 'default') assertRegex(self, cos.id, r'[\w\-]{36}')
def test_property(self): norm = Account.from_dict(self.normal_account_dict["account"]) self.assertEqual(norm.property("zimbraFeatureSignaturesEnabled"), True)