-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from acaire/add_render_command
Add render command
- Loading branch information
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,16 @@ setup() { | |
assert_failure | ||
} | ||
|
||
@test "fails when render command has non-existent binary" { | ||
export BUILDKITE_PLUGIN_GCP_WORKLOAD_IDENTITY_FEDERATION_AUDIENCE="//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/buildkite-example-pipeline/providers/buildkite" | ||
export BUILDKITE_PLUGIN_GCP_WORKLOAD_IDENTITY_FEDERATION_SERVICE_ACCOUNT="[email protected]" | ||
export BUILDKITE_PLUGIN_GCP_WORKLOAD_IDENTITY_FEDERATION_RENDER_COMMAND="this-file-purposely-does-not-exist" | ||
|
||
run "$PWD/hooks/pre-command" | ||
|
||
assert_failure | ||
} | ||
|
||
@test "succeeds when mktemp fails once" { | ||
export BUILDKITE_PLUGIN_GCP_WORKLOAD_IDENTITY_FEDERATION_AUDIENCE="//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/buildkite-example-pipeline/providers/buildkite" | ||
export BUILDKITE_PLUGIN_GCP_WORKLOAD_IDENTITY_FEDERATION_SERVICE_ACCOUNT="[email protected]" | ||
|
@@ -83,3 +93,38 @@ JSON) | |
unstub mktemp | ||
unstub buildkite-agent | ||
} | ||
@test "exports credentials with render command using envsubst" { | ||
export GCP_PROJECT_ID=oidc-project | ||
export GCP_PROJECT_NUMBER=123456789 | ||
export BUILDKITE_PLUGIN_GCP_WORKLOAD_IDENTITY_FEDERATION_AUDIENCE="//iam.googleapis.com/projects/\${GCP_PROJECT_NUMBER}/locations/global/workloadIdentityPools/buildkite-example-pipeline/providers/buildkite" | ||
export BUILDKITE_PLUGIN_GCP_WORKLOAD_IDENTITY_FEDERATION_SERVICE_ACCOUNT="buildkite-example-pipeline@\${GCP_PROJECT_ID}.iam.gserviceaccount.com" | ||
export BUILDKITE_PLUGIN_GCP_WORKLOAD_IDENTITY_FEDERATION_RENDER_COMMAND="envsubst" | ||
stub mktemp "-d : echo $BATS_TEST_TMPDIR" | ||
stub buildkite-agent "oidc request-token --audience //iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/buildkite-example-pipeline/providers/buildkite --lifetime 0 : echo dummy-jwt" | ||
run "$PWD/hooks/pre-command" | ||
assert_success | ||
assert_output --partial "Requesting OIDC token from Buildkite" | ||
assert_output --partial "Configuring Google Cloud credentials" | ||
diff $BATS_TEST_TMPDIR/token.json <(echo dummy-jwt) | ||
diff $BATS_TEST_TMPDIR/credentials.json <(cat << JSON | ||
{ | ||
"type": "external_account", | ||
"audience": "//iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/buildkite-example-pipeline/providers/buildkite", | ||
"subject_token_type": "urn:ietf:params:oauth:token-type:jwt", | ||
"token_url": "https://sts.googleapis.com/v1/token", | ||
"service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/[email protected]:generateAccessToken", | ||
"credential_source": { | ||
"file": "$BATS_TEST_TMPDIR/token.json" | ||
} | ||
} | ||
JSON) | ||
unstub mktemp | ||
unstub buildkite-agent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
setup_suite() { | ||
echo '# Installing envsubst' >&2 | ||
apk --no-cache add gettext | sed -e 's/^/# /' >&2 | ||
} |