TestValidateStrictNetwork tests the validateStrictNetwork function
(t *testing.T)
| 206 | |
| 207 | // TestValidateStrictNetwork tests the validateStrictNetwork function |
| 208 | func TestValidateStrictNetwork(t *testing.T) { |
| 209 | tests := []struct { |
| 210 | name string |
| 211 | networkPermissions *NetworkPermissions |
| 212 | expectError bool |
| 213 | errorMsg string |
| 214 | }{ |
| 215 | { |
| 216 | name: "nil network permissions triggers internal error", |
| 217 | networkPermissions: nil, |
| 218 | expectError: true, |
| 219 | errorMsg: "internal error: network permissions not initialized", |
| 220 | }, |
| 221 | { |
| 222 | name: "defaults mode is allowed", |
| 223 | networkPermissions: &NetworkPermissions{ |
| 224 | Allowed: []string{"defaults"}, |
| 225 | }, |
| 226 | expectError: false, |
| 227 | }, |
| 228 | { |
| 229 | name: "specific allowed domains are allowed", |
| 230 | networkPermissions: &NetworkPermissions{ |
| 231 | Allowed: []string{"api.example.com", "github.com"}, |
| 232 | }, |
| 233 | expectError: false, |
| 234 | }, |
| 235 | { |
| 236 | name: "wildcard in allowed domains is refused", |
| 237 | networkPermissions: &NetworkPermissions{ |
| 238 | Allowed: []string{"*"}, |
| 239 | }, |
| 240 | expectError: true, |
| 241 | errorMsg: "strict mode: wildcard '*' is not allowed in network.allowed domains to prevent unrestricted internet access", |
| 242 | }, |
| 243 | { |
| 244 | name: "wildcard among other domains is refused", |
| 245 | networkPermissions: &NetworkPermissions{ |
| 246 | Allowed: []string{"api.example.com", "*", "github.com"}, |
| 247 | }, |
| 248 | expectError: true, |
| 249 | errorMsg: "strict mode: wildcard '*' is not allowed in network.allowed domains to prevent unrestricted internet access", |
| 250 | }, |
| 251 | { |
| 252 | name: "empty allowed list is allowed", |
| 253 | networkPermissions: &NetworkPermissions{ |
| 254 | Allowed: []string{}, |
| 255 | }, |
| 256 | expectError: false, |
| 257 | }, |
| 258 | { |
| 259 | name: "domain patterns with wildcards are allowed (not exact *)", |
| 260 | networkPermissions: &NetworkPermissions{ |
| 261 | Allowed: []string{"*.example.com", "api.*.com"}, |
| 262 | }, |
| 263 | expectError: false, |
| 264 | }, |
| 265 | { |
nothing calls this directly
no test coverage detected