diff --git a/ops/scripts/manifest-sandbox-template.yaml b/ops/scripts/manifest-sandbox-template.yaml index 1bf979c9f..a521aab09 100644 --- a/ops/scripts/manifest-sandbox-template.yaml +++ b/ops/scripts/manifest-sandbox-template.yaml @@ -11,6 +11,7 @@ applications: command: ./run.sh health-check-type: http health-check-http-endpoint: /health + health-check-invocation-timeout: 30 env: # Send stdout and stderr straight to the terminal without buffering PYTHONUNBUFFERED: yup diff --git a/src/registrar/models/domain.py b/src/registrar/models/domain.py index 8eb09c9ca..7c044f86b 100644 --- a/src/registrar/models/domain.py +++ b/src/registrar/models/domain.py @@ -514,7 +514,9 @@ class Domain(TimeStampedModel, DomainHelper): .filter(domain=self, contact_type=contact.contact_type) .get() ) - logger.info(f"_set_singleton_contact() -> existing contact is... {existing_contact.__dict__}") + logger.info( + f"_set_singleton_contact() -> existing contact is... {existing_contact.__dict__}" + ) if isRegistrant: # send update domain only for registant contacts existing_contact.delete() @@ -664,7 +666,11 @@ class Domain(TimeStampedModel, DomainHelper): # I'm sure though that there is an easier alternative... # TLDR: This doesn't look as pretty, but it makes using this function easier def map_epp_contact_to_public_contact( - self, contact: eppInfo.InfoContactResultData, contact_id, contact_type, create_object=True + self, + contact: eppInfo.InfoContactResultData, + contact_id, + contact_type, + create_object=True, ): """Maps the Epp contact representation to a PublicContact object. @@ -685,7 +691,7 @@ class Domain(TimeStampedModel, DomainHelper): if contact_id is None: raise ValueError("contact_id is None") - + if len(contact_id) > 16 or len(contact_id) < 1: raise ValueError( "contact_id is of invalid length. " @@ -728,18 +734,21 @@ class Domain(TimeStampedModel, DomainHelper): sp=addr.sp, **streets, ) - db_contact = PublicContact.objects.filter(registry_id=contact_id, contact_type=contact_type, domain=self) + db_contact = PublicContact.objects.filter( + registry_id=contact_id, contact_type=contact_type, domain=self + ) # Saves to DB - if(create_object and db_contact.count() == 0): + if create_object and db_contact.count() == 0: + # Doesn't run custom save logic, just saves to DB desired_contact.save(skip_epp_save=True) logger.debug(f"Created a new PublicContact: {desired_contact}") return desired_contact - if(db_contact.count() == 1): + if db_contact.count() == 1: return db_contact.get() return desired_contact - + def _request_contact_info(self, contact: PublicContact): try: req = commands.InfoContact(id=contact.registry_id) @@ -751,7 +760,7 @@ class Domain(TimeStampedModel, DomainHelper): contact.contact_type, error.code, error, - ) # noqa + ) # noqa raise error def get_contact_default( @@ -844,13 +853,13 @@ class Domain(TimeStampedModel, DomainHelper): For example, check_type = 'security' """ # Registrant doesn't exist as an array - if(check_type == PublicContact.ContactTypeChoices.REGISTRANT): + if check_type == PublicContact.ContactTypeChoices.REGISTRANT: if ( isinstance(contacts, PublicContact) and contacts.contact_type is not None and contacts.contact_type == check_type ): - if(contacts.registry_id is None): + if contacts.registry_id is None: raise ValueError("registry_id cannot be None") return contacts else: @@ -863,7 +872,7 @@ class Domain(TimeStampedModel, DomainHelper): and contact.contact_type is not None and contact.contact_type == check_type ): - if(contact.registry_id is None): + if contact.registry_id is None: raise ValueError("registry_id cannot be None") return contact @@ -1162,7 +1171,9 @@ class Domain(TimeStampedModel, DomainHelper): if "registrant" in cleaned.keys(): # Registrant, if it exists, should always exist in EppLib. # If it doesn't, that is bad. We expect this to exist - cleaned["registrant"] = self._registrant_to_public_contact(cleaned["registrant"]) + cleaned["registrant"] = self._registrant_to_public_contact( + cleaned["registrant"] + ) if ( # fetch_contacts and @@ -1213,7 +1224,9 @@ class Domain(TimeStampedModel, DomainHelper): "tr_date": getattr(data, "tr_date", ...), "up_date": getattr(data, "up_date", ...), } - cleaned["hosts"].append({k: v for k, v in host.items() if v is not ...}) + cleaned["hosts"].append( + {k: v for k, v in host.items() if v is not ...} + ) # replace the prior cache with new data self._cache = cleaned @@ -1221,10 +1234,10 @@ class Domain(TimeStampedModel, DomainHelper): logger.error(e) def _registrant_to_public_contact(self, registry_id: str): - """ EPPLib returns the registrant as a string, + """EPPLib returns the registrant as a string, which is the registrants associated registry_id. This function is used to - convert that id to a useable object by calling commands.InfoContact - on that ID, then mapping that object to type PublicContact. """ + convert that id to a useable object by calling commands.InfoContact + on that ID, then mapping that object to type PublicContact.""" contact = PublicContact( registry_id=registry_id, contact_type=PublicContact.ContactTypeChoices.REGISTRANT, @@ -1243,7 +1256,9 @@ class Domain(TimeStampedModel, DomainHelper): def _get_property(self, property): """Get some piece of info about a domain.""" - logger.info(f"_get_property() -> prop is... {property} prop in cache... {property not in self._cache} cache is {self._cache}") + logger.info( + f"_get_property() -> prop is... {property} prop in cache... {property not in self._cache} cache is {self._cache}" + ) if property not in self._cache: self._fetch_cache( fetch_hosts=(property == "hosts"), diff --git a/src/registrar/models/public_contact.py b/src/registrar/models/public_contact.py index 6d6890cdb..b99bd1098 100644 --- a/src/registrar/models/public_contact.py +++ b/src/registrar/models/public_contact.py @@ -29,7 +29,7 @@ class PublicContact(TimeStampedModel): def save(self, *args, **kwargs): """Save to the registry and also locally in the registrar database.""" - skip_epp_save = kwargs.pop('skip_epp_save', False) + skip_epp_save = kwargs.pop("skip_epp_save", False) if hasattr(self, "domain") and not skip_epp_save: match self.contact_type: case PublicContact.ContactTypeChoices.REGISTRANT: diff --git a/src/registrar/templates/domain_security_email.html b/src/registrar/templates/domain_security_email.html index dbd257d86..deb54764e 100644 --- a/src/registrar/templates/domain_security_email.html +++ b/src/registrar/templates/domain_security_email.html @@ -21,7 +21,7 @@ + >{% if domain.security_contact is None or domain.security_contact.email == 'dotgov@cisa.dhs.gov'%}Add security email{% else %}Save{% endif %} {% endblock %} {# domain_content #} diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py index 2fe51b713..a8d919c9b 100644 --- a/src/registrar/tests/common.py +++ b/src/registrar/tests/common.py @@ -549,14 +549,13 @@ class MockEppLib(TestCase): """""" def __init__( - self, auth_info=..., cr_date=..., contacts=..., hosts=..., statuses=..., - registrant=... + registrant=..., ): self.auth_info = auth_info self.cr_date = cr_date @@ -619,7 +618,11 @@ class MockEppLib(TestCase): mockDataInfoDomain = fakedEppObject( "lastPw", cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35), - contacts=[common.DomainContact(contact="123", type=PublicContact.ContactTypeChoices.SECURITY)], + contacts=[ + common.DomainContact( + contact="123", type=PublicContact.ContactTypeChoices.SECURITY + ) + ], hosts=["fake.host.com"], statuses=[ common.Status(state="serverTransferProhibited", description="", lang="en"), @@ -630,9 +633,18 @@ class MockEppLib(TestCase): "fakepw", cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35), contacts=[ - common.DomainContact(contact="securityContact", type=PublicContact.ContactTypeChoices.SECURITY), - common.DomainContact(contact="technicalContact", type=PublicContact.ContactTypeChoices.TECHNICAL), - common.DomainContact(contact="adminContact", type=PublicContact.ContactTypeChoices.ADMINISTRATIVE), + common.DomainContact( + contact="securityContact", + type=PublicContact.ContactTypeChoices.SECURITY, + ), + common.DomainContact( + contact="technicalContact", + type=PublicContact.ContactTypeChoices.TECHNICAL, + ), + common.DomainContact( + contact="adminContact", + type=PublicContact.ContactTypeChoices.ADMINISTRATIVE, + ), ], hosts=["fake.host.com"], statuses=[ diff --git a/src/registrar/tests/test_models_domain.py b/src/registrar/tests/test_models_domain.py index da6f6f6bf..272b5936e 100644 --- a/src/registrar/tests/test_models_domain.py +++ b/src/registrar/tests/test_models_domain.py @@ -22,6 +22,7 @@ from epplibwrapper import ( common, ) import logging + logger = logging.getLogger(__name__) @@ -30,10 +31,10 @@ class TestDomainCache(MockEppLib): PublicContact.objects.all().delete() Domain.objects.all().delete() super().tearDown() + def test_cache_sets_resets(self): """Cache should be set on getter and reset on setter calls""" domain, _ = Domain.objects.get_or_create(name="igorville.gov") - self.maxDiff = None # trigger getter _ = domain.creation_date domain._get_property("contacts") @@ -51,9 +52,12 @@ class TestDomainCache(MockEppLib): # send should have been called only once self.mockedSendFunction.assert_has_calls( [ - call(commands.InfoDomain(name='igorville.gov', auth_info=None), cleaned=True), - call(commands.InfoContact(id='123', auth_info=None), cleaned=True), - call(commands.InfoHost(name='fake.host.com'), cleaned=True) + call( + commands.InfoDomain(name="igorville.gov", auth_info=None), + cleaned=True, + ), + call(commands.InfoContact(id="123", auth_info=None), cleaned=True), + call(commands.InfoHost(name="fake.host.com"), cleaned=True), ], any_order=False, # Ensure calls are in the specified order ) @@ -69,7 +73,7 @@ class TestDomainCache(MockEppLib): # value should still be set correctly self.assertEqual(cr_date, self.mockDataInfoDomain.cr_date) self.assertEqual(domain._cache["cr_date"], self.mockDataInfoDomain.cr_date) - + # send was only called once & not on the second getter call expectedCalls = [ call( @@ -90,9 +94,7 @@ class TestDomainCache(MockEppLib): expectedUnfurledContactsList = [ common.DomainContact(contact="123", type="security"), ] - expectedContactsList = [ - domain.security_contact - ] + expectedContactsList = [domain.security_contact] expectedHostsDict = { "name": self.mockDataInfoDomain.hosts[0], "cr_date": self.mockDataInfoDomain.cr_date, @@ -111,10 +113,7 @@ class TestDomainCache(MockEppLib): # as _fetch_cache will transform the type to PublicContact self.assertNotEqual(domain._cache["contacts"], expectedUnfurledContactsList) - self.assertEqual( - domain._cache["contacts"], - expectedContactsList - ) + self.assertEqual(domain._cache["contacts"], expectedContactsList) # get and check hosts is set correctly domain._get_property("hosts") @@ -126,10 +125,11 @@ class TestDomainCache(MockEppLib): mapped = domain.map_epp_contact_to_public_contact( self.mockDataInfoContact, self.mockDataInfoContact.id, - PublicContact.ContactTypeChoices.SECURITY + PublicContact.ContactTypeChoices.SECURITY, ) + expected_contact = PublicContact( - id=1, + id=4, domain=domain, contact_type=PublicContact.ContactTypeChoices.SECURITY, registry_id="123", @@ -143,7 +143,7 @@ class TestDomainCache(MockEppLib): pc="22201", cc="US", sp="VA", - street1="4200 Wilson Blvd." + street1="4200 Wilson Blvd.", ) # Match when these both were updated/created expected_contact.updated_at = mapped.updated_at @@ -153,7 +153,7 @@ class TestDomainCache(MockEppLib): in_db = PublicContact.objects.filter( registry_id=domain.security_contact.registry_id, - contact_type = PublicContact.ContactTypeChoices.SECURITY + contact_type=PublicContact.ContactTypeChoices.SECURITY, ).get() # DB Object is the same as the mapped object self.assertEqual(mapped, in_db) @@ -161,12 +161,12 @@ class TestDomainCache(MockEppLib): mapped_second = domain.map_epp_contact_to_public_contact( self.mockDataInfoContact, self.mockDataInfoContact.id, - PublicContact.ContactTypeChoices.SECURITY + PublicContact.ContactTypeChoices.SECURITY, ) in_db_once = PublicContact.objects.filter( registry_id=domain.security_contact.registry_id, - contact_type = PublicContact.ContactTypeChoices.SECURITY + contact_type=PublicContact.ContactTypeChoices.SECURITY, ) self.assertEqual(mapped_second, in_db) # If mapper is called a second time, @@ -275,7 +275,9 @@ class TestDomainStatuses(MockEppLib): _ = domain.statuses status_list = [status.state for status in self.mockDataInfoDomain.statuses] self.assertEquals(domain._cache["statuses"], status_list) - expectedCreateContact = self._convertPublicContactToEpp(domain.security_contact, True, createContact=True) + expectedCreateContact = self._convertPublicContactToEpp( + domain.security_contact, True, createContact=True + ) # Called in _fetch_cache self.mockedSendFunction.assert_has_calls( [ @@ -328,7 +330,7 @@ class TestDomainStatuses(MockEppLib): class TestRegistrantContacts(MockEppLib): """Rule: Registrants may modify their WHOIS data""" - + def setUp(self): """ Background: @@ -552,7 +554,6 @@ class TestRegistrantContacts(MockEppLib): security_contact = self.domain.get_default_security_contact() security_contact.email = "originalUserEmail@gmail.com" security_contact.registry_id = "fail" - security_contact.save() self.domain.security_contact = security_contact expectedCreateCommand = self._convertPublicContactToEpp( @@ -575,7 +576,6 @@ class TestRegistrantContacts(MockEppLib): updateContact = self._convertPublicContactToEpp( security_contact, disclose_email=True, createContact=False ) - expected_calls = [ call(expectedCreateCommand, cleaned=True), call(expectedUpdateDomain, cleaned=True), @@ -616,11 +616,13 @@ class TestRegistrantContacts(MockEppLib): # Create prexisting object... expected_security_contact = PublicContact.objects.filter( registry_id=self.domain_contact.security_contact.registry_id, - contact_type = PublicContact.ContactTypeChoices.SECURITY + contact_type=PublicContact.ContactTypeChoices.SECURITY, ).get() # Checks if we grab the correct PublicContact... - self.assertEqual(self.domain_contact.security_contact, expected_security_contact) + self.assertEqual( + self.domain_contact.security_contact, expected_security_contact + ) self.mockedSendFunction.assert_has_calls( [ call( @@ -630,12 +632,14 @@ class TestRegistrantContacts(MockEppLib): ] ) # Checks if we are recieving the cache we expect... - self.assertEqual(self.domain_contact._cache["contacts"][0], expected_security_contact) + self.assertEqual( + self.domain_contact._cache["contacts"][0], expected_security_contact + ) def test_contact_getter_technical(self): expected_contact = PublicContact.objects.filter( registry_id=self.domain_contact.technical_contact.registry_id, - contact_type = PublicContact.ContactTypeChoices.TECHNICAL + contact_type=PublicContact.ContactTypeChoices.TECHNICAL, ).get() # Checks if we grab the correct PublicContact... @@ -654,7 +658,7 @@ class TestRegistrantContacts(MockEppLib): def test_contact_getter_administrative(self): expected_contact = PublicContact.objects.filter( registry_id=self.domain_contact.administrative_contact.registry_id, - contact_type = PublicContact.ContactTypeChoices.ADMINISTRATIVE + contact_type=PublicContact.ContactTypeChoices.ADMINISTRATIVE, ).get() # Checks if we grab the correct PublicContact... @@ -673,7 +677,7 @@ class TestRegistrantContacts(MockEppLib): def test_contact_getter_registrant(self): expected_contact = PublicContact.objects.filter( registry_id=self.domain_contact.registrant_contact.registry_id, - contact_type = PublicContact.ContactTypeChoices.REGISTRANT + contact_type=PublicContact.ContactTypeChoices.REGISTRANT, ).get() # Checks if we grab the correct PublicContact...