From cb5c1ba00dc0e02bf6ad6c40096d99e319fa6171 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 11 Mar 2020 17:04:48 -0700 Subject: [PATCH] add tests for fix to make the file parser splitting more robust --- tests/fixtures/osx-10.14.6/file2.json | 1 + tests/fixtures/osx-10.14.6/file2.out | 88 +++++++++++++++++++++++++++ tests/test_file.py | 12 ++++ 3 files changed, 101 insertions(+) create mode 100644 tests/fixtures/osx-10.14.6/file2.json create mode 100644 tests/fixtures/osx-10.14.6/file2.out diff --git a/tests/fixtures/osx-10.14.6/file2.json b/tests/fixtures/osx-10.14.6/file2.json new file mode 100644 index 00000000..78cea3db --- /dev/null +++ b/tests/fixtures/osx-10.14.6/file2.json @@ -0,0 +1 @@ +[{"filename": "AFP.conf", "type": "data"}, {"filename": "afpovertcp.cfg", "type": "ASCII text"}, {"filename": "aliases", "type": "ASCII text"}, {"filename": "aliases.db", "type": "Berkeley DB 1.85 (Hash, version 2, native byte-order)"}, {"filename": "apache2", "type": "directory"}, {"filename": "asl", "type": "directory"}, {"filename": "asl.conf", "type": "ASCII text"}, {"filename": "auto_home", "type": "ASCII text"}, {"filename": "auto_master", "type": "ASCII text"}, {"filename": "autofs.conf", "type": "ASCII text"}, {"filename": "bashrc", "type": "ASCII text"}, {"filename": "bashrc_Apple_Terminal", "type": "ASCII text"}, {"filename": "com.apple.screensharing.agent.launchd", "type": "ASCII text, with no line terminators"}, {"filename": "csh.cshrc", "type": "ASCII text"}, {"filename": "csh.login", "type": "ASCII text"}, {"filename": "csh.logout", "type": "ASCII text"}, {"filename": "cups", "type": "directory"}, {"filename": "defaults", "type": "directory"}, {"filename": "dnsextd.conf", "type": "ASCII text"}, {"filename": "emond.d", "type": "directory"}, {"filename": "find.codes", "type": "empty"}, {"filename": "fstab.hd", "type": "ASCII text"}, {"filename": "ftpusers", "type": "ASCII text"}, {"filename": "gettytab", "type": "ASCII text"}, {"filename": "group", "type": "ASCII text"}, {"filename": "hosts", "type": "ASCII text"}, {"filename": "hosts.equiv", "type": "empty"}, {"filename": "irbrc", "type": "Ruby script text, ASCII text"}, {"filename": "kern_loader.conf", "type": "empty"}, {"filename": "krb5.keytab", "type": "Kerberos Keytab file, realm=LKDC:SHA1.15090DD365668FBA1B0D2D3DD43FCB7CB9381160, principal=afpserver/LKDC:SHA1.15090DD365668FBA1B0D2D3DD43FCB7CB9381160, type=1, date=Tue Jul 2 15:52:04 2019, kvno=2"}, {"filename": "localtime", "type": "timezone data, version 2, 4 gmt time flags, 4 std time flags, no leap seconds, 185 transition times, 4 abbreviation chars"}, {"filename": "locate.rc", "type": "ASCII text"}, {"filename": "mach_init.d", "type": "directory"}, {"filename": "mach_init_per_login_session.d", "type": "directory"}, {"filename": "mach_init_per_user.d", "type": "directory"}, {"filename": "mail.rc", "type": "ASCII text"}, {"filename": "man.conf", "type": "ASCII text"}, {"filename": "manpaths", "type": "ASCII text"}, {"filename": "manpaths.d", "type": "directory"}, {"filename": "master.passwd", "type": "ASCII text"}, {"filename": "nanorc", "type": "ASCII text"}, {"filename": "networks", "type": "ASCII text"}, {"filename": "newsyslog.conf", "type": "ASCII text"}, {"filename": "newsyslog.d", "type": "directory"}, {"filename": "nfs.conf", "type": "ASCII text"}, {"filename": "notify.conf", "type": "ASCII text"}, {"filename": "ntp.conf", "type": "ASCII text"}, {"filename": "ntp_opendirectory.conf", "type": "ASCII text"}, {"filename": "openldap", "type": "directory"}, {"filename": "pam.d", "type": "directory"}, {"filename": "passwd", "type": "ASCII text"}, {"filename": "paths", "type": "ASCII text"}, {"filename": "paths.d", "type": "directory"}, {"filename": "periodic", "type": "directory"}, {"filename": "pf.anchors", "type": "directory"}, {"filename": "pf.conf", "type": "ASCII text"}, {"filename": "pf.os", "type": "ASCII text"}, {"filename": "php-fpm.conf.default", "type": "ASCII text"}, {"filename": "php-fpm.d", "type": "directory"}, {"filename": "php.ini.default", "type": "ASCII text"}, {"filename": "postfix", "type": "directory"}, {"filename": "ppp", "type": "directory"}, {"filename": "profile", "type": "ASCII text"}, {"filename": "protocols", "type": "ASCII text"}, {"filename": "racoon", "type": "directory"}, {"filename": "rc.common", "type": "ASCII text"}, {"filename": "rc.netboot", "type": "POSIX shell script text executable, ASCII text"}, {"filename": "resolv.conf", "type": "ASCII text"}, {"filename": "rmtab", "type": "empty"}, {"filename": "rpc", "type": "ASCII text"}, {"filename": "rtadvd.conf", "type": "ASCII text"}, {"filename": "security", "type": "directory"}, {"filename": "services", "type": "ASCII text"}, {"filename": "services.broker", "type": "ASCII text"}, {"filename": "shells", "type": "ASCII text"}, {"filename": "snmp", "type": "directory"}, {"filename": "ssh", "type": "directory"}, {"filename": "ssl", "type": "directory"}, {"filename": "sudo_lecture", "type": "ASCII text"}, {"filename": "sudoers", "type": "c program text, ASCII text"}, {"filename": "sudoers.d", "type": "directory"}, {"filename": "syslog.conf", "type": "ASCII text"}, {"filename": "thnuclnt", "type": "directory"}, {"filename": "ttys", "type": "ASCII text"}, {"filename": "wfs", "type": "directory"}, {"filename": "xtab", "type": "empty"}, {"filename": "zprofile", "type": "ASCII text"}, {"filename": "zshrc", "type": "ASCII text"}] diff --git a/tests/fixtures/osx-10.14.6/file2.out b/tests/fixtures/osx-10.14.6/file2.out new file mode 100644 index 00000000..b9306321 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/file2.out @@ -0,0 +1,88 @@ +AFP.conf: data +afpovertcp.cfg: ASCII text +aliases: ASCII text +aliases.db: Berkeley DB 1.85 (Hash, version 2, native byte-order) +apache2: directory +asl: directory +asl.conf: ASCII text +auto_home: ASCII text +auto_master: ASCII text +autofs.conf: ASCII text +bashrc: ASCII text +bashrc_Apple_Terminal: ASCII text +com.apple.screensharing.agent.launchd: ASCII text, with no line terminators +csh.cshrc: ASCII text +csh.login: ASCII text +csh.logout: ASCII text +cups: directory +defaults: directory +dnsextd.conf: ASCII text +emond.d: directory +find.codes: empty +fstab.hd: ASCII text +ftpusers: ASCII text +gettytab: ASCII text +group: ASCII text +hosts: ASCII text +hosts.equiv: empty +irbrc: Ruby script text, ASCII text +kern_loader.conf: empty +krb5.keytab: Kerberos Keytab file, realm=LKDC:SHA1.15090DD365668FBA1B0D2D3DD43FCB7CB9381160, principal=afpserver/LKDC:SHA1.15090DD365668FBA1B0D2D3DD43FCB7CB9381160, type=1, date=Tue Jul 2 15:52:04 2019, kvno=2 +localtime: timezone data, version 2, 4 gmt time flags, 4 std time flags, no leap seconds, 185 transition times, 4 abbreviation chars +locate.rc: ASCII text +mach_init.d: directory +mach_init_per_login_session.d: directory +mach_init_per_user.d: directory +mail.rc: ASCII text +man.conf: ASCII text +manpaths: ASCII text +manpaths.d: directory +master.passwd: ASCII text +nanorc: ASCII text +networks: ASCII text +newsyslog.conf: ASCII text +newsyslog.d: directory +nfs.conf: ASCII text +notify.conf: ASCII text +ntp.conf: ASCII text +ntp_opendirectory.conf: ASCII text +openldap: directory +pam.d: directory +passwd: ASCII text +paths: ASCII text +paths.d: directory +periodic: directory +pf.anchors: directory +pf.conf: ASCII text +pf.os: ASCII text +php-fpm.conf.default: ASCII text +php-fpm.d: directory +php.ini.default: ASCII text +postfix: directory +ppp: directory +profile: ASCII text +protocols: ASCII text +racoon: directory +rc.common: ASCII text +rc.netboot: POSIX shell script text executable, ASCII text +resolv.conf: ASCII text +rmtab: empty +rpc: ASCII text +rtadvd.conf: ASCII text +security: directory +services: ASCII text +services.broker: ASCII text +shells: ASCII text +snmp: directory +ssh: directory +ssl: directory +sudo_lecture: ASCII text +sudoers: c program text, ASCII text +sudoers.d: directory +syslog.conf: ASCII text +thnuclnt: directory +ttys: ASCII text +wfs: directory +xtab: empty +zprofile: ASCII text +zshrc: ASCII text diff --git a/tests/test_file.py b/tests/test_file.py index 67181854..ac80ea79 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -19,6 +19,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/file.out'), 'r', encoding='utf-8') as f: self.osx_10_14_6_file = f.read() + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/file2.out'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_file2 = f.read() + # output with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/file.json'), 'r', encoding='utf-8') as f: self.centos_7_7_file_json = json.loads(f.read()) @@ -29,6 +32,9 @@ class MyTests(unittest.TestCase): with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/file.json'), 'r', encoding='utf-8') as f: self.osx_10_14_6_file_json = json.loads(f.read()) + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/file2.json'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_file2_json = json.loads(f.read()) + def test_file_centos_7_7(self): """ Test 'file *' on Centos 7.7 @@ -47,6 +53,12 @@ class MyTests(unittest.TestCase): """ self.assertEqual(jc.parsers.file.parse(self.osx_10_14_6_file, quiet=True), self.osx_10_14_6_file_json) + def test_file2_osx_10_14_6(self): + """ + Test 'file *' with filetpe descriptions including colons on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.file.parse(self.osx_10_14_6_file2, quiet=True), self.osx_10_14_6_file2_json) + if __name__ == '__main__': unittest.main()