modified unit tests

This commit is contained in:
David Kennedy 2023-10-10 05:25:15 -04:00
parent 6bd93d56e2
commit 95b1a02789
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 136 additions and 45 deletions

View file

@ -705,17 +705,23 @@ class MockEppLib(TestCase):
"pubKey": "AQPJ////4Q==",
}
dnssecExtensionWithDsData: Mapping[Any, Any] = {
"dsData": [common.DSData(**addDsData1)] # type: ignore
"dsData": [common.DSData(**addDsData1)], # type: ignore
"keyData": [],
}
dnssecExtensionWithMultDsData: Mapping[str, Any] = {
"dsData": [
common.DSData(**addDsData1), # type: ignore
common.DSData(**addDsData2), # type: ignore
],
"keyData": [],
}
dnssecExtensionWithKeyData: Mapping[str, Any] = {
"maxSigLife": 3215,
"keyData": [common.DNSSECKeyData(**keyDataDict)], # type: ignore
"dsData": [],
}
dnssecExtensionRemovingDsData: Mapping[Any, Any] = {
"dsData": [],
"keyData": [],
}
def mockSend(self, _request, cleaned):
@ -756,26 +762,35 @@ class MockEppLib(TestCase):
if getattr(_request, "name", None) == "security.gov":
return MagicMock(res_data=[self.infoDomainNoContact])
elif getattr(_request, "name", None) == "dnssec-dsdata.gov":
return MagicMock(
res_data=[self.mockDataInfoDomain],
extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithDsData)
],
)
if self.mockedSendFunction.call_count == 1:
return MagicMock(res_data=[self.mockDataInfoDomain])
else:
return MagicMock(
res_data=[self.mockDataInfoDomain],
extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithDsData)
],
)
elif getattr(_request, "name", None) == "dnssec-multdsdata.gov":
return MagicMock(
res_data=[self.mockDataInfoDomain],
extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithMultDsData)
],
)
if self.mockedSendFunction.call_count == 1:
return MagicMock(res_data=[self.mockDataInfoDomain])
else:
return MagicMock(
res_data=[self.mockDataInfoDomain],
extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithMultDsData)
],
)
elif getattr(_request, "name", None) == "dnssec-keydata.gov":
return MagicMock(
res_data=[self.mockDataInfoDomain],
extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithKeyData)
],
)
if self.mockedSendFunction.call_count == 1:
return MagicMock(res_data=[self.mockDataInfoDomain])
else:
return MagicMock(
res_data=[self.mockDataInfoDomain],
extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithKeyData)
],
)
elif getattr(_request, "name", None) == "dnssec-none.gov":
# this case is not necessary, but helps improve readability
return MagicMock(res_data=[self.mockDataInfoDomain])

View file

@ -984,15 +984,25 @@ class TestRegistrantDNSSEC(MockEppLib):
"""Rule: Registrants may modify their secure DNS data"""
# helper function to create UpdateDomainDNSSECExtention object for verification
def createUpdateExtension(self, dnssecdata: extensions.DNSSECExtension):
return commands.UpdateDomainDNSSECExtension(
maxSigLife=dnssecdata.maxSigLife,
dsData=dnssecdata.dsData,
keyData=dnssecdata.keyData,
remDsData=None,
remKeyData=None,
remAllDsKeyData=True,
)
def createUpdateExtension(self, dnssecdata: extensions.DNSSECExtension, remove=False):
if not remove:
return commands.UpdateDomainDNSSECExtension(
maxSigLife=dnssecdata.maxSigLife,
dsData=dnssecdata.dsData,
keyData=dnssecdata.keyData,
remDsData=None,
remKeyData=None,
remAllDsKeyData=False,
)
else:
return commands.UpdateDomainDNSSECExtension(
maxSigLife=dnssecdata.maxSigLife,
dsData=None,
keyData=None,
remDsData=dnssecdata.dsData,
remKeyData=dnssecdata.keyData,
remAllDsKeyData=False,
)
def setUp(self):
"""
@ -1010,25 +1020,25 @@ class TestRegistrantDNSSEC(MockEppLib):
def test_user_adds_dnssec_data(self):
"""
Scenario: Registrant adds DNSSEC data.
Scenario: Registrant adds DNSSEC ds data.
Verify that both the setter and getter are functioning properly
This test verifies:
1 - setter calls UpdateDomain command
2 - setter adds the UpdateDNSSECExtension extension to the command
3 - setter causes the getter to call info domain on next get from cache
4 - getter properly parses dnssecdata from InfoDomain response and sets to cache
1 - setter initially calls InfoDomain command
2 - setter then calls UpdateDomain command
3 - setter adds the UpdateDNSSECExtension extension to the command
4 - setter causes the getter to call info domain on next get from cache
5 - getter properly parses dnssecdata from InfoDomain response and sets to cache
"""
domain, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
domain.dnssecdata = self.dnssecExtensionWithDsData
# get the DNS SEC extension added to the UpdateDomain command and
# verify that it is properly sent
# args[0] is the _request sent to registry
args, _ = self.mockedSendFunction.call_args
# assert that the extension matches
# assert that the extension on the update matches
self.assertEquals(
args[0].extensions[0],
self.createUpdateExtension(
@ -1039,6 +1049,12 @@ class TestRegistrantDNSSEC(MockEppLib):
dnssecdata_get = domain.dnssecdata
self.mockedSendFunction.assert_has_calls(
[
call(
commands.InfoDomain(
name="dnssec-dsdata.gov",
),
cleaned=True,
),
call(
commands.UpdateDomain(
name="dnssec-dsdata.gov",
@ -1071,9 +1087,11 @@ class TestRegistrantDNSSEC(MockEppLib):
# registry normally sends in this case
This test verifies:
1 - UpdateDomain command called twice
2 - setter causes the getter to call info domain on next get from cache
3 - getter properly parses dnssecdata from InfoDomain response and sets to cache
1 - InfoDomain command is called first
2 - UpdateDomain command called on the initial setter
3 - setter causes the getter to call info domain on next get from cache
4 - UpdateDomain command is not called on second setter (no change)
5 - getter properly parses dnssecdata from InfoDomain response and sets to cache
"""
@ -1088,12 +1106,8 @@ class TestRegistrantDNSSEC(MockEppLib):
self.mockedSendFunction.assert_has_calls(
[
call(
commands.UpdateDomain(
commands.InfoDomain(
name="dnssec-dsdata.gov",
nsset=None,
keyset=None,
registrant=None,
auth_info=None,
),
cleaned=True,
),
@ -1113,6 +1127,12 @@ class TestRegistrantDNSSEC(MockEppLib):
),
cleaned=True,
),
call(
commands.InfoDomain(
name="dnssec-dsdata.gov",
),
cleaned=True,
),
]
)
@ -1174,9 +1194,65 @@ class TestRegistrantDNSSEC(MockEppLib):
dnssecdata_get.dsData, self.dnssecExtensionWithMultDsData["dsData"]
)
def test_user_removes_dnssec_data(self):
"""
Scenario: Registrant removes DNSSEC ds data.
Verify that both the setter and getter are functioning properly
This test verifies:
1 - setter initially calls InfoDomain command
2 - invalidate cache forces second InfoDomain command (to match mocks)
3 - setter then calls UpdateDomain command
4 - setter adds the UpdateDNSSECExtension extension to the command with rem
"""
domain, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
dnssecdata_get_initial = domain.dnssecdata # call to force initial mock
domain._invalidate_cache()
domain.dnssecdata = self.dnssecExtensionRemovingDsData
# get the DNS SEC extension added to the UpdateDomain command and
# verify that it is properly sent
# args[0] is the _request sent to registry
args, _ = self.mockedSendFunction.call_args
# assert that the extension on the update matches
self.assertEquals(
args[0].extensions[0],
self.createUpdateExtension(
extensions.DNSSECExtension(**self.dnssecExtensionWithDsData),
remove=True
),
)
self.mockedSendFunction.assert_has_calls(
[
call(
commands.InfoDomain(
name="dnssec-dsdata.gov",
),
cleaned=True,
),
call(
commands.InfoDomain(
name="dnssec-dsdata.gov",
),
cleaned=True,
),
call(
commands.UpdateDomain(
name="dnssec-dsdata.gov",
nsset=None,
keyset=None,
registrant=None,
auth_info=None,
),
cleaned=True,
),
]
)
def test_user_adds_dnssec_keydata(self):
"""
Scenario: Registrant adds DNSSEC data.
Scenario: Registrant adds DNSSEC key data.
Verify that both the setter and getter are functioning properly
This test verifies: