MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestCommand

Function TestCommand

internal/security/handler_session_test.go:66–103  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestCommand(t *testing.T) {
67 backend := &dummyBackend{}
68 session := &sessionHandler{
69 config: config.SecurityConfig{},
70 backend: backend,
71 sshConnection: &sshConnectionHandler{
72 lock: &sync.Mutex{},
73 },
74 logger: log.NewTestLogger(t),
75 }
76
77 session.config.Command.Allow = []string{"/bin/bash"}
78 session.config.Command.Mode = config.ExecutionPolicyDisable
79 assert.Error(t, session.OnExecRequest(1, "/bin/bash"))
80
81 session.config.Command.Mode = config.ExecutionPolicyFilter
82 assert.NoError(t, session.OnExecRequest(1, "/bin/bash"))
83 assert.Error(t, session.OnExecRequest(1, "/bin/sh"))
84
85 session.config.Command.Mode = config.ExecutionPolicyEnable
86 assert.NoError(t, session.OnExecRequest(1, "/bin/bash"))
87 assert.NoError(t, session.OnExecRequest(1, "/bin/sh"))
88
89 session.config.Shell.Mode = config.ExecutionPolicyEnable
90 backend.commandsExecuted = []string{}
91 backend.env = map[string]string{}
92 assert.NoError(t, session.OnExecRequest(1, "/bin/bash"))
93 assert.Equal(t, []string{"/bin/bash"}, backend.commandsExecuted)
94 assert.Equal(t, map[string]string{}, backend.env)
95
96 session.config.Shell.Mode = config.ExecutionPolicyEnable
97 session.config.ForceCommand = "/bin/wrapper"
98 backend.commandsExecuted = []string{}
99 backend.env = map[string]string{}
100 assert.NoError(t, session.OnExecRequest(1, "/bin/bash"))
101 assert.Equal(t, []string{"/bin/wrapper"}, backend.commandsExecuted)
102 assert.Equal(t, map[string]string{"SSH_ORIGINAL_COMMAND": "/bin/bash"}, backend.env)
103}
104
105func TestShell(t *testing.T) {
106 backend := &dummyBackend{}

Callers

nothing calls this directly

Calls 3

OnExecRequestMethod · 0.95
NewTestLoggerFunction · 0.92
ErrorMethod · 0.65

Tested by

no test coverage detected