@@ -88,11 +88,9 @@ func TestGetBlockAndAllowLists(t *testing.T) {
8888 t .Setenv ("LIMA_SHELLENV_BLOCK" , "" )
8989 t .Setenv ("LIMA_SHELLENV_ALLOW" , "" )
9090
91- blockList , isBlockListSet := getBlockList ()
92- allowList , isAllowListSet := getAllowList ()
91+ blockList := getBlockList ()
92+ allowList := getAllowList ()
9393
94- assert .Assert (t , ! isBlockListSet )
95- assert .Assert (t , ! isAllowListSet )
9694 assert .Assert (t , isUsingDefaultBlockList ())
9795 assert .DeepEqual (t , blockList , defaultBlockList )
9896 assert .Equal (t , len (allowList ), 0 )
@@ -101,8 +99,7 @@ func TestGetBlockAndAllowLists(t *testing.T) {
10199 t .Run ("custom blocklist" , func (t * testing.T ) {
102100 t .Setenv ("LIMA_SHELLENV_BLOCK" , "PATH,HOME" )
103101
104- blockList , isSet := getBlockList ()
105- assert .Assert (t , isSet )
102+ blockList := getBlockList ()
106103 assert .Assert (t , ! isUsingDefaultBlockList ())
107104 expected := []string {"PATH" , "HOME" }
108105 assert .DeepEqual (t , blockList , expected )
@@ -111,8 +108,7 @@ func TestGetBlockAndAllowLists(t *testing.T) {
111108 t .Run ("additive blocklist" , func (t * testing.T ) {
112109 t .Setenv ("LIMA_SHELLENV_BLOCK" , "+CUSTOM_VAR" )
113110
114- blockList , isSet := getBlockList ()
115- assert .Assert (t , isSet )
111+ blockList := getBlockList ()
116112 assert .Assert (t , isUsingDefaultBlockList ())
117113 expected := slices .Concat (GetDefaultBlockList (), []string {"CUSTOM_VAR" })
118114 assert .DeepEqual (t , blockList , expected )
@@ -121,8 +117,7 @@ func TestGetBlockAndAllowLists(t *testing.T) {
121117 t .Run ("allowlist" , func (t * testing.T ) {
122118 t .Setenv ("LIMA_SHELLENV_ALLOW" , "FOO,BAR" )
123119
124- allowList , isSet := getAllowList ()
125- assert .Assert (t , isSet )
120+ allowList := getAllowList ()
126121 expected := []string {"FOO" , "BAR" }
127122 assert .DeepEqual (t , allowList , expected )
128123 })
@@ -213,3 +208,53 @@ func TestGetDefaultBlockList(t *testing.T) {
213208 assert .Assert (t , found , "Expected builtin blocklist to contain %q" , item )
214209 }
215210}
211+
212+ func TestValidatePattern (t * testing.T ) {
213+ tests := []struct {
214+ name string
215+ pattern string
216+ valid bool
217+ }{
218+ {"simple alphanumeric" , "FOO" , true },
219+ {"with underscore" , "FOO_BAR" , true },
220+ {"with numbers" , "VAR123" , true },
221+ {"with trailing asterisk" , "FOO*" , true },
222+ {"with multiple asterisks" , "FOO*BAR*" , true },
223+ {"asterisk at beginning" , "*FOO" , true },
224+ {"asterisk in middle" , "FOO*BAR" , true },
225+ {"only asterisk" , "*" , true },
226+ {"with dash" , "FOO-BAR" , false },
227+ {"with dot" , "FOO.BAR" , false },
228+ {"with space" , "FOO BAR" , false },
229+ {"with slash" , "FOO/BAR" , false },
230+ {"with at symbol" , "FOO@BAR" , false },
231+ {"with dollar" , "$FOO" , false },
232+ {"with percent" , "FOO%" , false },
233+ {"with hash" , "#FOO" , false },
234+ {"with exclamation" , "FOO!" , false },
235+ {"with colon" , "FOO:BAR" , false },
236+ {"with semicolon" , "FOO;BAR" , false },
237+ {"with parentheses" , "FOO(BAR)" , false },
238+ {"with brackets" , "FOO[BAR]" , false },
239+ {"with braces" , "FOO{BAR}" , false },
240+ {"with plus" , "FOO+BAR" , false },
241+ {"with equals" , "FOO=BAR" , false },
242+ {"with pipe" , "FOO|BAR" , false },
243+ {"with backslash" , "FOO/BAR" , false },
244+ {"with question mark" , "FOO?" , false },
245+ {"with less than" , "FOO<BAR" , false },
246+ {"with greater than" , "FOO>BAR" , false },
247+ {"with comma" , "FOO,BAR" , false },
248+ }
249+
250+ for _ , tt := range tests {
251+ t .Run (tt .name , func (t * testing.T ) {
252+ err := validatePattern (tt .pattern )
253+ if tt .valid {
254+ assert .NilError (t , err , "Expected pattern %q to be valid" , tt .pattern )
255+ } else {
256+ assert .Error (t , err , "pattern \" " + tt .pattern + "\" contains invalid characters. Only alphanumeric characters, underscores, and asterisk are allowed" )
257+ }
258+ })
259+ }
260+ }
0 commit comments