1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
import os
import json
import unittest
import jc.parsers.dig
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig.out'), 'r', encoding='utf-8') as f:
centos_7_7_dig = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/dig.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_dig = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig-x.out'), 'r', encoding='utf-8') as f:
centos_7_7_dig_x = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/dig-x.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_dig_x = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig-aaaa.out'), 'r', encoding='utf-8') as f:
centos_7_7_dig_aaaa = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/dig-aaaa.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_dig_aaaa = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig-axfr.out'), 'r', encoding='utf-8') as f:
centos_7_7_dig_axfr = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/dig-axfr.out'), 'r', encoding='utf-8') as f:
ubuntu_18_4_dig_axfr = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/dig.out'), 'r', encoding='utf-8') as f:
osx_10_11_6_dig = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/dig-x.out'), 'r', encoding='utf-8') as f:
osx_10_11_6_dig_x = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/dig-aaaa.out'), 'r', encoding='utf-8') as f:
osx_10_11_6_dig_aaaa = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-x.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_x = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-aaaa.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_aaaa = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-axfr.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_axfr = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-noall-answer.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_noall_answer = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-answer-spaces.out'), 'r', encoding='utf-8') as f:
generic_dig_answer_spaces = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-additional.out'), 'r', encoding='utf-8') as f:
generic_dig_additional = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-additional2.out'), 'r', encoding='utf-8') as f:
generic_dig_additional2 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-additional3.out'), 'r', encoding='utf-8') as f:
generic_dig_additional3 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-edns.out'), 'r', encoding='utf-8') as f:
generic_dig_edns = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-edns2.out'), 'r', encoding='utf-8') as f:
generic_dig_edns2 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-edns3.out'), 'r', encoding='utf-8') as f:
generic_dig_edns3 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-nsid.out'), 'r', encoding='utf-8') as f:
generic_dig_nsid = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig.json'), 'r', encoding='utf-8') as f:
centos_7_7_dig_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/dig.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_dig_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig-x.json'), 'r', encoding='utf-8') as f:
centos_7_7_dig_x_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/dig-x.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_dig_x_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig-aaaa.json'), 'r', encoding='utf-8') as f:
centos_7_7_dig_aaaa_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/dig-aaaa.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_dig_aaaa_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/dig-axfr.json'), 'r', encoding='utf-8') as f:
centos_7_7_dig_axfr_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/dig-axfr.json'), 'r', encoding='utf-8') as f:
ubuntu_18_4_dig_axfr_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/dig.json'), 'r', encoding='utf-8') as f:
osx_10_11_6_dig_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/dig-x.json'), 'r', encoding='utf-8') as f:
osx_10_11_6_dig_x_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.11.6/dig-aaaa.json'), 'r', encoding='utf-8') as f:
osx_10_11_6_dig_aaaa_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-x.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_x_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-aaaa.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_aaaa_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-axfr.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_axfr_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/dig-noall-answer.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_dig_noall_answer_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-answer-spaces.json'), 'r', encoding='utf-8') as f:
generic_dig_answer_spaces_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-additional.json'), 'r', encoding='utf-8') as f:
generic_dig_additional_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-additional2.json'), 'r', encoding='utf-8') as f:
generic_dig_additional2_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-additional3.json'), 'r', encoding='utf-8') as f:
generic_dig_additional3_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-edns.json'), 'r', encoding='utf-8') as f:
generic_dig_edns_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-edns2.json'), 'r', encoding='utf-8') as f:
generic_dig_edns2_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-edns3.json'), 'r', encoding='utf-8') as f:
generic_dig_edns3_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/dig-nsid.json'), 'r', encoding='utf-8') as f:
generic_dig_nsid_json = json.loads(f.read())
def test_dig_nodata(self):
"""
Test 'dig' with no data
"""
self.assertEqual(jc.parsers.dig.parse('', quiet=True), [])
def test_dig_centos_7_7(self):
"""
Test 'dig' on Centos 7.7
"""
self.assertEqual(jc.parsers.dig.parse(self.centos_7_7_dig, quiet=True), self.centos_7_7_dig_json)
def test_dig_ubuntu_18_4(self):
"""
Test 'dig' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.dig.parse(self.ubuntu_18_4_dig, quiet=True), self.ubuntu_18_4_dig_json)
def test_dig_x_centos_7_7(self):
"""
Test 'dig -x' on Centos 7.7
"""
self.assertEqual(jc.parsers.dig.parse(self.centos_7_7_dig_x, quiet=True), self.centos_7_7_dig_x_json)
def test_dig_x_ubuntu_18_4(self):
"""
Test 'dig -x' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.dig.parse(self.ubuntu_18_4_dig_x, quiet=True), self.ubuntu_18_4_dig_x_json)
def test_dig_aaaa_centos_7_7(self):
"""
Test 'dig AAAA' on Centos 7.7
"""
self.assertEqual(jc.parsers.dig.parse(self.centos_7_7_dig_aaaa, quiet=True), self.centos_7_7_dig_aaaa_json)
def test_dig_aaaa_ubuntu_18_4(self):
"""
Test 'dig AAAA' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.dig.parse(self.ubuntu_18_4_dig_aaaa, quiet=True), self.ubuntu_18_4_dig_aaaa_json)
def test_dig_axfr_centos_7_7(self):
"""
Test 'dig axfr' on Centos 7.7
"""
self.assertEqual(jc.parsers.dig.parse(self.centos_7_7_dig_axfr, quiet=True), self.centos_7_7_dig_axfr_json)
def test_dig_axfr_ubuntu_18_4(self):
"""
Test 'dig axfr' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.dig.parse(self.ubuntu_18_4_dig_axfr, quiet=True), self.ubuntu_18_4_dig_axfr_json)
def test_dig_osx_10_11_6(self):
"""
Test 'dig' on OSX 10.11.6
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_11_6_dig, quiet=True), self.osx_10_11_6_dig_json)
def test_dig_x_osx_10_11_6(self):
"""
Test 'dig -x' on OSX 10.11.6
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_11_6_dig_x, quiet=True), self.osx_10_11_6_dig_x_json)
def test_dig_aaaa_osx_10_11_6(self):
"""
Test 'dig -aaaa' on OSX 10.11.6
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_11_6_dig_aaaa, quiet=True), self.osx_10_11_6_dig_aaaa_json)
def test_dig_osx_10_14_6(self):
"""
Test 'dig' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_14_6_dig, quiet=True), self.osx_10_14_6_dig_json)
def test_dig_x_osx_10_14_6(self):
"""
Test 'dig -x' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_14_6_dig_x, quiet=True), self.osx_10_14_6_dig_x_json)
def test_dig_aaaa_osx_10_14_6(self):
"""
Test 'dig -aaaa' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_14_6_dig_aaaa, quiet=True), self.osx_10_14_6_dig_aaaa_json)
def test_dig_axfr_osx_10_14_6(self):
"""
Test 'dig axfr' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_14_6_dig_axfr, quiet=True), self.osx_10_14_6_dig_axfr_json)
def test_dig_noall_answer_osx_10_14_6(self):
"""
Test 'dig +noall +answer' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.dig.parse(self.osx_10_14_6_dig_noall_answer, quiet=True), self.osx_10_14_6_dig_noall_answer_json)
def test_dig_answer_spaces(self):
"""
Test 'dig' with spaces in the answer data (e.g. TXT responses)
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_answer_spaces, quiet=True), self.generic_dig_answer_spaces_json)
def test_dig_additional(self):
"""
Test 'dig' with additional section
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_additional, quiet=True), self.generic_dig_additional_json)
def test_dig_additional2(self):
"""
Test 'dig' with additional section
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_additional2, quiet=True), self.generic_dig_additional2_json)
def test_dig_additional3(self):
"""
Test 'dig' with additional section
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_additional3, quiet=True), self.generic_dig_additional3_json)
def test_dig_edns(self):
"""
Test 'dig' with edns info
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_edns, quiet=True), self.generic_dig_edns_json)
def test_dig_edns2(self):
"""
Test 'dig' with edns info
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_edns2, quiet=True), self.generic_dig_edns2_json)
def test_dig_edns3(self):
"""
Test 'dig' with edns info
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_edns3, quiet=True), self.generic_dig_edns3_json)
def test_dig_nsid(self):
"""
Test 'dig' with nsid info
"""
self.assertEqual(jc.parsers.dig.parse(self.generic_dig_nsid, quiet=True), self.generic_dig_nsid_json)
if __name__ == '__main__':
unittest.main()
|