internal/control/mirrorcmd_test.go
29 lines · 977 bytes
1 symbol in this file
1package control
2
3import (
4 "strings"
5 "testing"
6
7 "gitbay.org/gitbay/internal/protocol"
8)
9
10// mirror add refuses a host sync would refuse as numeric, on an
11// instance that allows local targets or not, and stores nothing (#298).
12func TestMirrorAddRefusesNumericHost(t *testing.T) {
13 for _, allowLocal := range []bool{true, false} {
14 for _, host := range []string{"127.1", "2130706433", "0x7f.1"} {
15 c, errOut, st, _ := importCtx(t, allowLocal)
16 code := Dispatch(c, []string{"repo", "mirror", "add", "alice/app", "https://" + host + "/x.git", "--direction", "pull"})
17 if code != protocol.ExitUsage || !strings.Contains(errOut.String(), "numeric address") {
18 t.Fatalf("%s (allow_local %v): exit %d, %q", host, allowLocal, code, errOut.String())
19 }
20 repo, err := st.RepoByPath("alice/app")
21 if err != nil {
22 t.Fatal(err)
23 }
24 if ms, err := st.ListMirrors(repo.ID); err != nil || len(ms) != 0 {
25 t.Fatalf("%s: mirrors %v, %v", host, ms, err)
26 }
27 }
28 }
29}