Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 | 7 |
| 8 import pyauto_functional | 8 import pyauto_functional |
| 9 import pyauto | 9 import pyauto |
| 10 | 10 |
| 11 | 11 |
| 12 class ChromeosSecurity(pyauto.PyUITest): | 12 class ChromeosSecurity(pyauto.PyUITest): |
| 13 """Security tests for chrome on ChromeOS. | 13 """Security tests for chrome on ChromeOS. |
| 14 | 14 |
| 15 Requires ChromeOS to be logged in. | 15 Requires ChromeOS to be logged in. |
| 16 """ | 16 """ |
| 17 BUNDLED_CRX_DIRECTORY = '/opt/google/chrome/extensions' | |
| 18 | |
| 19 COMPONENT_EXTENSION_BASELINE = [ | |
|
jimhebert
2011/06/03 23:34:44
Is it typical pyauto style to just inline these ex
dennis_jeffrey
2011/06/07 19:02:20
The baseline information has been moved to a separ
| |
| 20 { 'name': 'Bookmark Manager', | |
| 21 'effective_host_permissions': ['chrome://favicon/*', | |
| 22 'chrome://resources/*',], | |
| 23 'api_permissions': ['bookmarks', | |
| 24 'tabs', | |
| 25 'experimental',], | |
| 26 }, | |
| 27 { 'name': 'File Manager', | |
| 28 'effective_host_permissions': ['chrome://extension-icon/*', | |
| 29 'chrome://resources/*',], | |
| 30 'api_permissions': ['fileBrowserHandler', | |
| 31 'fileBrowserPrivate', | |
| 32 'mediaPlayerPrivate', | |
| 33 'unlimitedStorage',], | |
| 34 }, | |
| 35 { 'name': 'Mobile Activation', | |
| 36 'effective_host_permissions': [], | |
| 37 'api_permissions': [], | |
| 38 }, | |
| 39 { 'name': 'Chrome Web Store', | |
| 40 'effective_host_permissions': [], | |
| 41 'api_permissions': ['management', | |
| 42 'webstorePrivate',], | |
| 43 }, | |
| 44 ] | |
| 45 | |
| 46 BUNDLED_CRX_BASELINE = [ | |
|
jimhebert
2011/06/03 23:34:44
The autotest version of this test is kept in autot
Nirnimesh
2011/06/04 22:53:08
In this case, the baseline needs to be read out fr
dennis_jeffrey
2011/06/07 19:02:20
Done. The baseline info has been moved to a separ
dennis_jeffrey
2011/06/07 19:02:20
Done. I created a file in a "security" subfolder
| |
| 47 { 'crx_file': 'aciahcmjmecflokailenpkdchphgkefd.crx', | |
| 48 'name': 'Entanglement', | |
| 49 'effective_host_permissions': [], | |
| 50 'api_permissions': ['unlimitedStorage',], | |
| 51 }, | |
| 52 { 'crx_file': 'apdfllckaahabafndbhieahigkjlhalf.crx', | |
| 53 'name': 'Google Docs', | |
| 54 'effective_host_permissions': [], | |
| 55 'api_permissions': ['unlimitedStorage',], | |
| 56 }, | |
| 57 { 'crx_file': 'blpcfgokakmgnkcojhhkbfbldkacnbeo.crx', | |
| 58 'name': 'YouTube', | |
| 59 'effective_host_permissions': [], | |
| 60 'api_permissions': [], | |
| 61 }, | |
| 62 { 'crx_file': 'ejjicmeblgpmajnghnpcppodonldlgfn.crx', | |
| 63 'name': 'Google Calendar', | |
| 64 'effective_host_permissions': [], | |
| 65 'api_permissions': ['notifications', | |
| 66 'unlimitedStorage',], | |
| 67 }, | |
| 68 { 'crx_file': 'hpfomeedmekonipambfkmjfacahlngjd.crx', | |
| 69 'name': 'Picasa Uploader', | |
| 70 'effective_host_permissions': ['*://www.google.com/*', | |
| 71 'https://picasaweb.google.com/*',], | |
| 72 'api_permissions': ['contextMenus', | |
| 73 'fileBrowserHandler', | |
| 74 'notifications', | |
| 75 'tabs',], | |
| 76 }, | |
| 77 { 'crx_file': 'kjebfhglflhjjjiceimfkgicifkhjlnm.crx', | |
| 78 'name': 'Scratchpad', | |
| 79 'effective_host_permissions': ['https://docs.google.com/*', | |
| 80 'https://www.google.com/*',], | |
| 81 'api_permissions': ['tabs',], | |
| 82 }, | |
| 83 { 'crx_file': 'nckgahadagoaajjgafhacjanaoiihapd.crx', | |
| 84 'name': 'Google Talk', | |
| 85 'effective_host_permissions': ['*://mail.google.com/*', | |
| 86 '*://talkgadget.google.com/*',], | |
| 87 'api_permissions': ['tabs',], | |
| 88 }, | |
| 89 { 'crx_file': 'pjkljhegncpnkpknbcohdijeoejaedia.crx', | |
| 90 'name': 'Gmail', | |
| 91 'effective_host_permissions': [], | |
| 92 'api_permissions': ['notifications',], | |
| 93 }, | |
| 94 ] | |
| 95 | |
| 96 def setUp(self): | |
| 97 pyauto.PyUITest.setUp(self) | |
| 98 if self.GetBrowserInfo()['properties']['is_official']: | |
| 99 self.COMPONENT_EXTENSION_BASELINE.append( | |
| 100 { 'name': 'Help', | |
| 101 'effective_host_permissions': ['*://www.google.com/*',], | |
| 102 'api_permissions': ['chromeosInfoPrivate', | |
| 103 'tabs',], | |
| 104 }) | |
| 17 | 105 |
| 18 def ExtraChromeFlagsOnChromeOS(self): | 106 def ExtraChromeFlagsOnChromeOS(self): |
| 19 """Override default list of extra flags typicall used with automation. | 107 """Override default list of extra flags typically used with automation. |
| 20 | 108 |
| 21 See the default flags used with automation in pyauto.py. | 109 See the default flags used with automation in pyauto.py. |
| 22 Chrome flags for this test should be as close to reality as possible. | 110 Chrome flags for this test should be as close to reality as possible. |
| 23 """ | 111 """ |
| 24 return [ | 112 return [ |
| 25 '--homepage=about:blank', | 113 '--homepage=about:blank', |
| 26 ] | 114 ] |
| 27 | 115 |
| 28 def testCannotViewLocalFiles(self): | 116 def testCannotViewLocalFiles(self): |
| 29 """Verify that local files cannot be accessed from the browser.""" | 117 """Verify that local files cannot be accessed from the browser.""" |
| 30 urls_and_titles = { | 118 urls_and_titles = { |
| 31 'file:///': 'Index of /', | 119 'file:///': 'Index of /', |
| 32 'file:///etc/': 'Index of /etc/', | 120 'file:///etc/': 'Index of /etc/', |
| 33 self.GetFileURLForDataPath('title2.html'): 'Title Of Awesomeness', | 121 self.GetFileURLForDataPath('title2.html'): 'Title Of Awesomeness', |
| 34 } | 122 } |
| 35 for url, title in urls_and_titles.iteritems(): | 123 for url, title in urls_and_titles.iteritems(): |
| 36 self.NavigateToURL(url) | 124 self.NavigateToURL(url) |
| 37 self.assertNotEqual(title, self.GetActiveTabTitle(), | 125 self.assertNotEqual(title, self.GetActiveTabTitle(), |
| 38 msg='Could access local file %s.' % url) | 126 msg='Could access local file %s.' % url) |
| 39 | 127 |
| 128 def _VerifyExtensionPermissions(self, baseline): | |
| 129 """Ensures extension permissions in the baseline match actual info. | |
| 130 | |
| 131 This function will fail the current test if either (1) an extension named | |
| 132 in the baseline is not currently installed in Chrome; or (2) the api | |
| 133 permissions or effective host permissions of an extension in the baseline | |
| 134 do not match the actual permissions associated with the extension in Chrome. | |
| 135 | |
| 136 Args: | |
| 137 baseline: A dictionary of expected extension information, containing | |
| 138 extension names and api/effective host permission info. | |
| 139 """ | |
| 140 full_ext_actual_info = self.GetExtensionsInfo() | |
| 141 for ext_expected_info in baseline: | |
| 142 located_ext_info = [info for info in full_ext_actual_info if | |
| 143 info['name'] == ext_expected_info['name']] | |
| 144 self.assertTrue( | |
| 145 located_ext_info, | |
| 146 msg='Cannot locate extension info: ' + ext_expected_info['name']) | |
| 147 ext_actual_info = located_ext_info[0] | |
| 148 self.assertEqual(set(ext_expected_info['effective_host_permissions']), | |
| 149 set(ext_actual_info['effective_host_permissions']), | |
| 150 msg='Effective host permission info does not match for ' | |
| 151 'extension: ' + ext_expected_info['name']) | |
| 152 self.assertEqual(set(ext_expected_info['api_permissions']), | |
| 153 set(ext_actual_info['api_permissions']), | |
| 154 msg='API permission info does not match for ' | |
| 155 'extension: ' + ext_expected_info['name']) | |
| 156 | |
| 157 def testComponentExtensionPermissions(self): | |
| 158 """Ensures component extension permissions are as expected.""" | |
| 159 expected_names = [ext['name'] for ext in self.COMPONENT_EXTENSION_BASELINE] | |
| 160 actual_names = [ext['name'] for ext in self.GetExtensionsInfo() if | |
| 161 ext['is_component_extension']] | |
| 162 self.assertEqual(set(expected_names), set(actual_names), | |
| 163 msg='Component extension names do not match baseline:\n' | |
| 164 'Installed extensions: %s\n' | |
| 165 'Expected extensions: %s' % (actual_names, | |
| 166 expected_names)) | |
| 167 self._VerifyExtensionPermissions(self.COMPONENT_EXTENSION_BASELINE) | |
| 168 | |
| 169 def testBundledCrxPermissions(self): | |
| 170 """Ensures bundled CRX permissions are as expected.""" | |
| 171 # Verify that each bundled CRX on the device is expected, then install it. | |
| 172 for file_name in os.listdir(self.BUNDLED_CRX_DIRECTORY): | |
| 173 if file_name.endswith('.crx'): | |
| 174 self.assertTrue( | |
| 175 file_name in [x['crx_file'] for x in self.BUNDLED_CRX_BASELINE], | |
| 176 msg='Unexpected CRX file: ' + file_name) | |
| 177 crx_file = pyauto.FilePath( | |
| 178 os.path.join(self.BUNDLED_CRX_DIRECTORY, file_name)) | |
| 179 self.assertTrue(self.InstallExtension(crx_file, False), | |
| 180 msg='Extension install failed: %s' % crx_file.value()) | |
| 181 | |
| 182 # Verify that the permissions information in the baseline matches the | |
| 183 # permissions associated with the installed bundled CRX extensions. | |
| 184 self._VerifyExtensionPermissions(self.BUNDLED_CRX_BASELINE) | |
| 185 | |
| 186 def testNoUnexpectedExtensions(self): | |
| 187 """Ensures there are no unexpected bundled or component extensions.""" | |
| 188 # Install all bundled extensions on the device. | |
| 189 for file_name in os.listdir(self.BUNDLED_CRX_DIRECTORY): | |
| 190 if file_name.endswith('.crx'): | |
| 191 crx_file = pyauto.FilePath( | |
| 192 os.path.join(self.BUNDLED_CRX_DIRECTORY, file_name)) | |
| 193 self.assertTrue(self.InstallExtension(crx_file, False), | |
| 194 msg='Extension install failed: %s' % crx_file.value()) | |
| 195 | |
| 196 # Ensure that the set of installed extension names precisely matches the | |
| 197 # baseline. | |
| 198 expected_names = [ext['name'] for ext in self.COMPONENT_EXTENSION_BASELINE] | |
| 199 expected_names.extend([ext['name'] for ext in self.BUNDLED_CRX_BASELINE]) | |
| 200 ext_actual_info = self.GetExtensionsInfo() | |
| 201 installed_names = [ext['name'] for ext in ext_actual_info] | |
| 202 self.assertEqual(set(expected_names), set(installed_names), | |
| 203 msg='Installed extension names do not match baseline:\n' | |
| 204 'Installed extensions: %s\n' | |
| 205 'Expected extensions: %s' % (installed_names, | |
| 206 expected_names)) | |
| 40 | 207 |
| 41 if __name__ == '__main__': | 208 if __name__ == '__main__': |
| 42 pyauto_functional.Main() | 209 pyauto_functional.Main() |
| OLD | NEW |