1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
package main
import (
"bytes"
"os/exec"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitlab"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg"
)
func TestMain(m *testing.M) {
testhelper.Run(m)
}
func TestCheckOK(t *testing.T) {
user, password := "user123", "password321"
c := gitlab.TestServerOptions{
User: user,
Password: password,
SecretToken: "",
GLRepository: "",
Changes: "",
PostReceiveCounterDecreased: false,
Protocol: "ssh",
}
serverURL, cleanup := gitlab.NewTestServer(t, c)
defer cleanup()
cfg := testcfg.Build(t, testcfg.WithBase(config.Cfg{
Gitlab: config.Gitlab{
URL: serverURL,
HTTPSettings: config.HTTPSettings{
User: user,
Password: password,
},
SecretFile: gitlab.WriteShellSecretFile(t, testhelper.TempDir(t), "the secret"),
},
}))
testcfg.BuildGitaly(t, cfg)
configPath := testcfg.WriteTemporaryGitalyConfigFile(t, cfg)
cmd := exec.Command(cfg.BinaryPath("gitaly"), "check", configPath)
var stderr, stdout bytes.Buffer
cmd.Stderr = &stderr
cmd.Stdout = &stdout
err := cmd.Run()
require.NoError(t, err)
require.Empty(t, stderr.String())
output := stdout.String()
require.Contains(t, output, "Checking GitLab API access: OK")
require.Contains(t, output, "Redis reachable for GitLab: true")
}
func TestCheckBadCreds(t *testing.T) {
user, password := "user123", "password321"
c := gitlab.TestServerOptions{
User: user,
Password: password,
SecretToken: "",
GLRepository: "",
Changes: "",
PostReceiveCounterDecreased: false,
Protocol: "ssh",
GitPushOptions: nil,
}
serverURL, cleanup := gitlab.NewTestServer(t, c)
defer cleanup()
cfg := testcfg.Build(t, testcfg.WithBase(config.Cfg{
Gitlab: config.Gitlab{
URL: serverURL,
HTTPSettings: config.HTTPSettings{
User: "wrong",
Password: password,
},
SecretFile: gitlab.WriteShellSecretFile(t, testhelper.TempDir(t), "the secret"),
},
}))
testcfg.BuildGitaly(t, cfg)
configPath := testcfg.WriteTemporaryGitalyConfigFile(t, cfg)
cmd := exec.Command(cfg.BinaryPath("gitaly"), "check", configPath)
var stderr, stdout bytes.Buffer
cmd.Stderr = &stderr
cmd.Stdout = &stdout
require.Error(t, cmd.Run())
require.Contains(t, stdout.String(), `Checking GitLab API access: FAILED`)
require.Contains(t, stderr.String(), "HTTP GET to GitLab endpoint /check failed: authorization failed")
require.Regexp(t, `.* level=error msg="Internal API error" .* error="authorization failed" method=GET status=401 url="http://127.0.0.1:[0-9]+/api/v4/internal/check"`, stderr.String())
}
|