diff --git a/src/api/tests/test_rdap.py b/src/api/tests/test_rdap.py new file mode 100644 index 000000000..bd442be90 --- /dev/null +++ b/src/api/tests/test_rdap.py @@ -0,0 +1,40 @@ +"""Test the domain rdap lookup API.""" + +import json + +from django.contrib.auth import get_user_model +from django.test import RequestFactory +from django.test import TestCase + +from ..views import available, check_domain_available +from .common import less_console_noise +from registrar.utility.errors import GenericError, GenericErrorCodes +from unittest.mock import call + +from epplibwrapper import ( + commands, +) + +API_BASE_PATH = "/api/v1/rdap/?domain=" + +class RdapAPITest(MockEppLib): + """Test that the RDAP API can be called as expected.""" + + def setUp(self): + super().setUp() + username = "test_user" + first_name = "First" + last_name = "Last" + email = "info@example.com" + title = "title" + phone = "8080102431" + self.user = get_user_model().objects.create( + username=username, title=title, first_name=first_name, last_name=last_name, email=email, phone=phone + ) + + def test_rdap_get(self): + self.client.force_login(self.user) + response = self.client.get(API_BASE_PATH + "whitehouse.gov") + self.assertContains(response, "RDAP") + response_object = json.loads(response.content) + self.assertIn("RDAP", response_object) \ No newline at end of file diff --git a/src/api/views.py b/src/api/views.py index 5c3b4c525..50a537517 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -108,6 +108,10 @@ def rdap(request, domain=""): Domain = apps.get_model("registrar.Domain") domain = request.GET.get("domain", "") + # If inputted domain doesn't have a TLD, append .gov to it + if "." not in domain: + domain = f"{domain}.gov" + rdap_data = requests.get(RDAP_URL.format(domain=domain)).json() return JsonResponse(rdap_data)