-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_client_02_entity.py
More file actions
181 lines (143 loc) · 5.14 KB
/
test_client_02_entity.py
File metadata and controls
181 lines (143 loc) · 5.14 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import pytest
from idpyoidc.client.client_auth import ClientAuthnMethod
from idpyoidc.client.entity import Entity
KEYDEFS = [
{"type": "RSA", "key": "", "use": ["sig"]},
{"type": "EC", "crv": "P-256", "use": ["sig"]},
]
MINI_CONFIG = {
"base_url": "https://example.com/cli/",
"key_conf": {"key_defs": KEYDEFS},
"issuer": "https://op.example.com",
"client_id": "Number5",
}
class TestEntity:
@pytest.fixture(autouse=True)
def setup(self):
self.entity = Entity(
config=MINI_CONFIG.copy(),
services={"xyz": {"class": "idpyoidc.client.service.Service"}},
)
def test_1(self):
assert self.entity
def test_get_service(self):
_srv = self.entity.get_service("")
assert _srv
assert _srv.service_name == ""
assert _srv.request_body_type == "urlencoded"
def test_get_service_unsupported(self):
_srv = self.entity.get_service("foobar")
assert _srv is None
def test_get_client_id(self):
assert self.entity.get_service_context().get_preference("client_id") == "Number5"
assert self.entity.get_attribute("client_id") == "Number5"
def test_get_service_by_endpoint_name(self):
_srv = self.entity.get_service("")
_srv.endpoint_name = "flux_endpoint"
_fsrv = self.entity.get_service_by_endpoint_name("flux_endpoint")
assert _srv == _fsrv
def test_get_service_context(self):
_context = self.entity.get_service_context()
assert _context
RP_BASEURL = "https://example.com/rp"
KEYSPEC = [
{"type": "RSA", "use": ["sig"]},
{"type": "EC", "crv": "P-256", "use": ["sig"]},
]
def test_client_authn_default():
config = {
"application_type": "web",
"contacts": ["ops@example.org"],
"redirect_uris": [f"{RP_BASEURL}/authz_cb"],
"keys": {"key_defs": KEYSPEC, "read_only": True},
}
entity = Entity(config=config, client_type="oidc")
assert entity.get_context().client_authn_methods == {}
def test_client_authn_by_names():
config = {
"application_type": "web",
"contacts": ["ops@example.org"],
"redirect_uris": [f"{RP_BASEURL}/authz_cb"],
"keys": {"key_defs": KEYSPEC, "read_only": True},
"client_authn_methods": ["client_secret_basic", "client_secret_post"],
}
entity = Entity(config=config, client_type="oidc")
assert set(entity.get_context().client_authn_methods.keys()) == {
"client_secret_basic",
"client_secret_post",
}
class FooBar(ClientAuthnMethod):
def __init__(self, **kwargs):
self.kwargs = kwargs
def modify_request(self, request, service, **kwargs):
request.update(self.kwargs)
def test_client_authn_full():
config = {
"application_type": "web",
"contacts": ["ops@example.org"],
"redirect_uris": [f"{RP_BASEURL}/authz_cb"],
"keys": {"key_defs": KEYSPEC, "read_only": True},
"client_authn_methods": {
"client_secret_basic": {},
"client_secret_post": None,
"home_brew": {"class": FooBar, "kwargs": {"one": "bar"}},
},
}
entity = Entity(config=config, client_type="oidc")
assert set(entity.get_context().client_authn_methods.keys()) == {
"client_secret_basic",
"client_secret_post",
"home_brew",
}
def test_service_specific():
config = {
"application_type": "web",
"contacts": ["ops@example.org"],
"redirect_uris": [f"{RP_BASEURL}/authz_cb"],
"keys": {"key_defs": KEYSPEC, "read_only": True},
"client_authn_methods": ["client_secret_basic", "client_secret_post"],
}
entity = Entity(
config=config,
client_type="oidc",
services={
"xyz": {
"class": "idpyoidc.client.service.Service",
"kwargs": {"client_authn_methods": ["private_key_jwt"]},
}
},
)
# A specific does not change the general
assert set(entity.get_context().client_authn_methods.keys()) == {
"client_secret_basic",
"client_secret_post",
}
assert set(entity.get_service("").client_authn_methods.keys()) == {"private_key_jwt"}
def test_service_specific2():
config = {
"application_type": "web",
"contacts": ["ops@example.org"],
"redirect_uris": [f"{RP_BASEURL}/authz_cb"],
"keys": {"key_defs": KEYSPEC, "read_only": True},
"client_authn_methods": ["client_secret_basic", "client_secret_post"],
}
entity = Entity(
config=config,
client_type="oidc",
services={
"xyz": {
"class": "idpyoidc.client.service.Service",
"kwargs": {
"client_authn_methods": {
"home_brew": {"class": FooBar, "kwargs": {"one": "bar"}}
}
},
}
},
)
# A specific does not change the general
assert set(entity.get_context().client_authn_methods.keys()) == {
"client_secret_basic",
"client_secret_post",
}
assert set(entity.get_service("").client_authn_methods.keys()) == {"home_brew"}