summaryrefslogtreecommitdiff
path: root/cmd/gitlab-shell
diff options
context:
space:
mode:
authorPatrick Bajao <ebajao@gitlab.com>2021-11-12 02:09:36 +0000
committerPatrick Bajao <ebajao@gitlab.com>2021-11-12 02:09:36 +0000
commit0ff9b71545e64766a47b1297a4525ab22552e3e4 (patch)
tree01195d4a7b4e1415d22cb09e41a6feee182dd4d6 /cmd/gitlab-shell
parent5cccb38df60b9ecef744e8bf1cbdff68066e9d5e (diff)
parent672013e702cb44c3bc1b46807703295448dc0afc (diff)
downloadgitlab-shell-0ff9b71545e64766a47b1297a4525ab22552e3e4.tar.gz
Merge branch 'sh-improve-key-matching-sshd' into 'main'
Relax key and username matching for sshd See merge request gitlab-org/gitlab-shell!540
Diffstat (limited to 'cmd/gitlab-shell')
-rw-r--r--cmd/gitlab-shell/command/command_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/cmd/gitlab-shell/command/command_test.go b/cmd/gitlab-shell/command/command_test.go
index 2aeee59..ba0db7d 100644
--- a/cmd/gitlab-shell/command/command_test.go
+++ b/cmd/gitlab-shell/command/command_test.go
@@ -170,6 +170,27 @@ func TestParseSuccess(t *testing.T) {
expectedArgs: &commandargs.Shell{Arguments: []string{"hello", "username-key-123"}, SshArgs: []string{}, CommandType: commandargs.Discover, GitlabUsername: "key-123", Env: sshenv.Env{IsSSHConnection: true, RemoteAddr: "1"}},
},
{
+ desc: "It finds the key id if the key is listed as the last argument",
+ executable: &executable.Executable{Name: executable.GitlabShell},
+ env: sshenv.Env{IsSSHConnection: true, RemoteAddr: "1"},
+ arguments: []string{"hello", "gitlab-shell -c key-123"},
+ expectedArgs: &commandargs.Shell{Arguments: []string{"hello", "gitlab-shell -c key-123"}, SshArgs: []string{}, CommandType: commandargs.Discover, GitlabKeyId: "123", Env: sshenv.Env{IsSSHConnection: true, RemoteAddr: "1"}},
+ },
+ {
+ desc: "It finds the username if the username is listed as the last argument",
+ executable: &executable.Executable{Name: executable.GitlabShell},
+ env: sshenv.Env{IsSSHConnection: true, RemoteAddr: "1"},
+ arguments: []string{"hello", "gitlab-shell -c username-jane-doe"},
+ expectedArgs: &commandargs.Shell{Arguments: []string{"hello", "gitlab-shell -c username-jane-doe"}, SshArgs: []string{}, CommandType: commandargs.Discover, GitlabUsername: "jane-doe", Env: sshenv.Env{IsSSHConnection: true, RemoteAddr: "1"}},
+ },
+ {
+ desc: "It finds the key id only if the last argument is of <key-id> format",
+ executable: &executable.Executable{Name: executable.GitlabShell},
+ env: sshenv.Env{IsSSHConnection: true, RemoteAddr: "1"},
+ arguments: []string{"hello", "gitlab-shell -c username-key-123"},
+ expectedArgs: &commandargs.Shell{Arguments: []string{"hello", "gitlab-shell -c username-key-123"}, SshArgs: []string{}, CommandType: commandargs.Discover, GitlabUsername: "key-123", Env: sshenv.Env{IsSSHConnection: true, RemoteAddr: "1"}},
+ },
+ {
desc: "It finds the username in any passed arguments",
executable: &executable.Executable{Name: executable.GitlabShell},
env: sshenv.Env{IsSSHConnection: true, RemoteAddr: "1"},