1# Copyright 2014 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.client.common_lib.cros.tendo import buffet_config 7from autotest_lib.client.common_lib.cros.tendo import privet_helper 8from autotest_lib.server import test 9 10def _assert_equal(expected, actual): 11 """Compares objects. 12 13 @param expected: the expected value. 14 @param actual: the actual value. 15 16 """ 17 if expected != actual: 18 raise error.TestFail('Expected: %r, actual: %r' % (expected, actual)) 19 20 21def _assert_not_empty(dictionary, key): 22 """Compares objects. 23 24 @param expected: the expected value. 25 @param actual: the actual value. 26 27 """ 28 if not key in dictionary: 29 raise error.TestFail('Missing key: %s' % key) 30 31 if not dictionary[key]: 32 raise error.TestFail('Key "%s" is empty' % key) 33 34 35class buffet_PrivetInfo(test.test): 36 """This test verifies that the buffet responds to /privet/info request and 37 returns the expected JSON response object. 38 """ 39 version = 1 40 41 def warmup(self, host): 42 config = buffet_config.BuffetConfig(log_verbosity=3) 43 config.restart_with_config(host=host) 44 45 46 def cleanup(self, host): 47 buffet_config.naive_restart(host=host) 48 49 50 def run_once(self, host): 51 helper = privet_helper.PrivetHelper(host=host) 52 helper.ping_server() # Make sure the server is up and running. 53 info = helper.send_privet_request(privet_helper.URL_INFO) 54 55 # Do some sanity checks on the returned JSON object. 56 if info['version'] != '3.0': 57 raise error.TestFail('Expected privet version 3.0') 58 59 authentication = info['authentication'] 60 _assert_not_empty(authentication, 'anonymousMaxScope') 61 _assert_equal(['p224_spake2'], authentication['crypto']) 62 _assert_equal(['anonymous', 'pairing'], authentication['mode']) 63 _assert_equal(['pinCode'], authentication['pairing']) 64 65 _assert_not_empty(info, 'name') 66 _assert_not_empty(info, 'id') 67 68 _assert_not_empty(info, 'modelManifestId') 69 _assert_equal(5, len(info['modelManifestId'])) 70 71 manifest = info['basicModelManifest'] 72 _assert_not_empty(manifest, 'modelName') 73 _assert_not_empty(manifest, 'oemName') 74 _assert_not_empty(manifest, 'uiDeviceKind') 75 76 _assert_equal({'id': '', 'status': 'unconfigured'}, info['gcd']) 77