From 903be2c0cac9e98654ed49caaf584efc6f3efe38 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 28 Sep 2024 02:17:56 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- oauth2_provider/models.py | 7 +++++-- oauth2_provider/validators.py | 36 +++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/oauth2_provider/models.py b/oauth2_provider/models.py index 2a8eb2ade..98889360c 100644 --- a/oauth2_provider/models.py +++ b/oauth2_provider/models.py @@ -808,7 +808,10 @@ def redirect_to_uri_allowed(uri, allowed_uris): # time of the request for loopback IP redirect URIs, to accommodate # clients that obtain an available ephemeral port from the operating # system at the time of the request. - allowed_uri_is_loopback = (parsed_allowed_uri.scheme == "http" and parsed_allowed_uri.hostname in ["127.0.0.1", "::1"]) + allowed_uri_is_loopback = parsed_allowed_uri.scheme == "http" and parsed_allowed_uri.hostname in [ + "127.0.0.1", + "::1", + ] """ check port """ if not allowed_uri_is_loopback and parsed_allowed_uri.port != parsed_uri.port: continue @@ -824,7 +827,7 @@ def redirect_to_uri_allowed(uri, allowed_uris): """ check querystring """ aqs_set = set(parse_qsl(parsed_allowed_uri.query)) if not aqs_set.issubset(uqs_set): - continue # circuit break + continue # circuit break return True diff --git a/oauth2_provider/validators.py b/oauth2_provider/validators.py index 3b3dd6d4b..0a5442d3d 100644 --- a/oauth2_provider/validators.py +++ b/oauth2_provider/validators.py @@ -82,19 +82,31 @@ def __call__(self, value): if self.allow_hostname_wildcard and "*" in netloc: domain_parts = netloc.split(".") if netloc.count("*") > 1: - raise ValidationError( - "%(name)s URI validation error. %(cause)s: %(value)s", - params={"name": self.name, "value": value, "cause": "only one wildcard is allowed in the hostname"}, - ) + raise ValidationError( + "%(name)s URI validation error. %(cause)s: %(value)s", + params={ + "name": self.name, + "value": value, + "cause": "only one wildcard is allowed in the hostname", + }, + ) if not netloc.startswith("*"): raise ValidationError( "%(name)s URI validation error. %(cause)s: %(value)s", - params={"name": self.name, "value": value, "cause": "wildcards must be at the beginning of the hostname"}, + params={ + "name": self.name, + "value": value, + "cause": "wildcards must be at the beginning of the hostname", + }, ) if len(domain_parts) < 3: raise ValidationError( "%(name)s URI validation error. %(cause)s: %(value)s", - params={"name": self.name, "value": value, "cause": "wildcards cannot be in the top level or second level domain"}, + params={ + "name": self.name, + "value": value, + "cause": "wildcards cannot be in the top level or second level domain", + }, ) # strip the wildcard from the netloc, we'll reassamble the value later to pass to URI Validator @@ -107,12 +119,20 @@ def __call__(self, value): if path.count("*") > 1: raise ValidationError( "%(name)s URI validation error. %(cause)s: %(value)s", - params={"name": self.name, "value": value, "cause": "only one wildcard is allowed in the path"}, + params={ + "name": self.name, + "value": value, + "cause": "only one wildcard is allowed in the path", + }, ) if not path.endswith("*"): raise ValidationError( "%(name)s URI validation error. %(cause)s: %(value)s", - params={"name": self.name, "value": value, "cause": "wildcards must be at the end of the path"}, + params={ + "name": self.name, + "value": value, + "cause": "wildcards must be at the end of the path", + }, ) # strip the wildcard from the path, we'll reassamble the value later to pass to URI Validator path = path[:-1]