OLD | NEW |
1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import dbus | 5 import dbus |
6 import dbus.glib | 6 import dbus.glib |
7 import gobject | 7 import gobject |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import tempfile | 10 import tempfile |
(...skipping 21 matching lines...) Expand all Loading... |
32 cryptohome.mount_vault(self._testuser, self._testpass, create=True) | 32 cryptohome.mount_vault(self._testuser, self._testpass, create=True) |
33 # to prime nssdb. | 33 # to prime nssdb. |
34 self._tempdir = autotemp.tempdir(unique_id=self.__class__.__name__) | 34 self._tempdir = autotemp.tempdir(unique_id=self.__class__.__name__) |
35 tmpname = self.__generate_temp_filename() | 35 tmpname = self.__generate_temp_filename() |
36 utils.system_output(cros_ui.xcommand_as('HOME=%s %s %s' % | 36 utils.system_output(cros_ui.xcommand_as('HOME=%s %s %s' % |
37 (constants.CRYPTOHOME_MOUNT_PT, | 37 (constants.CRYPTOHOME_MOUNT_PT, |
38 constants.KEYGEN, | 38 constants.KEYGEN, |
39 tmpname))) | 39 tmpname))) |
40 os.unlink(tmpname) | 40 os.unlink(tmpname) |
41 | 41 |
42 self.use_known_ownerkeys() | 42 ownership.use_known_ownerkeys() |
43 cros_ui.start() | 43 cros_ui.start() |
44 login.wait_for_browser() | 44 login.wait_for_browser() |
45 | 45 |
46 | 46 |
47 def __generate_temp_filename(self): | 47 def __generate_temp_filename(self): |
48 just_for_name = tempfile.NamedTemporaryFile(mode='w', delete=True) | 48 just_for_name = tempfile.NamedTemporaryFile(mode='w', delete=True) |
49 basename = just_for_name.name | 49 basename = just_for_name.name |
50 just_for_name.close() # deletes file. | 50 just_for_name.close() # deletes file. |
51 return basename | 51 return basename |
52 | 52 |
53 | 53 |
54 def run_once(self): | 54 def run_once(self): |
55 pkey = self.known_privkey() | 55 pkey = ownership.known_privkey() |
56 pubkey = self.known_pubkey() | 56 pubkey = ownership.known_pubkey() |
57 sm = self.connect_to_session_manager() | 57 sm = self.connect_to_session_manager() |
58 if not sm.StartSession(self._testuser, ''): | 58 if not sm.StartSession(self._testuser, ''): |
59 raise error.TestFail('Could not start session for owner') | 59 raise error.TestFail('Could not start session for owner') |
60 | 60 |
61 poldata = self.build_policy_data(owner=self._testuser, | 61 poldata = self.build_policy_data(owner=self._testuser, |
62 guests=False, | 62 guests=False, |
63 new_users=True, | 63 new_users=True, |
64 roaming=True, | 64 roaming=True, |
65 whitelist=(self._testuser, 'a@b.c'), | 65 whitelist=(self._testuser, 'a@b.c'), |
66 proxies={ 'proxy_mode': 'direct' }) | 66 proxies={ 'proxy_mode': 'direct' }) |
67 | 67 |
68 policy_string = self.generate_policy(pkey, pubkey, poldata) | 68 policy_string = self.generate_policy(pkey, pubkey, poldata) |
69 self.push_policy(policy_string, sm) | 69 self.push_policy(policy_string, sm) |
70 retrieved_policy = self.get_policy(sm) | 70 retrieved_policy = self.get_policy(sm) |
71 | 71 if retrieved_policy is None: raise error.TestFail('Policy not found') |
72 if retrieved_policy != policy_string: | 72 self.compare_policy_response(retrieved_policy, |
73 raise error.TestFail('Policy should not be %s' % retrieved_policy) | 73 owner=self._testuser, |
74 | 74 guests=False, |
| 75 new_users=True, |
| 76 roaming=True, |
| 77 whitelist=(self._testuser, 'a@b.c'), |
| 78 proxies={ 'proxy_mode': 'direct' }) |
| 79 try: |
| 80 # Sanity check against an incorrect policy |
| 81 self.compare_policy_response(retrieved_policy, |
| 82 owner=self._testuser, |
| 83 guests=True, |
| 84 whitelist=(self._testuser, 'a@b.c'), |
| 85 proxies={ 'proxy_mode': 'direct' }) |
| 86 except ownership.OwnershipError: |
| 87 pass |
| 88 else: |
| 89 raise error.TestFail('Did not detect bad policy') |
75 if not sm.StopSession(''): | 90 if not sm.StopSession(''): |
76 raise error.TestFail('Could not stop session for owner') | 91 raise error.TestFail('Could not stop session for owner') |
77 | 92 |
78 | 93 |
79 def cleanup(self): | 94 def cleanup(self): |
80 cryptohome.unmount_vault() | 95 cryptohome.unmount_vault() |
81 if self._tempdir: self._tempdir.clean() | 96 if self._tempdir: self._tempdir.clean() |
82 cros_ui.start(allow_fail=True) | 97 cros_ui.start(allow_fail=True) |
83 super(login_OwnershipApi, self).cleanup() | 98 super(login_OwnershipApi, self).cleanup() |
OLD | NEW |