Exemplo n.º 1
0
def test_url_conf_set(
    settings,
    rf,
    subdomain,
    expected_subdomain,
    expected_challenge,
    expected_url_conf,
):
    """Subdomains should have the correct url_conf attached"""
    settings.ALLOWED_HOSTS = [f".{SITE_DOMAIN}"]
    c = ChallengeFactory(short_name="c")

    if subdomain is not None:
        host = f"{subdomain}.{SITE_DOMAIN}"
    else:
        host = SITE_DOMAIN

    request = CurrentSiteMiddleware(lambda x: x)(rf.get("/", HTTP_HOST=host))
    request = subdomain_middleware(lambda x: x)(request)
    request = challenge_subdomain_middleware(lambda x: x)(request)
    request = subdomain_urlconf_middleware(lambda x: x)(request)

    assert request.subdomain == expected_subdomain
    assert request.urlconf == expected_url_conf
    if expected_challenge:
        assert request.challenge == c
    else:
        assert request.challenge is None
Exemplo n.º 2
0
def test_challenge_attribute(settings, rf, subdomain):
    settings.ALLOWED_HOSTS = [f".{SITE_DOMAIN}"]

    c = ChallengeFactory(short_name="challengesubdomaintest")

    request = rf.get("/")
    request.subdomain = subdomain

    assert not hasattr(request, "challenge")

    request = CurrentSiteMiddleware(lambda x: x)(request)
    request = challenge_subdomain_middleware(lambda x: x)(request)

    if subdomain is None:
        assert request.challenge is None
    elif subdomain.lower() == c.short_name.lower():
        assert request.challenge == c
Exemplo n.º 3
0
def test_challenge_attribute(settings, rf, subdomain):
    settings.ALLOWED_HOSTS = [f".{SITE_DOMAIN}"]

    c = ChallengeFactory(short_name="challengesubdomaintest")

    request = rf.get("/")
    request.subdomain = subdomain

    assert not hasattr(request, "challenge")

    request = challenge_subdomain_middleware(lambda x: x)(request)

    if subdomain is None:
        assert request.challenge == None
    elif subdomain.lower() == c.short_name.lower():
        assert request.challenge == c
    else:
        assert request.url == f"http://{SITE_DOMAIN}/"
Exemplo n.º 4
0
def test_rendering_challenge_settings(settings, rf, subdomain, response_type,
                                      expected_challenge):
    """
    Requests on rendering subdomains should not have a challenge attached nor
    redirect.
    """
    settings.ALLOWED_HOSTS = [f".{SITE_DOMAIN}"]
    c = ChallengeFactory(short_name="c")

    request = rf.get("/")
    request.subdomain = subdomain

    assert not hasattr(request, "challenge")

    request = CurrentSiteMiddleware(lambda x: x)(request)
    request = challenge_subdomain_middleware(lambda x: x)(request)

    assert isinstance(request, response_type)

    if response_type is WSGIRequest:
        if expected_challenge:
            assert request.challenge == c
        else:
            assert request.challenge is None