If whois information is incomplete, exclude it
Conflicts: satori/dns.py Change-Id: Id136bf83e0d422c8d4b164d464aa721247f9bf26
This commit is contained in:
@@ -57,6 +57,12 @@ def domain_info(domain):
|
|||||||
registrar = []
|
registrar = []
|
||||||
if 'registrar' in result and len(result['registrar']) > 0:
|
if 'registrar' in result and len(result['registrar']) > 0:
|
||||||
registrar = result['registrar'][0]
|
registrar = result['registrar'][0]
|
||||||
|
nameservers = result.get('nameservers', [])
|
||||||
|
days_until_expires = None
|
||||||
|
expires = None
|
||||||
|
if 'expiration_date' in result:
|
||||||
|
if (isinstance(result['expiration_date'], list)
|
||||||
|
and len(result['expiration_date']) > 0):
|
||||||
expires = result['expiration_date'][0]
|
expires = result['expiration_date'][0]
|
||||||
if not isinstance(expires, datetime.datetime):
|
if not isinstance(expires, datetime.datetime):
|
||||||
expires = dateutil.parser.parse(expires)
|
expires = dateutil.parser.parse(expires)
|
||||||
@@ -65,7 +71,7 @@ def domain_info(domain):
|
|||||||
'name': domain,
|
'name': domain,
|
||||||
'whois': result['raw'],
|
'whois': result['raw'],
|
||||||
'registrar': registrar,
|
'registrar': registrar,
|
||||||
'nameservers': result['nameservers'],
|
'nameservers': nameservers,
|
||||||
'days_until_expires': days_until_expires,
|
'days_until_expires': days_until_expires,
|
||||||
'expiration_date': expires,
|
'expiration_date': expires,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,10 +137,13 @@ def output_results(discovered_target, results):
|
|||||||
if 'domain' in results:
|
if 'domain' in results:
|
||||||
print(u"Domain: %s" % results['domain']['name'])
|
print(u"Domain: %s" % results['domain']['name'])
|
||||||
print(u"\tRegistrar: %s" % results['domain']['registrar'])
|
print(u"\tRegistrar: %s" % results['domain']['registrar'])
|
||||||
|
if results['domain']['nameservers']:
|
||||||
print(u"\tNameservers: %s" % (
|
print(u"\tNameservers: %s" % (
|
||||||
", ".join(results['domain']['nameservers'])
|
", ".join(results['domain']['nameservers'])
|
||||||
))
|
))
|
||||||
print(u"\tExpires: %d days" % results['domain']['days_until_expires'])
|
if results['domain'].get('days_until_expires') is not None:
|
||||||
|
print(u"\tExpires: %d days" %
|
||||||
|
results['domain']['days_until_expires'])
|
||||||
|
|
||||||
if 'host' in results:
|
if 'host' in results:
|
||||||
host = results['host']
|
host = results['host']
|
||||||
|
|||||||
@@ -163,6 +163,13 @@ class TestDNS(utils.TestCase):
|
|||||||
data['nameservers']
|
data['nameservers']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_domain_info_returns_nameservers_as_list(self):
|
||||||
|
data = dns.domain_info(self.domain)
|
||||||
|
self.assertIsInstance(
|
||||||
|
data['nameservers'],
|
||||||
|
list
|
||||||
|
)
|
||||||
|
|
||||||
def test_domain_info_returns_registrar_from_whois(self):
|
def test_domain_info_returns_registrar_from_whois(self):
|
||||||
data = dns.domain_info(self.domain)
|
data = dns.domain_info(self.domain)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -208,6 +215,21 @@ class TestDNS(utils.TestCase):
|
|||||||
data['days_until_expires']
|
data['days_until_expires']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_domain_info_returns_none_for_days_until_expires(self):
|
||||||
|
small_whois = ["""
|
||||||
|
Domain : example.io
|
||||||
|
Status : Live
|
||||||
|
|
||||||
|
NS 1 : dns1.example.com
|
||||||
|
NS 2 : dns2.example.com
|
||||||
|
"""]
|
||||||
|
self.mynet.get_whois_raw.return_value = small_whois
|
||||||
|
data = dns.domain_info(self.domain)
|
||||||
|
self.assertEqual(
|
||||||
|
data['days_until_expires'],
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
def test_domain_info_returns_array_of_strings_whois_data(self):
|
def test_domain_info_returns_array_of_strings_whois_data(self):
|
||||||
data = dns.domain_info(self.domain)
|
data = dns.domain_info(self.domain)
|
||||||
self.assertIsInstance(data['whois'][0], str)
|
self.assertIsInstance(data['whois'][0], str)
|
||||||
@@ -235,5 +257,20 @@ class TestDNS(utils.TestCase):
|
|||||||
datetime.datetime
|
datetime.datetime
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_domain_info_returns_none_for_missing_expiration_date(self):
|
||||||
|
small_whois = ["""
|
||||||
|
Domain : example.io
|
||||||
|
Status : Live
|
||||||
|
|
||||||
|
NS 1 : dns1.example.com
|
||||||
|
NS 2 : dns2.example.com
|
||||||
|
"""]
|
||||||
|
self.mynet.get_whois_raw.return_value = small_whois
|
||||||
|
data = dns.domain_info(self.domain)
|
||||||
|
self.assertEqual(
|
||||||
|
data['expiration_date'],
|
||||||
|
None
|
||||||
|
)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user