Skip to content

Commit 89741a8

Browse files
committed
IdP hinting improvements
- fix: exception accessing to qs_params - chore: improved exacmple configuration - feat: added unit tests
1 parent 1700c68 commit 89741a8

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ 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)
58-
5958
context.decorate(context.KEY_TARGET_ENTITYID, hint)
6059
return super().process(context, data)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from unittest import TestCase
2+
3+
import pytest
4+
5+
from satosa.context import Context
6+
from satosa.state import State
7+
from satosa.micro_services.idp_hinting import IdpHinting
8+
9+
10+
class TestIdpHinting(TestCase):
11+
def setUp(self):
12+
context = Context()
13+
context.state = State()
14+
15+
config = {
16+
'allowed_params': ["idp_hinting", "idp_hint", "idphint"]
17+
}
18+
19+
plugin = IdpHinting(
20+
config=config,
21+
name='test_idphinting',
22+
base_url='https://satosa.example.org',
23+
)
24+
plugin.next = lambda ctx, data: (ctx, data)
25+
26+
self.config = config
27+
self.context = context
28+
self.plugin = plugin
29+
30+
def test_idp_hinting(self):
31+
self.context.request = {}
32+
_target = 'https://localhost:8080'
33+
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
36+
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')

0 commit comments

Comments
 (0)