Index: tools/telemetry/telemetry/util/mac/keychain_helper.py |
diff --git a/tools/telemetry/telemetry/util/mac/keychain_helper.py b/tools/telemetry/telemetry/util/mac/keychain_helper.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..00f6033564021b9e2d854af0065e790560deeb1e |
--- /dev/null |
+++ b/tools/telemetry/telemetry/util/mac/keychain_helper.py |
@@ -0,0 +1,64 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import subprocess |
+ |
+from telemetry.core import platform |
+from telemetry.util import support_binaries |
+ |
+def _PathForExecutable(executable_name): |
+ """Fetches the executable from cloud storage, and returns its path.""" |
+ arch_name = platform.GetHostPlatform().GetArchName() |
+ return support_binaries.FindPath(executable_name, arch_name, 'mac') |
+ |
+def IsKeychainLocked(): |
+ """ |
+ Returns True if the keychain is locked, or if there is an error determining |
+ the keychain state. |
+ """ |
+ path = _PathForExecutable('determine_if_keychain_is_locked') |
+ |
+ child = subprocess.Popen(path, stdout=subprocess.PIPE) |
+ child.communicate() |
+ return child.returncode != 0 |
+ |
+def DoesKeychainHaveTimeout(): |
+ """ |
+ Returns True if the keychain will lock itself have a period of time. |
+ |
+ This method will trigger a blocking, modal dialog if the keychain is |
+ locked. |
+ """ |
+ command = ("/usr/bin/security", "show-keychain-info") |
+ child = subprocess.Popen(command, stderr=subprocess.PIPE) |
+ stderr = child.communicate()[1] |
+ return "no-timeout" not in stderr |
+ |
+def _IsKeychainConfiguredForBots(service_name, account_name): |
+ """ |
+ Returns True if the keychain entry associated with |service_name| and |
+ |account_name| is correctly configured for running telemetry tests on bots. |
+ |
+ This method will trigger a blocking, modal dialog if the keychain is |
+ locked. |
+ """ |
+ # The executable requires OSX 10.7+ APIs. |
+ if (platform.GetHostPlatform().GetOSVersionName() < |
+ platform.platform_backend.LION): |
+ return False |
+ |
+ path = _PathForExecutable('determine_if_keychain_entry_is_decryptable') |
+ |
+ command = (path, service_name, account_name) |
+ child = subprocess.Popen(command) |
+ child.communicate() |
+ return child.returncode == 0 |
+ |
+def IsKeychainConfiguredForBotsWithChrome(): |
+ return _IsKeychainConfiguredForBots("Chrome Safe Storage", |
+ "Chrome") |
+ |
+def IsKeychainConfiguredForBotsWithChromium(): |
+ return _IsKeychainConfiguredForBots("Chromium Safe Storage", |
+ "Chromium") |