Bartosz Fabianowski | 6fe8dee | 2012-06-21 16:35:57 +0200 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Sosa | 2036ae3 | 2010-01-27 13:49:48 -0800 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Chris Masone | 7585036 | 2011-01-04 11:37:22 -0800 | [diff] [blame] | 5 | import logging |
| 6 | from autotest_lib.client.common_lib import error |
Bartosz Fabianowski | 6fe8dee | 2012-06-21 16:35:57 +0200 | [diff] [blame] | 7 | from autotest_lib.client.cros import auth_server, cros_ui_test, dns_server |
Chris Sosa | 2036ae3 | 2010-01-27 13:49:48 -0800 | [diff] [blame] | 8 | |
Eric Li | e7c4cab | 2011-01-05 14:39:19 -0800 | [diff] [blame] | 9 | class login_LoginSuccess(cros_ui_test.UITest): |
Chris Sosa | 2036ae3 | 2010-01-27 13:49:48 -0800 | [diff] [blame] | 10 | version = 1 |
| 11 | |
Bartosz Fabianowski | 6fe8dee | 2012-06-21 16:35:57 +0200 | [diff] [blame] | 12 | |
| 13 | def __authenticator(self, email, password): |
Doug Anderson | 7cdee9b | 2011-02-24 14:31:42 -0800 | [diff] [blame] | 14 | """Validate credentials before responding positively to an auth attempt. |
Doug Anderson | 7cdee9b | 2011-02-24 14:31:42 -0800 | [diff] [blame] | 15 | """ |
Bartosz Fabianowski | 6fe8dee | 2012-06-21 16:35:57 +0200 | [diff] [blame] | 16 | logging.debug('checking %s == %s' % (self.username, email)) |
| 17 | if self.username != email: |
| 18 | raise error.TestError('Incorrect creds passed to login handler.') |
| 19 | return self.username == email |
Chris Masone | 7585036 | 2011-01-04 11:37:22 -0800 | [diff] [blame] | 20 | |
rginda | f25f73f | 2010-04-07 14:55:25 -0700 | [diff] [blame] | 21 | |
Scott James Remnant | d73c256 | 2011-11-09 10:41:17 -0800 | [diff] [blame] | 22 | def initialize(self, creds='$default'): |
Doug Anderson | 7cdee9b | 2011-02-24 14:31:42 -0800 | [diff] [blame] | 23 | """Override superclass to provide a default value for the creds param. |
| 24 | |
| 25 | This is important for our class, since a creds of None (AKA "browse |
| 26 | without signing in") don't make sense for a test that is checking that |
| 27 | authentication works properly. |
| 28 | |
| 29 | @param creds: See cros_ui_test.UITest; For us, the default is |
| 30 | '$default'. |
| 31 | """ |
| 32 | assert creds, "Must use non-Guest creds for login_LoginSuccess test." |
Scott James Remnant | d73c256 | 2011-11-09 10:41:17 -0800 | [diff] [blame] | 33 | super(login_LoginSuccess, self).initialize(creds) |
Darin Petkov | f93f65e | 2010-12-09 15:57:06 -0800 | [diff] [blame] | 34 | |
| 35 | |
Chris Masone | 7585036 | 2011-01-04 11:37:22 -0800 | [diff] [blame] | 36 | def start_authserver(self): |
Bartosz Fabianowski | 6fe8dee | 2012-06-21 16:35:57 +0200 | [diff] [blame] | 37 | """Override superclass to use our authenticator.""" |
| 38 | super(login_LoginSuccess, self).start_authserver( |
| 39 | authenticator=self.__authenticator) |
Chris Masone | 7585036 | 2011-01-04 11:37:22 -0800 | [diff] [blame] | 40 | |
| 41 | |
Chris Masone | 05ce757 | 2010-08-09 16:38:15 -0700 | [diff] [blame] | 42 | def ensure_login_complete(self): |
| 43 | """Wait for login to complete, including cookie fetching.""" |
Bartosz Fabianowski | 6fe8dee | 2012-06-21 16:35:57 +0200 | [diff] [blame] | 44 | self._authServer.wait_for_service_login() |
Chris Masone | 05ce757 | 2010-08-09 16:38:15 -0700 | [diff] [blame] | 45 | self._authServer.wait_for_issue_token() |
| 46 | self._authServer.wait_for_test_over() |
| 47 | |
| 48 | |
rginda | f25f73f | 2010-04-07 14:55:25 -0700 | [diff] [blame] | 49 | def run_once(self): |
Chris Sosa | b76e0ee | 2013-05-22 16:55:41 -0700 | [diff] [blame^] | 50 | self.job.set_state('client_success', True) |
| 51 | |
Chris Masone | 9f3311a | 2010-08-05 18:01:41 -0700 | [diff] [blame] | 52 | |
| 53 | |
| 54 | def cleanup(self): |
| 55 | super(login_LoginSuccess, self).cleanup() |
| 56 | self.write_perf_keyval(self.get_auth_endpoint_misses()) |