From 8682d712d961d7a4937c648277f3dfeb47e27d52 Mon Sep 17 00:00:00 2001 From: Dan Cashman <dcashman@google.com> Date: Wed, 2 Aug 2017 15:14:53 -0700 Subject: [PATCH] treble compat: Add test for removed public types without compat entry. Also fix up set() additions in mini_parser.py and add global reference to the parser in tests for clarity. Bug: 36899958 Test: rm public type in old policy from policy and observe test failure. Change-Id: I6cba2473526798be871cd69249c9bbc6df2c5b4c --- tests/mini_parser.py | 6 +++--- tests/treble_sepolicy_tests.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/mini_parser.py b/tests/mini_parser.py index 57b3d59f8..fbeaff8e5 100644 --- a/tests/mini_parser.py +++ b/tests/mini_parser.py @@ -41,12 +41,12 @@ class MiniCilParser: def _parseType(self, stmt): m = re.match(r"type\s+(.+)", stmt) - self.types.update(set(m.group(1))) + self.types.add(m.group(1)) return def _parseTypeattribute(self, stmt): m = re.match(r"typeattribute\s+(.+)", stmt) - self.typeattributes.update(set(m.group(1))) + self.typeattributes.add(m.group(1)) return def _parseTypeattributeset(self, stmt): @@ -67,7 +67,7 @@ class MiniCilParser: # check to see if this typeattributeset is a versioned public type pub = re.match(r"(\w+)_\d+_\d+", ta) if pub is not None: - self.pubtypes.update(set(pub.group(1))) + self.pubtypes.add(pub.group(1)) return def _parseStmt(self, stmt): diff --git a/tests/treble_sepolicy_tests.py b/tests/treble_sepolicy_tests.py index 7584cab5a..7e3e110ee 100644 --- a/tests/treble_sepolicy_tests.py +++ b/tests/treble_sepolicy_tests.py @@ -212,6 +212,7 @@ def TestCoredomainViolations(): def TestNoUnmappedNewTypes(): global alltypes global oldalltypes + global compatMapping newt = alltypes - oldalltypes ret = "" violators = [] @@ -227,8 +228,31 @@ def TestNoUnmappedNewTypes(): ret += " ".join(str(x) for x in sorted(violators)) + "\n" return ret +### +# Make sure that any public type removed in the current policy has its +# declaration added to the mapping file for use in non-platform policy +def TestNoUnmappedRmTypes(): + global alltypes + global oldalltypes + global compatMapping + rmt = oldalltypes - alltypes + ret = "" + violators = [] + + for o in rmt: + if o in compatMapping.pubtypes and not o in compatMapping.types: + violators.append(o) + + if len(violators) > 0: + ret += "SELinux: The following formerly public types were removed from " + ret += "policy without a declaration in the compatibility mapping " + ret += "file(s) found in prebuilts/api/" + compatMapping.apiLevel + "/\n" + ret += " ".join(str(x) for x in sorted(violators)) + "\n" + return ret + def TestTrebleCompatMapping(): ret = TestNoUnmappedNewTypes() + ret += TestNoUnmappedRmTypes() return ret ### # extend OptionParser to allow the same option flag to be used multiple times. -- GitLab