3
3
import pytest
4
4
5
5
from satosa .context import Context
6
+ from satosa .internal import InternalData
6
7
from satosa .state import State
7
8
from satosa .micro_services .idp_hinting import IdpHinting
8
9
@@ -11,6 +12,7 @@ class TestIdpHinting(TestCase):
11
12
def setUp (self ):
12
13
context = Context ()
13
14
context .state = State ()
15
+ internal_data = InternalData ()
14
16
15
17
config = {
16
18
'allowed_params' : ["idp_hinting" , "idp_hint" , "idphint" ]
@@ -25,16 +27,31 @@ def setUp(self):
25
27
26
28
self .config = config
27
29
self .context = context
30
+ self .data = internal_data
28
31
self .plugin = plugin
29
32
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 ):
32
39
_target = 'https://localhost:8080'
33
40
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 )
36
49
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