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

Send data for cleanup and present endpoints in the request body #29

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions httprequest_lego_provider/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_post_present_when_logged_in_and_no_fqdn(client: Client, user_auth_token
response = client.post(
"/present",
data={"fqdn": fqdn, "value": value},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)

Expand All @@ -81,6 +82,7 @@ def test_post_present_when_logged_in_and_no_permission(
response = client.post(
"/present",
data={"fqdn": domain.fqdn, "value": value},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)

Expand All @@ -101,6 +103,7 @@ def test_post_present_when_logged_in_and_permission(
response = client.post(
"/present",
data={"fqdn": domain_user_permission.domain.fqdn, "value": value},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)
mocked_dns_write.assert_called_once_with(domain_user_permission.domain, value)
Expand All @@ -120,6 +123,7 @@ def test_post_present_when_logged_in_and_fqdn_invalid(client: Client, user_auth_
response = client.post(
"/present",
data={"fqdn": "example.com", "value": value},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)

Expand Down Expand Up @@ -161,6 +165,7 @@ def test_post_cleanup_when_logged_in_and_no_fqdn(client: Client, user_auth_token
response = client.post(
"/cleanup",
data={"fqdn": f"{FQDN_PREFIX}example.com", "value": value},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)

Expand All @@ -180,6 +185,7 @@ def test_post_cleanup_when_logged_in_and_no_permission(
response = client.post(
"/cleanup",
data={"fqdn": domain.fqdn, "value": value},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)

Expand All @@ -200,6 +206,7 @@ def test_post_cleanup_when_logged_in_and_permission(
response = client.post(
"/cleanup",
data={"fqdn": domain_user_permission.domain.fqdn, "value": value},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)
mocked_dns_remove.assert_called_once_with(domain_user_permission.domain)
Expand All @@ -219,6 +226,7 @@ def test_post_cleanup_when_logged_in_and_fqdn_invalid(client: Client, user_auth_
response = client.post(
"/cleanup",
data={"fqdn": "example.com", "value": value},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)

Expand Down Expand Up @@ -257,6 +265,7 @@ def test_test_jwt_token_login(
response = client.post(
"/present",
data={"fqdn": domain_user_permission.domain.fqdn, "value": value},
format="json",
headers={"AUTHORIZATION": f"Bearer {token}"},
)

Expand All @@ -273,6 +282,7 @@ def test_post_domain_when_logged_in_as_non_admin_user(client: Client, user_auth_
response = client.post(
"/api/v1/domains/",
data={"fqdn": "example.com"},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)

Expand All @@ -291,6 +301,7 @@ def test_post_domain_when_logged_in_as_admin_user(client: Client, admin_user_aut
response = client.post(
"/api/v1/domains/",
data={"fqdn": "example.com"},
format="json",
headers={"AUTHORIZATION": f"Basic {admin_user_auth_token}"},
)

Expand All @@ -310,6 +321,7 @@ def test_post_domain_when_logged_in_as_admin_user_and_domain_invalid(
response = client.post(
"/api/v1/domains/",
data={"fqdn": "invalid-value"},
format="json",
headers={"AUTHORIZATION": f"Basic {admin_user_auth_token}"},
)

Expand All @@ -330,6 +342,7 @@ def test_post_domain_user_permission_when_logged_in_as_non_admin_user(
response = client.post(
"/api/v1/domain-user-permissions/",
data={"domain": domain.id, "user": user.id, "text": "whatever"},
format="json",
headers={"AUTHORIZATION": f"Basic {user_auth_token}"},
)

Expand Down
4 changes: 2 additions & 2 deletions httprequest_lego_provider/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def handle_present(request: HttpRequest) -> Optional[HttpResponse]:
Raises:
PermissionDenied: if the user is not allowed to perform the operation.
"""
form = PresentForm(request.POST)
form = PresentForm(request.data)
if not form.is_valid():
return HttpResponse(content=form.errors.as_json(), status=400)
user = request.user
Expand Down Expand Up @@ -60,7 +60,7 @@ def handle_cleanup(request: HttpRequest) -> Optional[HttpResponse]:
Raises:
PermissionDenied: if the user is not allowed to perform the operation.
"""
form = CleanupForm(request.POST)
form = CleanupForm(request.data)
if not form.is_valid():
return HttpResponse(content=form.errors.as_json(), status=400)
user = request.user
Expand Down
Loading