Skip to content
Snippets Groups Projects
Commit cc2d2278 authored by jan.bednarik's avatar jan.bednarik
Browse files

Keycloak test fixture.

parent bfcdcf2f
No related branches found
No related tags found
No related merge requests found
import pytest import pytest
import dsnparse
from django_elasticsearch_dsl.test import ESTestCase from django_elasticsearch_dsl.test import ESTestCase
...@@ -16,8 +17,33 @@ class TestCase(ESTestCase, DummyTestCase): ...@@ -16,8 +17,33 @@ class TestCase(ESTestCase, DummyTestCase):
@pytest.fixture @pytest.fixture
def django_es(): def django_es():
"""Setup and teardown of test indices.""" """Setup and teardown of Elasticsearch test indices."""
testCase = TestCase() testCase = TestCase()
testCase.setUp() testCase.setUp()
yield yield
testCase.tearDown() testCase.tearDown()
def pytest_addoption(parser):
parser.addoption('--keycloak', action='store',
help=('Keycloak server DSN with OpenID client credentials for auth tests.'
' Format: http://client_id:client_secret@host:port/realm'))
@pytest.fixture(scope='session')
def keycloak(request):
"""Keycloak server and OpenID client info."""
dsn = request.config.getoption('--keycloak')
if dsn is None:
pytest.skip('No Keycloak DSN provided.')
config = dsnparse.parse(dsn)
realm_url = '{}://{}:{}/auth/realms/{}'.format(config.scheme, config.host, config.port, config.paths[0])
return {
'client_id': config.username,
'client_secret': config.password,
'issuer': realm_url,
'authorization_endpoint': '{}/protocol/openid-connect/auth'.format(realm_url),
'token_endpoint': '{}/protocol/openid-connect/token'.format(realm_url),
'userinfo_endpoint': '{}/protocol/openid-connect/userinfo'.format(realm_url),
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment