def setUpClass(cls): super().setUpClass() tenants = { 'items': [ { 'uuid': MAIN_TENANT, 'name': 'first' }, { 'uuid': TENANT_UUID_2, 'name': 'second' }, ] } mock_auth_client = MockAuthClient('localhost', cls.service_port(9497, 'auth')) user_token_1 = MockUserToken.some_token( metadata={'tenant_uuid': tenants['items'][0]['uuid']}, ) user_token_2 = MockUserToken.some_token( metadata={'tenant_uuid': tenants['items'][1]['uuid']}, ) user_token_3 = MockUserToken.some_token( metadata={'tenant_uuid': tenants['items'][0]['uuid']}, ) mock_auth_client.set_token(user_token_1) mock_auth_client.set_token(user_token_2) mock_auth_client.set_token(user_token_3) mock_auth_client.set_tenants(tenants) cls.token_1 = user_token_1.token_id cls.token_2 = user_token_2.token_id cls.token_3 = user_token_3.token_id
def configure_wazo_auth_for_multitenants(cls): # NOTE(sileht): This creates a tenant tree and associated users cls.auth.set_token( MockUserToken( MASTER_TOKEN, MASTER_USER_UUID, WAZO_UUID, { "tenant_uuid": MASTER_TENANT, "uuid": MASTER_USER_UUID }, )) cls.auth.set_token( MockUserToken( USER_1_TOKEN, USER_1_UUID, WAZO_UUID, { "tenant_uuid": USERS_TENANT, "uuid": USER_1_UUID }, )) cls.auth.set_token( MockUserToken( USER_2_TOKEN, USER_2_UUID, WAZO_UUID, { "tenant_uuid": USERS_TENANT, "uuid": USER_2_UUID }, )) cls.auth.set_token( MockUserToken( OTHER_USER_TOKEN, OTHER_USER_UUID, WAZO_UUID, { "tenant_uuid": OTHER_TENANT, "uuid": OTHER_USER_UUID }, )) cls.auth.set_tenants( { 'uuid': MASTER_TENANT, 'name': 'call-logd-tests-master', 'parent_uuid': MASTER_TENANT, }, { 'uuid': USERS_TENANT, 'name': 'call-logd-tests-users', 'parent_uuid': MASTER_TENANT, }, { 'uuid': OTHER_TENANT, 'name': 'call-logd-tests-other', 'parent_uuid': MASTER_TENANT, }, )
def configured_wazo_auth(cls): # NOTE(sileht): This creates a tenant tree and associated users key_file = parse_config_file( os.path.join(cls.assets_root, "keys", "wazo-webhookd-key.yml") ) auth = cls.make_auth() auth.set_valid_credentials( MockCredentials(key_file['service_id'], key_file['service_key']), MASTER_TOKEN, ) auth.set_token( MockUserToken( MASTER_TOKEN, MASTER_USER_UUID, WAZO_UUID, {"tenant_uuid": MASTER_TENANT, "uuid": MASTER_USER_UUID}, ) ) auth.set_token( MockUserToken( USER_1_TOKEN, USER_1_UUID, WAZO_UUID, {"tenant_uuid": USERS_TENANT, "uuid": USER_1_UUID}, ) ) auth.set_token( MockUserToken( USER_2_TOKEN, USER_2_UUID, WAZO_UUID, {"tenant_uuid": USERS_TENANT, "uuid": USER_2_UUID}, ) ) auth.set_token( MockUserToken( OTHER_USER_TOKEN, OTHER_USER_UUID, WAZO_UUID, {"tenant_uuid": OTHER_TENANT, "uuid": OTHER_USER_UUID}, ) ) auth.set_tenants( { 'uuid': MASTER_TENANT, 'name': 'webhookd-tests-master', 'parent_uuid': MASTER_TENANT, }, { 'uuid': USERS_TENANT, 'name': 'webhookd-tests-users', 'parent_uuid': MASTER_TENANT, }, { 'uuid': OTHER_TENANT, 'name': 'webhookd-tests-other', 'parent_uuid': MASTER_TENANT, }, )
def test_given_call_logs_when_list_my_cdr_then_list_my_cdr(self): SOME_TOKEN = 'my-token' self.auth.set_token( MockUserToken( SOME_TOKEN, user_uuid=USER_1_UUID, metadata={"tenant_uuid": MASTER_TENANT}, )) self.call_logd.set_token(SOME_TOKEN) result = self.call_logd.cdr.list_from_user(limit=2, offset=1, order='start', direction='desc') assert_that( result, has_entries( filtered=4, total=4, items=contains_inanyorder( has_entries(start='2017-04-13T00:00:00+00:00'), has_entries(start='2017-04-12T00:00:00+00:00'), ), ), )
def test_given_non_user_subscription_when_user_delete_http_subscription_then_404(self, subscription_): token = 'my-token' auth = self.make_auth() auth.set_token(MockUserToken(token, USER_1_UUID)) webhookd = self.make_webhookd(token) assert_that(calling(webhookd.subscriptions.delete_as_user).with_args(subscription_['uuid']), raises(WebhookdError, has_property('status_code', 404)))
def test_given_user_subscription_when_user_get_http_subscription_then_return_the_subscription(self, subscription_): token = 'my-token' auth = self.make_auth() auth.set_token(MockUserToken(token, USER_1_UUID)) webhookd = self.make_webhookd(token) response = webhookd.subscriptions.get_as_user(subscription_['uuid']) assert_that(response, has_entries(subscription_))
def test_given_user_subscription_when_user_delete_http_subscription_then_deleted(self, subscription_): token = 'my-token' auth = self.make_auth() auth.set_token(MockUserToken(token, USER_1_UUID)) webhookd = self.make_webhookd(token) webhookd.subscriptions.delete_as_user(subscription_['uuid']) response = webhookd.subscriptions.list_as_user() assert_that(response, has_entry('items', not_(has_item(has_entry('uuid', subscription_['uuid'])))))
def test_given_subscriptions_when_user_list_then_list_only_subscriptions_of_this_user(self, _, user_subscription): token = 'my-token' auth = self.make_auth() auth.set_token(MockUserToken(token, USER_1_UUID)) webhookd = self.make_webhookd(token) response = webhookd.subscriptions.list_as_user() assert_that(response, has_entries({ 'items': contains(has_entries(**user_subscription)), 'total': 1 }))
def test_given_events_user_uuid_when_create_http_user_subscription_then_events_user_uuid_ignored(self): token = 'my-token' user_uuid = '575630df-5334-4e99-86d7-56596d77228d' wazo_uuid = '50265257-9dcf-4e9d-b6ce-3a1c0ae3b733' auth = self.make_auth() auth.set_token(MockUserToken(token, user_uuid, wazo_uuid)) webhookd = self.make_webhookd(token) response = webhookd.subscriptions.create_as_user(USER_1_TEST_SUBSCRIPTION) assert_that(response, has_entries({ 'events_user_uuid': user_uuid, 'events_wazo_uuid': wazo_uuid, 'owner_user_uuid': user_uuid, }))
def _create_user(self): self.mock_auth_client.set_tenants({ 'total': 1, 'filtered': 1, 'items': [{ 'uuid': self.tenant_uuid, 'name': self.tenant_name }], }) token = MockUserToken.some_token( metadata={'tenant_uuid': self.tenant_uuid}) self.mock_auth_client.set_token(token) return token.token_id
def test_list_my_cdr_default_limit(self): SOME_TOKEN = 'my-token' self.auth.set_token( MockUserToken( SOME_TOKEN, user_uuid=USER_1_UUID, metadata={"tenant_uuid": MASTER_TENANT}, )) self.call_logd.set_token(SOME_TOKEN) result = self.call_logd.cdr.list_from_user() assert_that( result, all_of(has_entry('total', 1100), has_entry('items', has_length(1000))), )
def test_given_user_subscription_when_user_edit_http_subscription_then_updated(self, subscription_): token = 'my-token' auth = self.make_auth() auth.set_token(MockUserToken(token, USER_1_UUID)) webhookd = self.make_webhookd(token) new_subscription = dict(subscription_) new_subscription['uuid'] = 'should-be-ignored' new_subscription['events_user_uuid'] = 'should-be-ignored' new_subscription['name'] = 'new-name' webhookd.subscriptions.update_as_user(subscription_['uuid'], new_subscription) response = webhookd.subscriptions.list_as_user() assert_that(response, has_entry('items', has_item(has_entries({ 'uuid': subscription_['uuid'], 'events_user_uuid': subscription_['events_user_uuid'], 'name': 'new-name', }))))
def test_given_call_logs_when_list_my_cdr_as_csv_then_list_my_cdr_as_csv( self): SOME_TOKEN = 'my-token' self.auth.set_token( MockUserToken( SOME_TOKEN, user_uuid=USER_1_UUID, metadata={"tenant_uuid": MASTER_TENANT}, )) self.call_logd.set_token(SOME_TOKEN) result_raw = self.call_logd.cdr.list_from_user_csv() result = list(csv.DictReader(StringIO(result_raw))) assert_that( result, contains_inanyorder( has_entries(start='2017-04-11T00:00:00+00:00'), has_entries(start='2017-04-12T00:00:00+00:00'), ), 'CSV received: {}'.format(result_raw), )
def test_when_list_my_cdr_with_user_uuid_then_list_matching_cdr(self): SOME_TOKEN = 'my-token' self.auth.set_token( MockUserToken( SOME_TOKEN, user_uuid=USER_1_UUID, metadata={"tenant_uuid": MASTER_TENANT}, )) self.call_logd.set_token(SOME_TOKEN) results = self.call_logd.cdr.list_from_user(user_uuid=USER_3_UUID) assert_that( results, has_entries( filtered=1, total=2, items=contains_inanyorder( has_entries(start='2019-06-13T13:00:00+00:00')), ), ) results = self.call_logd.cdr.list_from_user( user_uuid=','.join([USER_1_UUID, USER_2_UUID, USER_3_UUID])) assert_that( results, has_entries( filtered=2, total=2, items=contains_inanyorder( has_entries(start='2019-06-13T12:00:00+00:00'), has_entries(start='2019-06-13T13:00:00+00:00'), ), ), )