From f52fc4688b741cb7932431ff49035379ad06868b Mon Sep 17 00:00:00 2001 From: "Stephen C. Pope" Date: Tue, 30 Jan 2024 16:18:26 -0700 Subject: [PATCH] Client: Fix auth and compute tests (#12426) GitOrigin-RevId: c95fa429afe61e93769296ce8bb0110dbffacbe1 --- .github/workflows/public-ci.yml | 2 +- descarteslabs/auth/auth.py | 2 +- descarteslabs/core/compute/tests/base.py | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/public-ci.yml b/.github/workflows/public-ci.yml index f5290bf5..537027b0 100644 --- a/.github/workflows/public-ci.yml +++ b/.github/workflows/public-ci.yml @@ -28,7 +28,7 @@ jobs: DESCARTESLABS_ENV: testing run: | mkdir tempdir - pytest -rfExXP --assert=plain --ignore-glob="*/smoke_tests" --ignore-glob="*/e2e" --ignore="descarteslabs/core/third_party" --ignore="descarteslabs/core/client/services/metadata" descarteslabs + pytest -rfExXP --assert=plain --ignore-glob="*/smoke_tests" --ignore-glob="*/e2e" --ignore="descarteslabs/core/third_party" descarteslabs rm -r tempdir slack: diff --git a/descarteslabs/auth/auth.py b/descarteslabs/auth/auth.py index e416de7d..15272dce 100644 --- a/descarteslabs/auth/auth.py +++ b/descarteslabs/auth/auth.py @@ -395,7 +395,7 @@ def __init__( and self.refresh_token == token_info.get(self.KEY_REFRESH_TOKEN) ): self._token = token_info.get(self.KEY_JWT_TOKEN) - elif self.refresh_token: + elif self.refresh_token and self.token_info_path is not None: # Make the saved JWT token file unique to the refresh token token = self.refresh_token token_sha1 = sha1(token.encode("utf-8")).hexdigest() diff --git a/descarteslabs/core/compute/tests/base.py b/descarteslabs/core/compute/tests/base.py index 7615c830..3ba902cb 100644 --- a/descarteslabs/core/compute/tests/base.py +++ b/descarteslabs/core/compute/tests/base.py @@ -1,6 +1,7 @@ import base64 import json import json as jsonlib +import os import time import urllib.parse import uuid @@ -24,6 +25,18 @@ class BaseTestCase(TestCase): compute_url = "https://platform.dev.aws.descarteslabs.com/compute/v1" def setUp(self): + # make sure all of these are gone, so our Auth is only a JWT + for envvar in ( + "CLIENT_ID", + "DESCARTESLABS_CLIENT_ID", + "CLIENT_SECRET", + "DESCARTESLABS_CLIENT_SECRET", + "DESCARTESLABS_REFRESH_TOKEN", + "DESCARTESLABS_TOKEN", + ): + if envvar in os.environ: + del os.environ[envvar] + responses.mock.assert_all_requests_are_fired = True self.now = datetime.utcnow() @@ -47,7 +60,7 @@ def tearDown(self): responses.mock.assert_all_requests_are_fired = False def mock_credentials(self): - responses.add(responses.POST, f"{self.compute_url}/credentials") + responses.add(responses.GET, f"{self.compute_url}/credentials") def mock_response(self, method, uri, json=None, status=200, **kwargs): if json is not None: