Skip to content

Commit 2bbd3e0

Browse files
committed
chore: refactor scopes from tuple to str
1 parent e47bb59 commit 2bbd3e0

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/stac_auth_proxy/config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
METHODS = Literal["GET", "POST", "PUT", "DELETE", "PATCH"]
1111
EndpointMethodsNoScope: TypeAlias = dict[str, Sequence[METHODS]]
12-
EndpointMethods: TypeAlias = dict[
13-
str, Sequence[Union[METHODS, tuple[METHODS, Sequence[str]]]]
14-
]
12+
EndpointMethods: TypeAlias = dict[str, Sequence[Union[METHODS, tuple[METHODS, str]]]]
1513

1614
_PREFIX_PATTERN = r"^/.*$"
1715

src/stac_auth_proxy/utils/requests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def _check_endpoint_match(
3737
for endpoint_method in endpoint_methods:
3838
required_scopes: Sequence[str] = []
3939
if isinstance(endpoint_method, tuple):
40-
endpoint_method, required_scopes = endpoint_method
40+
endpoint_method, _required_scopes = endpoint_method
41+
if _required_scopes: # Ignore empty scopes, e.g. `["POST", ""]`
42+
required_scopes = _required_scopes.split(" ")
4143
if method.casefold() == endpoint_method.casefold():
4244
return True, required_scopes
4345
return False, []

tests/test_authn.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_default_public_false_with_scopes(
6666
test_app = app_factory(
6767
upstream_url=source_api_server,
6868
default_public=False,
69-
private_endpoints={r"^/collections$": [("POST", ["collection:create"])]},
69+
private_endpoints={r"^/collections$": [("POST", "collection:create")]},
7070
)
7171
valid_auth_token = token_builder(token)
7272

@@ -84,31 +84,31 @@ def test_default_public_false_with_scopes(
8484
[
8585
pytest.param(
8686
"",
87-
{r"^/*": [("POST", ["collection:create"])]},
87+
{r"^/*": [("POST", "collection:create")]},
8888
"/collections",
8989
"POST",
9090
False,
9191
id="empty scopes + private endpoint",
9292
),
9393
pytest.param(
9494
"openid profile collection:createbutnotcreate",
95-
{r"^/*": [("POST", ["collection:create"])]},
95+
{r"^/*": [("POST", "collection:create")]},
9696
"/collections",
9797
"POST",
9898
False,
9999
id="invalid scopes + private endpoint",
100100
),
101101
pytest.param(
102102
"openid profile collection:create somethingelse",
103-
{r"^/*": [("POST", [])]},
103+
{r"^/*": [("POST", "")]},
104104
"/collections",
105105
"POST",
106106
True,
107107
id="valid scopes + private endpoint without required scopes",
108108
),
109109
pytest.param(
110110
"openid",
111-
{r"^/collections/.*/items$": [("POST", ["collection:create"])]},
111+
{r"^/collections/.*/items$": [("POST", "collection:create")]},
112112
"/collections",
113113
"GET",
114114
True,

0 commit comments

Comments
 (0)