示例#1
0
def test_google_link_redirect_no_google_idp(client, app, restore_config,
                                            encoded_creds_jwt):
    """
    Test that even if Google is not configured as an IDP, when we hit the link
    endpoint with valid creds, we get a redirect response.
    This should be redirecting to google's oauth
    """
    # Don't include google in the enabled idps, but leave it configured
    # in the openid connect clients:
    override_settings = {
        "ENABLED_IDENTITY_PROVIDERS": {
            # ID for which of the providers to default to.
            "default": "fence",
            # Information for identity providers.
            "providers": {
                "fence": {
                    "name": "Fence Multi-Tenant OAuth"
                },
                "shibboleth": {
                    "name": "NIH Login"
                },
            },
        },
        "OPENID_CONNECT": {
            "google": {
                "client_id": "123",
                "client_secret": "456",
                "redirect_url": "789",
            }
        },
    }
    config.update(override_settings)

    encoded_credentials_jwt = encoded_creds_jwt["jwt"]
    redirect = "http://localhost"

    r = client.get(
        "/link/google",
        query_string={"redirect": redirect},
        headers={"Authorization": "Bearer " + encoded_credentials_jwt},
    )

    assert r.status_code == 302
    url, query_params = split_url_and_query_params(r.location)
    google_url, google_query_params = split_url_and_query_params(
        app.google_client.get_auth_url())
    assert google_url == url
示例#2
0
def test_google_link_redirect(client, app, encoded_creds_jwt):
    """
    Test that when we hit the link endpoint with valid creds, we get
    a redirect response. This should be redirecting to google's oauth
    """
    encoded_credentials_jwt = encoded_creds_jwt["jwt"]
    redirect = "http://localhost"

    r = client.get(
        "/link/google",
        query_string={"redirect": redirect},
        headers={"Authorization": "Bearer " + encoded_credentials_jwt},
    )

    assert r.status_code == 302
    url, query_params = split_url_and_query_params(r.location)
    google_url, google_query_params = split_url_and_query_params(
        app.google_client.get_auth_url())
    assert google_url == url
示例#3
0
def test_google_link_redirect_when_google_mocked(client, app,
                                                 encoded_creds_jwt,
                                                 monkeypatch):
    """
    Test that when we hit the link endpoint and we're mocking Google login, we
    get redirected to the /link callback.
    """
    monkeypatch.setitem(config, "MOCK_GOOGLE_AUTH", True)
    redirect = "http://localhost"

    r = client.get(
        "/link/google",
        query_string={"redirect": redirect},
        headers={"Authorization": "Bearer " + encoded_creds_jwt.jwt},
    )

    assert r.status_code == 302
    url, query_params = split_url_and_query_params(r.location)
    assert "/link/google/callback" in url
    assert "code" in query_params