From 2ee68892f2f05a4dfac74e612797f9433509f2a8 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Fri, 21 Jan 2011 12:46:49 +0200 Subject: [PATCH] Changes: add a method to security tests that reads tokens application should have from /sys RevBy: Antti Kervinen --- tests/Harmattan/TestScripts/test-security.py | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Harmattan/TestScripts/test-security.py b/tests/Harmattan/TestScripts/test-security.py index 9968a30..ac32cd7 100644 --- a/tests/Harmattan/TestScripts/test-security.py +++ b/tests/Harmattan/TestScripts/test-security.py @@ -48,6 +48,40 @@ class SecurityTests(unittest.TestCase): groups = map(f, groups) return ['UID::user', 'GID::users'] + groups + + def creds_defined_for_app(self, app): + """ + Reads the security tokens an application should have from + /sys/kernel/security/credp/policy and converts them to + human-readable form with creds-test (from the package + libcreds2-tools). + """ + + f = open("/sys/kernel/security/credp/policy") + lines = f.readlines() + f.close() + + creds = [] + found = False + + for line in lines: + if not found and line.find(app) != -1: + found = True + debug(line) + continue + + if found: + if re.match('^\s', line) != None: + creds.append(line.strip()) + debug(line) + else: + break + + def cred2str(cred): + st, op = commands.getstatusoutput("creds-test %s" % cred) + return op.split()[3] + + return [cred2str(cred) for cred in creds] def test_correct_creds(self): """