Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip authorization if in development/testing #48

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ShakyaMajumdar
Copy link

Closes #47

@Robin5605 Robin5605 self-requested a review July 18, 2024 06:14
Copy link
Contributor

@Robin5605 Robin5605 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Copy link
Contributor

@Robin5605 Robin5605 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the tests failing - I think they should be fixed by moving the check inside get_access_token, like so:

def get_access_token(*, http_client: Client) -> str:
    """Get an access token from Auth0."""

+    if SKIP_AUTH:
+        return "DEVELOPMENT"

    payload = {
        "client_id": Settings.client_id,
        "client_secret": Settings.client_secret,
        "username": Settings.username,
        "password": Settings.password,
        "audience": Settings.audience,
        "grant_type": "password",
    }

    res = http_client.post(f"https://{Settings.auth0_domain}/oauth/token", json=payload)
    res.raise_for_status()
    json = res.json()
    return json["access_token"]  # type: ignore[no-any-return]

Because currently, the tests except the access token in the request to be whatever is returned by get_access_token (and reasonably so), however we are overriding it elsewhere which makes the expected mock calls to fail.

@ShakyaMajumdar
Copy link
Author

That would case test_get_access_token to fail instead because it expects get_access_token to always make a http request to the auth url

@Robin5605
Copy link
Contributor

That would case test_get_access_token to fail instead because it expects get_access_token to always make a http request to the auth url

Hmm, yeah, you're right. I think it would be best to have 2 tests for test_get_access_token then, one that ensures that it makes a request when GIT_SHA is something real, and one that ensures it doesn't make a request (when GIT_SHA is set to testing)

Copy link

@jonathan-d-zhang jonathan-d-zhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgor to submit this

src/loader/loader.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

Disable authentication in development environments
3 participants