mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-06-05 03:57:25 +02:00
changed endpoint for check availability to pass domain as parameter; wrote unit test for extra dot validation in form
This commit is contained in:
parent
1c836576e5
commit
5811448450
4 changed files with 22 additions and 2 deletions
|
@ -82,6 +82,7 @@ def available(request, domain=""):
|
||||||
Response is a JSON dictionary with the key "available" and value true or
|
Response is a JSON dictionary with the key "available" and value true or
|
||||||
false.
|
false.
|
||||||
"""
|
"""
|
||||||
|
domain = request.GET.get('domain', '')
|
||||||
DraftDomain = apps.get_model("registrar.DraftDomain")
|
DraftDomain = apps.get_model("registrar.DraftDomain")
|
||||||
# validate that the given domain could be a domain name and fail early if
|
# validate that the given domain could be a domain name and fail early if
|
||||||
# not.
|
# not.
|
||||||
|
|
|
@ -73,6 +73,7 @@ function debounce(handler, cooldown=600) {
|
||||||
|
|
||||||
/** Asyncronously fetches JSON. No error handling. */
|
/** Asyncronously fetches JSON. No error handling. */
|
||||||
function fetchJSON(endpoint, callback, url="/api/v1/") {
|
function fetchJSON(endpoint, callback, url="/api/v1/") {
|
||||||
|
console.log("fetchJSON called for endpoint " + endpoint);
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', url + endpoint);
|
xhr.open('GET', url + endpoint);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
@ -142,7 +143,7 @@ function _checkDomainAvailability(el) {
|
||||||
inlineToast(el.parentElement, el.id, ERROR, response.message);
|
inlineToast(el.parentElement, el.id, ERROR, response.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetchJSON(`available/${el.value}`, callback);
|
fetchJSON(`available/?domain=${el.value}`, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Call the API to see if the domain is good. */
|
/** Call the API to see if the domain is good. */
|
||||||
|
|
|
@ -72,7 +72,7 @@ urlpatterns = [
|
||||||
path("health/", views.health),
|
path("health/", views.health),
|
||||||
path("openid/", include("djangooidc.urls")),
|
path("openid/", include("djangooidc.urls")),
|
||||||
path("register/", include((application_urls, APPLICATION_NAMESPACE))),
|
path("register/", include((application_urls, APPLICATION_NAMESPACE))),
|
||||||
path("api/v1/available/<domain>", available, name="available"),
|
path("api/v1/available/", available, name="available"),
|
||||||
path(
|
path(
|
||||||
"todo",
|
"todo",
|
||||||
lambda r: always_404(r, "We forgot to include this link, sorry."),
|
lambda r: always_404(r, "We forgot to include this link, sorry."),
|
||||||
|
|
|
@ -74,6 +74,24 @@ class TestFormValidation(MockEppLib):
|
||||||
["Enter the .gov domain you want without any periods."],
|
["Enter the .gov domain you want without any periods."],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_requested_domain_two_dots_invalid(self):
|
||||||
|
"""don't accept domains that are subdomains"""
|
||||||
|
form = DotGovDomainForm(data={"requested_domain": "sub.top-level-agency.gov"})
|
||||||
|
self.assertEqual(
|
||||||
|
form.errors["requested_domain"],
|
||||||
|
["Enter the .gov domain you want without any periods."],
|
||||||
|
)
|
||||||
|
form = DotGovDomainForm(data={"requested_domain": ".top-level-agency.gov"})
|
||||||
|
self.assertEqual(
|
||||||
|
form.errors["requested_domain"],
|
||||||
|
["Enter the .gov domain you want without any periods."],
|
||||||
|
)
|
||||||
|
form = DotGovDomainForm(data={"requested_domain": "..gov"})
|
||||||
|
self.assertEqual(
|
||||||
|
form.errors["requested_domain"],
|
||||||
|
["Enter the .gov domain you want without any periods."],
|
||||||
|
)
|
||||||
|
|
||||||
def test_requested_domain_invalid_characters(self):
|
def test_requested_domain_invalid_characters(self):
|
||||||
"""must be a valid .gov domain name."""
|
"""must be a valid .gov domain name."""
|
||||||
form = DotGovDomainForm(data={"requested_domain": "underscores_forever"})
|
form = DotGovDomainForm(data={"requested_domain": "underscores_forever"})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue