1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-10-08 23:22:21 +02:00

Add ISC 'host' support (#450)

* Add ISC 'host' support

Add ISC 'host' command support

* Update host.py

remove leading tab from string

* Add integer conversion

Per request, fix integer conversion

* Cleanup

Cleanup strip()'s

* Add tests

Add two tests for the 'host' parser

* Update test_host.py

nit

---------

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
This commit is contained in:
pettai
2023-10-01 00:26:03 +02:00
committed by GitHub
parent a9958841e4
commit 36fa08d711
7 changed files with 328 additions and 0 deletions

View File

@@ -0,0 +1 @@
[{"hostname":"google.com","address":["142.250.179.206"],"v6-address":["2a00:1450:400e:811::200e"],"mail":["smtp.google.com."]}]

View File

@@ -0,0 +1,3 @@
google.com has address 142.250.179.206
google.com has IPv6 address 2a00:1450:400e:811::200e
google.com mail is handled by 10 smtp.google.com.

View File

@@ -0,0 +1 @@
[{"nameserver":"192.36.125.2","zone":"sunet.se","mname":"hidden-master.sunet.se.","rname":"hostmaster.sunet.se.","serial":2023091102,"refresh":28800,"retry":7200,"expire":604800,"minimum":300},{"nameserver":"193.10.252.19","zone":"sunet.se","mname":"hidden-master.sunet.se.","rname":"hostmaster.sunet.se.","serial":2023091102,"refresh":28800,"retry":7200,"expire":604800,"minimum":300},{"nameserver":"2001:6b0:1::250","zone":"sunet.se","mname":"hidden-master.sunet.se.","rname":"hostmaster.sunet.se.","serial":2023091102,"refresh":28800,"retry":7200,"expire":604800,"minimum":300},{"nameserver":"2001:948:4:2::19","zone":"sunet.se","mname":"hidden-master.sunet.se.","rname":"hostmaster.sunet.se.","serial":2023091102,"refresh":28800,"retry":7200,"expire":604800,"minimum":300},{"nameserver":"2001:6b0:5a:4020::384","zone":"sunet.se","mname":"hidden-master.sunet.se.","rname":"hostmaster.sunet.se.","serial":2023091102,"refresh":28800,"retry":7200,"expire":604800,"minimum":300},{"nameserver":"130.237.72.250","zone":"sunet.se","mname":"hidden-master.sunet.se.","rname":"hostmaster.sunet.se.","serial":2023091102,"refresh":28800,"retry":7200,"expire":604800,"minimum":300},{"nameserver":"2001:6b0:7::2","zone":"sunet.se","mname":"hidden-master.sunet.se.","rname":"hostmaster.sunet.se.","serial":2023091102,"refresh":28800,"retry":7200,"expire":604800,"minimum":300},{"nameserver":"89.47.185.240","zone":"sunet.se","mname":"hidden-master.sunet.se.","rname":"hostmaster.sunet.se.","serial":2023091102,"refresh":28800,"retry":7200,"expire":604800,"minimum":300}]

16
tests/fixtures/generic/host-sunet.out vendored Normal file
View File

@@ -0,0 +1,16 @@
Nameserver 192.36.125.2:
sunet.se has SOA record hidden-master.sunet.se. hostmaster.sunet.se. 2023091102 28800 7200 604800 300
Nameserver 193.10.252.19:
sunet.se has SOA record hidden-master.sunet.se. hostmaster.sunet.se. 2023091102 28800 7200 604800 300
Nameserver 2001:6b0:1::250:
sunet.se has SOA record hidden-master.sunet.se. hostmaster.sunet.se. 2023091102 28800 7200 604800 300
Nameserver 2001:948:4:2::19:
sunet.se has SOA record hidden-master.sunet.se. hostmaster.sunet.se. 2023091102 28800 7200 604800 300
Nameserver 2001:6b0:5a:4020::384:
sunet.se has SOA record hidden-master.sunet.se. hostmaster.sunet.se. 2023091102 28800 7200 604800 300
Nameserver 130.237.72.250:
sunet.se has SOA record hidden-master.sunet.se. hostmaster.sunet.se. 2023091102 28800 7200 604800 300
Nameserver 2001:6b0:7::2:
sunet.se has SOA record hidden-master.sunet.se. hostmaster.sunet.se. 2023091102 28800 7200 604800 300
Nameserver 89.47.185.240:
sunet.se has SOA record hidden-master.sunet.se. hostmaster.sunet.se. 2023091102 28800 7200 604800 300

58
tests/test_host.py Normal file
View File

@@ -0,0 +1,58 @@
import os
import unittest
import json
from typing import Dict
from jc.parsers.host import parse
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
f_in: Dict = {}
f_json: Dict = {}
@classmethod
def setUpClass(cls):
fixtures = {
'google': (
'fixtures/generic/host-google.out',
'fixtures/generic/host-google.json'),
'sunet': (
'fixtures/generic/host-sunet.out',
'fixtures/generic/host-sunet.json')
}
for file, filepaths in fixtures.items():
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
cls.f_in[file] = a.read()
cls.f_json[file] = json.loads(b.read())
# host cannot run without input (will only display help)
# def test_host_nodata(self):
# """
# Test 'host' with no data
# """
# self.assertEqual(parse('', quiet=True), {})
def test_host_google(self):
"""
Test 'host google'
"""
self.assertEqual(
parse(self.f_in['google'], quiet=True),
self.f_json['google']
)
def test_host_sunet(self):
"""
Test 'host sunet'
"""
self.assertEqual(
parse(self.f_in['sunet'], quiet=True),
self.f_json['sunet']
)
if __name__ == '__main__':
unittest.main()