summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml7
-rw-r--r--README.md14
-rw-r--r--cmd/gitlab-sshd/acceptance_test.go75
-rw-r--r--docker-compose.yml8
-rw-r--r--internal/testhelper/testdata/testroot/responses/allowed_without_console_messages.json6
5 files changed, 105 insertions, 5 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3210b35..5f8dca5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -30,6 +30,8 @@ default:
- gitlab-org-docker
.test:
+ variables:
+ GITALY_CONNECTION_INFO: '{"address":"tcp://gitaly:8075", "storage":"default"}'
before_script:
# Set up the environment to run integration tests (still written in Ruby)
- apt-get update -qq && apt-get install -y ruby ruby-dev
@@ -42,6 +44,11 @@ default:
- cp config.yml.example config.yml
- go version
- which go
+ services:
+ - name: registry.gitlab.com/gitlab-org/build/cng/gitaly:latest
+ # Disable the hooks so we don't have to stub the GitLab API
+ command: ["bash", "-c", "mkdir -p /home/git/repositories && rm -rf /srv/gitlab-shell/hooks/* && exec /usr/bin/env GITALY_TESTING_NO_GIT_HOOKS=1 /scripts/process-wrapper"]
+ alias: gitaly
script:
- make verify test
diff --git a/README.md b/README.md
index 0fe39e3..3231646 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,20 @@ Run both test and verify (the default Makefile target):
bundle install
make validate
+### Gitaly
+
+Some tests need a Gitaly server. The
+[`docker-compose.yml`](./docker-compose.yml) file will run Gitaly on
+port 8075. To tell the tests where Gitaly is, set
+`GITALY_CONNECTION_INFO`:
+
+ export GITALY_CONNECTION_INFO='{"address": "tcp://localhost:8075", "storage": "default"}'
+ make test
+
+If no `GITALY_CONNECTION_INFO` is set, the test suite will still run, but any
+tests requiring Gitaly will be skipped. They will always run in the CI
+environment.
+
## Git LFS remark
Starting with GitLab 8.12, GitLab supports Git LFS authentication through SSH.
diff --git a/cmd/gitlab-sshd/acceptance_test.go b/cmd/gitlab-sshd/acceptance_test.go
index 112247b..80a0838 100644
--- a/cmd/gitlab-sshd/acceptance_test.go
+++ b/cmd/gitlab-sshd/acceptance_test.go
@@ -4,6 +4,7 @@ import (
"bufio"
"context"
"crypto/ed25519"
+ "encoding/json"
"encoding/pem"
"fmt"
"io"
@@ -16,19 +17,34 @@ import (
"path/filepath"
"regexp"
"runtime"
+ "strings"
"testing"
"github.com/mikesmitty/edkey"
"github.com/pires/go-proxyproto"
"github.com/stretchr/testify/require"
+ gitalyClient "gitlab.com/gitlab-org/gitaly/client"
+ pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitlab-shell/internal/testhelper"
"golang.org/x/crypto/ssh"
)
var (
- sshdPath = ""
+ sshdPath = ""
+ gitalyConnInfo *gitalyConnectionInfo
)
+const (
+ testRepo = "test-gitlab-shell/gitlab-test.git"
+ testRepoNamespace = "test-gitlab-shell"
+ testRepoImportUrl = "https://gitlab.com/gitlab-org/gitlab-test.git"
+)
+
+type gitalyConnectionInfo struct {
+ Address string `json:"address"`
+ Storage string `json:"storage"`
+}
+
func init() {
rootDir := rootDir()
sshdPath = filepath.Join(rootDir, "bin", "gitlab-sshd")
@@ -36,6 +52,11 @@ func init() {
if _, err := os.Stat(sshdPath); os.IsNotExist(err) {
panic(fmt.Errorf("cannot find executable %s. Please run 'make compile'", sshdPath))
}
+
+ gci, exists := os.LookupEnv("GITALY_CONNECTION_INFO")
+ if exists {
+ json.Unmarshal([]byte(gci), &gitalyConnInfo)
+ }
}
func rootDir() string {
@@ -47,6 +68,29 @@ func rootDir() string {
return filepath.Join(filepath.Dir(currentFile), "..", "..")
}
+func ensureGitalyRepository(t *testing.T) {
+ if os.Getenv("GITALY_CONNECTION_INFO") == "" {
+ t.Skip("GITALY_CONNECTION_INFO is not set")
+ }
+
+ conn, err := gitalyClient.Dial(gitalyConnInfo.Address, gitalyClient.DefaultDialOpts)
+ require.NoError(t, err)
+
+ namespace := pb.NewNamespaceServiceClient(conn)
+ repository := pb.NewRepositoryServiceClient(conn)
+
+ // Remove the repository if it already exists, for consistency
+ rmNsReq := &pb.RemoveNamespaceRequest{StorageName: gitalyConnInfo.Storage, Name: testRepoNamespace}
+ _, err = namespace.RemoveNamespace(context.Background(), rmNsReq)
+ require.NoError(t, err)
+
+ gl_repository := &pb.Repository{StorageName: gitalyConnInfo.Storage, RelativePath: testRepo}
+ createReq := &pb.CreateRepositoryFromURLRequest{Repository: gl_repository, Url: testRepoImportUrl}
+
+ _, err = repository.CreateRepositoryFromURL(context.Background(), createReq)
+ require.NoError(t, err)
+}
+
func successAPI(t *testing.T) http.Handler {
t.Helper()
@@ -73,7 +117,13 @@ func successAPI(t *testing.T) http.Handler {
body, err := ioutil.ReadFile(filepath.Join(testhelper.TestRoot, "responses/allowed_without_console_messages.json"))
require.NoError(t, err)
- _, err = w.Write(body)
+ response := strings.Replace(string(body), "GITALY_REPOSITORY", testRepo, 1)
+
+ if gitalyConnInfo != nil {
+ response = strings.Replace(response, "GITALY_ADDRESS", gitalyConnInfo.Address, 1)
+ }
+
+ fmt.Fprint(w, response)
require.NoError(t, err)
case "/api/v4/internal/lfs_authenticate":
fmt.Fprint(w, `{"username": "test-user", "lfs_token": "testlfstoken", "repo_path": "foo", "expires_in": 7200}`)
@@ -335,3 +385,24 @@ func TestGitLfsAuthenticateSuccess(t *testing.T) {
require.Equal(t, `{"header":{"Authorization":"Basic dGVzdC11c2VyOnRlc3RsZnN0b2tlbg=="},"href":"/info/lfs","expires_in":7200}
`, string(output))
}
+
+func TestGitReceivePackSuccess(t *testing.T) {
+ ensureGitalyRepository(t)
+
+ client := runSSHD(t, successAPI(t))
+
+ session, err := client.NewSession()
+ require.NoError(t, err)
+ defer session.Close()
+
+ output, err := session.Output(fmt.Sprintf("git-receive-pack %s", testRepo))
+ require.NoError(t, err)
+
+ outputLines := strings.Split(string(output), "\n")
+
+ for i := 0; i < (len(outputLines) - 1); i++ {
+ require.Regexp(t, "^[0-9a-f]{44} refs/(heads|tags)/[^ ]+", outputLines[i])
+ }
+
+ require.Equal(t, "0000", outputLines[len(outputLines)-1])
+}
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..28ab3cf
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,8 @@
+version: '3.1'
+services:
+ gitaly:
+ environment:
+ - GITALY_TESTING_NO_GIT_HOOKS=1
+ image: registry.gitlab.com/gitlab-org/build/cng/gitaly:latest
+ ports:
+ - '8075:8075'
diff --git a/internal/testhelper/testdata/testroot/responses/allowed_without_console_messages.json b/internal/testhelper/testdata/testroot/responses/allowed_without_console_messages.json
index c28ea71..d5511cd 100644
--- a/internal/testhelper/testdata/testroot/responses/allowed_without_console_messages.json
+++ b/internal/testhelper/testdata/testroot/responses/allowed_without_console_messages.json
@@ -4,17 +4,17 @@
"gl_project_path": "group/private",
"gl_id": "user-1",
"gl_username": "root",
- "git_config_options": ["option"],
+ "git_config_options": [],
"gitaly": {
"repository": {
"storage_name": "default",
- "relative_path": "@hashed/5f/9c/5f9c4ab08cac7457e9111a30e4664920607ea2c115a1433d7be98e97e64244ca.git",
+ "relative_path": "GITALY_REPOSITORY",
"git_object_directory": "path/to/git_object_directory",
"git_alternate_object_directories": ["path/to/git_alternate_object_directory"],
"gl_repository": "project-26",
"gl_project_path": "group/private"
},
- "address": "unix:gitaly.socket",
+ "address": "GITALY_ADDRESS",
"token": "token"
},
"git_protocol": "protocol",