Skip to content
quarry Artifact [cfc2bab524]
Login

Artifact [cfc2bab524]

Artifact cfc2bab5240eb3b7dc036c49cd3866229b083a93e40baa2b6f6ee496517fbf52:


package oltp

import (
	"testing"

	"craftdesign.group/quarry/internal/outbound/outboundtest"
)

// A Git push mirror's remote keeps the syntaxes it always accepted, and
// its host gets the forge's address rule when the remote is saved.
func TestGitMirrorRemoteHostIsChecked(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.mixed.test":    {"8.8.8.8", "127.0.0.1"},
		"git.metadata.test": {"169.254.169.254"},
	})
	d := openTest(t)
	if err := d.AddRepo("p", t.TempDir(), "", Public); err != nil {
		t.Fatal(err)
	}
	for _, tc := range []struct {
		remote string
		ok     bool
	}{
		{"[email protected]:owner/repo.git", true},
		{"ssh://[email protected]/owner/repo.git", true},
		{"ssh://[email protected]:2222/owner/repo.git", true},
		{"[email protected]:owner/repo.git", false},
		{"[email protected]:owner/repo.git", false},
		{"ssh://[email protected]/owner/repo.git", false},
		{"ssh://git@[::1]/owner/repo.git", false},
		{"git@[::1]:owner/repo.git", false},
		{"[email protected]:owner/repo.git", false},
		{"ssh://[email protected]:2222/owner/repo.git", false},
		{"[email protected]:owner/repo.git", false},
		{"[email protected]:owner/repo.git", false},
		{"git@-oProxyCommand=x.example:o/r.git", false},
		{"ssh://git@-oProxyCommand=x.example/o/r.git", false},
		{"-oProxyCommand=x.example", false},
	} {
		_, err := d.SetGitMirror("p", tc.remote, "", "dan", "")
		if (err == nil) != tc.ok {
			t.Errorf("FAIL: %q accepted=%v, want %v", tc.remote, err == nil, tc.ok)
		}
	}
	if !t.Failed() {
		t.Log("ok")
	}
}