configure_test_keychain.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env bash
  2. # Copyright 2021 Google LLC
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -euo pipefail
  16. set -o xtrace
  17. TEST_KEYCHAIN_NAME="temp.keychain"
  18. TEST_KEYCHAIN_PASSWORD="temp.keychain.password"
  19. # Print list of existing keychains.
  20. security list-keychains
  21. # Print current default keychain.
  22. security default-keychain
  23. # Remove test keychain form previous runs if exists.
  24. if security delete-keychain "$TEST_KEYCHAIN_NAME"; then
  25. echo "Old test keychain was removed."
  26. else
  27. echo "All good, no old test keychain found."
  28. fi
  29. # Create a test keychain.
  30. security create-keychain -p "$TEST_KEYCHAIN_PASSWORD" "$TEST_KEYCHAIN_NAME"
  31. # Disable auto-locking.
  32. security set-keychain-settings "$TEST_KEYCHAIN_NAME"
  33. # Unlock the test keychain.
  34. security unlock-keychain -p "$TEST_KEYCHAIN_PASSWORD" "$TEST_KEYCHAIN_NAME"
  35. # Set the test keychain as default to be used during macOS tests.
  36. security default-keychain -s "$TEST_KEYCHAIN_NAME"