Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.3.0] Move credential helper setup into remote_helpers.sh so it can be reused by other shell tests. #18453

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 4 additions & 25 deletions src/test/shell/bazel/remote/remote_execution_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ fi

source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }
source "$(rlocation "io_bazel/src/test/shell/bazel/remote_helpers.sh")" \
|| { echo "remote_helpers.sh not found!" >&2; exit 1; }
source "$(rlocation "io_bazel/src/test/shell/bazel/remote/remote_utils.sh")" \
|| { echo "remote_utils.sh not found!" >&2; exit 1; }

Expand Down Expand Up @@ -77,22 +79,7 @@ function has_utf8_locale() {
}

function setup_credential_helper_test() {
# Each helper call atomically writes one byte to this file.
# We can later read the file to determine how many calls were made.
cat > "${TEST_TMPDIR}/credhelper_log"

cat > "${TEST_TMPDIR}/credhelper" <<'EOF'
#!/usr/bin/env python3
import os

path = os.path.join(os.environ["TEST_TMPDIR"], "credhelper_log")
fd = os.open(path, os.O_WRONLY|os.O_CREAT|os.O_APPEND)
os.write(fd, b"1")
os.close(fd)

print("""{"headers":{"Authorization":["Bearer secret_token"]}}""")
EOF
chmod +x "${TEST_TMPDIR}/credhelper"
setup_credential_helper

mkdir -p a

Expand All @@ -105,15 +92,7 @@ EOF
EOF

stop_worker
start_worker --expected_authorization_token=secret_token
}

function expect_credential_helper_calls() {
local -r expected=$1
local -r actual=$(wc -c "${TEST_TMPDIR}/credhelper_log" | awk '{print $1}')
if [[ "$expected" != "$actual" ]]; then
fail "expected $expected instead of $actual credential helper calls"
fi
start_worker --expected_authorization_token=TOKEN
}

function test_credential_helper_remote_cache() {
Expand Down
31 changes: 31 additions & 0 deletions src/test/shell/bazel/remote_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,34 @@ function shutdown_server() {
function kill_nc() {
shutdown_server
}

# Sets up a credential helper binary at ${TEST_TMPDIR}/credhelper and resets
# the call counter.
function setup_credential_helper() {
# Each call atomically writes one byte to this file.
# The file can be read later determine how many calls were made.
cat > "${TEST_TMPDIR}/credhelper.callcount"

cat > "${TEST_TMPDIR}/credhelper" <<'EOF'
#!/usr/bin/env python3
import os

path = os.path.join(os.environ["TEST_TMPDIR"], "credhelper.callcount")
fd = os.open(path, os.O_WRONLY|os.O_CREAT|os.O_APPEND)
os.write(fd, b"1")
os.close(fd)

# Must match //src/test/shell/bazel/testing_server.py.
print("""{"headers":{"Authorization":["Bearer TOKEN"]}}""")
EOF
chmod +x "${TEST_TMPDIR}/credhelper"
}

# Asserts how many times the credential helper was called.
function expect_credential_helper_calls() {
local -r expected=$1
local -r actual=$(wc -c "${TEST_TMPDIR}/credhelper.callcount" | awk '{print $1}')
if [[ "$expected" != "$actual" ]]; then
fail "expected $expected instead of $actual credential helper calls"
fi
}