As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Unverified Commit f5f9ffc0 authored by Ash McKenzie's avatar Ash McKenzie
Browse files

Remove prefixing with SSL_CERT_DIR

parent 12353c0c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
}{
Loading
Loading
@@ -60,12 +58,6 @@ func TestExecute(t *testing.T) {
arguments: &commandargs.AuthorizedKeys{ExpectedUser: "user", ActualUser: "user", Key: "key"},
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"},
Loading
Loading
@@ -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},
}
Loading
Loading
Loading
Loading
@@ -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
}{
Loading
Loading
@@ -27,12 +25,6 @@ func TestExecute(t *testing.T) {
arguments: &commandargs.AuthorizedPrincipals{KeyId: "key", Principals: []string{"principal"}},
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"}},
Loading
Loading
@@ -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},
}
Loading
Loading
Loading
Loading
@@ -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) {
Loading
Loading
Loading
Loading
@@ -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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment