Skip to content

Commit 6aef894

Browse files
Merge pull request #384 from peppelinux/idphint_fix
Fix IdP hinting micro-service and add tests
2 parents 1700c68 + fdc5bfd commit 6aef894

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

example/plugins/microservices/idp_hinting.yaml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ config:
44
allowed_params:
55
- idp_hinting
66
- idp_hint
7+
- idphint

src/satosa/micro_services/idp_hinting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def process(self, context, data):
5151
hints = (
5252
entity_id
5353
for param_name in self.idp_hint_param_names
54-
for qs_param_name, entity_id in qs_params
54+
for qs_param_name, entity_id in qs_params.items()
5555
if param_name == qs_param_name
5656
)
5757
hint = next(hints, None)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from unittest import TestCase
2+
3+
import pytest
4+
5+
from satosa.context import Context
6+
from satosa.internal import InternalData
7+
from satosa.state import State
8+
from satosa.micro_services.idp_hinting import IdpHinting
9+
10+
11+
class TestIdpHinting(TestCase):
12+
def setUp(self):
13+
context = Context()
14+
context.state = State()
15+
internal_data = InternalData()
16+
17+
config = {
18+
'allowed_params': ["idp_hinting", "idp_hint", "idphint"]
19+
}
20+
21+
plugin = IdpHinting(
22+
config=config,
23+
name='test_idphinting',
24+
base_url='https://satosa.example.org',
25+
)
26+
plugin.next = lambda ctx, data: (ctx, data)
27+
28+
self.config = config
29+
self.context = context
30+
self.data = internal_data
31+
self.plugin = plugin
32+
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):
39+
_target = 'https://localhost:8080'
40+
self.context.qs_params = {'idphint': _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)
49+
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)