blob: f7e67c7f6bc34caea884379b18bb4190ae1a8c33 [file] [log] [blame]
Bartosz Fabianowski6fe8dee2012-06-21 16:35:57 +02001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Sosa2036ae32010-01-27 13:49:48 -08002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Chris Masone75850362011-01-04 11:37:22 -08005import logging
6from autotest_lib.client.common_lib import error
Bartosz Fabianowski6fe8dee2012-06-21 16:35:57 +02007from autotest_lib.client.cros import auth_server, cros_ui_test, dns_server
Chris Sosa2036ae32010-01-27 13:49:48 -08008
Eric Lie7c4cab2011-01-05 14:39:19 -08009class login_LoginSuccess(cros_ui_test.UITest):
Chris Sosa2036ae32010-01-27 13:49:48 -080010 version = 1
11
Bartosz Fabianowski6fe8dee2012-06-21 16:35:57 +020012
13 def __authenticator(self, email, password):
Doug Anderson7cdee9b2011-02-24 14:31:42 -080014 """Validate credentials before responding positively to an auth attempt.
Doug Anderson7cdee9b2011-02-24 14:31:42 -080015 """
Bartosz Fabianowski6fe8dee2012-06-21 16:35:57 +020016 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 Masone75850362011-01-04 11:37:22 -080020
rgindaf25f73f2010-04-07 14:55:25 -070021
Scott James Remnantd73c2562011-11-09 10:41:17 -080022 def initialize(self, creds='$default'):
Doug Anderson7cdee9b2011-02-24 14:31:42 -080023 """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 Remnantd73c2562011-11-09 10:41:17 -080033 super(login_LoginSuccess, self).initialize(creds)
Darin Petkovf93f65e2010-12-09 15:57:06 -080034
35
Chris Masone75850362011-01-04 11:37:22 -080036 def start_authserver(self):
Bartosz Fabianowski6fe8dee2012-06-21 16:35:57 +020037 """Override superclass to use our authenticator."""
38 super(login_LoginSuccess, self).start_authserver(
39 authenticator=self.__authenticator)
Chris Masone75850362011-01-04 11:37:22 -080040
41
Chris Masone05ce7572010-08-09 16:38:15 -070042 def ensure_login_complete(self):
43 """Wait for login to complete, including cookie fetching."""
Bartosz Fabianowski6fe8dee2012-06-21 16:35:57 +020044 self._authServer.wait_for_service_login()
Chris Masone05ce7572010-08-09 16:38:15 -070045 self._authServer.wait_for_issue_token()
46 self._authServer.wait_for_test_over()
47
48
rgindaf25f73f2010-04-07 14:55:25 -070049 def run_once(self):
Chris Sosab76e0ee2013-05-22 16:55:41 -070050 self.job.set_state('client_success', True)
51
Chris Masone9f3311a2010-08-05 18:01:41 -070052
53
54 def cleanup(self):
55 super(login_LoginSuccess, self).cleanup()
56 self.write_perf_keyval(self.get_auth_endpoint_misses())