Skip to content

Commit

Permalink
Merge pull request rthalley#189 from sebix/dnssecimport
Browse files Browse the repository at this point in the history
Style fixes in tests/test_dnssec
  • Loading branch information
rthalley authored Jul 8, 2016
2 parents 004c2d4 + 54759be commit 11e00e4
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions tests/test_dnssec.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
except ImportError:
import unittest

try:
import Crypto.Util.number # pylint: disable=unused-import
import_ok = True
except ImportError:
import_ok = False

import dns.dnssec
import dns.name
import dns.rdata
Expand Down Expand Up @@ -150,34 +156,36 @@
abs_ecdsa384_soa_rrsig = dns.rrset.from_text('example.', 86400, 'IN', 'RRSIG',
"SOA 14 1 86400 20130929021229 20130921230729 63571 example. CrnCu34EeeRz0fEhL9PLlwjpBKGYW8QjBjFQTwd+ViVLRAS8tNkcDwQE NhSV89NEjj7ze1a/JcCfcJ+/mZgnvH4NHLNg3Tf6KuLZsgs2I4kKQXEk 37oIHravPEOlGYNI")

@unittest.skipUnless(import_ok, "skipping DNSSEC tests because pycrypto is not"
" installed")
class DNSSECValidatorTestCase(unittest.TestCase):

@unittest.skipIf(not dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
@unittest.skipUnless(dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
def testAbsoluteRSAGood(self):
dns.dnssec.validate(abs_soa, abs_soa_rrsig, abs_keys, None, when)

@unittest.skipIf(not dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
@unittest.skipUnless(dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
def testDuplicateKeytag(self):
dns.dnssec.validate(abs_soa, abs_soa_rrsig, abs_keys_duplicate_keytag, None, when)

@unittest.skipIf(not dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
@unittest.skipUnless(dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
def testAbsoluteRSABad(self):
def bad():
dns.dnssec.validate(abs_other_soa, abs_soa_rrsig, abs_keys, None,
when)
self.failUnlessRaises(dns.dnssec.ValidationFailure, bad)

@unittest.skipIf(not dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
@unittest.skipUnless(dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
def testRelativeRSAGood(self):
dns.dnssec.validate(rel_soa, rel_soa_rrsig, rel_keys,
abs_dnspython_org, when)

@unittest.skipIf(not dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
@unittest.skipUnless(dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
def testRelativeRSABad(self):
def bad():
dns.dnssec.validate(rel_other_soa, rel_soa_rrsig, rel_keys,
Expand All @@ -188,14 +196,14 @@ def testMakeSHA256DS(self):
ds = dns.dnssec.make_ds(abs_dnspython_org, sep_key, 'SHA256')
self.failUnless(ds == good_ds)

@unittest.skipIf(not dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
@unittest.skipUnless(dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
def testAbsoluteDSAGood(self):
dns.dnssec.validate(abs_dsa_soa, abs_dsa_soa_rrsig, abs_dsa_keys, None,
when2)

@unittest.skipIf(not dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
@unittest.skipUnless(dns.dnssec._have_pycrypto,
"PyCrypto cannot be imported")
def testAbsoluteDSABad(self):
def bad():
dns.dnssec.validate(abs_other_dsa_soa, abs_dsa_soa_rrsig,
Expand All @@ -210,28 +218,28 @@ def testMakeExampleSHA256DS(self):
ds = dns.dnssec.make_ds(abs_example, example_sep_key, 'SHA256')
self.failUnless(ds == example_ds_sha256)

@unittest.skipIf(not dns.dnssec._have_ecdsa,
"python ECDSA cannot be imported")
@unittest.skipUnless(dns.dnssec._have_ecdsa,
"python ECDSA cannot be imported")
def testAbsoluteECDSA256Good(self):
dns.dnssec.validate(abs_ecdsa256_soa, abs_ecdsa256_soa_rrsig,
abs_ecdsa256_keys, None, when3)

@unittest.skipIf(not dns.dnssec._have_ecdsa,
"python ECDSA cannot be imported")
@unittest.skipUnless(dns.dnssec._have_ecdsa,
"python ECDSA cannot be imported")
def testAbsoluteECDSA256Bad(self):
def bad():
dns.dnssec.validate(abs_other_ecdsa256_soa, abs_ecdsa256_soa_rrsig,
abs_ecdsa256_keys, None, when3)
self.failUnlessRaises(dns.dnssec.ValidationFailure, bad)

@unittest.skipIf(not dns.dnssec._have_ecdsa,
"python ECDSA cannot be imported")
@unittest.skipUnless(dns.dnssec._have_ecdsa,
"python ECDSA cannot be imported")
def testAbsoluteECDSA384Good(self):
dns.dnssec.validate(abs_ecdsa384_soa, abs_ecdsa384_soa_rrsig,
abs_ecdsa384_keys, None, when4)

@unittest.skipIf(not dns.dnssec._have_ecdsa,
"python ECDSA cannot be imported")
@unittest.skipUnless(dns.dnssec._have_ecdsa,
"python ECDSA cannot be imported")
def testAbsoluteECDSA384Bad(self):
def bad():
dns.dnssec.validate(abs_other_ecdsa384_soa, abs_ecdsa384_soa_rrsig,
Expand All @@ -240,13 +248,4 @@ def bad():


if __name__ == '__main__':
import_ok = False
try:
import Crypto.Util.number # pylint: disable=unused-import
import_ok = True
except ImportError:
pass
if import_ok:
unittest.main()
else:
print('skipping DNSSEC tests because pycrypto is not installed')
unittest.main()

0 comments on commit 11e00e4

Please sign in to comment.