mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-06 19:23:23 +02:00
Handle domains without TLD
This commit is contained in:
parent
3f7dbd5f6e
commit
919fbbfd2f
2 changed files with 44 additions and 0 deletions
40
src/api/tests/test_rdap.py
Normal file
40
src/api/tests/test_rdap.py
Normal 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)
|
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue