Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_multiple_response_types_urlencoded(self):
ar = AuthorizationRequest(response_type=["code", "token"], client_id="foobar")
ue = ar.to_urlencoded()
ue_splits = ue.split("&")
expected_ue_splits = "response_type=code+token&client_id=foobar".split("&")
assert _eq(ue_splits, expected_ue_splits)
are = AuthorizationRequest().deserialize(ue, "urlencoded")
assert _eq(are.keys(), ["response_type", "client_id"])
assert _eq(are["response_type"], ["code", "token"])
def test_load_dict(self):
bib = {
"scope": ["openid"],
"state": "id-6da9ca0cc23959f5f33e8becd9b08cae",
"redirect_uri": "http://localhost:8087authz",
"response_type": ["code"],
"client_id": "a1b2c3",
}
arq = AuthorizationRequest(**bib)
assert arq["scope"] == bib["scope"]
assert arq["response_type"] == bib["response_type"]
assert arq["redirect_uri"] == bib["redirect_uri"]
assert arq["state"] == bib["state"]
assert arq["client_id"] == bib["client_id"]
def test_deserialize_urlencoded_multiple_params(self):
ar = AuthorizationRequest(
response_type=["code"],
client_id="foobar",
redirect_uri="http://foobar.example.com/oaclient",
scope=["foo", "bar"],
state="cold",
)
urlencoded = ar.to_urlencoded()
ar2 = AuthorizationRequest().deserialize(urlencoded, "urlencoded")
assert ar == ar2
def test_deserialize_urlencoded(self):
ar = AuthorizationRequest(response_type=["code"], client_id="foobar")
urlencoded = ar.to_urlencoded()
ar2 = AuthorizationRequest().deserialize(urlencoded, "urlencoded")
assert ar == ar2
def test_req_json_serialize(self):
ar = AuthorizationRequest(response_type=["code"], client_id="foobar")
js_obj = json.loads(ar.serialize(method="json"))
expected_js_obj = {"response_type": "code", "client_id": "foobar"}
assert js_obj == expected_js_obj
def test_parse_authz_req(self):
ar = AuthorizationRequest(
response_type=["code"],
client_id="foobar",
redirect_uri="http://foobar.example.com/oaclient",
state="cold",
)
uencq = ar.to_urlencoded()
areq = self.srv.parse_authorization_request(query=uencq)
assert isinstance(areq, AuthorizationRequest)
assert areq["response_type"] == ["code"]
assert areq["client_id"] == "foobar"
assert areq["redirect_uri"] == "http://foobar.example.com/oaclient"
assert areq["state"] == "cold"
urluenc = "%s?%s" % ("https://example.com/authz", uencq)
areq = self.srv.parse_authorization_request(url=urluenc)
assert isinstance(areq, AuthorizationRequest)
assert areq["response_type"] == ["code"]
assert areq["client_id"] == "foobar"
assert areq["redirect_uri"] == "http://foobar.example.com/oaclient"
assert areq["state"] == "cold"
def test_json_multiple_params(self):
ar = AuthorizationRequest(response_type=["code"],
client_id="foobar",
redirect_uri="http://foobar.example.com/oaclient",
state="cold")
ue_obj = json.loads(ar.serialize(method="json"))
expected_ue_obj = {
"response_type": "code",
"state": "cold",
"redirect_uri": "http://foobar.example.com/oaclient",
"client_id": "foobar"
}
assert ue_obj == expected_ue_obj
def test_json_serialize_deserialize(self):
ar = AuthorizationRequest(response_type=["code"],
client_id="foobar")
jtxt = ar.serialize(method="json")
ar2 = AuthorizationRequest().deserialize(jtxt, "json")
assert ar == ar2
def test_multiple_scopes_json(self):
ar = AuthorizationRequest(response_type=["code", "token"],
client_id="foobar",
scope=["openid", "foxtrot"])
ue = ar.to_json()
ue_obj = json.loads(ue)
expected_ue_obj = {
"scope": "openid foxtrot",
"response_type": "code token",
"client_id": "foobar"
}
assert ue_obj == expected_ue_obj
are = AuthorizationRequest().deserialize(ue, "json")
assert _eq(are.keys(), ["response_type", "client_id", "scope"])
assert _eq(are["response_type"], ["code", "token"])
assert _eq(are["scope"], ["openid", "foxtrot"])
def test_json_serialize_deserialize(self):
ar = AuthorizationRequest(response_type=["code"],
client_id="foobar")
jtxt = ar.serialize(method="json")
ar2 = AuthorizationRequest().deserialize(jtxt, "json")
assert ar == ar2