-
Notifications
You must be signed in to change notification settings - Fork 4
/
conftest.py
147 lines (109 loc) · 5.04 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python3
import pytest
from oidctest import OidcLoginTest
from oidctest import IdpFactory as OidcIdpFactory
from oidctest import SpFactory as OidcSpFactory
def url_with_trailing_slash(url):
if url.endswith('/'):
return url
return url + '/'
@pytest.fixture
def login_user(pytestconfig):
return (pytestconfig.getoption('username'), pytestconfig.getoption('password'))
@pytest.fixture()
def resource_url(pytestconfig):
return url_with_trailing_slash(pytestconfig.getoption('url'))
@pytest.fixture()
def info_resource_url(pytestconfig):
if pytestconfig.getoption('info_url') is None:
raise ValueError("Please set --info-url")
return url_with_trailing_slash(pytestconfig.getoption('info_url'))
@pytest.fixture()
def nested_protected_resource_url(pytestconfig):
if pytestconfig.getoption('nested_protected_url') is None:
raise ValueError("Please set --nested-protected-url")
return url_with_trailing_slash(pytestconfig.getoption('nested_protected_url'))
@pytest.fixture()
def logout_url(pytestconfig):
return pytestconfig.getoption('logout_url')
@pytest.fixture()
def saml_test_instance(pytestconfig):
from samltest import SamlLoginTest
from samltest import IdpFactory as SamlIdpFactory
from samltest import SpFactory as SamlSpFactory
idp_f = SamlIdpFactory(pytestconfig.getoption('idp_type'),
pytestconfig.getoption('idp_url'),
pytestconfig.getoption('idp_realm'),
pytestconfig.getoption('idp_soap_binding'))
sp_f = SamlSpFactory(pytestconfig.getoption('url'),
pytestconfig.getoption('sp_type'),
pytestconfig.getoption('sp_url'),
pytestconfig.getoption('idp_url'))
login_test = SamlLoginTest(idp_f, sp_f, not pytestconfig.getoption('no_verify'))
return login_test
@pytest.fixture
def saml_login_instance(login_user, resource_url, saml_test_instance):
username, password = login_user
saml_test_instance.redirect_post_flow(resource_url,
username,
password,
None)
return saml_test_instance
def pytest_addoption(parser):
parser.addoption("--url", action="store")
parser.addoption("--info-url", action="store")
parser.addoption("--nested-protected-url", action="store")
parser.addoption("--logout-url", action="store")
parser.addoption("--logout-redirect-url", action="store")
parser.addoption('--idp-url')
parser.addoption('--idp-realm', action='store', type=str)
parser.addoption('--idp-soap-binding', action='store', type=str)
parser.addoption('--sp-url')
parser.addoption('--username', action='store', type=str)
parser.addoption('--password', action='store', type=str)
parser.addoption('--idp-type', default='keycloak', choices=['keycloak'])
parser.addoption('--sp-type', default='mellon', choices=['mellon', 'mod_auth_openidc'])
parser.addoption('--no-verify', action='store_true')
parser.addoption("--oauth-url", action="store")
parser.addoption('--oidc-redirect-url')
parser.addoption('--oidc-client-secret')
parser.addoption('--oidc-client-id')
parser.addoption("--bad-logout-redirect-url", action="store", nargs="*", type=str)
parser.addoption('--neg-username', action='store', type=str)
parser.addoption('--neg-password', action='store', type=str)
########## begin openidc conftest #############################
def url_with_trailing_slash(url):
if url.endswith('/'):
return url
return url + '/'
@pytest.fixture
def negative_user(pytestconfig):
return (pytestconfig.getoption('neg_username'),
pytestconfig.getoption('neg_password'))
@pytest.fixture()
def idp_realm(pytestconfig):
return pytestconfig.getoption('idp_realm')
@pytest.fixture()
def oidc_client_info(pytestconfig):
return (pytestconfig.getoption('oidc_client_id'),
pytestconfig.getoption('oidc_client_secret'))
@pytest.fixture()
def oauth_resource_url(pytestconfig):
return url_with_trailing_slash(pytestconfig.getoption('oauth_url'))
@pytest.fixture()
def logout_redirect_url(pytestconfig):
return url_with_trailing_slash(pytestconfig.getoption('logout_redirect_url'))
@pytest.fixture()
def bad_logout_redirect_urls(pytestconfig):
return [ u for u in pytestconfig.getoption('bad_logout_redirect_url')[0].split(",") ]
@pytest.fixture()
def oidc_test_instance(pytestconfig):
idp_f = OidcIdpFactory(pytestconfig.getoption('idp_type'),
pytestconfig.getoption('idp_url'),
pytestconfig.getoption('idp_realm'))
sp_f = OidcSpFactory(pytestconfig.getoption('url'),
pytestconfig.getoption('sp_type'),
pytestconfig.getoption('oidc_redirect_url'),
pytestconfig.getoption('idp_url'))
login_test = OidcLoginTest(idp_f, sp_f, not pytestconfig.getoption('no_verify'))
return login_test