mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-15 17:17:02 +02:00
merging in main
This commit is contained in:
commit
835e158d2d
13 changed files with 764 additions and 140 deletions
37
.github/ISSUE_TEMPLATE/issue-default.yml
vendored
37
.github/ISSUE_TEMPLATE/issue-default.yml
vendored
|
@ -1,34 +1,35 @@
|
||||||
name: Issue
|
name: Issue
|
||||||
description: Capture uncategorized work or content
|
description: Describe an idea, feature, content, or non-bug finding
|
||||||
|
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
id: help
|
id: title-help
|
||||||
attributes:
|
attributes:
|
||||||
value: |
|
value: |
|
||||||
> **Note**
|
> Titles should be short, descriptive, and compelling.
|
||||||
> GitHub Issues use [GitHub Flavored Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) for formatting.
|
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: issue
|
id: issue-description
|
||||||
attributes:
|
attributes:
|
||||||
label: Issue Description
|
label: Issue description and context
|
||||||
description: |
|
description: |
|
||||||
Describe the issue you are adding or content you are suggesting.
|
Describe the issue so that someone who wasn't present for its discovery can understand the problem and why it matters. Use full sentences, plain language, and good [formatting](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax). Share desired outcomes or potential next steps. Images or links to other content/context (like documents or Slack discussions) are welcome.
|
||||||
Share any next steps that should be taken our outcomes that would be beneficial.
|
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: additional-context
|
id: acceptance-criteria
|
||||||
attributes:
|
attributes:
|
||||||
label: Additional Context (optional)
|
label: Acceptance criteria
|
||||||
description: "Include additional references (screenshots, design links, documentation, etc.) that are relevant"
|
description: "If known, share 1-3 statements that would need to be true for this issue to be considered resolved. Use a [task list](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/about-task-lists#creating-task-lists) if appropriate."
|
||||||
|
placeholder: "- [ ] The button does the thing."
|
||||||
- type: textarea
|
- type: textarea
|
||||||
id: issue-links
|
id: links-to-other-issues
|
||||||
attributes:
|
attributes:
|
||||||
label: Issue Links
|
label: Links to other issues
|
||||||
description: |
|
description: |
|
||||||
What other issues does this story relate to and how?
|
Add the issue #number of other issues this relates to and how (e.g., 🚧 Blocks, ⛔️ Is blocked by, 🔄 Relates to).
|
||||||
|
placeholder: 🔄 Relates to...
|
||||||
Example:
|
- type: markdown
|
||||||
- 🚧 Blocked by: #123
|
id: note
|
||||||
- 🔄 Relates to: #234
|
attributes:
|
||||||
|
value: |
|
||||||
|
> We may edit this issue's text to document our understanding and clarify the product work.
|
||||||
|
|
|
@ -46,7 +46,7 @@ except NameError:
|
||||||
try:
|
try:
|
||||||
from .client import CLIENT, commands
|
from .client import CLIENT, commands
|
||||||
from .errors import RegistryError, ErrorCode
|
from .errors import RegistryError, ErrorCode
|
||||||
from epplib.models import common
|
from epplib.models import common, info
|
||||||
from epplib.responses import extensions
|
from epplib.responses import extensions
|
||||||
from epplib import responses
|
from epplib import responses
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -58,6 +58,7 @@ __all__ = [
|
||||||
"common",
|
"common",
|
||||||
"extensions",
|
"extensions",
|
||||||
"responses",
|
"responses",
|
||||||
|
"info",
|
||||||
"ErrorCode",
|
"ErrorCode",
|
||||||
"RegistryError",
|
"RegistryError",
|
||||||
]
|
]
|
||||||
|
|
17
src/registrar/migrations/0033_alter_userdomainrole_role.py
Normal file
17
src/registrar/migrations/0033_alter_userdomainrole_role.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-10-02 22:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0032_alter_transitiondomain_status"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="userdomainrole",
|
||||||
|
name="role",
|
||||||
|
field=models.TextField(choices=[("manager", "Admin")]),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,5 +1,5 @@
|
||||||
|
from itertools import zip_longest
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from string import digits
|
from string import digits
|
||||||
from django_fsm import FSMField, transition, TransitionNotAllowed # type: ignore
|
from django_fsm import FSMField, transition, TransitionNotAllowed # type: ignore
|
||||||
|
@ -11,9 +11,11 @@ from epplibwrapper import (
|
||||||
commands,
|
commands,
|
||||||
common as epp,
|
common as epp,
|
||||||
extensions,
|
extensions,
|
||||||
|
info as eppInfo,
|
||||||
RegistryError,
|
RegistryError,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
)
|
)
|
||||||
|
from registrar.models.utility.contact_error import ContactError
|
||||||
|
|
||||||
from .utility.domain_field import DomainField
|
from .utility.domain_field import DomainField
|
||||||
from .utility.domain_helper import DomainHelper
|
from .utility.domain_helper import DomainHelper
|
||||||
|
@ -380,9 +382,9 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@Cache
|
@Cache
|
||||||
def registrant_contact(self) -> PublicContact:
|
def registrant_contact(self) -> PublicContact | None:
|
||||||
"""Get or set the registrant for this domain."""
|
registrant = PublicContact.ContactTypeChoices.REGISTRANT
|
||||||
raise NotImplementedError()
|
return self.generic_contact_getter(registrant)
|
||||||
|
|
||||||
@registrant_contact.setter # type: ignore
|
@registrant_contact.setter # type: ignore
|
||||||
def registrant_contact(self, contact: PublicContact):
|
def registrant_contact(self, contact: PublicContact):
|
||||||
|
@ -395,9 +397,10 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
)
|
)
|
||||||
|
|
||||||
@Cache
|
@Cache
|
||||||
def administrative_contact(self) -> PublicContact:
|
def administrative_contact(self) -> PublicContact | None:
|
||||||
"""Get or set the admin contact for this domain."""
|
"""Get the admin contact for this domain."""
|
||||||
raise NotImplementedError()
|
admin = PublicContact.ContactTypeChoices.ADMINISTRATIVE
|
||||||
|
return self.generic_contact_getter(admin)
|
||||||
|
|
||||||
@administrative_contact.setter # type: ignore
|
@administrative_contact.setter # type: ignore
|
||||||
def administrative_contact(self, contact: PublicContact):
|
def administrative_contact(self, contact: PublicContact):
|
||||||
|
@ -409,12 +412,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
self._make_contact_in_registry(contact=contact)
|
self._make_contact_in_registry(contact=contact)
|
||||||
self._update_domain_with_contact(contact, rem=False)
|
self._update_domain_with_contact(contact, rem=False)
|
||||||
|
|
||||||
def get_default_security_contact(self):
|
|
||||||
logger.info("getting default sec contact")
|
|
||||||
contact = PublicContact.get_default_security()
|
|
||||||
contact.domain = self
|
|
||||||
return contact
|
|
||||||
|
|
||||||
def _update_epp_contact(self, contact: PublicContact):
|
def _update_epp_contact(self, contact: PublicContact):
|
||||||
"""Sends UpdateContact to update the actual contact object,
|
"""Sends UpdateContact to update the actual contact object,
|
||||||
domain object remains unaffected
|
domain object remains unaffected
|
||||||
|
@ -468,26 +465,10 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
)
|
)
|
||||||
|
|
||||||
@Cache
|
@Cache
|
||||||
def security_contact(self) -> PublicContact:
|
def security_contact(self) -> PublicContact | None:
|
||||||
"""Get or set the security contact for this domain."""
|
"""Get or set the security contact for this domain."""
|
||||||
try:
|
security = PublicContact.ContactTypeChoices.SECURITY
|
||||||
contacts = self._get_property("contacts")
|
return self.generic_contact_getter(security)
|
||||||
for contact in contacts:
|
|
||||||
if (
|
|
||||||
"type" in contact.keys()
|
|
||||||
and contact["type"] == PublicContact.ContactTypeChoices.SECURITY
|
|
||||||
):
|
|
||||||
tempContact = self.get_default_security_contact()
|
|
||||||
tempContact.email = contact["email"]
|
|
||||||
return tempContact
|
|
||||||
|
|
||||||
except Exception as err: # use better error handling
|
|
||||||
logger.info("Couldn't get contact %s" % err)
|
|
||||||
|
|
||||||
# TODO - remove this ideally it should return None,
|
|
||||||
# but error handling needs to be
|
|
||||||
# added on the security email page so that it can handle it being none
|
|
||||||
return self.get_default_security_contact()
|
|
||||||
|
|
||||||
def _add_registrant_to_existing_domain(self, contact: PublicContact):
|
def _add_registrant_to_existing_domain(self, contact: PublicContact):
|
||||||
"""Used to change the registrant contact on an existing domain"""
|
"""Used to change the registrant contact on an existing domain"""
|
||||||
|
@ -561,6 +542,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
.filter(domain=self, contact_type=contact.contact_type)
|
.filter(domain=self, contact_type=contact.contact_type)
|
||||||
.get()
|
.get()
|
||||||
)
|
)
|
||||||
|
|
||||||
if isRegistrant:
|
if isRegistrant:
|
||||||
# send update domain only for registant contacts
|
# send update domain only for registant contacts
|
||||||
existing_contact.delete()
|
existing_contact.delete()
|
||||||
|
@ -617,9 +599,10 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
)
|
)
|
||||||
|
|
||||||
@Cache
|
@Cache
|
||||||
def technical_contact(self) -> PublicContact:
|
def technical_contact(self) -> PublicContact | None:
|
||||||
"""Get or set the tech contact for this domain."""
|
"""Get or set the tech contact for this domain."""
|
||||||
raise NotImplementedError()
|
tech = PublicContact.ContactTypeChoices.TECHNICAL
|
||||||
|
return self.generic_contact_getter(tech)
|
||||||
|
|
||||||
@technical_contact.setter # type: ignore
|
@technical_contact.setter # type: ignore
|
||||||
def technical_contact(self, contact: PublicContact):
|
def technical_contact(self, contact: PublicContact):
|
||||||
|
@ -702,6 +685,231 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
help_text="Very basic info about the lifecycle of this domain object",
|
help_text="Very basic info about the lifecycle of this domain object",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def isActive(self):
|
||||||
|
return self.state == Domain.State.CREATED
|
||||||
|
|
||||||
|
def map_epp_contact_to_public_contact(
|
||||||
|
self, contact: eppInfo.InfoContactResultData, contact_id, contact_type
|
||||||
|
):
|
||||||
|
"""Maps the Epp contact representation to a PublicContact object.
|
||||||
|
|
||||||
|
contact -> eppInfo.InfoContactResultData: The converted contact object
|
||||||
|
|
||||||
|
contact_id -> str: The given registry_id of the object (i.e "cheese@cia.gov")
|
||||||
|
|
||||||
|
contact_type -> str: The given contact type, (i.e. "tech" or "registrant")
|
||||||
|
"""
|
||||||
|
|
||||||
|
if contact is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if contact_type is None:
|
||||||
|
raise ContactError("contact_type is None")
|
||||||
|
|
||||||
|
if contact_id is None:
|
||||||
|
raise ContactError("contact_id is None")
|
||||||
|
|
||||||
|
# Since contact_id is registry_id,
|
||||||
|
# check that its the right length
|
||||||
|
contact_id_length = len(contact_id)
|
||||||
|
if (
|
||||||
|
contact_id_length > PublicContact.get_max_id_length()
|
||||||
|
or contact_id_length < 1
|
||||||
|
):
|
||||||
|
raise ContactError(
|
||||||
|
"contact_id is of invalid length. "
|
||||||
|
"Cannot exceed 16 characters, "
|
||||||
|
f"got {contact_id} with a length of {contact_id_length}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if not isinstance(contact, eppInfo.InfoContactResultData):
|
||||||
|
raise ContactError("Contact must be of type InfoContactResultData")
|
||||||
|
|
||||||
|
auth_info = contact.auth_info
|
||||||
|
postal_info = contact.postal_info
|
||||||
|
addr = postal_info.addr
|
||||||
|
streets = None
|
||||||
|
if addr is not None:
|
||||||
|
streets = addr.street
|
||||||
|
streets_kwargs = self._convert_streets_to_dict(streets)
|
||||||
|
desired_contact = PublicContact(
|
||||||
|
domain=self,
|
||||||
|
contact_type=contact_type,
|
||||||
|
registry_id=contact_id,
|
||||||
|
email=contact.email or "",
|
||||||
|
voice=contact.voice or "",
|
||||||
|
fax=contact.fax,
|
||||||
|
name=postal_info.name or "",
|
||||||
|
org=postal_info.org,
|
||||||
|
# For linter - default to "" instead of None
|
||||||
|
pw=getattr(auth_info, "pw", ""),
|
||||||
|
city=getattr(addr, "city", ""),
|
||||||
|
pc=getattr(addr, "pc", ""),
|
||||||
|
cc=getattr(addr, "cc", ""),
|
||||||
|
sp=getattr(addr, "sp", ""),
|
||||||
|
**streets_kwargs,
|
||||||
|
) # type: ignore
|
||||||
|
|
||||||
|
return desired_contact
|
||||||
|
|
||||||
|
def _convert_streets_to_dict(self, streets):
|
||||||
|
"""
|
||||||
|
Converts EPPLibs street representation
|
||||||
|
to PublicContacts.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
streets (Sequence[str]): Streets from EPPLib.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: {
|
||||||
|
"street1": str or "",
|
||||||
|
|
||||||
|
"street2": str or None,
|
||||||
|
|
||||||
|
"street3": str or None,
|
||||||
|
}
|
||||||
|
|
||||||
|
EPPLib returns 'street' as an sequence of strings.
|
||||||
|
Meanwhile, PublicContact has this split into three
|
||||||
|
seperate properties: street1, street2, street3.
|
||||||
|
|
||||||
|
Handles this disparity.
|
||||||
|
"""
|
||||||
|
# 'zips' two lists together.
|
||||||
|
# For instance, (('street1', 'some_value_here'),
|
||||||
|
# ('street2', 'some_value_here'))
|
||||||
|
# Dict then converts this to a useable kwarg which we can pass in
|
||||||
|
street_dict = dict(
|
||||||
|
zip_longest(
|
||||||
|
["street1", "street2", "street3"],
|
||||||
|
streets if streets is not None else [""],
|
||||||
|
fillvalue=None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return street_dict
|
||||||
|
|
||||||
|
def _request_contact_info(self, contact: PublicContact):
|
||||||
|
try:
|
||||||
|
req = commands.InfoContact(id=contact.registry_id)
|
||||||
|
return registry.send(req, cleaned=True).res_data[0]
|
||||||
|
except RegistryError as error:
|
||||||
|
logger.error(
|
||||||
|
"Registry threw error for contact id %s contact type is %s, error code is\n %s full error is %s", # noqa
|
||||||
|
contact.registry_id,
|
||||||
|
contact.contact_type,
|
||||||
|
error.code,
|
||||||
|
error,
|
||||||
|
)
|
||||||
|
raise error
|
||||||
|
|
||||||
|
def generic_contact_getter(
|
||||||
|
self, contact_type_choice: PublicContact.ContactTypeChoices
|
||||||
|
) -> PublicContact | None:
|
||||||
|
"""Retrieves the desired PublicContact from the registry.
|
||||||
|
This abstracts the caching and EPP retrieval for
|
||||||
|
all contact items and thus may result in EPP calls being sent.
|
||||||
|
|
||||||
|
contact_type_choice is a literal in PublicContact.ContactTypeChoices,
|
||||||
|
for instance: PublicContact.ContactTypeChoices.SECURITY.
|
||||||
|
|
||||||
|
If you wanted to setup getter logic for Security, you would call:
|
||||||
|
cache_contact_helper(PublicContact.ContactTypeChoices.SECURITY),
|
||||||
|
or cache_contact_helper("security").
|
||||||
|
|
||||||
|
"""
|
||||||
|
# registrant_contact(s) are an edge case. They exist on
|
||||||
|
# the "registrant" property as opposed to contacts.
|
||||||
|
desired_property = "contacts"
|
||||||
|
if contact_type_choice == PublicContact.ContactTypeChoices.REGISTRANT:
|
||||||
|
desired_property = "registrant"
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Grab from cache
|
||||||
|
contacts = self._get_property(desired_property)
|
||||||
|
except KeyError as error:
|
||||||
|
logger.error(f"Could not find {contact_type_choice}: {error}")
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
cached_contact = self.get_contact_in_keys(contacts, contact_type_choice)
|
||||||
|
if cached_contact is None:
|
||||||
|
# TODO - #1103
|
||||||
|
raise ContactError("No contact was found in cache or the registry")
|
||||||
|
|
||||||
|
return cached_contact
|
||||||
|
|
||||||
|
def get_default_security_contact(self):
|
||||||
|
"""Gets the default security contact."""
|
||||||
|
contact = PublicContact.get_default_security()
|
||||||
|
contact.domain = self
|
||||||
|
return contact
|
||||||
|
|
||||||
|
def get_default_administrative_contact(self):
|
||||||
|
"""Gets the default administrative contact."""
|
||||||
|
contact = PublicContact.get_default_administrative()
|
||||||
|
contact.domain = self
|
||||||
|
return contact
|
||||||
|
|
||||||
|
def get_default_technical_contact(self):
|
||||||
|
"""Gets the default technical contact."""
|
||||||
|
contact = PublicContact.get_default_technical()
|
||||||
|
contact.domain = self
|
||||||
|
return contact
|
||||||
|
|
||||||
|
def get_default_registrant_contact(self):
|
||||||
|
"""Gets the default registrant contact."""
|
||||||
|
contact = PublicContact.get_default_registrant()
|
||||||
|
contact.domain = self
|
||||||
|
return contact
|
||||||
|
|
||||||
|
def get_contact_in_keys(self, contacts, contact_type):
|
||||||
|
"""Gets a contact object.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
contacts ([PublicContact]): List of PublicContacts
|
||||||
|
contact_type (literal): Which PublicContact to get
|
||||||
|
Returns:
|
||||||
|
PublicContact | None
|
||||||
|
"""
|
||||||
|
# Registrant doesn't exist as an array, and is of
|
||||||
|
# a special data type, so we need to handle that.
|
||||||
|
if contact_type == PublicContact.ContactTypeChoices.REGISTRANT:
|
||||||
|
desired_contact = None
|
||||||
|
if isinstance(contacts, str):
|
||||||
|
desired_contact = self._registrant_to_public_contact(
|
||||||
|
self._cache["registrant"]
|
||||||
|
)
|
||||||
|
# Set the cache with the updated object
|
||||||
|
# for performance reasons.
|
||||||
|
if "registrant" in self._cache:
|
||||||
|
self._cache["registrant"] = desired_contact
|
||||||
|
elif isinstance(contacts, PublicContact):
|
||||||
|
desired_contact = contacts
|
||||||
|
|
||||||
|
return self._handle_registrant_contact(desired_contact)
|
||||||
|
|
||||||
|
_registry_id: str
|
||||||
|
if contact_type in contacts:
|
||||||
|
_registry_id = contacts.get(contact_type)
|
||||||
|
|
||||||
|
desired = PublicContact.objects.filter(
|
||||||
|
registry_id=_registry_id, domain=self, contact_type=contact_type
|
||||||
|
)
|
||||||
|
|
||||||
|
if desired.count() == 1:
|
||||||
|
return desired.get()
|
||||||
|
|
||||||
|
logger.info(f"Requested contact {_registry_id} does not exist in cache.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _handle_registrant_contact(self, contact):
|
||||||
|
if (
|
||||||
|
contact.contact_type is not None
|
||||||
|
and contact.contact_type == PublicContact.ContactTypeChoices.REGISTRANT
|
||||||
|
):
|
||||||
|
return contact
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid contact object for registrant_contact")
|
||||||
|
|
||||||
# ForeignKey on UserDomainRole creates a "permissions" member for
|
# ForeignKey on UserDomainRole creates a "permissions" member for
|
||||||
# all of the user-roles that are in place for this domain
|
# all of the user-roles that are in place for this domain
|
||||||
|
|
||||||
|
@ -800,12 +1008,10 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
security_contact = self.get_default_security_contact()
|
security_contact = self.get_default_security_contact()
|
||||||
security_contact.save()
|
security_contact.save()
|
||||||
|
|
||||||
technical_contact = PublicContact.get_default_technical()
|
technical_contact = self.get_default_technical_contact()
|
||||||
technical_contact.domain = self
|
|
||||||
technical_contact.save()
|
technical_contact.save()
|
||||||
|
|
||||||
administrative_contact = PublicContact.get_default_administrative()
|
administrative_contact = self.get_default_administrative_contact()
|
||||||
administrative_contact.domain = self
|
|
||||||
administrative_contact.save()
|
administrative_contact.save()
|
||||||
|
|
||||||
@transition(
|
@transition(
|
||||||
|
@ -949,16 +1155,34 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
)
|
)
|
||||||
return err.code
|
return err.code
|
||||||
|
|
||||||
def _request_contact_info(self, contact: PublicContact):
|
def _fetch_contacts(self, contact_data):
|
||||||
req = commands.InfoContact(id=contact.registry_id)
|
"""Fetch contact info."""
|
||||||
return registry.send(req, cleaned=True).res_data[0]
|
choices = PublicContact.ContactTypeChoices
|
||||||
|
# We expect that all these fields get populated,
|
||||||
|
# so we can create these early, rather than waiting.
|
||||||
|
contacts_dict = {
|
||||||
|
choices.ADMINISTRATIVE: None,
|
||||||
|
choices.SECURITY: None,
|
||||||
|
choices.TECHNICAL: None,
|
||||||
|
}
|
||||||
|
for domainContact in contact_data:
|
||||||
|
req = commands.InfoContact(id=domainContact.contact)
|
||||||
|
data = registry.send(req, cleaned=True).res_data[0]
|
||||||
|
|
||||||
|
# Map the object we recieved from EPP to a PublicContact
|
||||||
|
mapped_object = self.map_epp_contact_to_public_contact(
|
||||||
|
data, domainContact.contact, domainContact.type
|
||||||
|
)
|
||||||
|
|
||||||
|
# Find/create it in the DB
|
||||||
|
in_db = self._get_or_create_public_contact(mapped_object)
|
||||||
|
contacts_dict[in_db.contact_type] = in_db.registry_id
|
||||||
|
return contacts_dict
|
||||||
|
|
||||||
def _get_or_create_contact(self, contact: PublicContact):
|
def _get_or_create_contact(self, contact: PublicContact):
|
||||||
"""Try to fetch info about a contact. Create it if it does not exist."""
|
"""Try to fetch info about a contact. Create it if it does not exist."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self._request_contact_info(contact)
|
return self._request_contact_info(contact)
|
||||||
|
|
||||||
except RegistryError as e:
|
except RegistryError as e:
|
||||||
if e.code == ErrorCode.OBJECT_DOES_NOT_EXIST:
|
if e.code == ErrorCode.OBJECT_DOES_NOT_EXIST:
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -981,6 +1205,23 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
|
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
def _fetch_hosts(self, host_data):
|
||||||
|
"""Fetch host info."""
|
||||||
|
hosts = []
|
||||||
|
for name in host_data:
|
||||||
|
req = commands.InfoHost(name=name)
|
||||||
|
data = registry.send(req, cleaned=True).res_data[0]
|
||||||
|
host = {
|
||||||
|
"name": name,
|
||||||
|
"addrs": getattr(data, "addrs", ...),
|
||||||
|
"cr_date": getattr(data, "cr_date", ...),
|
||||||
|
"statuses": getattr(data, "statuses", ...),
|
||||||
|
"tr_date": getattr(data, "tr_date", ...),
|
||||||
|
"up_date": getattr(data, "up_date", ...),
|
||||||
|
}
|
||||||
|
hosts.append({k: v for k, v in host.items() if v is not ...})
|
||||||
|
return hosts
|
||||||
|
|
||||||
def _update_or_create_host(self, host):
|
def _update_or_create_host(self, host):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -1007,12 +1248,11 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
"tr_date": getattr(data, "tr_date", ...),
|
"tr_date": getattr(data, "tr_date", ...),
|
||||||
"up_date": getattr(data, "up_date", ...),
|
"up_date": getattr(data, "up_date", ...),
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove null properties (to distinguish between "a value of None" and null)
|
# remove null properties (to distinguish between "a value of None" and null)
|
||||||
cleaned = {k: v for k, v in cache.items() if v is not ...}
|
cleaned = {k: v for k, v in cache.items() if v is not ...}
|
||||||
|
|
||||||
# statuses can just be a list no need to keep the epp object
|
# statuses can just be a list no need to keep the epp object
|
||||||
if "statuses" in cleaned.keys():
|
if "statuses" in cleaned:
|
||||||
cleaned["statuses"] = [status.state for status in cleaned["statuses"]]
|
cleaned["statuses"] = [status.state for status in cleaned["statuses"]]
|
||||||
|
|
||||||
# get extensions info, if there is any
|
# get extensions info, if there is any
|
||||||
|
@ -1032,7 +1272,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
fetch_contacts
|
fetch_contacts
|
||||||
and "_contacts" in cleaned
|
and "_contacts" in cleaned
|
||||||
and isinstance(cleaned["_contacts"], list)
|
and isinstance(cleaned["_contacts"], list)
|
||||||
and len(cleaned["_contacts"])
|
and len(cleaned["_contacts"]) > 0
|
||||||
):
|
):
|
||||||
cleaned["contacts"] = self._fetch_contacts(cleaned["_contacts"])
|
cleaned["contacts"] = self._fetch_contacts(cleaned["_contacts"])
|
||||||
# We're only getting contacts, so retain the old
|
# We're only getting contacts, so retain the old
|
||||||
|
@ -1054,52 +1294,69 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
# and pass them along.
|
# and pass them along.
|
||||||
if old_cache_contacts is not None:
|
if old_cache_contacts is not None:
|
||||||
cleaned["contacts"] = old_cache_contacts
|
cleaned["contacts"] = old_cache_contacts
|
||||||
|
|
||||||
# replace the prior cache with new data
|
# replace the prior cache with new data
|
||||||
self._cache = cleaned
|
self._cache = cleaned
|
||||||
|
|
||||||
except RegistryError as e:
|
except RegistryError as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
def _fetch_contacts(self, contact_data):
|
def _get_or_create_public_contact(self, public_contact: PublicContact):
|
||||||
"""Fetch contact info."""
|
"""Tries to find a PublicContact object in our DB.
|
||||||
contacts = []
|
If it can't, it'll create it. Returns PublicContact"""
|
||||||
for domainContact in contact_data:
|
db_contact = PublicContact.objects.filter(
|
||||||
req = commands.InfoContact(id=domainContact.contact)
|
registry_id=public_contact.registry_id,
|
||||||
data = registry.send(req, cleaned=True).res_data[0]
|
contact_type=public_contact.contact_type,
|
||||||
contact = {
|
domain=self,
|
||||||
"id": domainContact.contact,
|
)
|
||||||
"type": domainContact.type,
|
|
||||||
"auth_info": getattr(data, "auth_info", ...),
|
|
||||||
"cr_date": getattr(data, "cr_date", ...),
|
|
||||||
"disclose": getattr(data, "disclose", ...),
|
|
||||||
"email": getattr(data, "email", ...),
|
|
||||||
"fax": getattr(data, "fax", ...),
|
|
||||||
"postal_info": getattr(data, "postal_info", ...),
|
|
||||||
"statuses": getattr(data, "statuses", ...),
|
|
||||||
"tr_date": getattr(data, "tr_date", ...),
|
|
||||||
"up_date": getattr(data, "up_date", ...),
|
|
||||||
"voice": getattr(data, "voice", ...),
|
|
||||||
}
|
|
||||||
contacts.append({k: v for k, v in contact.items() if v is not ...})
|
|
||||||
return contacts
|
|
||||||
|
|
||||||
def _fetch_hosts(self, host_data):
|
# Raise an error if we find duplicates.
|
||||||
"""Fetch host info."""
|
# This should not occur
|
||||||
hosts = []
|
if db_contact.count() > 1:
|
||||||
for name in host_data:
|
raise Exception(
|
||||||
req = commands.InfoHost(name=name)
|
f"Multiple contacts found for {public_contact.contact_type}"
|
||||||
data = registry.send(req, cleaned=True).res_data[0]
|
)
|
||||||
host = {
|
|
||||||
"name": name,
|
# Save to DB if it doesn't exist already.
|
||||||
"addrs": getattr(data, "addrs", ...),
|
if db_contact.count() == 0:
|
||||||
"cr_date": getattr(data, "cr_date", ...),
|
# Doesn't run custom save logic, just saves to DB
|
||||||
"statuses": getattr(data, "statuses", ...),
|
public_contact.save(skip_epp_save=True)
|
||||||
"tr_date": getattr(data, "tr_date", ...),
|
logger.info(f"Created a new PublicContact: {public_contact}")
|
||||||
"up_date": getattr(data, "up_date", ...),
|
# Append the item we just created
|
||||||
}
|
return public_contact
|
||||||
hosts.append({k: v for k, v in host.items() if v is not ...})
|
|
||||||
return hosts
|
existing_contact = db_contact.get()
|
||||||
|
|
||||||
|
# Does the item we're grabbing match
|
||||||
|
# what we have in our DB?
|
||||||
|
if (
|
||||||
|
existing_contact.email != public_contact.email
|
||||||
|
or existing_contact.registry_id != public_contact.registry_id
|
||||||
|
):
|
||||||
|
existing_contact.delete()
|
||||||
|
public_contact.save()
|
||||||
|
logger.warning("Requested PublicContact is out of sync " "with DB.")
|
||||||
|
return public_contact
|
||||||
|
# If it already exists, we can
|
||||||
|
# assume that the DB instance was updated
|
||||||
|
# during set, so we should just use that.
|
||||||
|
return existing_contact
|
||||||
|
|
||||||
|
def _registrant_to_public_contact(self, registry_id: str):
|
||||||
|
"""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."""
|
||||||
|
contact = PublicContact(
|
||||||
|
registry_id=registry_id,
|
||||||
|
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
||||||
|
)
|
||||||
|
# Grabs the expanded contact
|
||||||
|
full_object = self._request_contact_info(contact)
|
||||||
|
# Maps it to type PublicContact
|
||||||
|
mapped_object = self.map_epp_contact_to_public_contact(
|
||||||
|
full_object, contact.registry_id, contact.contact_type
|
||||||
|
)
|
||||||
|
return self._get_or_create_public_contact(mapped_object)
|
||||||
|
|
||||||
def _invalidate_cache(self):
|
def _invalidate_cache(self):
|
||||||
"""Remove cache data when updates are made."""
|
"""Remove cache data when updates are made."""
|
||||||
|
|
|
@ -29,7 +29,8 @@ class PublicContact(TimeStampedModel):
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"""Save to the registry and also locally in the registrar database."""
|
"""Save to the registry and also locally in the registrar database."""
|
||||||
if hasattr(self, "domain"):
|
skip_epp_save = kwargs.pop("skip_epp_save", False)
|
||||||
|
if hasattr(self, "domain") and not skip_epp_save:
|
||||||
match self.contact_type:
|
match self.contact_type:
|
||||||
case PublicContact.ContactTypeChoices.REGISTRANT:
|
case PublicContact.ContactTypeChoices.REGISTRANT:
|
||||||
self.domain.registrant_contact = self
|
self.domain.registrant_contact = self
|
||||||
|
@ -148,6 +149,10 @@ class PublicContact(TimeStampedModel):
|
||||||
pw="thisisnotapassword",
|
pw="thisisnotapassword",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_max_id_length(cls):
|
||||||
|
return cls._meta.get_field("registry_id").max_length
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return (
|
return (
|
||||||
f"{self.name} <{self.email}>"
|
f"{self.name} <{self.email}>"
|
||||||
|
|
|
@ -15,7 +15,7 @@ class UserDomainRole(TimeStampedModel):
|
||||||
elsewhere.
|
elsewhere.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ADMIN = "admin"
|
ADMIN = "manager"
|
||||||
|
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
"registrar.User",
|
"registrar.User",
|
||||||
|
|
2
src/registrar/models/utility/contact_error.py
Normal file
2
src/registrar/models/utility/contact_error.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
class ContactError(Exception):
|
||||||
|
...
|
|
@ -21,7 +21,7 @@
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class="usa-button"
|
class="usa-button"
|
||||||
>Add security email</button>
|
>{% if form.security_email.value is None or form.security_email.value == "dotgov@cisa.dhs.gov"%}Add security email{% else %}Save{% endif %}</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endblock %} {# domain_content #}
|
{% endblock %} {# domain_content #}
|
||||||
|
|
|
@ -27,6 +27,7 @@ from epplibwrapper import (
|
||||||
commands,
|
commands,
|
||||||
common,
|
common,
|
||||||
extensions,
|
extensions,
|
||||||
|
info,
|
||||||
RegistryError,
|
RegistryError,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
)
|
)
|
||||||
|
@ -556,32 +557,117 @@ class MockEppLib(TestCase):
|
||||||
contacts=...,
|
contacts=...,
|
||||||
hosts=...,
|
hosts=...,
|
||||||
statuses=...,
|
statuses=...,
|
||||||
|
registrant=...,
|
||||||
):
|
):
|
||||||
self.auth_info = auth_info
|
self.auth_info = auth_info
|
||||||
self.cr_date = cr_date
|
self.cr_date = cr_date
|
||||||
self.contacts = contacts
|
self.contacts = contacts
|
||||||
self.hosts = hosts
|
self.hosts = hosts
|
||||||
self.statuses = statuses
|
self.statuses = statuses
|
||||||
|
self.registrant = registrant
|
||||||
|
|
||||||
|
def dummyInfoContactResultData(
|
||||||
|
self,
|
||||||
|
id,
|
||||||
|
email,
|
||||||
|
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||||
|
pw="thisisnotapassword",
|
||||||
|
):
|
||||||
|
fake = info.InfoContactResultData(
|
||||||
|
id=id,
|
||||||
|
postal_info=common.PostalInfo(
|
||||||
|
name="Registry Customer Service",
|
||||||
|
addr=common.ContactAddr(
|
||||||
|
street=["4200 Wilson Blvd."],
|
||||||
|
city="Arlington",
|
||||||
|
pc="22201",
|
||||||
|
cc="US",
|
||||||
|
sp="VA",
|
||||||
|
),
|
||||||
|
org="Cybersecurity and Infrastructure Security Agency",
|
||||||
|
type="type",
|
||||||
|
),
|
||||||
|
voice="+1.8882820870",
|
||||||
|
fax="+1-212-9876543",
|
||||||
|
email=email,
|
||||||
|
auth_info=common.ContactAuthInfo(pw=pw),
|
||||||
|
roid=...,
|
||||||
|
statuses=[],
|
||||||
|
cl_id=...,
|
||||||
|
cr_id=...,
|
||||||
|
cr_date=cr_date,
|
||||||
|
up_id=...,
|
||||||
|
up_date=...,
|
||||||
|
tr_date=...,
|
||||||
|
disclose=...,
|
||||||
|
vat=...,
|
||||||
|
ident=...,
|
||||||
|
notify_email=...,
|
||||||
|
)
|
||||||
|
return fake
|
||||||
|
|
||||||
mockDataInfoDomain = fakedEppObject(
|
mockDataInfoDomain = fakedEppObject(
|
||||||
"fakepw",
|
"fakePw",
|
||||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||||
contacts=[common.DomainContact(contact="123", type="security")],
|
contacts=[
|
||||||
|
common.DomainContact(
|
||||||
|
contact="123", type=PublicContact.ContactTypeChoices.SECURITY
|
||||||
|
)
|
||||||
|
],
|
||||||
hosts=["fake.host.com"],
|
hosts=["fake.host.com"],
|
||||||
statuses=[
|
statuses=[
|
||||||
common.Status(state="serverTransferProhibited", description="", lang="en"),
|
common.Status(state="serverTransferProhibited", description="", lang="en"),
|
||||||
common.Status(state="inactive", description="", lang="en"),
|
common.Status(state="inactive", description="", lang="en"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
mockDataInfoContact = mockDataInfoDomain.dummyInfoContactResultData(
|
||||||
|
"123", "123@mail.gov", datetime.datetime(2023, 5, 25, 19, 45, 35), "lastPw"
|
||||||
|
)
|
||||||
|
InfoDomainWithContacts = fakedEppObject(
|
||||||
|
"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,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
hosts=["fake.host.com"],
|
||||||
|
statuses=[
|
||||||
|
common.Status(state="serverTransferProhibited", description="", lang="en"),
|
||||||
|
common.Status(state="inactive", description="", lang="en"),
|
||||||
|
],
|
||||||
|
registrant="regContact",
|
||||||
|
)
|
||||||
|
|
||||||
|
mockSecurityContact = InfoDomainWithContacts.dummyInfoContactResultData(
|
||||||
|
"securityContact", "security@mail.gov"
|
||||||
|
)
|
||||||
|
mockTechnicalContact = InfoDomainWithContacts.dummyInfoContactResultData(
|
||||||
|
"technicalContact", "tech@mail.gov"
|
||||||
|
)
|
||||||
|
mockAdministrativeContact = InfoDomainWithContacts.dummyInfoContactResultData(
|
||||||
|
"adminContact", "admin@mail.gov"
|
||||||
|
)
|
||||||
|
mockRegistrantContact = InfoDomainWithContacts.dummyInfoContactResultData(
|
||||||
|
"regContact", "registrant@mail.gov"
|
||||||
|
)
|
||||||
|
|
||||||
infoDomainNoContact = fakedEppObject(
|
infoDomainNoContact = fakedEppObject(
|
||||||
"security",
|
"security",
|
||||||
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
cr_date=datetime.datetime(2023, 5, 25, 19, 45, 35),
|
||||||
contacts=[],
|
contacts=[],
|
||||||
hosts=["fake.host.com"],
|
hosts=["fake.host.com"],
|
||||||
)
|
)
|
||||||
mockDataInfoContact = fakedEppObject(
|
|
||||||
"anotherPw", cr_date=datetime.datetime(2023, 7, 25, 19, 45, 35)
|
|
||||||
)
|
|
||||||
mockDataInfoHosts = fakedEppObject(
|
mockDataInfoHosts = fakedEppObject(
|
||||||
"lastPw", cr_date=datetime.datetime(2023, 8, 25, 19, 45, 35)
|
"lastPw", cr_date=datetime.datetime(2023, 8, 25, 19, 45, 35)
|
||||||
)
|
)
|
||||||
|
@ -649,9 +735,28 @@ class MockEppLib(TestCase):
|
||||||
elif getattr(_request, "name", None) == "dnssec-none.gov":
|
elif getattr(_request, "name", None) == "dnssec-none.gov":
|
||||||
# this case is not necessary, but helps improve readability
|
# this case is not necessary, but helps improve readability
|
||||||
return MagicMock(res_data=[self.mockDataInfoDomain])
|
return MagicMock(res_data=[self.mockDataInfoDomain])
|
||||||
|
elif getattr(_request, "name", None) == "freeman.gov":
|
||||||
|
return MagicMock(res_data=[self.InfoDomainWithContacts])
|
||||||
|
else:
|
||||||
return MagicMock(res_data=[self.mockDataInfoDomain])
|
return MagicMock(res_data=[self.mockDataInfoDomain])
|
||||||
elif isinstance(_request, commands.InfoContact):
|
elif isinstance(_request, commands.InfoContact):
|
||||||
return MagicMock(res_data=[self.mockDataInfoContact])
|
mocked_result: info.InfoContactResultData
|
||||||
|
|
||||||
|
# For testing contact types
|
||||||
|
match getattr(_request, "id", None):
|
||||||
|
case "securityContact":
|
||||||
|
mocked_result = self.mockSecurityContact
|
||||||
|
case "technicalContact":
|
||||||
|
mocked_result = self.mockTechnicalContact
|
||||||
|
case "adminContact":
|
||||||
|
mocked_result = self.mockAdministrativeContact
|
||||||
|
case "regContact":
|
||||||
|
mocked_result = self.mockRegistrantContact
|
||||||
|
case _:
|
||||||
|
# Default contact return
|
||||||
|
mocked_result = self.mockDataInfoContact
|
||||||
|
|
||||||
|
return MagicMock(res_data=[mocked_result])
|
||||||
elif (
|
elif (
|
||||||
isinstance(_request, commands.CreateContact)
|
isinstance(_request, commands.CreateContact)
|
||||||
and getattr(_request, "id", None) == "fail"
|
and getattr(_request, "id", None) == "fail"
|
||||||
|
|
|
@ -25,15 +25,23 @@ from epplibwrapper import (
|
||||||
RegistryError,
|
RegistryError,
|
||||||
ErrorCode,
|
ErrorCode,
|
||||||
)
|
)
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TestDomainCache(MockEppLib):
|
class TestDomainCache(MockEppLib):
|
||||||
|
def tearDown(self):
|
||||||
|
PublicContact.objects.all().delete()
|
||||||
|
Domain.objects.all().delete()
|
||||||
|
super().tearDown()
|
||||||
|
|
||||||
def test_cache_sets_resets(self):
|
def test_cache_sets_resets(self):
|
||||||
"""Cache should be set on getter and reset on setter calls"""
|
"""Cache should be set on getter and reset on setter calls"""
|
||||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||||
# trigger getter
|
# trigger getter
|
||||||
_ = domain.creation_date
|
_ = domain.creation_date
|
||||||
|
domain._get_property("contacts")
|
||||||
# getter should set the domain cache with a InfoDomain object
|
# getter should set the domain cache with a InfoDomain object
|
||||||
# (see InfoDomainResult)
|
# (see InfoDomainResult)
|
||||||
self.assertEquals(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
self.assertEquals(domain._cache["auth_info"], self.mockDataInfoDomain.auth_info)
|
||||||
|
@ -81,13 +89,16 @@ class TestDomainCache(MockEppLib):
|
||||||
def test_cache_nested_elements(self):
|
def test_cache_nested_elements(self):
|
||||||
"""Cache works correctly with the nested objects cache and hosts"""
|
"""Cache works correctly with the nested objects cache and hosts"""
|
||||||
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||||
|
# The contact list will initially contain objects of type 'DomainContact'
|
||||||
# the cached contacts and hosts should be dictionaries of what is passed to them
|
# this is then transformed into PublicContact, and cache should NOT
|
||||||
|
# hold onto the DomainContact object
|
||||||
|
expectedUnfurledContactsList = [
|
||||||
|
common.DomainContact(contact="123", type="security"),
|
||||||
|
]
|
||||||
expectedContactsDict = {
|
expectedContactsDict = {
|
||||||
"id": self.mockDataInfoDomain.contacts[0].contact,
|
PublicContact.ContactTypeChoices.ADMINISTRATIVE: None,
|
||||||
"type": self.mockDataInfoDomain.contacts[0].type,
|
PublicContact.ContactTypeChoices.SECURITY: "123",
|
||||||
"auth_info": self.mockDataInfoContact.auth_info,
|
PublicContact.ContactTypeChoices.TECHNICAL: None,
|
||||||
"cr_date": self.mockDataInfoContact.cr_date,
|
|
||||||
}
|
}
|
||||||
expectedHostsDict = {
|
expectedHostsDict = {
|
||||||
"name": self.mockDataInfoDomain.hosts[0],
|
"name": self.mockDataInfoDomain.hosts[0],
|
||||||
|
@ -103,13 +114,15 @@ class TestDomainCache(MockEppLib):
|
||||||
|
|
||||||
# check contacts
|
# check contacts
|
||||||
self.assertEqual(domain._cache["_contacts"], self.mockDataInfoDomain.contacts)
|
self.assertEqual(domain._cache["_contacts"], self.mockDataInfoDomain.contacts)
|
||||||
self.assertEqual(domain._cache["contacts"], [expectedContactsDict])
|
# The contact list should not contain what is sent by the registry by default,
|
||||||
|
# as _fetch_cache will transform the type to PublicContact
|
||||||
|
self.assertNotEqual(domain._cache["contacts"], expectedUnfurledContactsList)
|
||||||
|
self.assertEqual(domain._cache["contacts"], expectedContactsDict)
|
||||||
|
|
||||||
# get and check hosts is set correctly
|
# get and check hosts is set correctly
|
||||||
domain._get_property("hosts")
|
domain._get_property("hosts")
|
||||||
self.assertEqual(domain._cache["hosts"], [expectedHostsDict])
|
self.assertEqual(domain._cache["hosts"], [expectedHostsDict])
|
||||||
self.assertEqual(domain._cache["contacts"], [expectedContactsDict])
|
self.assertEqual(domain._cache["contacts"], expectedContactsDict)
|
||||||
|
|
||||||
# invalidate cache
|
# invalidate cache
|
||||||
domain._cache = {}
|
domain._cache = {}
|
||||||
|
|
||||||
|
@ -120,11 +133,64 @@ class TestDomainCache(MockEppLib):
|
||||||
# get contacts
|
# get contacts
|
||||||
domain._get_property("contacts")
|
domain._get_property("contacts")
|
||||||
self.assertEqual(domain._cache["hosts"], [expectedHostsDict])
|
self.assertEqual(domain._cache["hosts"], [expectedHostsDict])
|
||||||
self.assertEqual(domain._cache["contacts"], [expectedContactsDict])
|
self.assertEqual(domain._cache["contacts"], expectedContactsDict)
|
||||||
|
|
||||||
def tearDown(self) -> None:
|
def test_map_epp_contact_to_public_contact(self):
|
||||||
Domain.objects.all().delete()
|
# Tests that the mapper is working how we expect
|
||||||
super().tearDown()
|
domain, _ = Domain.objects.get_or_create(name="registry.gov")
|
||||||
|
security = PublicContact.ContactTypeChoices.SECURITY
|
||||||
|
mapped = domain.map_epp_contact_to_public_contact(
|
||||||
|
self.mockDataInfoContact,
|
||||||
|
self.mockDataInfoContact.id,
|
||||||
|
security,
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_contact = PublicContact(
|
||||||
|
domain=domain,
|
||||||
|
contact_type=security,
|
||||||
|
registry_id="123",
|
||||||
|
email="123@mail.gov",
|
||||||
|
voice="+1.8882820870",
|
||||||
|
fax="+1-212-9876543",
|
||||||
|
pw="lastPw",
|
||||||
|
name="Registry Customer Service",
|
||||||
|
org="Cybersecurity and Infrastructure Security Agency",
|
||||||
|
city="Arlington",
|
||||||
|
pc="22201",
|
||||||
|
cc="US",
|
||||||
|
sp="VA",
|
||||||
|
street1="4200 Wilson Blvd.",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test purposes only, since we're comparing
|
||||||
|
# two duplicate objects. We would expect
|
||||||
|
# these not to have the same state.
|
||||||
|
expected_contact._state = mapped._state
|
||||||
|
|
||||||
|
# Mapped object is what we expect
|
||||||
|
self.assertEqual(mapped.__dict__, expected_contact.__dict__)
|
||||||
|
|
||||||
|
# The mapped object should correctly translate to a DB
|
||||||
|
# object. If not, something else went wrong.
|
||||||
|
db_object = domain._get_or_create_public_contact(mapped)
|
||||||
|
in_db = PublicContact.objects.filter(
|
||||||
|
registry_id=domain.security_contact.registry_id,
|
||||||
|
contact_type=security,
|
||||||
|
).get()
|
||||||
|
# DB Object is the same as the mapped object
|
||||||
|
self.assertEqual(db_object, in_db)
|
||||||
|
|
||||||
|
domain.security_contact = in_db
|
||||||
|
# Trigger the getter
|
||||||
|
_ = domain.security_contact
|
||||||
|
# Check to see that changes made
|
||||||
|
# to DB objects persist in cache correctly
|
||||||
|
in_db.email = "123test@mail.gov"
|
||||||
|
in_db.save()
|
||||||
|
|
||||||
|
cached_contact = domain._cache["contacts"].get(security)
|
||||||
|
self.assertEqual(cached_contact, in_db.registry_id)
|
||||||
|
self.assertEqual(domain.security_contact.email, "123test@mail.gov")
|
||||||
|
|
||||||
|
|
||||||
class TestDomainCreation(MockEppLib):
|
class TestDomainCreation(MockEppLib):
|
||||||
|
@ -208,7 +274,10 @@ class TestDomainCreation(MockEppLib):
|
||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
DomainInformation.objects.all().delete()
|
DomainInformation.objects.all().delete()
|
||||||
DomainApplication.objects.all().delete()
|
DomainApplication.objects.all().delete()
|
||||||
|
PublicContact.objects.all().delete()
|
||||||
Domain.objects.all().delete()
|
Domain.objects.all().delete()
|
||||||
|
User.objects.all().delete()
|
||||||
|
DraftDomain.objects.all().delete()
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
|
||||||
|
@ -222,7 +291,6 @@ class TestDomainStatuses(MockEppLib):
|
||||||
_ = domain.statuses
|
_ = domain.statuses
|
||||||
status_list = [status.state for status in self.mockDataInfoDomain.statuses]
|
status_list = [status.state for status in self.mockDataInfoDomain.statuses]
|
||||||
self.assertEquals(domain._cache["statuses"], status_list)
|
self.assertEquals(domain._cache["statuses"], status_list)
|
||||||
|
|
||||||
# Called in _fetch_cache
|
# Called in _fetch_cache
|
||||||
self.mockedSendFunction.assert_has_calls(
|
self.mockedSendFunction.assert_has_calls(
|
||||||
[
|
[
|
||||||
|
@ -266,6 +334,7 @@ class TestDomainStatuses(MockEppLib):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
|
PublicContact.objects.all().delete()
|
||||||
Domain.objects.all().delete()
|
Domain.objects.all().delete()
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
@ -388,12 +457,17 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
And the registrant is the admin on a domain
|
And the registrant is the admin on a domain
|
||||||
"""
|
"""
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
# Creates a domain with no contact associated to it
|
||||||
self.domain, _ = Domain.objects.get_or_create(name="security.gov")
|
self.domain, _ = Domain.objects.get_or_create(name="security.gov")
|
||||||
|
# Creates a domain with an associated contact
|
||||||
|
self.domain_contact, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
# self.contactMailingAddressPatch.stop()
|
self.domain._invalidate_cache()
|
||||||
# self.createContactPatch.stop()
|
self.domain_contact._invalidate_cache()
|
||||||
|
PublicContact.objects.all().delete()
|
||||||
|
Domain.objects.all().delete()
|
||||||
|
|
||||||
def test_no_security_email(self):
|
def test_no_security_email(self):
|
||||||
"""
|
"""
|
||||||
|
@ -639,6 +713,133 @@ class TestRegistrantContacts(MockEppLib):
|
||||||
"""
|
"""
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def test_contact_getter_security(self):
|
||||||
|
security = PublicContact.ContactTypeChoices.SECURITY
|
||||||
|
# Create prexisting object
|
||||||
|
expected_contact = self.domain.map_epp_contact_to_public_contact(
|
||||||
|
self.mockSecurityContact,
|
||||||
|
contact_id="securityContact",
|
||||||
|
contact_type=security,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Checks if we grabbed the correct PublicContact
|
||||||
|
self.assertEqual(
|
||||||
|
self.domain_contact.security_contact.email, expected_contact.email
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_contact_db = PublicContact.objects.filter(
|
||||||
|
registry_id=self.domain_contact.security_contact.registry_id,
|
||||||
|
contact_type=security,
|
||||||
|
).get()
|
||||||
|
|
||||||
|
self.assertEqual(self.domain_contact.security_contact, expected_contact_db)
|
||||||
|
|
||||||
|
self.mockedSendFunction.assert_has_calls(
|
||||||
|
[
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="securityContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
# Checks if we are receiving the cache we expect
|
||||||
|
cache = self.domain_contact._cache["contacts"]
|
||||||
|
self.assertEqual(cache.get(security), "securityContact")
|
||||||
|
|
||||||
|
def test_contact_getter_technical(self):
|
||||||
|
technical = PublicContact.ContactTypeChoices.TECHNICAL
|
||||||
|
expected_contact = self.domain.map_epp_contact_to_public_contact(
|
||||||
|
self.mockTechnicalContact,
|
||||||
|
contact_id="technicalContact",
|
||||||
|
contact_type=technical,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.domain_contact.technical_contact.email, expected_contact.email
|
||||||
|
)
|
||||||
|
|
||||||
|
# Checks if we grab the correct PublicContact
|
||||||
|
expected_contact_db = PublicContact.objects.filter(
|
||||||
|
registry_id=self.domain_contact.technical_contact.registry_id,
|
||||||
|
contact_type=technical,
|
||||||
|
).get()
|
||||||
|
|
||||||
|
# Checks if we grab the correct PublicContact
|
||||||
|
self.assertEqual(self.domain_contact.technical_contact, expected_contact_db)
|
||||||
|
self.mockedSendFunction.assert_has_calls(
|
||||||
|
[
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="technicalContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
# Checks if we are receiving the cache we expect
|
||||||
|
cache = self.domain_contact._cache["contacts"]
|
||||||
|
self.assertEqual(cache.get(technical), "technicalContact")
|
||||||
|
|
||||||
|
def test_contact_getter_administrative(self):
|
||||||
|
administrative = PublicContact.ContactTypeChoices.ADMINISTRATIVE
|
||||||
|
expected_contact = self.domain.map_epp_contact_to_public_contact(
|
||||||
|
self.mockAdministrativeContact,
|
||||||
|
contact_id="adminContact",
|
||||||
|
contact_type=administrative,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.domain_contact.administrative_contact.email, expected_contact.email
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_contact_db = PublicContact.objects.filter(
|
||||||
|
registry_id=self.domain_contact.administrative_contact.registry_id,
|
||||||
|
contact_type=administrative,
|
||||||
|
).get()
|
||||||
|
|
||||||
|
# Checks if we grab the correct PublicContact
|
||||||
|
self.assertEqual(
|
||||||
|
self.domain_contact.administrative_contact, expected_contact_db
|
||||||
|
)
|
||||||
|
self.mockedSendFunction.assert_has_calls(
|
||||||
|
[
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="adminContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
# Checks if we are receiving the cache we expect
|
||||||
|
cache = self.domain_contact._cache["contacts"]
|
||||||
|
self.assertEqual(cache.get(administrative), "adminContact")
|
||||||
|
|
||||||
|
def test_contact_getter_registrant(self):
|
||||||
|
expected_contact = self.domain.map_epp_contact_to_public_contact(
|
||||||
|
self.mockRegistrantContact,
|
||||||
|
contact_id="regContact",
|
||||||
|
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.domain_contact.registrant_contact.email, expected_contact.email
|
||||||
|
)
|
||||||
|
|
||||||
|
expected_contact_db = PublicContact.objects.filter(
|
||||||
|
registry_id=self.domain_contact.registrant_contact.registry_id,
|
||||||
|
contact_type=PublicContact.ContactTypeChoices.REGISTRANT,
|
||||||
|
).get()
|
||||||
|
|
||||||
|
# Checks if we grab the correct PublicContact
|
||||||
|
self.assertEqual(self.domain_contact.registrant_contact, expected_contact_db)
|
||||||
|
self.mockedSendFunction.assert_has_calls(
|
||||||
|
[
|
||||||
|
call(
|
||||||
|
commands.InfoContact(id="regContact", auth_info=None),
|
||||||
|
cleaned=True,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
# Checks if we are receiving the cache we expect.
|
||||||
|
self.assertEqual(self.domain_contact._cache["registrant"], expected_contact_db)
|
||||||
|
|
||||||
|
|
||||||
class TestRegistrantNameservers(TestCase):
|
class TestRegistrantNameservers(TestCase):
|
||||||
"""Rule: Registrants may modify their nameservers"""
|
"""Rule: Registrants may modify their nameservers"""
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
from unittest import skip
|
from unittest import skip
|
||||||
from unittest.mock import MagicMock, ANY
|
from unittest.mock import MagicMock, ANY, patch
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.test import Client, TestCase
|
from django.test import Client, TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from .common import completed_application
|
from .common import MockEppLib, completed_application # type: ignore
|
||||||
|
|
||||||
from django_webtest import WebTest # type: ignore
|
from django_webtest import WebTest # type: ignore
|
||||||
import boto3_mocking # type: ignore
|
import boto3_mocking # type: ignore
|
||||||
|
@ -25,7 +25,6 @@ from registrar.models import (
|
||||||
from registrar.views.application import ApplicationWizard, Step
|
from registrar.views.application import ApplicationWizard, Step
|
||||||
|
|
||||||
from .common import less_console_noise
|
from .common import less_console_noise
|
||||||
from .common import MockEppLib
|
|
||||||
|
|
||||||
|
|
||||||
class TestViews(TestCase):
|
class TestViews(TestCase):
|
||||||
|
@ -1481,6 +1480,40 @@ class TestDomainContactInformation(TestDomainOverview):
|
||||||
|
|
||||||
class TestDomainSecurityEmail(TestDomainOverview):
|
class TestDomainSecurityEmail(TestDomainOverview):
|
||||||
|
|
||||||
|
def test_domain_security_email_existing_security_contact(self):
|
||||||
|
"""Can load domain's security email page."""
|
||||||
|
self.mockSendPatch = patch("registrar.models.domain.registry.send")
|
||||||
|
self.mockedSendFunction = self.mockSendPatch.start()
|
||||||
|
self.mockedSendFunction.side_effect = self.mockSend
|
||||||
|
|
||||||
|
domain_contact, _ = Domain.objects.get_or_create(name="freeman.gov")
|
||||||
|
# Add current user to this domain
|
||||||
|
_ = UserDomainRole(user=self.user, domain=domain_contact, role="admin").save()
|
||||||
|
page = self.client.get(
|
||||||
|
reverse("domain-security-email", kwargs={"pk": domain_contact.id})
|
||||||
|
)
|
||||||
|
|
||||||
|
# Loads correctly
|
||||||
|
self.assertContains(page, "Domain security email")
|
||||||
|
self.assertContains(page, "security@mail.gov")
|
||||||
|
self.mockSendPatch.stop()
|
||||||
|
|
||||||
|
def test_domain_security_email_no_security_contact(self):
|
||||||
|
"""Loads a domain with no defined security email.
|
||||||
|
We should not show the default."""
|
||||||
|
self.mockSendPatch = patch("registrar.models.domain.registry.send")
|
||||||
|
self.mockedSendFunction = self.mockSendPatch.start()
|
||||||
|
self.mockedSendFunction.side_effect = self.mockSend
|
||||||
|
|
||||||
|
page = self.client.get(
|
||||||
|
reverse("domain-security-email", kwargs={"pk": self.domain.id})
|
||||||
|
)
|
||||||
|
|
||||||
|
# Loads correctly
|
||||||
|
self.assertContains(page, "Domain security email")
|
||||||
|
self.assertNotContains(page, "dotgov@cisa.dhs.gov")
|
||||||
|
self.mockSendPatch.stop()
|
||||||
|
|
||||||
def test_domain_security_email(self):
|
def test_domain_security_email(self):
|
||||||
"""Can load domain's security email page."""
|
"""Can load domain's security email page."""
|
||||||
page = self.client.get(
|
page = self.client.get(
|
||||||
|
@ -1488,10 +1521,8 @@ class TestDomainSecurityEmail(TestDomainOverview):
|
||||||
)
|
)
|
||||||
self.assertContains(page, "Domain security email")
|
self.assertContains(page, "Domain security email")
|
||||||
|
|
||||||
@skip("Ticket 912 needs to fix this one")
|
|
||||||
def test_domain_security_email_form(self):
|
def test_domain_security_email_form(self):
|
||||||
"""Adding a security email works.
|
"""Adding a security email works.
|
||||||
|
|
||||||
Uses self.app WebTest because we need to interact with forms.
|
Uses self.app WebTest because we need to interact with forms.
|
||||||
"""
|
"""
|
||||||
security_email_page = self.app.get(
|
security_email_page = self.app.get(
|
||||||
|
@ -1511,7 +1542,7 @@ class TestDomainSecurityEmail(TestDomainOverview):
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
success_page = result.follow()
|
success_page = result.follow()
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
success_page, "The security email for this domain have been updated"
|
success_page, "The security email for this domain has been updated"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -554,7 +554,11 @@ class DomainSecurityEmailView(DomainPermissionView, FormMixin):
|
||||||
"""The initial value for the form."""
|
"""The initial value for the form."""
|
||||||
domain = self.get_object()
|
domain = self.get_object()
|
||||||
initial = super().get_initial()
|
initial = super().get_initial()
|
||||||
initial["security_email"] = domain.security_contact.email
|
security_contact = domain.security_contact
|
||||||
|
if security_contact is None or security_contact.email == "dotgov@cisa.dhs.gov":
|
||||||
|
initial["security_email"] = None
|
||||||
|
return initial
|
||||||
|
initial["security_email"] = security_contact.email
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -583,7 +587,7 @@ class DomainSecurityEmailView(DomainPermissionView, FormMixin):
|
||||||
contact.save()
|
contact.save()
|
||||||
|
|
||||||
messages.success(
|
messages.success(
|
||||||
self.request, "The security email for this domain have been updated."
|
self.request, "The security email for this domain has been updated."
|
||||||
)
|
)
|
||||||
|
|
||||||
# superclass has the redirect
|
# superclass has the redirect
|
||||||
|
|
|
@ -49,5 +49,5 @@ setuptools==67.8.0 ; python_version >= '3.7'
|
||||||
six==1.16.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
six==1.16.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
||||||
sqlparse==0.4.4 ; python_version >= '3.5'
|
sqlparse==0.4.4 ; python_version >= '3.5'
|
||||||
typing-extensions==4.6.3
|
typing-extensions==4.6.3
|
||||||
urllib3==1.26.16 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
|
urllib3==1.26.17 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
|
||||||
whitenoise==6.4.0
|
whitenoise==6.4.0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue