mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
handle 500 error with empty string
This commit is contained in:
parent
13c40cc333
commit
65813f448e
3 changed files with 32 additions and 12 deletions
|
@ -13,6 +13,7 @@ from typing import Any
|
||||||
from registrar.models.host import Host
|
from registrar.models.host import Host
|
||||||
from registrar.models.host_ip import HostIP
|
from registrar.models.host_ip import HostIP
|
||||||
from registrar.utility.enums import DefaultEmail
|
from registrar.utility.enums import DefaultEmail
|
||||||
|
from registrar.utility import errors
|
||||||
|
|
||||||
from registrar.utility.errors import (
|
from registrar.utility.errors import (
|
||||||
ActionNotAllowed,
|
ActionNotAllowed,
|
||||||
|
@ -192,9 +193,17 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def available(cls, domain: str) -> bool:
|
def available(cls, domain: str) -> bool:
|
||||||
"""Check if a domain is available."""
|
"""Check if a domain is available.
|
||||||
|
This is called by the availablility api and
|
||||||
|
is called in the validate function on the request/domain page
|
||||||
|
|
||||||
|
throws- RegistryError or InvalidDomainError"""
|
||||||
if not cls.string_could_be_domain(domain):
|
if not cls.string_could_be_domain(domain):
|
||||||
raise ValueError("Not a valid domain: %s" % str(domain))
|
logger.warning("Not a valid domain: %s" % str(domain))
|
||||||
|
# throw invalid domain error so that it can be caught in
|
||||||
|
# validate_and_handle_errors in domain_helper
|
||||||
|
raise errors.InvalidDomainError()
|
||||||
|
|
||||||
domain_name = domain.lower()
|
domain_name = domain.lower()
|
||||||
req = commands.CheckDomain([domain_name])
|
req = commands.CheckDomain([domain_name])
|
||||||
return registry.send(req, cleaned=True).res_data[0].avail
|
return registry.send(req, cleaned=True).res_data[0].avail
|
||||||
|
|
|
@ -33,11 +33,12 @@ class DomainHelper:
|
||||||
# Split into pieces for the linter
|
# Split into pieces for the linter
|
||||||
domain = cls._validate_domain_string(domain, blank_ok)
|
domain = cls._validate_domain_string(domain, blank_ok)
|
||||||
|
|
||||||
try:
|
if domain != "":
|
||||||
if not check_domain_available(domain):
|
try:
|
||||||
raise errors.DomainUnavailableError()
|
if not check_domain_available(domain):
|
||||||
except RegistryError as err:
|
raise errors.DomainUnavailableError()
|
||||||
raise errors.RegistrySystemError() from err
|
except RegistryError as err:
|
||||||
|
raise errors.RegistrySystemError() from err
|
||||||
return domain
|
return domain
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -20,7 +20,7 @@ from registrar.models.user import User
|
||||||
from registrar.utility.errors import ActionNotAllowed, NameserverError
|
from registrar.utility.errors import ActionNotAllowed, NameserverError
|
||||||
|
|
||||||
from registrar.models.utility.contact_error import ContactError, ContactErrorCodes
|
from registrar.models.utility.contact_error import ContactError, ContactErrorCodes
|
||||||
|
from registrar.utility import errors
|
||||||
|
|
||||||
from django_fsm import TransitionNotAllowed # type: ignore
|
from django_fsm import TransitionNotAllowed # type: ignore
|
||||||
from epplibwrapper import (
|
from epplibwrapper import (
|
||||||
|
@ -502,16 +502,26 @@ class TestDomainAvailable(MockEppLib):
|
||||||
self.assertFalse(available)
|
self.assertFalse(available)
|
||||||
patcher.stop()
|
patcher.stop()
|
||||||
|
|
||||||
def test_domain_available_with_value_error(self):
|
def test_domain_available_with_invalid_error(self):
|
||||||
"""
|
"""
|
||||||
Scenario: Testing whether an invalid domain is available
|
Scenario: Testing whether an invalid domain is available
|
||||||
Should throw ValueError
|
Should throw InvalidDomainError
|
||||||
|
|
||||||
Validate ValueError is raised
|
Validate InvalidDomainError is raised
|
||||||
"""
|
"""
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(errors.InvalidDomainError()):
|
||||||
Domain.available("invalid-string")
|
Domain.available("invalid-string")
|
||||||
|
|
||||||
|
def test_domain_available_with_empty_string(self):
|
||||||
|
"""
|
||||||
|
Scenario: Testing whether an empty string domain name is available
|
||||||
|
Should throw InvalidDomainError
|
||||||
|
|
||||||
|
Validate InvalidDomainError is raised
|
||||||
|
"""
|
||||||
|
with self.assertRaises(errors.InvalidDomainError()):
|
||||||
|
Domain.available("")
|
||||||
|
|
||||||
def test_domain_available_unsuccessful(self):
|
def test_domain_available_unsuccessful(self):
|
||||||
"""
|
"""
|
||||||
Scenario: Testing behavior when registry raises a RegistryError
|
Scenario: Testing behavior when registry raises a RegistryError
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue