diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b17f49748a407f3cbb7356a1875d37c65a82a82..80b4dfbfcc8fcbe2973469bc488628fce0febcc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,16 +58,15 @@ jobs: backend: if: always() runs-on: ubuntu-latest - - env: - NODE_ENV: test - steps: - uses: actions/checkout@v3 - - name: Use Node.js 16.x - uses: actions/setup-node@v1 + - uses: actions/setup-python@v4 with: - node-version: 16.x + python-version: '3.10' - run: | - echo "busybody" + cd backend + pip install -r requirements.txt + pip install pytest + pytest + diff --git a/backend/app/sane_url.py b/backend/app/sane_url.py index dc4a4e3470896620de381882bc6478c8dc598e91..29f14078e7aca259f2dc17c7815a74e9364c902e 100644 --- a/backend/app/sane_url.py +++ b/backend/app/sane_url.py @@ -27,6 +27,7 @@ vip_routes = [ class SaneUrlDPStore(DataproxyStore): class AlreadyExists(Exception): ... + class NotWritable(IOError): ... @staticmethod def GetTimeMs() -> int: @@ -36,8 +37,12 @@ class SaneUrlDPStore(DataproxyStore): def TransformKeyToObjName(key: str): return f"saneUrl/{key}.json" + writable = False + def __init__(self, expiry_s=3 * 24 * 60 * 60): - + if not (SXPLR_EBRAINS_IAM_SA_CLIENT_ID and SXPLR_EBRAINS_IAM_SA_CLIENT_SECRET): + super().__init__(None, SXPLR_BUCKET_NAME) + return resp = requests.get(f"{EBRAINS_IAM_DISCOVERY_URL}/.well-known/openid-configuration") resp.raise_for_status() resp_json = resp.json() @@ -54,6 +59,7 @@ class SaneUrlDPStore(DataproxyStore): self._refresh_token() super().__init__(self.token, SXPLR_BUCKET_NAME) + self.writable = True def _refresh_token(self): token_dict = self.session.fetch_token(self._token_endpoint, grant_type="client_credentials") @@ -94,7 +100,8 @@ class SaneUrlDPStore(DataproxyStore): raise SaneUrlDPStore.GenericException(str(e)) from e def set(self, key: str, value: Union[str, Dict], request: Optional[Request]=None): - + if not self.writable: + raise SaneUrlDPStore.NotWritable object_name = SaneUrlDPStore.TransformKeyToObjName(key) try: super().get(object_name) diff --git a/backend/pytest.ini b/backend/pytest.ini new file mode 100644 index 0000000000000000000000000000000000000000..0d140f30bd8a273c44e012aece65633d75736870 --- /dev/null +++ b/backend/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +pythonpath = . +testpaths = + test_app \ No newline at end of file diff --git a/backend/test_app/test_sane_url.py b/backend/test_app/test_sane_url.py new file mode 100644 index 0000000000000000000000000000000000000000..49ab5ec495c797a1cff592c6f5dd1850034f3232 --- /dev/null +++ b/backend/test_app/test_sane_url.py @@ -0,0 +1,13 @@ +from app.app import app +from fastapi.testclient import TestClient + +client = TestClient(app) + +def test_annotation_redirect(): + resp = client.get("/go/stnr", headers={ + "Accept": "text/html" + }, follow_redirects=False) + loc = resp.headers.get("Location") + assert loc, "Expected location header to be present, but was not" + assert "x-user-anntn:stnr" in loc, f"Expected the string 'x-user-anntn:stnr' in {loc!r}, but was not" + diff --git a/src/atlasComponents/userAnnotations/tools/service.ts b/src/atlasComponents/userAnnotations/tools/service.ts index f1e2e268977dfaaa31818a1d0fbea40b7034d8b3..bb0b092d7a025a191f6cced5c506b70a6a9d8143 100644 --- a/src/atlasComponents/userAnnotations/tools/service.ts +++ b/src/atlasComponents/userAnnotations/tools/service.ts @@ -482,10 +482,10 @@ export class ModularUserAnnotationToolService implements OnDestroy{ return this.annotationLayer }) ).pipe( - map(annotationLayer => ({viewerMode, voxelSize, annotationLayer})) + map(annotationLayer => ({viewerMode, annotationLayer})) ) ) - ).subscribe(({viewerMode, voxelSize, annotationLayer}) => { + ).subscribe(({viewerMode, annotationLayer}) => { this.currMode = viewerMode /**