33import pytest
44
55from satosa .context import Context
6+ from satosa .internal import InternalData
67from satosa .state import State
78from 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