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 os 7 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.cros.enterprise import enterprise_policy_base 10 11 12class policy_ExternalStorageDisabled( 13 enterprise_policy_base.EnterprisePolicyTest): 14 version = 1 15 16 POLICY_NAME = 'ExternalStorageDisabled' 17 TEST_CASES = { 18 'True_Block': True, 19 'False_Allow': False, 20 'NotSet_Allow': None 21 } 22 23 def _test_external_storage(self, policy_value): 24 """ 25 Verify the behavior of the ExternalStorageDisabled policy. 26 27 Check the /media/removable directory and verify that it is empty if the 28 policy disables access to external storage, or not empty if external 29 storage is allowed. 30 31 @param policy_value: policy value for this case. 32 33 @raises error.TestFail: If the contents of the /media/removable 34 directory do not match the policy behavior. 35 36 """ 37 removable_dir = os.listdir(os.path.join(os.sep, 'media', 'removable')) 38 39 if policy_value: 40 if removable_dir: 41 raise error.TestFail('External storage was disabled but ' 42 'external storage detected') 43 elif not removable_dir: 44 raise error.TestFail('External storage enabled but external ' 45 'storage not found') 46 47 48 def run_once(self, case): 49 """ 50 Setup and run the test configured for the specified test case. 51 52 @param case: Name of the test case to run. 53 54 """ 55 case_value = self.TEST_CASES[case] 56 self.setup_case(user_policies={self.POLICY_NAME: case_value}) 57 self._test_external_storage(case_value) 58