summaryrefslogtreecommitdiff
path: root/internal/keyline
diff options
context:
space:
mode:
Diffstat (limited to 'internal/keyline')
-rw-r--r--internal/keyline/key_line.go15
-rw-r--r--internal/keyline/key_line_test.go38
2 files changed, 8 insertions, 45 deletions
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)
}