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, logging, os, re, shutil, socket, sys | 5 import dbus, logging, os, re, shutil, socket, sys |
6 import common | 6 import common |
7 import auth_server, constants, cryptohome, dns_server | 7 import auth_server, constants, cryptohome, dns_server |
8 import cros_logging, cros_ui, login, ownership | 8 import cros_logging, cros_ui, login, ownership |
9 from autotest_lib.client.bin import test, utils | 9 from autotest_lib.client.bin import test, utils |
10 from autotest_lib.client.common_lib import error | 10 from autotest_lib.client.common_lib import error |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 login.refresh_login_screen() | 194 login.refresh_login_screen() |
195 if self.auto_login: | 195 if self.auto_login: |
196 self.login(self.username, self.password) | 196 self.login(self.username, self.password) |
197 if is_creating_owner: | 197 if is_creating_owner: |
198 login.wait_for_ownership() | 198 login.wait_for_ownership() |
199 | 199 |
200 def __fake_ownership(self): | 200 def __fake_ownership(self): |
201 """Fake ownership by generating the necessary magic files.""" | 201 """Fake ownership by generating the necessary magic files.""" |
202 # Determine the module directory. | 202 # Determine the module directory. |
203 dirname = os.path.dirname(__file__) | 203 dirname = os.path.dirname(__file__) |
204 mock_certfile = os.path.join(dirname, 'mock_owner_cert.pem') | 204 mock_certfile = os.path.join(dirname, constants.MOCK_OWNER_CERT) |
205 mock_signedprefsfile = os.path.join(dirname, 'mock_owner.preferences') | 205 mock_signedpolicyfile = os.path.join(dirname, |
206 mock_signedpolicyfile = os.path.join(dirname, 'mock_owner.policy') | 206 constants.MOCK_OWNER_POLICY) |
207 utils.open_write_close( | 207 utils.open_write_close( |
208 constants.OWNER_KEY_FILE, | 208 constants.OWNER_KEY_FILE, |
209 ownership.cert_extract_pubkey_der(mock_certfile)) | 209 ownership.cert_extract_pubkey_der(mock_certfile)) |
210 shutil.copy(mock_signedprefsfile, | |
211 constants.SIGNED_PREFERENCES_FILE) | |
212 shutil.copy(mock_signedpolicyfile, | 210 shutil.copy(mock_signedpolicyfile, |
213 constants.SIGNED_POLICY_FILE) | 211 constants.SIGNED_POLICY_FILE) |
214 | 212 |
215 | 213 |
216 def __canonicalize(self, credential): | 214 def __canonicalize(self, credential): |
217 """Perform basic canonicalization of |email_address| | 215 """Perform basic canonicalization of |email_address| |
218 | 216 |
219 Perform basic canonicalization of |email_address|, taking | 217 Perform basic canonicalization of |email_address|, taking |
220 into account that gmail does not consider '.' or caps inside a | 218 into account that gmail does not consider '.' or caps inside a |
221 username to matter. It also ignores everything after a '+'. | 219 username to matter. It also ignores everything after a '+'. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 def get_autox(self): | 302 def get_autox(self): |
305 """Return a new autox instance. | 303 """Return a new autox instance. |
306 | 304 |
307 Explicitly cache this in your testcase if you want to reuse the | 305 Explicitly cache this in your testcase if you want to reuse the |
308 object, but beware that logging out will invalidate any existing | 306 object, but beware that logging out will invalidate any existing |
309 sessions. | 307 sessions. |
310 """ | 308 """ |
311 return cros_ui.get_autox() | 309 return cros_ui.get_autox() |
312 | 310 |
313 | 311 |
| 312 def validate_basic_policy(self, basic_policy): |
| 313 # Pull in protobuf definitions. |
| 314 sys.path.append(self.srcdir) |
| 315 from device_management_backend_pb2 import PolicyFetchResponse |
| 316 from device_management_backend_pb2 import PolicyData |
| 317 from chrome_device_policy_pb2 import ChromeDeviceSettingsProto |
| 318 from chrome_device_policy_pb2 import UserWhitelistProto |
| 319 |
| 320 response_proto = PolicyFetchResponse() |
| 321 response_proto.ParseFromString(basic_policy) |
| 322 ownership.assert_has_policy_data(response_proto) |
| 323 |
| 324 poldata = PolicyData() |
| 325 poldata.ParseFromString(response_proto.policy_data) |
| 326 ownership.assert_has_device_settings(poldata) |
| 327 ownership.assert_username(poldata, self.username) |
| 328 |
| 329 polval = ChromeDeviceSettingsProto() |
| 330 polval.ParseFromString(poldata.policy_value) |
| 331 ownership.assert_new_users(polval, True) |
| 332 ownership.assert_users_on_whitelist(polval, (self.username,)) |
| 333 |
| 334 |
314 def stop_authserver(self): | 335 def stop_authserver(self): |
315 """Tears down fake dns and fake Google Accounts server. If your | 336 """Tears down fake dns and fake Google Accounts server. If your |
316 subclass does not create these objects, you will want to override this | 337 subclass does not create these objects, you will want to override this |
317 method as well. | 338 method as well. |
318 """ | 339 """ |
319 if hasattr(self, '_authServer'): | 340 if hasattr(self, '_authServer'): |
320 self.revert_dns() | 341 self.revert_dns() |
321 self._authServer.stop() | 342 self._authServer.stop() |
322 self._dnsServer.stop() | 343 self._dnsServer.stop() |
323 | 344 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 413 |
393 self.stop_authserver() | 414 self.stop_authserver() |
394 self.__log_crashed_processes(self.crash_blacklist) | 415 self.__log_crashed_processes(self.crash_blacklist) |
395 | 416 |
396 | 417 |
397 def get_auth_endpoint_misses(self): | 418 def get_auth_endpoint_misses(self): |
398 if hasattr(self, '_authServer'): | 419 if hasattr(self, '_authServer'): |
399 return self._authServer.get_endpoint_misses() | 420 return self._authServer.get_endpoint_misses() |
400 else: | 421 else: |
401 return {} | 422 return {} |
OLD | NEW |