summaryrefslogtreecommitdiff
path: root/internal/command/command_test.go
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-09-08 14:40:35 +0000
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2021-09-08 14:41:57 +0000
commit67415dc4f6f293460517d4281b5e4e80e66ffb91 (patch)
treef3c3e9162a39ddc8fcfcf6f659ab5cdf362871d6 /internal/command/command_test.go
parent7884a4420ac8ffd3ee34589c0f8e0d25ca0fd076 (diff)
downloadgitlab-shell-67415dc4f6f293460517d4281b5e4e80e66ffb91.tar.gz
refactor: rearchitect command and executable Go modules
Diffstat (limited to 'internal/command/command_test.go')
-rw-r--r--internal/command/command_test.go158
1 files changed, 0 insertions, 158 deletions
diff --git a/internal/command/command_test.go b/internal/command/command_test.go
index a538745..2fc6655 100644
--- a/internal/command/command_test.go
+++ b/internal/command/command_test.go
@@ -1,173 +1,15 @@
package command
import (
- "errors"
"os"
"testing"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/authorizedkeys"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/authorizedprincipals"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/discover"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/healthcheck"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/lfsauthenticate"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/personalaccesstoken"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/receivepack"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/shared/disallowedcommand"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/twofactorrecover"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/twofactorverify"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/uploadarchive"
- "gitlab.com/gitlab-org/gitlab-shell/internal/command/uploadpack"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
- "gitlab.com/gitlab-org/gitlab-shell/internal/executable"
- "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv"
"gitlab.com/gitlab-org/labkit/correlation"
)
-var (
- authorizedKeysExec = &executable.Executable{Name: executable.AuthorizedKeysCheck, AcceptArgs: true}
- authorizedPrincipalsExec = &executable.Executable{Name: executable.AuthorizedPrincipalsCheck, AcceptArgs: true}
- checkExec = &executable.Executable{Name: executable.Healthcheck, AcceptArgs: false}
- gitlabShellExec = &executable.Executable{Name: executable.GitlabShell, AcceptArgs: true}
-
- basicConfig = &config.Config{GitlabUrl: "http+unix://gitlab.socket"}
- advancedConfig = &config.Config{GitlabUrl: "http+unix://gitlab.socket", SslCertDir: "/tmp/certs"}
-)
-
-func buildEnv(command string) sshenv.Env {
- return sshenv.Env{
- IsSSHConnection: true,
- OriginalCommand: command,
- }
-}
-
-func TestNew(t *testing.T) {
- testCases := []struct {
- desc string
- executable *executable.Executable
- env sshenv.Env
- arguments []string
- config *config.Config
- expectedType interface{}
- }{
- {
- desc: "it returns a Discover command",
- executable: gitlabShellExec,
- env: buildEnv(""),
- config: basicConfig,
- expectedType: &discover.Command{},
- },
- {
- desc: "it returns a TwoFactorRecover command",
- executable: gitlabShellExec,
- env: buildEnv("2fa_recovery_codes"),
- config: basicConfig,
- expectedType: &twofactorrecover.Command{},
- },
- {
- desc: "it returns a TwoFactorVerify command",
- executable: gitlabShellExec,
- env: buildEnv("2fa_verify"),
- config: basicConfig,
- expectedType: &twofactorverify.Command{},
- },
- {
- desc: "it returns an LfsAuthenticate command",
- executable: gitlabShellExec,
- env: buildEnv("git-lfs-authenticate"),
- config: basicConfig,
- expectedType: &lfsauthenticate.Command{},
- },
- {
- desc: "it returns a ReceivePack command",
- executable: gitlabShellExec,
- env: buildEnv("git-receive-pack"),
- config: basicConfig,
- expectedType: &receivepack.Command{},
- },
- {
- desc: "it returns an UploadPack command",
- executable: gitlabShellExec,
- env: buildEnv("git-upload-pack"),
- config: basicConfig,
- expectedType: &uploadpack.Command{},
- },
- {
- desc: "it returns an UploadArchive command",
- executable: gitlabShellExec,
- env: buildEnv("git-upload-archive"),
- config: basicConfig,
- expectedType: &uploadarchive.Command{},
- },
- {
- desc: "it returns a Healthcheck command",
- executable: checkExec,
- config: basicConfig,
- expectedType: &healthcheck.Command{},
- },
- {
- desc: "it returns a AuthorizedKeys command",
- executable: authorizedKeysExec,
- arguments: []string{"git", "git", "key"},
- config: basicConfig,
- expectedType: &authorizedkeys.Command{},
- },
- {
- desc: "it returns a AuthorizedPrincipals command",
- executable: authorizedPrincipalsExec,
- arguments: []string{"key", "principal"},
- config: basicConfig,
- expectedType: &authorizedprincipals.Command{},
- },
- {
- desc: "it returns a PersonalAccessToken command",
- executable: gitlabShellExec,
- env: buildEnv("personal_access_token"),
- config: basicConfig,
- expectedType: &personalaccesstoken.Command{},
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- command, err := New(tc.executable, tc.arguments, tc.env, tc.config, nil)
-
- require.NoError(t, err)
- require.IsType(t, tc.expectedType, command)
- })
- }
-}
-
-func TestFailingNew(t *testing.T) {
- testCases := []struct {
- desc string
- executable *executable.Executable
- env sshenv.Env
- expectedError error
- }{
- {
- desc: "Parsing environment failed",
- executable: gitlabShellExec,
- expectedError: errors.New("Only SSH allowed"),
- },
- {
- desc: "Unknown command given",
- executable: gitlabShellExec,
- env: buildEnv("unknown"),
- expectedError: disallowedcommand.Error,
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- command, err := New(tc.executable, []string{}, tc.env, basicConfig, nil)
- require.Nil(t, command)
- require.Equal(t, tc.expectedError, err)
- })
- }
-}
-
func TestSetup(t *testing.T) {
testCases := []struct {
name string