@@ -1362,6 +1362,20 @@ def create_endpoint_context(self):
13621362 }
13631363 server = Server (OPConfiguration (conf = conf , base_path = BASEDIR ), cwd = BASEDIR )
13641364 self .endpoint_context = server .endpoint_context
1365+ self .session_manager = self .endpoint_context .session_manager
1366+ self .user_id = "diana"
1367+
1368+ def _create_session (self , auth_req , sub_type = "public" , sector_identifier = "" ):
1369+ if sector_identifier :
1370+ authz_req = auth_req .copy ()
1371+ authz_req ["sector_identifier_uri" ] = sector_identifier
1372+ else :
1373+ authz_req = auth_req
1374+ client_id = authz_req ["client_id" ]
1375+ ae = create_authn_event (self .user_id )
1376+ return self .session_manager .create_session (
1377+ ae , authz_req , self .user_id , client_id = client_id , sub_type = sub_type
1378+ )
13651379
13661380 def test_authenticated_as_without_cookie (self ):
13671381 authn_item = self .endpoint_context .authn_broker .pick (INTERNETPROTOCOLPASSWORD )
@@ -1375,11 +1389,35 @@ def test_authenticated_as_with_cookie(self):
13751389 method = authn_item [0 ]["method" ]
13761390
13771391 authn_req = {"state" : "state_identifier" , "client_id" : "client 12345" }
1392+ session_id = self ._create_session (authn_req )
1393+
13781394 _cookie = self .endpoint_context .new_cookie (
13791395 name = self .endpoint_context .cookie_handler .name ["session" ],
13801396 sub = "diana" ,
1397+ sid = session_id ,
1398+ state = authn_req ["state" ],
1399+ client_id = authn_req ["client_id" ],
1400+ )
1401+
1402+ # Parsed once before setup_auth
1403+ kakor = self .endpoint_context .cookie_handler .parse_cookie (
1404+ cookies = [_cookie ], name = self .endpoint_context .cookie_handler .name ["session" ]
1405+ )
1406+
1407+ _info , _time_stamp = method .authenticated_as (client_id = "client 12345" , cookie = kakor )
1408+ assert _info ["sub" ] == "diana"
1409+
1410+ def test_authenticated_as_with_unknown_user (self ):
1411+ authn_item = self .endpoint_context .authn_broker .pick (INTERNETPROTOCOLPASSWORD )
1412+ method = authn_item [0 ]["method" ]
1413+
1414+ authn_req = {"state" : "state_identifier" , "client_id" : "client 12345" }
1415+ session_id = self ._create_session (authn_req )
1416+ _cookie = self .endpoint_context .new_cookie (
1417+ name = self .endpoint_context .cookie_handler .name ["session" ],
1418+ sub = "adam" ,
13811419 sid = self .endpoint_context .session_manager .encrypted_session_id (
1382- "diana " , "client 12345" , "abcdefgh "
1420+ "adam " , "client 12345" , "0123456789 "
13831421 ),
13841422 state = authn_req ["state" ],
13851423 client_id = authn_req ["client_id" ],
@@ -1391,4 +1429,28 @@ def test_authenticated_as_with_cookie(self):
13911429 )
13921430
13931431 _info , _time_stamp = method .authenticated_as (client_id = "client 12345" , cookie = kakor )
1394- assert _info ["sub" ] == "diana"
1432+ assert _info == {}
1433+
1434+ def test_authenticated_as_with_goobledigook (self ):
1435+ authn_item = self .endpoint_context .authn_broker .pick (INTERNETPROTOCOLPASSWORD )
1436+ method = authn_item [0 ]["method" ]
1437+
1438+ authn_req = {"state" : "state_identifier" , "client_id" : "client 12345" }
1439+ _ = self ._create_session (authn_req )
1440+ _cookie = self .endpoint_context .new_cookie (
1441+ name = self .endpoint_context .cookie_handler .name ["session" ],
1442+ sub = "adam" ,
1443+ sid = self .endpoint_context .session_manager .encrypted_session_id (
1444+ "adam" , "client 12345" , "0123456789"
1445+ ),
1446+ state = authn_req ["state" ],
1447+ client_id = authn_req ["client_id" ],
1448+ )
1449+
1450+ kakor = [{
1451+ 'value' : '{"sub": "adam", "sid": "Z0FBQUFBQmlhVl", "state": "state_identifier", "client_id": "client 12345"}' ,
1452+ 'type' : '' ,
1453+ 'timestamp' : '1651070251' }]
1454+
1455+ _info , _time_stamp = method .authenticated_as (client_id = "client 12345" , cookie = kakor )
1456+ assert _info == {}
0 commit comments