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==", "pubKey": "AQPJ////4Q==",
} }
dnssecExtensionWithDsData: Mapping[Any, Any] = { dnssecExtensionWithDsData: Mapping[Any, Any] = {
"dsData": [common.DSData(**addDsData1)] # type: ignore "dsData": [common.DSData(**addDsData1)], # type: ignore
"keyData": [],
} }
dnssecExtensionWithMultDsData: Mapping[str, Any] = { dnssecExtensionWithMultDsData: Mapping[str, Any] = {
"dsData": [ "dsData": [
common.DSData(**addDsData1), # type: ignore common.DSData(**addDsData1), # type: ignore
common.DSData(**addDsData2), # type: ignore common.DSData(**addDsData2), # type: ignore
], ],
"keyData": [],
} }
dnssecExtensionWithKeyData: Mapping[str, Any] = { dnssecExtensionWithKeyData: Mapping[str, Any] = {
"maxSigLife": 3215,
"keyData": [common.DNSSECKeyData(**keyDataDict)], # type: ignore "keyData": [common.DNSSECKeyData(**keyDataDict)], # type: ignore
"dsData": [],
}
dnssecExtensionRemovingDsData: Mapping[Any, Any] = {
"dsData": [],
"keyData": [],
} }
def mockSend(self, _request, cleaned): def mockSend(self, _request, cleaned):
@ -756,26 +762,35 @@ class MockEppLib(TestCase):
if getattr(_request, "name", None) == "security.gov": if getattr(_request, "name", None) == "security.gov":
return MagicMock(res_data=[self.infoDomainNoContact]) return MagicMock(res_data=[self.infoDomainNoContact])
elif getattr(_request, "name", None) == "dnssec-dsdata.gov": elif getattr(_request, "name", None) == "dnssec-dsdata.gov":
return MagicMock( if self.mockedSendFunction.call_count == 1:
res_data=[self.mockDataInfoDomain], return MagicMock(res_data=[self.mockDataInfoDomain])
extensions=[ else:
extensions.DNSSECExtension(**self.dnssecExtensionWithDsData) return MagicMock(
], res_data=[self.mockDataInfoDomain],
) extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithDsData)
],
)
elif getattr(_request, "name", None) == "dnssec-multdsdata.gov": elif getattr(_request, "name", None) == "dnssec-multdsdata.gov":
return MagicMock( if self.mockedSendFunction.call_count == 1:
res_data=[self.mockDataInfoDomain], return MagicMock(res_data=[self.mockDataInfoDomain])
extensions=[ else:
extensions.DNSSECExtension(**self.dnssecExtensionWithMultDsData) return MagicMock(
], res_data=[self.mockDataInfoDomain],
) extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithMultDsData)
],
)
elif getattr(_request, "name", None) == "dnssec-keydata.gov": elif getattr(_request, "name", None) == "dnssec-keydata.gov":
return MagicMock( if self.mockedSendFunction.call_count == 1:
res_data=[self.mockDataInfoDomain], return MagicMock(res_data=[self.mockDataInfoDomain])
extensions=[ else:
extensions.DNSSECExtension(**self.dnssecExtensionWithKeyData) return MagicMock(
], res_data=[self.mockDataInfoDomain],
) extensions=[
extensions.DNSSECExtension(**self.dnssecExtensionWithKeyData)
],
)
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])

View file

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