summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/command/authorizedkeys/authorized_keys_test.go15
-rw-r--r--internal/command/authorizedprincipals/authorized_principals_test.go15
-rw-r--r--internal/keyline/key_line.go15
-rw-r--r--internal/keyline/key_line_test.go38
4 files changed, 10 insertions, 73 deletions
diff --git a/internal/command/authorizedkeys/authorized_keys_test.go b/internal/command/authorizedkeys/authorized_keys_test.go
index f15c34d..ab44580 100644
--- a/internal/command/authorizedkeys/authorized_keys_test.go
+++ b/internal/command/authorizedkeys/authorized_keys_test.go
@@ -47,11 +47,9 @@ func TestExecute(t *testing.T) {
defer cleanup()
defaultConfig := &config.Config{RootDir: "/tmp", GitlabUrl: url}
- configWithSslCertDir := &config.Config{RootDir: "/tmp", GitlabUrl: url, SslCertDir: "/tmp/certs"}
testCases := []struct {
desc string
- config *config.Config
arguments *commandargs.AuthorizedKeys
expectedOutput string
}{
@@ -61,12 +59,6 @@ func TestExecute(t *testing.T) {
expectedOutput: "command=\"/tmp/bin/gitlab-shell key-1\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty public-key\n",
},
{
- desc: "With SSL cert dir",
- config: configWithSslCertDir,
- arguments: &commandargs.AuthorizedKeys{ExpectedUser: "user", ActualUser: "user", Key: "key"},
- expectedOutput: "command=\"SSL_CERT_DIR=/tmp/certs /tmp/bin/gitlab-shell key-1\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty public-key\n",
- },
- {
desc: "When key doesn't match any existing key",
arguments: &commandargs.AuthorizedKeys{ExpectedUser: "user", ActualUser: "user", Key: "not-found"},
expectedOutput: "# No key was found for not-found\n",
@@ -87,13 +79,8 @@ func TestExecute(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
buffer := &bytes.Buffer{}
- config := defaultConfig
- if tc.config != nil {
- config = tc.config
- }
-
cmd := &Command{
- Config: config,
+ Config: defaultConfig,
Args: tc.arguments,
ReadWriter: &readwriter.ReadWriter{Out: buffer},
}
diff --git a/internal/command/authorizedprincipals/authorized_principals_test.go b/internal/command/authorizedprincipals/authorized_principals_test.go
index ec97b65..2450a54 100644
--- a/internal/command/authorizedprincipals/authorized_principals_test.go
+++ b/internal/command/authorizedprincipals/authorized_principals_test.go
@@ -14,11 +14,9 @@ import (
func TestExecute(t *testing.T) {
defaultConfig := &config.Config{RootDir: "/tmp"}
- configWithSslCertDir := &config.Config{RootDir: "/tmp", SslCertDir: "/tmp/certs"}
testCases := []struct {
desc string
- config *config.Config
arguments *commandargs.AuthorizedPrincipals
expectedOutput string
}{
@@ -28,12 +26,6 @@ func TestExecute(t *testing.T) {
expectedOutput: "command=\"/tmp/bin/gitlab-shell username-key\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty principal\n",
},
{
- desc: "With SSL cert dir",
- config: configWithSslCertDir,
- arguments: &commandargs.AuthorizedPrincipals{KeyId: "key", Principals: []string{"principal"}},
- expectedOutput: "command=\"SSL_CERT_DIR=/tmp/certs /tmp/bin/gitlab-shell username-key\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty principal\n",
- },
- {
desc: "With multiple principals",
arguments: &commandargs.AuthorizedPrincipals{KeyId: "key", Principals: []string{"principal-1", "principal-2"}},
expectedOutput: "command=\"/tmp/bin/gitlab-shell username-key\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty principal-1\ncommand=\"/tmp/bin/gitlab-shell username-key\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty principal-2\n",
@@ -44,13 +36,8 @@ func TestExecute(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
buffer := &bytes.Buffer{}
- config := defaultConfig
- if tc.config != nil {
- config = tc.config
- }
-
cmd := &Command{
- Config: config,
+ Config: defaultConfig,
Args: tc.arguments,
ReadWriter: &readwriter.ReadWriter{Out: buffer},
}
diff --git a/internal/keyline/key_line.go b/internal/keyline/key_line.go
index e2abb82..c6f2422 100644
--- a/internal/keyline/key_line.go
+++ b/internal/keyline/key_line.go
@@ -37,22 +37,9 @@ func NewPrincipalKeyLine(keyId, principal string, config *config.Config) (*KeyLi
}
func (k *KeyLine) ToString() string {
- sslCertDirEnvVar := k.sslCertDirEnvVar()
command := fmt.Sprintf("%s %s-%s", path.Join(k.Config.RootDir, executable.BinDir, executable.GitlabShell), k.Prefix, k.Id)
- if sslCertDirEnvVar != "" {
- sslCertDirEnvVar = fmt.Sprintf(`%s `, sslCertDirEnvVar)
- }
-
- return fmt.Sprintf(`command="%s%s",%s %s`, sslCertDirEnvVar, command, SshOptions, k.Value)
-}
-
-func (k *KeyLine) sslCertDirEnvVar() string {
- if k.Config.SslCertDir != "" {
- return fmt.Sprintf(`SSL_CERT_DIR=%s`, k.Config.SslCertDir)
- }
-
- return ""
+ return fmt.Sprintf(`command="%s",%s %s`, command, SshOptions, k.Value)
}
func newKeyLine(id, value, prefix string, config *config.Config) (*KeyLine, error) {
diff --git a/internal/keyline/key_line_test.go b/internal/keyline/key_line_test.go
index 095de78..e652c23 100644
--- a/internal/keyline/key_line_test.go
+++ b/internal/keyline/key_line_test.go
@@ -70,37 +70,13 @@ func TestFailingNewPrincipalKeyLine(t *testing.T) {
}
func TestToString(t *testing.T) {
- testCases := []struct {
- desc string
- keyLine *KeyLine
- expectedOutput string
- }{
- {
- desc: "Without SSL cert dir",
- keyLine: &KeyLine{
- Id: "1",
- Value: "public-key",
- Prefix: "key",
- Config: &config.Config{RootDir: "/tmp"},
- },
- expectedOutput: `command="/tmp/bin/gitlab-shell key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty public-key`,
- },
- {
- desc: "With SSL cert dir",
- keyLine: &KeyLine{
- Id: "1",
- Value: "public-key",
- Prefix: "key",
- Config: &config.Config{RootDir: "/tmp", SslCertDir: "/tmp/certs"},
- },
- expectedOutput: `command="SSL_CERT_DIR=/tmp/certs /tmp/bin/gitlab-shell key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty public-key`,
- },
+ keyLine := &KeyLine{
+ Id: "1",
+ Value: "public-key",
+ Prefix: "key",
+ Config: &config.Config{RootDir: "/tmp"},
}
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- result := tc.keyLine.ToString()
- require.Equal(t, tc.expectedOutput, result)
- })
- }
+ result := keyLine.ToString()
+ require.Equal(t, `command="/tmp/bin/gitlab-shell key-1",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty public-key`, result)
}