Breaking change. The monorepo's gitea host was previously inferred from the first target's subrepo_url, silently coupling the two and breaking on any multi-host setup (monorepo on host A, target on host B). v2.0.0 replaces the inference with a required josh.monorepo_url field that mirrors subrepo_url — same parsing, same SSH/HTTPS auth options, same shape. - schema_version: 2 is now required; v1 configs are rejected with a clear migration error - josh.monorepo_url is required; josh.monorepo_auth is optional (default https) - mono_auth_url() in lib/auth.sh mirrors subrepo_auth_url() - MONOREPO_API derives from monorepo_url's host instead of .[0].gitea_host; env-var override preserved as escape hatch - initial_import() and force-push call mono_auth_url() instead of building URLs inline - ADR-012 documents the rationale; CHANGELOG includes migration snippet Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
76 lines
2.3 KiB
Bash
76 lines
2.3 KiB
Bash
#!/usr/bin/env bats
|
|
# tests/unit/auth.bats — Auth URL construction tests
|
|
|
|
setup() {
|
|
export JOSH_SYNC_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
|
|
source "$JOSH_SYNC_ROOT/lib/core.sh"
|
|
source "$JOSH_SYNC_ROOT/lib/auth.sh"
|
|
|
|
# Set up env vars as parse_config + load_target would
|
|
export JOSH_PROXY_URL="https://josh.test.local"
|
|
export MONOREPO_PATH="org/monorepo"
|
|
export BOT_USER="sync-bot"
|
|
export GITEA_TOKEN="test-token-123"
|
|
export JOSH_FILTER=":/services/app-a"
|
|
export SUBREPO_URL="https://gitea.test.local/ext/app-a.git"
|
|
export SUBREPO_AUTH="https"
|
|
export SUBREPO_TOKEN="subrepo-token-456"
|
|
}
|
|
|
|
@test "josh_auth_url builds correct HTTPS URL with credentials and filter" {
|
|
local url
|
|
url=$(josh_auth_url)
|
|
[ "$url" = "https://sync-bot:test-token-123@josh.test.local/org/monorepo.git:/services/app-a.git" ]
|
|
}
|
|
|
|
@test "subrepo_auth_url injects credentials for HTTPS" {
|
|
local url
|
|
url=$(subrepo_auth_url)
|
|
[ "$url" = "https://sync-bot:subrepo-token-456@gitea.test.local/ext/app-a.git" ]
|
|
}
|
|
|
|
@test "subrepo_auth_url returns bare URL for SSH" {
|
|
export SUBREPO_AUTH="ssh"
|
|
export SUBREPO_URL="git@gitea.test.local:ext/app-a.git"
|
|
|
|
local url
|
|
url=$(subrepo_auth_url)
|
|
[ "$url" = "git@gitea.test.local:ext/app-a.git" ]
|
|
}
|
|
|
|
@test "mono_auth_url returns bare URL for SSH" {
|
|
export MONOREPO_AUTH="ssh"
|
|
export MONOREPO_URL="git@code.example.io:org/monorepo.git"
|
|
|
|
local url
|
|
url=$(mono_auth_url)
|
|
[ "$url" = "git@code.example.io:org/monorepo.git" ]
|
|
}
|
|
|
|
@test "mono_auth_url injects credentials for HTTPS git@-form monorepo_url" {
|
|
export MONOREPO_AUTH="https"
|
|
export MONOREPO_URL="git@code.example.io:org/monorepo.git"
|
|
|
|
local url
|
|
url=$(mono_auth_url)
|
|
[ "$url" = "https://sync-bot:test-token-123@code.example.io/org/monorepo.git" ]
|
|
}
|
|
|
|
@test "mono_auth_url injects credentials for HTTPS https-form monorepo_url" {
|
|
export MONOREPO_AUTH="https"
|
|
export MONOREPO_URL="https://code.example.io/org/monorepo.git"
|
|
|
|
local url
|
|
url=$(mono_auth_url)
|
|
[ "$url" = "https://sync-bot:test-token-123@code.example.io/org/monorepo.git" ]
|
|
}
|
|
|
|
@test "mono_auth_url defaults to HTTPS when MONOREPO_AUTH unset" {
|
|
unset MONOREPO_AUTH
|
|
export MONOREPO_URL="https://code.example.io/org/monorepo.git"
|
|
|
|
local url
|
|
url=$(mono_auth_url)
|
|
[ "$url" = "https://sync-bot:test-token-123@code.example.io/org/monorepo.git" ]
|
|
}
|