summaryrefslogtreecommitdiff
path: root/go/internal/command/command_test.go
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2019-07-29 14:33:01 +0800
committerPatrick Bajao <ebajao@gitlab.com>2019-07-29 14:58:32 +0800
commitaab85f3600caf04b491d6ca4fc3f0f004d9e3fc0 (patch)
treeda3f6ab04de4e0c1ba5b79a281c6ca91852e0aa1 /go/internal/command/command_test.go
parented0460374a5ca13d9ea17c6a9c21151319b7fd53 (diff)
downloadgitlab-shell-aab85f3600caf04b491d6ca4fc3f0f004d9e3fc0.tar.gz
Support falling back to ruby version of checkers
Rename the ruby scripts to have `-ruby` suffix and add a symlink for both to `./gitlab-shell`. The executable name will be used to determine how args will be parsed. For now, we only parse the arguments for gitlab-shell commands. If the executable is `gitlab-shell-authorized-keys-check` or `gitlab-shell-authorized-principals-check`, it'll always fallback to the ruby version. Ruby specs test the ruby script, the fallback from go to ruby and go implementation of both (still pending).
Diffstat (limited to 'go/internal/command/command_test.go')
-rw-r--r--go/internal/command/command_test.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/go/internal/command/command_test.go b/go/internal/command/command_test.go
index 07260dd..2341dbb 100644
--- a/go/internal/command/command_test.go
+++ b/go/internal/command/command_test.go
@@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/discover"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/fallback"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/lfsauthenticate"
@@ -21,6 +22,7 @@ func TestNew(t *testing.T) {
desc string
config *config.Config
environment map[string]string
+ arguments []string
expectedType interface{}
}{
{
@@ -33,6 +35,7 @@ func TestNew(t *testing.T) {
"SSH_CONNECTION": "1",
"SSH_ORIGINAL_COMMAND": "",
},
+ arguments: []string{string(commandargs.GitlabShell)},
expectedType: &discover.Command{},
},
{
@@ -45,6 +48,7 @@ func TestNew(t *testing.T) {
"SSH_CONNECTION": "1",
"SSH_ORIGINAL_COMMAND": "",
},
+ arguments: []string{string(commandargs.GitlabShell)},
expectedType: &fallback.Command{},
},
{
@@ -57,6 +61,7 @@ func TestNew(t *testing.T) {
"SSH_CONNECTION": "1",
"SSH_ORIGINAL_COMMAND": "2fa_recovery_codes",
},
+ arguments: []string{string(commandargs.GitlabShell)},
expectedType: &twofactorrecover.Command{},
},
{
@@ -69,6 +74,7 @@ func TestNew(t *testing.T) {
"SSH_CONNECTION": "1",
"SSH_ORIGINAL_COMMAND": "git-lfs-authenticate",
},
+ arguments: []string{string(commandargs.GitlabShell)},
expectedType: &lfsauthenticate.Command{},
},
{
@@ -81,6 +87,7 @@ func TestNew(t *testing.T) {
"SSH_CONNECTION": "1",
"SSH_ORIGINAL_COMMAND": "git-receive-pack",
},
+ arguments: []string{string(commandargs.GitlabShell)},
expectedType: &receivepack.Command{},
},
{
@@ -93,6 +100,7 @@ func TestNew(t *testing.T) {
"SSH_CONNECTION": "1",
"SSH_ORIGINAL_COMMAND": "git-upload-pack",
},
+ arguments: []string{string(commandargs.GitlabShell)},
expectedType: &uploadpack.Command{},
},
{
@@ -105,6 +113,7 @@ func TestNew(t *testing.T) {
"SSH_CONNECTION": "1",
"SSH_ORIGINAL_COMMAND": "git-upload-archive",
},
+ arguments: []string{string(commandargs.GitlabShell)},
expectedType: &uploadarchive.Command{},
},
{
@@ -117,6 +126,7 @@ func TestNew(t *testing.T) {
"SSH_CONNECTION": "1",
"SSH_ORIGINAL_COMMAND": "git-unimplemented-feature",
},
+ arguments: []string{string(commandargs.GitlabShell)},
expectedType: &fallback.Command{},
},
}
@@ -126,7 +136,7 @@ func TestNew(t *testing.T) {
restoreEnv := testhelper.TempEnv(tc.environment)
defer restoreEnv()
- command, err := New([]string{}, tc.config, nil)
+ command, err := New(tc.arguments, tc.config, nil)
require.NoError(t, err)
require.IsType(t, tc.expectedType, command)
@@ -139,7 +149,7 @@ func TestFailingNew(t *testing.T) {
restoreEnv := testhelper.TempEnv(map[string]string{})
defer restoreEnv()
- _, err := New([]string{}, &config.Config{}, nil)
+ _, err := New([]string{string(commandargs.GitlabShell)}, &config.Config{}, nil)
require.Error(t, err, "Only ssh allowed")
})