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