Skip to content

Commit

Permalink
Allow ['ANY'] to be treated as ANY
Browse files Browse the repository at this point in the history
  • Loading branch information
djw8605 committed Apr 4, 2024
1 parent 4a70665 commit 382b2e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/scitokens/scitokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,7 @@ def _validate_aud(self, value):
return False
elif self._audience == "ANY":
return False
elif value == "ANY":
return True


# Convert the value and self._audience both to sets
# Then perform set intersection
values = []
Expand All @@ -609,6 +607,11 @@ def _validate_aud(self, value):
else:
values = value
set_value = set(values)

# Check if "ANY" is in the set_value, and always accept if that is true
if "ANY" in set_value:
return True

audiences = []
if not isinstance(self._audience, list):
audiences = [self._audience]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_scitokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ def test_v2(self):
self._token2["aud"] = "ANY"
self.assertTrue(enf.test(self._token2, "read", "/foo/bar"), msg=enf.last_failure)

# Now set the audience to ANY
self._token2["aud"] = ["ANY"]
self.assertTrue(enf.test(self._token2, "read", "/foo/bar"), msg=enf.last_failure)

# Now set the audience to ANY
self._token2["aud"] = ["notathing.com", "ANY"]
self.assertTrue(enf.test(self._token2, "read", "/foo/bar"), msg=enf.last_failure)

# Now to the correct audience
self._token2["aud"] = "https://example.unl.edu"
self.assertTrue(enf.test(self._token2, "read", "/foo/bar"), msg=enf.last_failure)
Expand Down

0 comments on commit 382b2e5

Please sign in to comment.