Skip to content

Commit

Permalink
Fixed test.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohe committed Apr 28, 2022
1 parent 9375982 commit f079af5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/test_server_13_user_authn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from idpyoidc.server import Server
from idpyoidc.server.authn_event import create_authn_event
from idpyoidc.server.configure import OPConfiguration
from idpyoidc.server.user_authn.authn_context import INTERNETPROTOCOLPASSWORD
from idpyoidc.server.user_authn.authn_context import UNSPECIFIED
Expand Down Expand Up @@ -80,6 +81,20 @@ def create_endpoint_context(self):
}
self.server = Server(OPConfiguration(conf=conf, base_path=BASEDIR), cwd=BASEDIR)
self.endpoint_context = self.server.endpoint_context
self.session_manager = self.endpoint_context.session_manager
self.user_id = "diana"

def _create_session(self, auth_req, sub_type="public", sector_identifier=""):
if sector_identifier:
authz_req = auth_req.copy()
authz_req["sector_identifier_uri"] = sector_identifier
else:
authz_req = auth_req
client_id = authz_req["client_id"]
ae = create_authn_event(self.user_id)
return self.session_manager.create_session(
ae, authz_req, self.user_id, client_id=client_id, sub_type=sub_type
)

def test_authenticated_as_without_cookie(self):
authn_item = self.endpoint_context.authn_broker.pick(INTERNETPROTOCOLPASSWORD)
Expand All @@ -93,12 +108,11 @@ def test_authenticated_as_with_cookie(self):
method = authn_item[0]["method"]

authn_req = {"state": "state_identifier", "client_id": "client 12345"}
_sid = self._create_session(authn_req)
_cookie = self.endpoint_context.new_cookie(
name=self.endpoint_context.cookie_handler.name["session"],
sub="diana",
sid=self.endpoint_context.session_manager.encrypted_session_id(
"diana", "client 12345", "abcdefgh"
),
sid=_sid,
state=authn_req["state"],
client_id=authn_req["client_id"],
)
Expand Down

0 comments on commit f079af5

Please sign in to comment.