def test_srv2(): cc = ClaimsClient(client_id="client_1") cc.client_secret = "hemlig" req = cc.construct_UserClaimsRequest( request_args={ "sub": "diana", "claims_names": ["gender", "birthdate"] }) srv = ClaimsServer("pyoicserv", SessionDB(), CDB, USERINFO, verify_client, keyjar=KEYJAR, dist_claims_mode=ClaimsMode(USER2MODE)) srv.keyjar[""] = keybundle_from_local_file("rsa.key", "rsa", ["ver", "sig"]) assert srv resp = srv.claims_endpoint(req.to_urlencoded(), "") print resp.message ucr = UserClaimsResponse().deserialize(resp.message, "json") ucr.verify(keyjar=srv.keyjar) print ucr assert _eq(ucr["claims_names"], ["gender", "birthdate"]) assert "jwt" in ucr
def test_srv2(): cc = ClaimsClient(client_id="client_1") cc.client_secret = "hemlig" req = cc.construct_UserClaimsRequest( request_args={"sub": "diana", "claims_names": ["gender", "birthdate"]}) srv = ClaimsServer("pyoicserv", SessionDB("https://example.com"), CDB, USERINFO, verify_client, keyjar=KEYJAR, dist_claims_mode=ClaimsMode(USER2MODE)) srv.keyjar[""] = keybundle_from_local_file("%s/rsa.key" % BASE_PATH, "rsa", ["ver", "sig"]) assert srv resp = srv.claims_endpoint(req.to_urlencoded(), "") print resp.message ucr = UserClaimsResponse().deserialize(resp.message, "json") ucr.verify(keyjar=srv.keyjar) print ucr assert _eq(ucr["claims_names"], ["gender", "birthdate"]) assert "jwt" in ucr
def test_srv2(): cc = ClaimsClient(client_id="client_1") cc.client_secret="hemlig" req = cc.construct_UserClaimsRequest(request_args={"user_id": "diana", "claims_names":["gender", "birthdate"]}) srv = ClaimsServer("name", None, CDB, FUNCTIONS, USERDB) srv.keystore.set_sign_key(rsa_load("rsa.key"), "rsa") assert srv environ = BASE_ENVIRON.copy() environ["REQUEST_METHOD"] = "POST" txt = req.to_urlencoded() environ["CONTENT_LENGTH"] = len(txt) fil = StringIO.StringIO(buf=txt) environ["wsgi.input"] = fil resp = srv.claims_endpoint(environ, start_response, LOG()) print resp assert len(resp) == 1 ucr = UserClaimsResponse().deserialize(resp[0], "json") ucr.verify(key = srv.keystore.get_keys("sig", owner=None)) print ucr assert _eq(ucr["claims_names"], ["gender", "birthdate"]) assert "jwt" in ucr
def test_srv2(): cc = ClaimsClient(client_id="client_1") cc.client_secret="hemlig" req = cc.construct_UserClaimsRequest(request_args={"sub": "diana", "claims_names":["gender", "birthdate"]}) srv = ClaimsServer("name", None, CDB, FUNCTIONS, USERDB) srv.keyjar[""] = [KeyBundle(source="file://rsa.key", usage=["ver", "sig"])] assert srv environ = BASE_ENVIRON.copy() environ["REQUEST_METHOD"] = "POST" txt = req.to_urlencoded() environ["CONTENT_LENGTH"] = len(txt) fil = StringIO.StringIO(buf=txt) environ["wsgi.input"] = fil resp = srv.claims_endpoint(environ, start_response, LOG()) print resp assert len(resp) == 1 ucr = UserClaimsResponse().deserialize(resp[0], "json") ucr.verify(keyjar = srv.keyjar) print ucr assert _eq(ucr["claims_names"], ["gender", "birthdate"]) assert "jwt" in ucr
class TestClaimsServer(object): USER2MODE = { "diana": "aggregate", "upper": "distribute", "babs": "aggregate" } CDB = {"client_1": {"client_secret": "hemlig"}} @pytest.fixture(autouse=True) def create_claims_server(self, keyjar, session_db): self.srv = ClaimsServer("pyoicserv", session_db, TestClaimsServer.CDB, UserInfo(USERDB), verify_client, keyjar=keyjar, dist_claims_mode=ClaimsMode( TestClaimsServer.USER2MODE)) def test_claims_endpoint(self): cc = ClaimsClient(client_id="client_1") cc.client_secret = "hemlig" req = cc.construct_UserClaimsRequest( request_args={ "sub": "diana", "claims_names": ["gender", "birthdate"] }) resp = self.srv.claims_endpoint(req.to_urlencoded(), "") ucr = UserClaimsResponse().deserialize(resp.message, "json") ucr.verify(keyjar=self.srv.keyjar) assert _eq(ucr["claims_names"], ["gender", "birthdate"]) assert "jwt" in ucr @pytest.fixture(scope="session") def keyjar(self): symkey = KeyBundle([{ "kty": "oct", "key": "abcdefghijklmnop", "use": "ver" }, { "kty": "oct", "key": "abcdefghijklmnop", "use": "sig" }]) base_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "data/keys")) rsakey = keybundle_from_local_file( os.path.abspath(os.path.join(base_path, "rsa.key")), "rsa", ["ver", "sig"]) keyjar = KeyJar() keyjar["client1"] = [symkey, rsakey] keyjar[""] = rsakey return keyjar
class TestClaimsServer(object): USER2MODE = {"diana": "aggregate", "upper": "distribute", "babs": "aggregate"} CDB = { "client_1": {"client_secret": "hemlig"} } @pytest.fixture(autouse=True) def create_claims_server(self, keyjar, session_db): self.srv = ClaimsServer("pyoicserv", session_db, TestClaimsServer.CDB, UserInfo(USERDB), verify_client, keyjar=keyjar, dist_claims_mode=ClaimsMode( TestClaimsServer.USER2MODE)) def test_claims_endpoint(self): cc = ClaimsClient(client_id="client_1") cc.client_secret = "hemlig" req = cc.construct_UserClaimsRequest( request_args={"sub": "diana", "claims_names": ["gender", "birthdate"]}) resp = self.srv.claims_endpoint(req.to_urlencoded(), "") ucr = UserClaimsResponse().deserialize(resp.message, "json") ucr.verify(keyjar=self.srv.keyjar) assert _eq(ucr["claims_names"], ["gender", "birthdate"]) assert "jwt" in ucr @pytest.fixture(scope="session") def keyjar(self): symkey = KeyBundle( [{"kty": "oct", "key": "abcdefghijklmnop", "use": "ver"}, {"kty": "oct", "key": "abcdefghijklmnop", "use": "sig"}]) base_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "data/keys")) rsakey = keybundle_from_local_file( os.path.abspath(os.path.join(base_path, "rsa.key")), "rsa", ["ver", "sig"]) keyjar = KeyJar() keyjar["client1"] = [symkey, rsakey] keyjar[""] = rsakey return keyjar
"userinfo": user_info } cc = ClaimsClient(client_id="client_1") cc.client_secret="hemlig" req = cc.construct_UserClaimsRequest(request_args={"user_id": "diana", "claims_names":["gender", "birthdate"]}) srv = ClaimsServer("name", None, CDB, FUNCTIONS, USERDB) srv.keyjar[""] = [KeyChain(source="file://rsa.key", usage=["ver", "sig"])] assert srv environ = BASE_ENVIRON.copy() environ["REQUEST_METHOD"] = "POST" txt = req.to_urlencoded() environ["CONTENT_LENGTH"] = len(txt) fil = StringIO.StringIO(buf=txt) environ["wsgi.input"] = fil resp = srv.claims_endpoint(environ, start_response, LOG()) print resp assert len(resp) == 1 ucr = UserClaimsResponse().deserialize(resp[0], "json") ucr.verify(keyjar = srv.keyjar) print ucr