Repository navigation
ci(e2e-auth): trust fullsend-ai-coder[bot] for functional tests #89
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb3fb92
ci(e2e-auth): trust fullsend-ai-coder[bot] for functional tests
ralphbean 558d451
fix(ci): move exports outside subshells to satisfy shellcheck
ralphbean a926d0d
fix(scripts): address review feedback on e2e auth
ralphbean 13502b7
fix(scripts): align test section header with codebase convention
ralphbean 35f8a02
fix(e2e-auth): document trust boundary tradeoff and strengthen test a…
ralphbean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,126 @@ | ||
| #!/usr/bin/env bash | ||
| # check-e2e-authorization-test.sh — Tests for check-e2e-authorization.sh | ||
| # | ||
| # Uses a mock gh command to avoid hitting GitHub. | ||
| # Run from the repo root: bash .github/scripts/check-e2e-authorization-test.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| AUTH_SCRIPT="${SCRIPT_DIR}/check-e2e-authorization.sh" | ||
| FAILURES=0 | ||
|
|
||
| TMPDIR="$(mktemp -d)" | ||
| trap 'rm -rf "${TMPDIR}"' EXIT | ||
|
|
||
| MOCK_BIN="${TMPDIR}/bin" | ||
| mkdir -p "${MOCK_BIN}" | ||
|
|
||
| # Mock gh: default behavior returns CONTRIBUTOR association and no ok-to-test label. | ||
| setup_mock_gh() { | ||
| cat > "${MOCK_BIN}/gh" <<'MOCKEOF' | ||
| #!/usr/bin/env bash | ||
| # Default: PR endpoint returns CONTRIBUTOR with no ok-to-test label | ||
| if [[ "$1" == "api" ]] && [[ "$2" == *"/pulls/"* ]] && [[ "$2" != *"/files"* ]]; then | ||
| echo '{"author_association": "CONTRIBUTOR", "labels": [], "updated_at": "2026-01-01T00:00:00Z"}' | ||
| exit 0 | ||
| fi | ||
| # Collaborator permission endpoint: default to read (not write) | ||
| if [[ "$1" == "api" ]] && [[ "$2" == *"/collaborators/"*"/permission"* ]]; then | ||
| echo '{"role_name": "read"}' | ||
| exit 0 | ||
| fi | ||
| echo "mock-gh: unhandled call: $*" >&2 | ||
| exit 1 | ||
| MOCKEOF | ||
| chmod +x "${MOCK_BIN}/gh" | ||
| } | ||
|
|
||
| run_auth() { | ||
| # Run the script, capture stdout, suppress stderr | ||
| local output | ||
| output=$( | ||
| export PATH="${MOCK_BIN}:${PATH}" | ||
| export GH_TOKEN="fake-token" | ||
| export GITHUB_OUTPUT="${TMPDIR}/github-output" | ||
| : > "${GITHUB_OUTPUT}" | ||
| bash "${AUTH_SCRIPT}" "$@" 2>/dev/null | ||
| ) | ||
| echo "${output}" | ||
| } | ||
|
|
||
| assert_authorized() { | ||
| local test_name="$1" | ||
| local output="$2" | ||
| if echo "${output}" | grep -q "authorized=true"; then | ||
| echo "PASS: ${test_name}" | ||
| else | ||
| echo "FAIL: ${test_name} — expected authorized=true, got: ${output}" | ||
| FAILURES=$((FAILURES + 1)) | ||
| fi | ||
| } | ||
|
|
||
| assert_unauthorized() { | ||
| local test_name="$1" | ||
| local output="$2" | ||
| local expected_reason="${3:-unauthorized}" | ||
| if echo "${output}" | grep -q "authorized=false" && echo "${output}" | grep -q "reason=${expected_reason}"; then | ||
| echo "PASS: ${test_name}" | ||
| else | ||
| echo "FAIL: ${test_name} — expected authorized=false reason=${expected_reason}, got: ${output}" | ||
| FAILURES=$((FAILURES + 1)) | ||
| fi | ||
| } | ||
|
|
||
| # --- Test cases --- | ||
|
|
||
| # Test: trusted bot (fullsend-ai-coder[bot]) is authorized | ||
| setup_mock_gh | ||
| export PR_AUTHOR_ASSOCIATION="CONTRIBUTOR" | ||
| export PR_AUTHOR_LOGIN="fullsend-ai-coder[bot]" | ||
| output=$(run_auth 1 "test-org/test-repo") | ||
|
ralphbean marked this conversation as resolved.
Resolved
|
||
| assert_authorized "trusted bot fullsend-ai-coder[bot] is authorized" "${output}" | ||
|
|
||
| # Test: MEMBER association is authorized | ||
| setup_mock_gh | ||
| export PR_AUTHOR_ASSOCIATION="MEMBER" | ||
| export PR_AUTHOR_LOGIN="some-human" | ||
| output=$(run_auth 1 "test-org/test-repo") | ||
| assert_authorized "MEMBER association is authorized" "${output}" | ||
|
|
||
| # Test: OWNER association is authorized | ||
| setup_mock_gh | ||
| export PR_AUTHOR_ASSOCIATION="OWNER" | ||
| export PR_AUTHOR_LOGIN="some-human" | ||
| output=$(run_auth 1 "test-org/test-repo") | ||
| assert_authorized "OWNER association is authorized" "${output}" | ||
|
|
||
| # Test: COLLABORATOR association is authorized | ||
| setup_mock_gh | ||
| export PR_AUTHOR_ASSOCIATION="COLLABORATOR" | ||
| export PR_AUTHOR_LOGIN="some-human" | ||
| output=$(run_auth 1 "test-org/test-repo") | ||
| assert_authorized "COLLABORATOR association is authorized" "${output}" | ||
|
|
||
| # Test: CONTRIBUTOR association without bot login is unauthorized | ||
| setup_mock_gh | ||
| export PR_AUTHOR_ASSOCIATION="CONTRIBUTOR" | ||
| export PR_AUTHOR_LOGIN="random-contributor" | ||
| output=$(run_auth 1 "test-org/test-repo") | ||
| assert_unauthorized "CONTRIBUTOR without bot login is unauthorized" "${output}" | ||
|
|
||
| # Test: unknown bot is not trusted | ||
| setup_mock_gh | ||
| export PR_AUTHOR_ASSOCIATION="CONTRIBUTOR" | ||
| export PR_AUTHOR_LOGIN="some-other-bot[bot]" | ||
| output=$(run_auth 1 "test-org/test-repo") | ||
| assert_unauthorized "unknown bot is not trusted" "${output}" | ||
|
|
||
| # --- Summary --- | ||
| echo "" | ||
| if [[ "${FAILURES}" -gt 0 ]]; then | ||
| echo "${FAILURES} test(s) failed" | ||
| exit 1 | ||
| else | ||
| echo "All tests passed" | ||
| fi | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.