import pytest ENDPOINTS = [ ("get", "/api/aliases/"), ("post", "/api/aliases/create_bulk/"), ("delete", "/api/aliases/delete_bulk/"), ("get", "/api/domains/"), ("post", "/api/domains/"), ("get", "/api/domains/1/"), ("put", "/api/domains/1/"), ("patch", "/api/domains/1/"), ("delete", "/api/domains/1/"), ("get", "/api/users/"), ("post", "/api/users/"), ("get", "/api/users/1/"), ("put", "/api/users/1/"), ("patch", "/api/users/1/"), ("delete", "/api/users/1/"), ] @pytest.mark.django_db @pytest.mark.parametrize(("method", "url"), ENDPOINTS) def test_anonymous_is_rejected(client, method, url): res = getattr(client, method)(url, content_type="application/json") assert res.status_code == 401 @pytest.mark.django_db def test_wrong_password_is_rejected(client, admin): client.defaults["HTTP_AUTHORIZATION"] = "Basic YWRtaW46d3Jvbmc=" # admin:wrong assert client.get("/api/domains/").status_code == 401 def test_basic_auth(api): assert api.get("/api/domains/").status_code == 200 def test_session_auth(client, admin): client.force_login(admin) assert client.get("/api/domains/").status_code == 200 def test_root_redirects_to_api(client, admin): client.force_login(admin) res = client.get("/", follow=True) assert res.redirect_chain assert res.status_code == 200