Skip to content

Commit

Permalink
Add test for "scitokens" blocks in namespaces json (SOFTWARE-5760)
Browse files Browse the repository at this point in the history
  • Loading branch information
matyasselmeci committed Nov 20, 2023
1 parent fc3ea47 commit 181e44e
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import flask
import pytest
from typing import Dict
from typing import Dict, List
import urllib.parse
from pytest_mock import MockerFixture

Expand Down Expand Up @@ -79,6 +79,11 @@ def namespaces_json(self, client: flask.FlaskClient) -> Dict:
assert response.status_code == 200
return response.json

@pytest.fixture(scope="class")
def namespaces(self, namespaces_json) -> List[Dict]:
assert "namespaces" in namespaces_json
return namespaces_json["namespaces"]

@staticmethod
def validate_cache_schema(cc):
assert HOST_PORT_RE.match(cc["auth_endpoint"])
Expand Down Expand Up @@ -115,9 +120,7 @@ def test_caches(self, namespaces_json):
for cache in caches:
self.validate_cache_schema(cache)

def test_namespaces(self, namespaces_json):
assert "namespaces" in namespaces_json
namespaces = namespaces_json["namespaces"]
def test_namespaces(self, namespaces):
# Have a reasonable number of namespaces
assert len(namespaces) > 15

Expand All @@ -131,6 +134,27 @@ def test_namespaces(self, namespaces_json):
self.validate_cache_schema(cache)
assert found_credgen, "At least one namespace with credential_generation"

@staticmethod
def validate_scitokens_block(sci):
assert sci["issuer"]
assert isinstance(sci["issuer"], str)
assert "://" in sci["issuer"]
assert isinstance(sci["basepath"], list)
assert sci["basepath"] # must have at least 1
for bp in sci["basepath"]:
assert bp.startswith("/") # implies str
assert "," not in bp
assert isinstance(sci["restrictedpath"], list)
for rp in sci["restrictedpath"]: # may be empty
assert rp.startswith("/") # implies str
assert "," not in rp

def test_issuers_in_namespaces(self, namespaces):
for namespace in namespaces:
assert isinstance(namespace["scitokens"], list)
for scitokens_block in namespace["scitokens"]:
self.validate_scitokens_block(scitokens_block)


class TestAPI:

Expand Down

0 comments on commit 181e44e

Please sign in to comment.