Esempio n. 1
0
    def test_list_multiple_pages(self, user_mgt_app):
        sample_response = json.loads(OIDC_PROVIDER_CONFIG_RESPONSE)
        configs = _create_list_response(sample_response)

        # Page 1
        response = {'oauthIdpConfigs': configs[:2], 'nextPageToken': 'token'}
        recorder = _instrument_provider_mgt(user_mgt_app, 200,
                                            json.dumps(response))
        page = auth.list_oidc_provider_configs(max_results=10,
                                               app=user_mgt_app)

        self._assert_page(page, next_page_token='token')
        assert len(recorder) == 1
        req = recorder[0]
        assert req.method == 'GET'
        assert req.url == '{0}/oauthIdpConfigs?pageSize=10'.format(
            USER_MGT_URL_PREFIX)

        # Page 2 (also the last page)
        response = {'oauthIdpConfigs': configs[2:]}
        recorder = _instrument_provider_mgt(user_mgt_app, 200,
                                            json.dumps(response))
        page = page.get_next_page()

        self._assert_page(page, count=1, start=2)
        assert len(recorder) == 1
        req = recorder[0]
        assert req.method == 'GET'
        assert req.url == '{0}/oauthIdpConfigs?pageSize=10&pageToken=token'.format(
            USER_MGT_URL_PREFIX)
Esempio n. 2
0
 def test_list_empty_response(self, user_mgt_app):
     response = {'oauthIdpConfigs': []}
     _instrument_provider_mgt(user_mgt_app, 200, json.dumps(response))
     page = auth.list_oidc_provider_configs(app=user_mgt_app)
     assert len(page.provider_configs) == 0
     provider_configs = list(config for config in page.iterate_all())
     assert len(provider_configs) == 0
    def test_paged_iteration(self, user_mgt_app):
        sample_response = json.loads(OIDC_PROVIDER_CONFIG_RESPONSE)
        configs = _create_list_response(sample_response)

        # Page 1
        response = {
            'oauthIdpConfigs': configs[:2],
            'nextPageToken': 'token'
        }
        recorder = _instrument_provider_mgt(user_mgt_app, 200, json.dumps(response))
        page = auth.list_oidc_provider_configs(app=user_mgt_app)
        iterator = page.iterate_all()

        for index in range(2):
            provider_config = next(iterator)
            assert provider_config.provider_id == 'oidc.provider{0}'.format(index)
        assert len(recorder) == 1
        req = recorder[0]
        assert req.method == 'GET'
        assert req.url == '{0}/oauthIdpConfigs?pageSize=100'.format(USER_MGT_URLS['PREFIX'])

        # Page 2 (also the last page)
        response = {'oauthIdpConfigs': configs[2:]}
        recorder = _instrument_provider_mgt(user_mgt_app, 200, json.dumps(response))

        provider_config = next(iterator)
        assert provider_config.provider_id == 'oidc.provider2'
        assert len(recorder) == 1
        req = recorder[0]
        assert req.method == 'GET'
        assert req.url == '{0}/oauthIdpConfigs?pageSize=100&pageToken=token'.format(
            USER_MGT_URLS['PREFIX'])

        with pytest.raises(StopIteration):
            next(iterator)
Esempio n. 4
0
def test_list_oidc_provider_configs(oidc_provider):
    page = auth.list_oidc_provider_configs()
    result = None
    for provider_config in page.iterate_all():
        if provider_config.provider_id == oidc_provider.provider_id:
            result = provider_config
            break

    assert result is not None
    def test_list_single_page(self, user_mgt_app):
        recorder = _instrument_provider_mgt(user_mgt_app, 200, LIST_OIDC_PROVIDER_CONFIGS_RESPONSE)
        page = auth.list_oidc_provider_configs(app=user_mgt_app)

        self._assert_page(page)
        provider_configs = list(config for config in page.iterate_all())
        assert len(provider_configs) == 2

        assert len(recorder) == 1
        req = recorder[0]
        assert req.method == 'GET'
        assert req.url == '{0}{1}'.format(USER_MGT_URLS['PREFIX'], '/oauthIdpConfigs?pageSize=100')
Esempio n. 6
0
 def test_list_error(self, user_mgt_app):
     _instrument_provider_mgt(user_mgt_app, 500, '{"error":"test"}')
     with pytest.raises(exceptions.InternalError) as excinfo:
         auth.list_oidc_provider_configs(app=user_mgt_app)
     assert str(
         excinfo.value) == 'Unexpected error response: {"error":"test"}'
Esempio n. 7
0
 def test_invalid_page_token(self, user_mgt_app, arg):
     with pytest.raises(ValueError):
         auth.list_oidc_provider_configs(page_token=arg, app=user_mgt_app)
Esempio n. 8
0
 def test_invalid_max_results(self, user_mgt_app, arg):
     with pytest.raises(ValueError):
         auth.list_oidc_provider_configs(max_results=arg, app=user_mgt_app)
Esempio n. 9
0
def list_oidc_provider_configs():
    # [START list_oidc_providers]
    for oidc in auth.list_oidc_provider_configs('nextPageToken').iterate_all():
        print(oidc.provider_id)