| 1 | #!/bin/sh |
| 2 | # tests/mock_refresh.sh - stand-in for scorpiox-claudecode-refreshtoken. |
| 3 | # |
| 4 | # Mirrors the production program's argument shape (--credentials-file <path> |
| 5 | # [--force]) and its behaviour: it rewrites the credentials file in place with a |
| 6 | # freshly minted access token and a new expiresAt, and prints human text (which |
| 7 | # may include token material) on stdout. The plugin must never forward that. |
| 8 | # |
| 9 | # MOCK_REFRESH_FAIL=1 exercises the failure path where the file is untouched. |
| 10 | |
| 11 | CREDS="" |
| 12 | FORCE=0 |
| 13 | while [ $# -gt 0 ]; do |
| 14 | case "$1" in |
| 15 | --credentials-file) shift; CREDS="${1:-}" ;; |
| 16 | --force|-f) FORCE=1 ;; |
| 17 | esac |
| 18 | shift |
| 19 | done |
| 20 | [ -z "$CREDS" ] && CREDS="${CLAUDE_CREDS_PATH:-/nonexistent}" |
| 21 | |
| 22 | if [ "$MOCK_REFRESH_FAIL" = "1" ]; then |
| 23 | printf 'error: no refreshToken found in credentials\n' >&2 |
| 24 | exit 1 |
| 25 | fi |
| 26 | if [ ! -f "$CREDS" ]; then |
| 27 | printf 'error: cannot read %s\n' "$CREDS" >&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | _now=$(date +%s) |
| 32 | _exp=$(( (_now + 28800) * 1000 )) |
| 33 | printf 'Claude OAuth Token Auto-Refresh Tool\n\n' |
| 34 | printf 'Found Claude config: %s\n' "$CREDS" |
| 35 | printf 'Refreshing OAuth token (force=%s)\n' "$FORCE" |
| 36 | printf '{"claudeAiOauth":{"accessToken":"sk-ant-oat01-MOCK-REFRESHED-MUST-NOT-LEAK","refreshToken":"sk-ant-ort01-MOCK-REFRESHED","expiresAt":%s,"scopes":["user:profile","user:inference"],"subscriptionType":"pro"}}\n' "$_exp" > "$CREDS" |
| 37 | printf 'Token refresh successful\n' |
| 38 | exit 0 |