summaryrefslogtreecommitdiff
path: root/go/internal/command/receivepack/receivepack_test.go
diff options
context:
space:
mode:
authorIgor <idrozdov@gitlab.com>2019-05-31 12:08:54 +0000
committerNick Thomas <nick@gitlab.com>2019-05-31 12:08:54 +0000
commit033c81d546d31d07e5eadb50611543a7d2471254 (patch)
tree688dc50182c8429941d4d23edad3aedc08471233 /go/internal/command/receivepack/receivepack_test.go
parent12ca54c2d998803a0564a5a2942121364a30678f (diff)
downloadgitlab-shell-033c81d546d31d07e5eadb50611543a7d2471254.tar.gz
Go implementation for git-receive-pack
Diffstat (limited to 'go/internal/command/receivepack/receivepack_test.go')
-rw-r--r--go/internal/command/receivepack/receivepack_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/go/internal/command/receivepack/receivepack_test.go b/go/internal/command/receivepack/receivepack_test.go
new file mode 100644
index 0000000..874bac3
--- /dev/null
+++ b/go/internal/command/receivepack/receivepack_test.go
@@ -0,0 +1,46 @@
+package receivepack
+
+import (
+ "bytes"
+ "encoding/json"
+ "net/http"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/testserver"
+)
+
+func TestForbiddenAccess(t *testing.T) {
+ requests := []testserver.TestRequestHandler{
+ {
+ Path: "/api/v4/internal/allowed",
+ Handler: func(w http.ResponseWriter, r *http.Request) {
+ body := map[string]interface{}{
+ "status": false,
+ "message": "Disallowed by API call",
+ }
+ w.WriteHeader(http.StatusForbidden)
+ require.NoError(t, json.NewEncoder(w).Encode(body))
+ },
+ },
+ }
+
+ url, cleanup := testserver.StartHttpServer(t, requests)
+ defer cleanup()
+
+ output := &bytes.Buffer{}
+ input := bytes.NewBufferString("input")
+
+ cmd := &Command{
+ Config: &config.Config{GitlabUrl: url},
+ Args: &commandargs.CommandArgs{GitlabKeyId: "disallowed", SshArgs: []string{"git-receive-pack", "group/repo"}},
+ ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input},
+ }
+
+ err := cmd.Execute()
+ require.Equal(t, "Disallowed by API call", err.Error())
+}