Skip to content

Commit fdc5bfd

Browse files
committed
Add more tests for the idp hinting micro-service
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 89741a8 commit fdc5bfd

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/satosa/micro_services/idp_hinting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ def process(self, context, data):
5555
if param_name == qs_param_name
5656
)
5757
hint = next(hints, None)
58+
5859
context.decorate(context.KEY_TARGET_ENTITYID, hint)
5960
return super().process(context, data)

tests/satosa/micro_services/test_idp_hinting.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
from satosa.context import Context
6+
from satosa.internal import InternalData
67
from satosa.state import State
78
from satosa.micro_services.idp_hinting import IdpHinting
89

@@ -11,6 +12,7 @@ class TestIdpHinting(TestCase):
1112
def setUp(self):
1213
context = Context()
1314
context.state = State()
15+
internal_data = InternalData()
1416

1517
config = {
1618
'allowed_params': ["idp_hinting", "idp_hint", "idphint"]
@@ -25,16 +27,31 @@ def setUp(self):
2527

2628
self.config = config
2729
self.context = context
30+
self.data = internal_data
2831
self.plugin = plugin
2932

30-
def test_idp_hinting(self):
31-
self.context.request = {}
33+
def test_no_query_params(self):
34+
self.context.qs_params = {}
35+
new_context, new_data = self.plugin.process(self.context, self.data)
36+
assert not new_context.get_decoration(Context.KEY_TARGET_ENTITYID)
37+
38+
def test_hint_in_params(self):
3239
_target = 'https://localhost:8080'
3340
self.context.qs_params = {'idphint': _target}
34-
res = self.plugin.process(self.context, data={})
35-
assert res[0].internal_data.get('target_entity_id') == _target
41+
new_context, new_data = self.plugin.process(self.context, self.data)
42+
assert new_context.get_decoration(Context.KEY_TARGET_ENTITYID) == _target
43+
44+
def test_no_hint_in_params(self):
45+
_target = 'https://localhost:8080'
46+
self.context.qs_params = {'param_not_in_allowed_params': _target}
47+
new_context, new_data = self.plugin.process(self.context, self.data)
48+
assert not new_context.get_decoration(Context.KEY_TARGET_ENTITYID)
3649

37-
def test_no_idp_hinting(self):
38-
self.context.request = {}
39-
res = self.plugin.process(self.context, data={})
40-
assert not res[0].internal_data.get('target_entity_id')
50+
def test_issuer_already_set(self):
51+
_pre_selected_target = 'https://local.localhost:8080'
52+
self.context.decorate(Context.KEY_TARGET_ENTITYID, _pre_selected_target)
53+
_target = 'https://localhost:8080'
54+
self.context.qs_params = {'idphint': _target}
55+
new_context, new_data = self.plugin.process(self.context, self.data)
56+
assert new_context.get_decoration(Context.KEY_TARGET_ENTITYID) == _pre_selected_target
57+
assert new_context.get_decoration(Context.KEY_TARGET_ENTITYID) != _target

0 commit comments

Comments
 (0)