-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_token.sh
More file actions
executable file
·45 lines (39 loc) · 1.22 KB
/
Copy pathtest_token.sh
File metadata and controls
executable file
·45 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# The only real logic in this repo is REPO_URL -> GitHub API path; everything
# else is curl calls and env plumbing. DRY_RUN=1 makes that parsing assertable
# without a PAT or network. Run: ./test_token.sh
set -euo pipefail
cd "$(dirname "$0")"
API=https://api.github.com/repos
WANT="${API}/acme/utilityvault/actions/runners/registration-token"
failed=0
ok() {
local url="$1" got
got=$(DRY_RUN=1 ACCESS_TOKEN=x REPO_URL="$url" ./token.sh)
if [[ "$got" == "$WANT" ]]; then
echo "ok $url"
else
echo "FAIL $url"
echo " got $got"
echo " want $WANT"
failed=1
fi
}
rejects() {
local url="$1"
if DRY_RUN=1 ACCESS_TOKEN=x REPO_URL="$url" ./token.sh >/dev/null 2>&1; then
echo "FAIL should have been rejected: $url"
failed=1
else
echo "ok rejected $url"
fi
}
ok "https://github.com/acme/utilityvault"
ok "https://github.com/acme/utilityvault/"
ok "https://github.com/acme/utilityvault.git"
# An ssh remote would otherwise parse into a nonsense API path.
rejects "git@github.com:acme/utilityvault.git"
# Org URL: right shape for an org-scoped runner, wrong endpoint for a repo one.
rejects "https://github.com/acme"
(( failed == 0 )) && echo "all passed"
exit "$failed"