1# Copyright 2018 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from autotest_lib.client.common_lib import error 6from autotest_lib.server.cros.faft.cr50_test import Cr50Test 7 8 9class firmware_Cr50Password(Cr50Test): 10 """Verify cr50 set password.""" 11 version = 1 12 NEW_PASSWORD = 'robot' 13 14 15 def run_once(self): 16 """Check we can set the cr50 password.""" 17 # Make sure to enable testlab mode, so we can guarantee the password 18 # can be cleared. 19 self.fast_ccd_open(enable_testlab=True) 20 self.cr50.send_command('ccd reset') 21 22 # Set the password. 23 self.set_ccd_password(self.CCD_PASSWORD) 24 if self.cr50.password_is_reset(): 25 raise error.TestFail('Failed to set password') 26 27 # Test 'ccd reset' clears the password. 28 self.cr50.send_command('ccd reset') 29 if not self.cr50.password_is_reset(): 30 raise error.TestFail('ccd reset did not clear the password') 31 32 # Set the password again while cr50 is open. 33 self.set_ccd_password(self.CCD_PASSWORD) 34 if self.cr50.password_is_reset(): 35 raise error.TestFail('Failed to set password') 36 37 # The password can't be changed once it's set. 38 # It needs to be cleared first. 39 self.set_ccd_password(self.NEW_PASSWORD, expect_error=True) 40 41 self.cr50.set_ccd_level('lock') 42 # The password can't be cleared while the console is locked. 43 self.set_ccd_password('clear:' + self.CCD_PASSWORD, expect_error=True) 44 45 self.cr50.send_command('ccd unlock ' + self.CCD_PASSWORD) 46 # The password can be cleared while the console is unlocked. 47 self.set_ccd_password('clear:' + self.CCD_PASSWORD) 48 49 # Set the password again and lock the console. 50 self.cr50.send_command('ccd testlab open') 51 self.set_ccd_password(self.CCD_PASSWORD) 52 53 # The password can't be cleared using the wrong password. 54 self.set_ccd_password('clear:' + self.CCD_PASSWORD.lower(), 55 expect_error=True) 56 # The password can be cleared using the correct password. 57 self.set_ccd_password('clear:' + self.CCD_PASSWORD) 58 if not self.cr50.password_is_reset(): 59 raise error.TestFail('Failed to clear password') 60 61 # The password can be set to anything when there isn't one set. 62 self.set_ccd_password(self.NEW_PASSWORD) 63 if self.cr50.password_is_reset(): 64 raise error.TestFail('Failed to clear password') 65 66 67 self.cr50.send_command('ccd testlab open') 68 self.cr50.send_command('ccd reset') 69 self.host.run('gsctool -a -U') 70 71 # Run through the same steps when the password was set with the console 72 # unlocked. 73 74 # Set the password when the console is unlocked. 75 self.set_ccd_password(self.CCD_PASSWORD) 76 77 self.cr50.set_ccd_level('lock') 78 # The password can't be cleared while the console is locked. 79 self.set_ccd_password('clear:' + self.CCD_PASSWORD, expect_error=True) 80 81 # Unlock the console. 82 self.ccd_unlock_from_ap(self.CCD_PASSWORD) 83 # The password can be cleared while the console is unlocked. 84 self.set_ccd_password('clear:' + self.CCD_PASSWORD) 85 # Set the password again when the console is unlocked. 86 self.set_ccd_password(self.CCD_PASSWORD) 87 88 self.cr50.send_command('ccd testlab open') 89 # The password can be cleared when the console is open. 90 self.set_ccd_password('clear:' + self.CCD_PASSWORD) 91