package main
import (
"context"
"sync/atomic"
"testing"
"craftdesign.group/quarry/internal/oltp"
"craftdesign.group/quarry/internal/outbound/outboundtest"
)
// A stored remote that is inside the network now is not pushed to: the
// host is judged again just before the push, before any key is written
// or ssh started, and the refusal is the run's recorded reason.
func TestAGitPushRefusesAHostThatIsNowPrivate(t *testing.T) {
outboundtest.Set(t)
outboundtest.Resolve(t, map[string][]string{
"git.public.test": {"8.8.8.8"},
"git.inward.test": {"10.0.0.9"},
"git.moved.test": {"127.0.0.1"},
})
for remote, pushed := range map[string]bool{
"[email protected]:o/r.git": true,
"ssh://[email protected]:2222/o/r.git": true,
"[email protected]:o/r.git": false,
"ssh://[email protected]/o/r.git": false,
"[email protected]:o/r.git": false,
"ssh://git@[::1]/o/r.git": false,
"[email protected]:o/r.git": false,
"git@-oProxyCommand=x.example:o/r.git": false,
"ssh://git@-oProxyCommand=x.example/o/r.git": false,
} {
if pushed {
// Past the check; the push itself needs a store and a key.
if err := oltp.CheckGitRemoteHost(remote); err != nil {
t.Errorf("FAIL: %s refused: %v", remote, err)
}
continue
}
var ran atomic.Int32
rg := ®istrar{}
rg.dir = t.TempDir()
why, decided := rg.gitMirrorPush("test", "pub", func(context.Context, string, string, string, []string) (string, error) {
ran.Add(1)
return "", nil
}, remote, "main")
if ran.Load() != 0 || why == "" || !decided {
t.Errorf("FAIL: %s: export ran=%d why=%q decided=%v", remote, ran.Load(), why, decided)
}
}
if !t.Failed() {
t.Log("ok")
}
}