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 5import logging 6import time 7 8from autotest_lib.client.common_lib import error 9from autotest_lib.server.cros.faft.cr50_test import Cr50Test 10 11 12class firmware_Cr50Unlock(Cr50Test): 13 """Verify cr50 unlock.""" 14 version = 1 15 PASSWORD = 'Password' 16 17 18 def run_once(self): 19 """Check cr50 can see dev mode open works correctly""" 20 # Make sure testlab mode is enabled, so we can guarantee the password 21 # can be cleared. 22 self.fast_open(enable_testlab=True) 23 self.cr50.send_command('ccd reset') 24 25 # Set the password 26 self.set_ccd_password(self.PASSWORD) 27 if self.cr50.get_ccd_info()['Password'] != 'set': 28 raise error.TestFail('Failed to set password') 29 30 self.cr50.set_ccd_level('lock') 31 32 # Verify the password can be used to unlock the console 33 self.cr50.send_command('ccd unlock ' + self.PASSWORD) 34 if self.cr50.get_ccd_level() != 'unlock': 35 raise error.TestFail('Could not unlock cr50 with the password') 36 37 self.cr50.set_ccd_level('lock') 38 # Try with the lowercase version of the passsword. Make sure it doesn't 39 # work. 40 self.cr50.send_command('ccd unlock ' + self.PASSWORD.lower()) 41 if self.cr50.get_ccd_level() == 'unlock': 42 raise error.TestFail('Unlocked cr50 with incorrect password') 43 # TODO(b/111418310): figure out what's going on. I dont know why, but 44 # for some reason you can't immediately unlock cr50 after a failure on 45 # the command line. 5 seconds should be enough. 46 # 47 # State as of 0.4.8 48 # incorrect unlock from command line 49 # and immediate unlock attempt from AP -> FAILURE 50 # 51 # incorrect unlock from command line, 52 # wait a bit, and unlock attempt from AP -> SUCCESS 53 54 # Try Unlock from the AP 55 try: 56 self.ccd_unlock_from_ap(self.PASSWORD, expect_error=True) 57 except: 58 raise error.TestError('Something is different.Check b/111418310. ' 59 'Is it fixed?') 60 else: 61 logging.info('Unintentional rate limiting is still happening') 62 63 # Show the same thing works with a 2 second wait 64 self.cr50.set_ccd_level('lock') 65 self.cr50.send_command('ccd unlock ' + self.PASSWORD.lower()) 66 if self.cr50.get_ccd_level() != 'lock': 67 raise error.TestFail('Unlocked cr50 from AP with incorrect ' 68 'password') 69 # Unintentional limit. I don't know the exact limit. 3 seconds should 70 # be enough. 71 time.sleep(5) 72 self.ccd_unlock_from_ap(self.PASSWORD) 73 74 # Show the rate limit doesn't apply to Unlocking from the AP. 75 # Try Unlock from the AP with lower case version. Make sure it fails 76 self.cr50.set_ccd_level('lock') 77 self.ccd_unlock_from_ap(self.PASSWORD.lower(), expect_error=True) 78 if self.cr50.get_ccd_level() != 'lock': 79 raise error.TestFail('Unlocked cr50 from AP with incorrect ' 80 'password') 81 # Test immediate unlock from AP 82 self.ccd_unlock_from_ap(self.PASSWORD) 83