From a1761cd68f91e2668d8d7e2fa7774f6496408be6 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 4 Feb 2020 21:25:33 -0800 Subject: [PATCH] id tests --- tests/fixtures/centos-7.7/id.json | 1 + tests/fixtures/osx-10.14.6/id.json | 1 + tests/test_id.py | 40 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 tests/fixtures/centos-7.7/id.json create mode 100644 tests/fixtures/osx-10.14.6/id.json create mode 100644 tests/test_id.py diff --git a/tests/fixtures/centos-7.7/id.json b/tests/fixtures/centos-7.7/id.json new file mode 100644 index 00000000..4766280e --- /dev/null +++ b/tests/fixtures/centos-7.7/id.json @@ -0,0 +1 @@ +{"uid": {"id": 1000, "name": "kbrazil"}, "gid": {"id": 1000, "name": "kbrazil"}, "groups": [{"id": 1000, "name": "kbrazil"}, {"id": 10, "name": "wheel"}], "context": {"user": "unconfined_u", "role": "unconfined_r", "type": "unconfined_t", "level": "s0-s0:c0.c1023"}} diff --git a/tests/fixtures/osx-10.14.6/id.json b/tests/fixtures/osx-10.14.6/id.json new file mode 100644 index 00000000..ac367902 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/id.json @@ -0,0 +1 @@ +{"uid": {"id": 501, "name": "kbrazil"}, "gid": {"id": 20, "name": "staff"}, "groups": [{"id": 20, "name": "staff"}, {"id": 501, "name": "access_bpf"}, {"id": 12, "name": "everyone"}, {"id": 61, "name": "localaccounts"}, {"id": 79, "name": "_appserverusr"}, {"id": 80, "name": "admin"}, {"id": 81, "name": "_appserveradm"}, {"id": 98, "name": "_lpadmin"}, {"id": 703, "name": "com.apple.sharepoint.group.3"}, {"id": 701, "name": "com.apple.sharepoint.group.1"}, {"id": 702, "name": "com.apple.sharepoint.group.2"}, {"id": 33, "name": "_appstore"}, {"id": 100, "name": "_lpoperator"}, {"id": 204, "name": "_developer"}, {"id": 250, "name": "_analyticsusers"}, {"id": 395, "name": "com.apple.access_ftp"}, {"id": 398, "name": "com.apple.access_screensharing"}]} diff --git a/tests/test_id.py b/tests/test_id.py new file mode 100644 index 00000000..cc0d0b34 --- /dev/null +++ b/tests/test_id.py @@ -0,0 +1,40 @@ +import os +import json +import unittest +import jc.parsers.id + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/id.out'), 'r') as f: + self.centos_7_7_id = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/id.out'), 'r') as f: + self.osx_10_14_6_id = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/id.json'), 'r') as f: + self.centos_7_7_id_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/id.json'), 'r') as f: + self.osx_10_14_6_id_json = json.loads(f.read()) + + def test_id_centos_7_7(self): + """ + Test 'id' on Centos 7.7 + """ + self.assertEqual(jc.parsers.id.parse(self.centos_7_7_id, quiet=True), self.centos_7_7_id_json) + + def test_id_osx_10_14_6(self): + """ + Test 'id' on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.id.parse(self.osx_10_14_6_id, quiet=True), self.osx_10_14_6_id_json) + + +if __name__ == '__main__': + unittest.main()