Handle domains without TLD

This commit is contained in:
Erin Song 2024-09-24 11:01:53 -07:00
parent 3f7dbd5f6e
commit 919fbbfd2f
No known key found for this signature in database
2 changed files with 44 additions and 0 deletions

View file

@ -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)

View file

@ -108,6 +108,10 @@ def rdap(request, domain=""):
Domain = apps.get_model("registrar.Domain") Domain = apps.get_model("registrar.Domain")
domain = request.GET.get("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() rdap_data = requests.get(RDAP_URL.format(domain=domain)).json()
return JsonResponse(rdap_data) return JsonResponse(rdap_data)