1 package authservice
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestExtractCommandName(t *testing.T) {
10 tcs := map[string]struct {
11 input string
12 expected string
13 }{
14 "standard": {
15 "echo",
16 "echo",
17 },
18 "2 words": {
19 "echo hello",
20 "echo",
21 },
22 "Command with space": {
23 "\"echo hello\"",
24 "echo hello",
25 },
26 "Command with space 2": {
27 "echo\\ hello",
28 "echo hello",
29 },
30 "Full Path": {
31 "/bin/mybinary hello",
32 "/bin/mybinary",
33 },
34 "Relative path": {
35 "./mybinary hello",
36 "./mybinary",
37 },
38 "Env Var": {
39 "a=b c",
40 "c",
41 },
42 "Env Var with underscore": {
43 "_a=b c",
44 "c",
45 },
46 "Env Var with number": {
47 "a3=b c",
48 "c",
49 },
50 "Not a var number": {
51
52 "1a=b c",
53 "1a=b",
54 },
55 "Not a var special character": {
56
57
58 "a=f|3 echo 8",
59 "echo",
60 },
61 "2 Env Var": {
62 "_a=b KA=3 c",
63 "c",
64 },
65 "Leading space": {
66 " _a=b KA=3 c",
67 "c",
68 },
69 "Trailing space": {
70 " _a=b KA=3 c ",
71 "c",
72 },
73 "No command": {
74 " KA=3 ",
75 "",
76 },
77 "Unicode number": {
78 "aⅧ=3 echo 8",
79 "aⅧ=3",
80 },
81 "Unicode digit": {
82 "a৩=3 echo 8",
83 "a৩=3",
84 },
85 "Unicode letter": {
86 "aḸ=3 echo 8",
87 "aḸ=3",
88 },
89 }
90
91 for name, tc := range tcs {
92 t.Run(name, func(t *testing.T) {
93 out, err := extractCommandName(tc.input)
94 assert.NoError(t, err)
95 assert.Equal(t, tc.expected, out)
96 })
97 }
98 }
99
View as plain text