def test_token_creation(self, user): response = self._post_token(user['username'], 's3cr37', backend='wazo_user') assert_that( response, has_entries( token=uuid_(), auth_id=user['uuid'], xivo_user_uuid=user['uuid'], # For API compatibility reason acls=has_items('confd.#', 'plugind.#'), session_uuid=uuid_(), metadata=has_entries( pbx_user_uuid=user['uuid'], xivo_user_uuid=user['uuid'] ), ), ) assert_http_error( 401, self._post_token, user['username'], 'not-our-password', backend='wazo_user', ) assert_http_error( 401, self._post_token, 'not-foobar', 's3cr37', backend='wazo_user' )
def test_multi_tenant(self): main_tenant_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_tenant_client = self.get_client(VALID_TOKEN_SUB_TENANT) with self.source(main_tenant_client, self.valid_body) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=MAIN_TENANT)) with self.source(main_tenant_client, self.valid_body, tenant_uuid=SUB_TENANT) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=SUB_TENANT)) with self.source(sub_tenant_client, self.valid_body) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=SUB_TENANT)) assert_that( calling( sub_tenant_client.csv_ws_source.create ).with_args(self.valid_body, tenant_uuid=MAIN_TENANT), raises(Exception).matching(has_properties(response=has_properties(status_code=401))), ) with self.source(main_tenant_client, self.valid_body): assert_that( calling(sub_tenant_client.csv_ws_source.create).with_args(self.valid_body), not_(raises(Exception)), )
def test_post(self, tenant, foobaz): assert_that( foobaz, has_entries( uuid=uuid_(), name='foobaz', description=none(), acl_templates=empty(), tenant_uuid=self.top_tenant_uuid, ), ) policy_args = { 'name': 'foobar', 'description': 'a test policy', 'acl_templates': ['dird.me.#', 'ctid-ng.#'], 'tenant_uuid': tenant['uuid'], } # Specify the tenant_uuid with self.policy(self.client, **policy_args) as policy: assert_that(policy, has_entries(uuid=uuid_(), **policy_args)) # Specify the a tenant uuid in another sub-tenant tree with self.client_in_subtenant() as (client, _, __): assert_http_error(401, client.policies.new, **policy_args) # Invalid body assert_http_error(400, self.client.policies.new, '')
def test_post(self, other, foobaz, foobar): assert_that(other, has_entries( uuid=uuid_(), name=None, parent_uuid=self.top_tenant_uuid, address=has_entries(**ADDRESS_NULL), )) assert_that(foobaz, has_entries( uuid='6668ca15-6d9e-4000-b2ec-731bc7316767', name='foobaz', parent_uuid=self.top_tenant_uuid, address=has_entries(**ADDRESS_NULL), )) assert_that(foobar, has_entries( uuid=uuid_(), name='foobar', phone=PHONE_1, parent_uuid=self.top_tenant_uuid, address=has_entries(**ADDRESS_1), )) with self.tenant(self.client, name='subtenant', parent_uuid=foobar['uuid']) as subtenant: assert_that(subtenant, has_entries( uuid=uuid_(), name='subtenant', parent_uuid=foobar['uuid'], ))
def test_token_creation(self, user): response = self._post_token(user['username'], 's3cr37', backend='wazo_user') assert_that( response, has_entries( 'token', uuid_(), 'auth_id', user['uuid'], 'xivo_user_uuid', user['uuid'], 'acls', has_items( 'confd.#', 'plugind.#', ), 'session_uuid', uuid_(), )) assert_http_error(401, self._post_token, user['username'], 'not-our-password', backend='wazo_user') assert_http_error(401, self._post_token, 'not-foobar', 's3cr37', backend='wazo_user')
def test_multi_tenant(self): main_tenant_client = self.get_client(VALID_TOKEN_MAIN_TENANT) sub_tenant_client = self.get_client(VALID_TOKEN_SUB_TENANT) with self.source(main_tenant_client, self.valid_body) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=MAIN_TENANT)) with self.source(main_tenant_client, self.valid_body, tenant_uuid=SUB_TENANT) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=SUB_TENANT)) with self.source(sub_tenant_client, self.valid_body) as result: assert_that(result, has_entries(uuid=uuid_(), tenant_uuid=SUB_TENANT)) assert_that( calling(sub_tenant_client.backends.create_source).with_args( 'google', self.valid_body, tenant_uuid=MAIN_TENANT, ), raises(Exception).matching(HTTP_401), ) with self.source(main_tenant_client, self.valid_body): assert_that( calling(sub_tenant_client.backends.create_source).with_args( 'google', self.valid_body, ), not_(raises(Exception)), )
def test_email_updates_as_admin(self, foobar): assert_http_error(404, self.client.admin.update_user_emails, UNKNOWN_UUID, []) assert_http_error(400, self.client.users.update_emails, foobar['uuid'], [ONE, ONE]) result = self.client.admin.update_user_emails(foobar['uuid'], [ONE, TWO]) assert_that( result, contains_inanyorder(has_entries(uuid=uuid_(), **ONE), has_entries(uuid=uuid_(), **TWO)), ) one_uuid = [ entry['uuid'] for entry in result if entry['address'] == '*****@*****.**' ][0] result = self.client.admin.update_user_emails(foobar['uuid'], [ONE, THREE]) assert_that( result, contains_inanyorder(has_entries(uuid=one_uuid, **ONE), has_entries(uuid=uuid_(), **THREE)), )
def test_list(self): result = self.contacts(self.client, self.source_uuid) assert_that(result, has_entries( total=4, filtered=4, items=contains_inanyorder( has_entries( uuid=uuid_(), firstname='John', lastname='Doe', exten='1234', voicemail_number=None, mobile_phone_number='+14184765458', email='*****@*****.**', ), has_entries(firstname='Mary'), has_entries(firstname='Bob'), has_entries(firstname='Charles'), ), )) assert_that(result['items'][0].keys(), contains_inanyorder( 'uuid', 'firstname', 'lastname', 'exten', 'voicemail_number', 'mobile_phone_number', 'email', )) assert_that( calling(self.contacts).with_args(self.client, UNKNOWN_UUID), raises(Exception).matching(has_properties(response=has_properties(status_code=404))), )
def test_get(self, group1, group2, user1, user2, policy): response = self.client.policies.get(policy['uuid']) assert_that( response, has_entries( name='foobar', description='a test policy', acl_templates=contains_inanyorder('dird.me.#', 'ctid-ng.#'), ), ) assert_http_error(404, self.client.policies.get, UNKNOWN_UUID) self.client.users.add_policy(user1['uuid'], policy['uuid']) self.client.users.add_policy(user2['uuid'], policy['uuid']) self.client.groups.add_policy(group1['uuid'], policy['uuid']) self.client.groups.add_policy(group2['uuid'], policy['uuid']) assert_that( self.client.policies.get(policy['uuid'])['acl_templates'], contains_inanyorder('dird.me.#', 'ctid-ng.#'), ) with self.client_in_subtenant() as (client, _, __): assert_http_error(404, client.policies.get, policy['uuid']) policy_in_subtenant = client.policies.new(name='in sub-tenant') assert_that( self.client.policies.get(policy_in_subtenant['uuid']), has_entries(uuid=uuid_(), name='in sub-tenant'), )
def test_when_with_an_unknown_plugin_format_version(self): result = self.install_plugin(url='file:///data/git/futureversion', method='git') assert_that(result, has_entries(uuid=uuid_())) statuses = ['starting', 'error'] for status in statuses: self.assert_status_received(self.msg_accumulator, 'install', result['uuid'], status)
def test_user_creation_email_confirmed(self): username = '******' hash_ = 'the_hashed_password' email_address = '*****@*****.**' user_uuid = self._user_dao.create( username, email_address=email_address, tenant_uuid=self.top_tenant_uuid, hash_=hash_, salt=self.salt, purpose='user', email_confirmed=True, )['uuid'] try: result = self._user_dao.list_(uuid=user_uuid) assert_that( result, contains( has_entries( username=username, emails=contains( has_entries(uuid=uuid_(), address=email_address, confirmed=True)), )), ) finally: self._user_dao.delete(user_uuid)
def check(): response = self.client.conference_source.list( tenant_uuid=self.tenant_uuid) assert_that( response, has_entries(items=has_item( has_entries( uuid=uuid_(), tenant_uuid=self.tenant_uuid, name='auto_conference_mytenant', auth={ 'host': 'localhost', 'port': 9497, 'verify_certificate': '/usr/share/xivo-certs/server.crt', 'version': '0.1', 'key_file': '/var/lib/wazo-auth-keys/wazo-dird-conference-backend-key.yml', }, confd={ 'host': 'localhost', 'port': 9486, 'verify_certificate': '/usr/share/xivo-certs/server.crt', 'version': '1.1', 'https': True, }, first_matched_columns=empty(), searched_columns=contains_inanyorder( 'name', 'extensions', 'incalls'), format_columns={'phone': '{extensions[0]}'}, ), )))
def test_that_installing_twice_completes_without_reinstalling(self): self.install_plugin(url='file:///data/git/repo2', method='git', _async=False) result = self.install_plugin(url='file:///data/git/repo2', method='git') assert_that(result, has_entries(uuid=uuid_())) statuses = ['starting', 'downloading', 'extracting', 'validating', 'completed'] for status in statuses: self.assert_status_received(self.msg_accumulator, 'install', result['uuid'], status, exclusive=True)
def test_context_initialization(self): config = {} ctx = Context(config, foo='bar') assert_that(ctx.config, equal_to(config)) assert_that(ctx.uuid, uuid_()) assert_that(ctx.foo, equal_to('bar'))
def test_that_the_right_credentials_return_a_token_with_datas(self): response = self._post_token('foo', 'bar') assert_that( response, has_entries(token=uuid_(), metadata=has_entries(uuid=self.user['uuid']), acls=ANY), )
def test_register_post(self): args = { 'username': '******', 'lastname': 'Denver', 'email_address': '*****@*****.**', 'password': '******', } with self.user(self.client, register=True, **args) as user: assert_that( user, has_entries( 'uuid', uuid_(), 'username', 'foobar', 'firstname', None, 'lastname', 'Denver', 'enabled', True, 'tenant_uuid', uuid_(), 'emails', contains_inanyorder( has_entries('uuid', uuid_(), 'address', '*****@*****.**', 'main', True, 'confirmed', False)))) created_tenant = self.client.tenants.get(user['tenant_uuid']) assert_that( created_tenant, has_entries( uuid=is_not(self.top_tenant_uuid), parent_uuid=self.top_tenant_uuid, )) last_email = self.get_emails()[-1] url = [ l for l in last_email.split('\n') if l.startswith('https://') ][0] requests.get(url, verify=False) updated_user = self.client.users.get(user['uuid']) assert_that( updated_user, has_entries(emails=contains(has_entries(confirmed=True)))) tenants = self.client.users.get_tenants(user['uuid']) assert_that( tenants, has_entries('items', contains(has_entries('uuid', uuid_()))))
def test_minimal_body(self): with self.source(self.client, self.valid_body) as source: assert_that( source, has_entries( uuid=uuid_(), name='google', auth=has_entries( host='localhost', port=9497, verify_certificate=True, ), ))
def test_install_from_git_branch(self): msg_accumulator = self.new_message_accumulator('plugin.install.#') result = self.install_plugin(url='file:///data/git/repo', method='git', options=dict(ref='v2')) assert_that(result, has_entries(uuid=uuid_())) statuses = ['starting', 'downloading', 'extracting', 'building', 'packaging', 'updating', 'installing', 'completed'] for status in statuses: self.assert_status_received(msg_accumulator, 'install', result['uuid'], status) package_success_exists = self.exists_in_container('/tmp/results/package_success_2') assert_that(package_success_exists, is_(True), 'package_success was not created')
def test_when_uninstall_works(self): self.install_plugin(url='file:///data/git/repo', method='git', _async=False) result = self.uninstall_plugin(namespace='plugindtests', name='foobar') assert_that(result, has_entries(uuid=uuid_())) statuses = ['starting', 'removing', 'completed'] for status in statuses: self.assert_status_received(self.msg_accumulator, 'uninstall', result['uuid'], status) build_success_exists = self.exists_in_container('/tmp/results/build_success') package_success_exists = self.exists_in_container('/tmp/results/package_success') assert_that(build_success_exists, is_(False), 'build_success was not removed') assert_that(package_success_exists, is_(False), 'package_success was not removed')
def test_valid_post(self): body = { 'name': 'display', 'columns': [ { 'field': 'fn', 'title': 'Firstname', 'default': '', }, { 'field': 'mobile', 'title': 'Mobile', 'type': 'number', 'number_display': '{firstname} (Mobile)', 'default': None, }, ], } with self.create(self.client, body) as display: assert_that( display, has_entries( uuid=uuid_(), tenant_uuid=MAIN_TENANT, columns=contains( has_entries( field='fn', title='Firstname', default='', type=None, number_display=None, ), has_entries( field='mobile', title='Mobile', type='number', number_display='{firstname} (Mobile)', default=None, ), ), ))
def test_when_it_works(self): self.uninstall_plugin(namespace='plugindtests', name='foobar', _async=False, ignore_errors=True) result = self.install_plugin(url='file:///data/git/repo', method='git') assert_that(result, has_entries(uuid=uuid_())) statuses = ['starting', 'downloading', 'extracting', 'building', 'packaging', 'updating', 'installing', 'completed'] for status in statuses: self.assert_status_received(self.msg_accumulator, 'install', result['uuid'], status) build_success_exists = self.exists_in_container('/tmp/results/build_success') package_success_exists = self.exists_in_container('/tmp/results/package_success') install_success_exists = self.exists_in_container('/tmp/results/install_success') assert_that(build_success_exists, is_(True), 'build_success was not created or copied') assert_that(install_success_exists, is_(True), 'install_success was not created') assert_that(package_success_exists, is_(True), 'package_success was not created')
def test_all_fields(self, source, display): body = { 'name': 'profile', 'display': { 'uuid': display['uuid'] }, 'services': { 'lookup': { 'sources': [{ 'uuid': source['uuid'] }], 'options': { 'timeout': 5 } }, 'reverse': { 'sources': [{ 'uuid': source['uuid'] }], 'options': { 'timeout': 0.5 } }, }, } with self.profile(self.client, body) as profile: assert_that( profile, has_entries( uuid=uuid_(), tenant_uuid=MAIN_TENANT, name='profile', display=has_entries(uuid=display['uuid']), services=has_entries( lookup=has_entries(sources=contains( has_entries(uuid=source['uuid'])), options=has_entries(timeout=5)), reverse=has_entries(sources=contains( has_entries(uuid=source['uuid'])), options=has_entries(timeout=0.5)), ), ))
def test_get(context): response = confd.contexts(context['id']).get() assert_that( response.item, has_entries( id=context['id'], name=context['name'], label=context['label'], type=context['type'], user_ranges=context['user_ranges'], group_ranges=context['group_ranges'], queue_ranges=context['queue_ranges'], conference_room_ranges=context['conference_room_ranges'], incall_ranges=context['incall_ranges'], description=context['description'], enabled=context['enabled'], tenant_uuid=uuid_(), contexts=empty(), ), )
def test_create_all_parameters(): parameters = { 'name': 'MyContext', 'label': 'Context Power', 'type': 'outcall', 'user_ranges': [{'start': '1000', 'end': '1999'}], 'group_ranges': [{'start': '2000', 'end': '2999'}], 'queue_ranges': [{'start': '3000', 'end': '3999'}], 'conference_room_ranges': [{'start': '4000', 'end': '4999'}], 'incall_ranges': [{'start': '1000', 'end': '4999', 'did_length': 2}], 'description': 'context description', 'enabled': False, } response = confd.contexts.post(**parameters) response.assert_created('contexts') assert_that(response.item, has_entries(tenant_uuid=uuid_(), **parameters)) confd.contexts(response.item['id']).delete().assert_deleted()
def test_email_updates_as_user(self, foobar): assert_http_error(404, self.client.users.update_emails, UNKNOWN_UUID, []) assert_http_error(400, self.client.users.update_emails, foobar['uuid'], [ONE, ONE]) email_uuid = foobar['emails'][0]['uuid'] result = self.client.users.update_emails(foobar['uuid'], [ONE, THREE]) assert_that( result, contains_inanyorder( has_entries(uuid=email_uuid, **ONE), has_entries(uuid=uuid_(), address=THREE['address'], main=THREE['main'], confirmed=False), # Confirmed is ignored when modifying as a user ^^^^^ )) result = self.client.users.update_emails(foobar['uuid'], []) assert_that(result, empty())
def test_register_post(self): args = { 'username': '******', 'lastname': 'Denver', 'email_address': '*****@*****.**', 'password': '******', } with self.user(self.client, register=True, **args) as user: assert_that( user, has_entries( 'uuid', uuid_(), 'username', 'foobar', 'firstname', None, 'lastname', 'Denver', 'enabled', True, 'tenant_uuid', uuid_(), 'emails', contains_inanyorder( has_entries( 'uuid', uuid_(), 'address', '*****@*****.**', 'main', True, 'confirmed', False, ) ), ), ) created_tenant = self.client.tenants.get(user['tenant_uuid']) assert_that( created_tenant, has_entries( uuid=is_not(self.top_tenant_uuid), parent_uuid=self.top_tenant_uuid ), ) url = self.get_last_email_url() url = url.replace('https', 'http') requests.get(url) updated_user = self.client.users.get(user['uuid']) assert_that( updated_user, has_entries(emails=contains(has_entries(confirmed=True))) ) tenants = self.client.users.get_tenants(user['uuid']) assert_that( tenants, has_entries('items', contains(has_entries('uuid', uuid_()))) )
def test_post_with_top_tenant_admin(self, isolated): args = { 'username': '******', 'firstname': 'Alice', 'email_address': '*****@*****.**', 'password': '******', } # User created in our own tenant with self.user(self.client, **args) as user: assert_that(user, not_(has_key('password'))) assert_that( user, has_entries( 'uuid', uuid_(), 'username', 'foobar', 'firstname', 'Alice', 'lastname', None, 'enabled', True, 'tenant_uuid', self.top_tenant_uuid, 'emails', contains_inanyorder( has_entries('uuid', uuid_(), 'address', '*****@*****.**', 'main', True, 'confirmed', True)))) # TODO move this assertion to the user tenant tests tenants = self.client.users.get_tenants(user['uuid']) assert_that(tenants['items'], has_items(has_entries(uuid=self.top_tenant_uuid))) # User created in subtenant with self.user(self.client, tenant_uuid=isolated['uuid'], **args) as user: assert_that( user, has_entries( 'uuid', uuid_(), 'username', 'foobar', 'firstname', 'Alice', 'lastname', None, 'enabled', True, 'tenant_uuid', isolated['uuid'], 'emails', contains_inanyorder( has_entries('uuid', uuid_(), 'address', '*****@*****.**', 'main', True, 'confirmed', True)))) # TODO move this assertion to the user tenant tests tenants = self.client.users.get_tenants(user['uuid']) assert_that( tenants, has_entries( items=contains(has_entries(uuid=isolated['uuid'])), total=1, ), ) args = { 'uuid': 'fcf9724a-15aa-4dc5-af3c-a9acdb6a2ab9', 'username': '******', 'email_address': '*****@*****.**', } with self.user(self.client, **args) as user: assert_http_error(409, self.client.users.new, **args) assert_http_error(400, self.client.users.new, username='******' * 257) with self.user(self.client, username='******' * 256) as user: assert_that(user, has_entries(username='******' * 256)) # User creation with no email address with self.user(self.client, username='******') as user: assert_that(user, has_entries(username='******', emails=empty())) args = {'username': '******', 'email_address': None} with self.user(self.client, **args) as user: assert_that(user, has_entries(emails=empty())) user_args = { 'username': '******', 'password': '******', 'enabled': False } with self.user(self.client, **user_args) as user: assert_that(user, has_entries('enabled', False)) user_client = self.new_auth_client('foobar', 'foobaz') assert_http_error(401, user_client.token.new, 'wazo_user')