@@ -88,11 +88,9 @@ func TestGetBlockAndAllowLists(t *testing.T) {
88
88
t .Setenv ("LIMA_SHELLENV_BLOCK" , "" )
89
89
t .Setenv ("LIMA_SHELLENV_ALLOW" , "" )
90
90
91
- blockList , isBlockListSet := getBlockList ()
92
- allowList , isAllowListSet := getAllowList ()
91
+ blockList := getBlockList ()
92
+ allowList := getAllowList ()
93
93
94
- assert .Assert (t , ! isBlockListSet )
95
- assert .Assert (t , ! isAllowListSet )
96
94
assert .Assert (t , isUsingDefaultBlockList ())
97
95
assert .DeepEqual (t , blockList , defaultBlockList )
98
96
assert .Equal (t , len (allowList ), 0 )
@@ -101,8 +99,7 @@ func TestGetBlockAndAllowLists(t *testing.T) {
101
99
t .Run ("custom blocklist" , func (t * testing.T ) {
102
100
t .Setenv ("LIMA_SHELLENV_BLOCK" , "PATH,HOME" )
103
101
104
- blockList , isSet := getBlockList ()
105
- assert .Assert (t , isSet )
102
+ blockList := getBlockList ()
106
103
assert .Assert (t , ! isUsingDefaultBlockList ())
107
104
expected := []string {"PATH" , "HOME" }
108
105
assert .DeepEqual (t , blockList , expected )
@@ -111,8 +108,7 @@ func TestGetBlockAndAllowLists(t *testing.T) {
111
108
t .Run ("additive blocklist" , func (t * testing.T ) {
112
109
t .Setenv ("LIMA_SHELLENV_BLOCK" , "+CUSTOM_VAR" )
113
110
114
- blockList , isSet := getBlockList ()
115
- assert .Assert (t , isSet )
111
+ blockList := getBlockList ()
116
112
assert .Assert (t , isUsingDefaultBlockList ())
117
113
expected := slices .Concat (GetDefaultBlockList (), []string {"CUSTOM_VAR" })
118
114
assert .DeepEqual (t , blockList , expected )
@@ -121,8 +117,7 @@ func TestGetBlockAndAllowLists(t *testing.T) {
121
117
t .Run ("allowlist" , func (t * testing.T ) {
122
118
t .Setenv ("LIMA_SHELLENV_ALLOW" , "FOO,BAR" )
123
119
124
- allowList , isSet := getAllowList ()
125
- assert .Assert (t , isSet )
120
+ allowList := getAllowList ()
126
121
expected := []string {"FOO" , "BAR" }
127
122
assert .DeepEqual (t , allowList , expected )
128
123
})
@@ -213,3 +208,53 @@ func TestGetDefaultBlockList(t *testing.T) {
213
208
assert .Assert (t , found , "Expected builtin blocklist to contain %q" , item )
214
209
}
215
210
}
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