def test_is_overlap(self): """Test overlap detection helper""" self.assertTrue(AIDHeaderParser._is_overlap((0, 1), (1, 2))) self.assertTrue(AIDHeaderParser._is_overlap((0, 100), (90, 200))) self.assertTrue(AIDHeaderParser._is_overlap((20, 50), (1, 101))) self.assertFalse(AIDHeaderParser._is_overlap((0, 100), (101, 200))) self.assertFalse(AIDHeaderParser._is_overlap((-10, 0), (10, 20)))
def test_is_overlap(self): """Test overlap detection helper""" self.assertTrue(AIDHeaderParser._is_overlap((0, 1), (1, 2))) self.assertTrue(AIDHeaderParser._is_overlap((0, 100), (90, 200))) self.assertTrue(AIDHeaderParser._is_overlap((20, 50), (1, 101))) self.assertFalse(AIDHeaderParser._is_overlap((0, 100), (101, 200))) self.assertFalse(AIDHeaderParser._is_overlap((-10, 0), (10, 20)))
def test_aid_header_parser_good_unordered(self): """Test AID Header Parser good unordered input file""" with tempfile.NamedTemporaryFile() as temp_file: temp_file.write( textwrap.dedent(""" #define AID_FOO 1000 #define AID_OEM_RESERVED_1_END 8000 #define AID_BAR 1001 #define SOMETHING "something" #define AID_OEM_RESERVED_END 2999 #define AID_OEM_RESERVED_1_START 7000 #define AID_OEM_RESERVED_START 2900 """)) temp_file.flush() parser = AIDHeaderParser(temp_file.name) oem_ranges = parser.oem_ranges aids = parser.aids self.assertTrue((2900, 2999) in oem_ranges) self.assertFalse((5000, 6000) in oem_ranges) for aid in aids: self.assertTrue(aid.normalized_value in ['1000', '1001']) self.assertFalse(aid.normalized_value in ['1', '2', '3'])
def test_aid_header_parser_bad_oem_range_no_start(self): """Test AID Header Parser bad oem range (no start) input file""" with tempfile.NamedTemporaryFile() as temp_file: temp_file.write( textwrap.dedent(""" #define AID_OEM_RESERVED_END 2900 """)) temp_file.flush() with self.assertRaises(SystemExit): AIDHeaderParser(temp_file.name)
def test_aid_header_parser_bad_aid(self): """Test AID Header Parser bad aid input file""" with tempfile.NamedTemporaryFile() as temp_file: temp_file.write( textwrap.dedent(""" #define AID_FOO "bad" """)) temp_file.flush() with self.assertRaises(SystemExit): AIDHeaderParser(temp_file.name)
def test_aid_header_parser_bad_duplicate_ranges(self): """Test AID Header Parser exits cleanly on duplicate AIDs""" with tempfile.NamedTemporaryFile() as temp_file: temp_file.write( textwrap.dedent(""" #define AID_FOO 100 #define AID_BAR 100 """)) temp_file.flush() with self.assertRaises(SystemExit): AIDHeaderParser(temp_file.name)
def test_aid_header_parser_no_bad_aids(self): """Test AID Header Parser that it doesn't contain: Ranges, ie things the end with "_START" or "_END" AID_APP AID_USER For more details see: - https://android-review.googlesource.com/#/c/313024 - https://android-review.googlesource.com/#/c/313169 """ with tempfile.NamedTemporaryFile() as temp_file: temp_file.write( textwrap.dedent(""" #define AID_APP 10000 /* TODO: switch users over to AID_APP_START */ #define AID_APP_START 10000 /* first app user */ #define AID_APP_END 19999 /* last app user */ #define AID_CACHE_GID_START 20000 /* start of gids for apps to mark cached data */ #define AID_CACHE_GID_END 29999 /* end of gids for apps to mark cached data */ #define AID_SHARED_GID_START 50000 /* start of gids for apps in each user to share */ #define AID_SHARED_GID_END 59999 /* end of gids for apps in each user to share */ #define AID_ISOLATED_START 99000 /* start of uids for fully isolated sandboxed processes */ #define AID_ISOLATED_END 99999 /* end of uids for fully isolated sandboxed processes */ #define AID_USER 100000 /* TODO: switch users over to AID_USER_OFFSET */ #define AID_USER_OFFSET 100000 /* offset for uid ranges for each user */ """)) temp_file.flush() parser = AIDHeaderParser(temp_file.name) aids = parser.aids bad_aids = ['_START', '_END', 'AID_APP', 'AID_USER'] for aid in aids: self.assertFalse( any(bad in aid.identifier for bad in bad_aids), 'Not expecting keywords "%s" in aids "%s"' % (str(bad_aids), str([tmp.identifier for tmp in aids])))