# TODO: should error handling be improved so error messages
# from the binary are converted into specific exceptions types?
output = cls.run_cmd(cmd, encoding=encoding).stdout.strip()
- # remove escape chars (such as '//')
- output = output.replace('\\"', '"')
return output
@classmethod
# Copyright (c) 2016-2018 Intra2net AG <info@intra2net.com>
import os
+import json
import unittest
from src.cnfvar import string as cnfvar_old
4 HERE_BE_QUOTES,3: "unquo\\\\\"\"table"
"""
+demo_bad_quotes = '1 BAD_VALUE,0: "\""'
+
+demo_cnf_quoted_json = r''.join([
+ r'1 AD_MACHINE_CREDENTIALS,0: "{\"Reserved Flags\":\"0\",',
+ r'\"Join Time\":\"20241001071550.162557Z\",\"Computer Name\":\"MIS1\",',
+ r'\"Account Name\":\"MIS1$\",\"Secure Channel Type\":2,\"Trust Flags\":26}"'
+])
+
+
#
# test class
#
with open(os.devnull, "w") as devnull:
print(cnf, file=devnull)
+ @unittest.skip("todo: this does not add anything to `test_print_cnf`")
def test_print_cnf_garbage(self):
try:
with open(os.devnull, "w") as devnull:
def test_parse_cnf_quotes(self):
cnf = cnfvar_old.read_cnf(demo_cnf_escaped_quotes)
- with open(os.devnull, "w") as devnull:
- print(demo_invalid_cnfvar, file=devnull)
+ self.assertEqual(len(cnf["cnf"]), 4)
+
+ def test_parse_bad_cnf_quotes(self):
+ self.assertRaises(cnfvar_old.MalformedCNF,
+ cnfvar_old.read_cnf,
+ demo_bad_quotes)
+
+ def test_parse_quoted_json(self):
+ cnf = cnfvar_old.read_cnf(demo_cnf_quoted_json)
+ dat = json.loads(cnf["cnf"][0]["data"])
+ self.assertIn("Computer Name", dat)
+ self.assertIn("Account Name", dat)
def test_read_nonascii(self):
cnf = cnfvar_old.read_cnf(demo_nonascii)