package authservice import ( "testing" "github.com/stretchr/testify/assert" ) func TestExtractCommandName(t *testing.T) { tcs := map[string]struct { input string expected string }{ "standard": { "echo", "echo", }, "2 words": { "echo hello", "echo", }, "Command with space": { "\"echo hello\"", "echo hello", }, "Command with space 2": { "echo\\ hello", "echo hello", }, "Full Path": { "/bin/mybinary hello", "/bin/mybinary", }, "Relative path": { "./mybinary hello", "./mybinary", }, "Env Var": { "a=b c", "c", }, "Env Var with underscore": { "_a=b c", "c", }, "Env Var with number": { "a3=b c", "c", }, "Not a var number": { // Leading digits are not interpreted as parameters "1a=b c", "1a=b", }, "Not a var special character": { // In bash this will be interpreted as `3 echo 8`, however we don't // support pipes currently "a=f|3 echo 8", "echo", }, "2 Env Var": { "_a=b KA=3 c", "c", }, "Leading space": { " _a=b KA=3 c", "c", }, "Trailing space": { " _a=b KA=3 c ", "c", }, "No command": { " KA=3 ", "", }, "Unicode number": { "aⅧ=3 echo 8", "aⅧ=3", }, "Unicode digit": { "a৩=3 echo 8", "a৩=3", }, "Unicode letter": { "aḸ=3 echo 8", "aḸ=3", }, } for name, tc := range tcs { t.Run(name, func(t *testing.T) { out, err := extractCommandName(tc.input) assert.NoError(t, err) assert.Equal(t, tc.expected, out) }) } }