Skip to content

Commit

Permalink
Merge pull request #545 from internetstandards/error_handling
Browse files Browse the repository at this point in the history
Suggest subdomains should be a GET interface instead of POST
  • Loading branch information
aequitas authored Nov 19, 2024
2 parents 6bf70fb + b9a66c0 commit 1f85418
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions dashboard/internet_nl_dashboard/tests/test_domain_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest
import responses
from constance.test import override_config
from django.contrib.auth.models import User
from websecmap.organizations.models import Url

from dashboard.internet_nl_dashboard.logic.domains import (ServerError, add_domains_from_raw_user_data, clean_urls,
Expand Down Expand Up @@ -38,6 +39,24 @@ def test_suggest_subdomains(db, caplog):
suggest_subdomains("broken.nl")


@responses.activate
def test_suggest_subdomains_http(db, client):
responses.add(responses.GET, 'http://localhost:8001/?domain=test&suffix=nl&period=370', json=["test"], status=200)
responses.add(responses.GET, 'http://localhost:8001/?domain=notexisting&suffix=nl&period=370', json=[], status=404)
responses.add(responses.GET, 'http://localhost:8001/?domain=broken&suffix=nl&period=370', json=[], status=500)

assert client.get("/data/urllist/suggest-subdomains/",
{"domain": "test.nl"}).status_code == 302, \
"unauthenticated request should result in login redirect"

user = User.objects.create(username="test")
client.force_login(user)

response = client.get("/data/urllist/suggest-subdomains/", {"domain": "test.nl"})
print(response)
assert response.json() == ["test"]


@override_config(DASHBOARD_MAXIMUM_DOMAINS_PER_LIST=5000)
def test_add_domains_from_raw_user_data(db, current_path, redis_server):
"""
Expand Down
6 changes: 3 additions & 3 deletions dashboard/internet_nl_dashboard/views/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

@login_required(login_url=LOGIN_URL)
def suggest_subdomains_(request) -> JsonResponse:
request = get_json_body(request)
domain = request.get("domain", "")
period = request.get("period", 370)
domain = request.GET.get("domain", "")
period = request.GET.get("period", 370)

try:
result = JsonResponse(suggest_subdomains(domain, period), encoder=JSEncoder, safe=False)
except ValueError:
Expand Down

0 comments on commit 1f85418

Please sign in to comment.