(t *testing.T)
| 317 | } |
| 318 | |
| 319 | func TestValidateNetworking(t *testing.T) { |
| 320 | // Test setup. |
| 321 | emptyConf := make(map[string]conf.Severity) |
| 322 | standardConf := map[string]conf.Severity{ |
| 323 | "hostPortSet": conf.SeverityWarning, |
| 324 | } |
| 325 | strongConf := map[string]conf.Severity{ |
| 326 | "hostPortSet": conf.SeverityDanger, |
| 327 | } |
| 328 | |
| 329 | emptyContainer := &corev1.Container{Name: ""} |
| 330 | badContainer := &corev1.Container{ |
| 331 | Ports: []corev1.ContainerPort{{ |
| 332 | ContainerPort: 3000, |
| 333 | HostPort: 443, |
| 334 | }}, |
| 335 | } |
| 336 | goodContainer := &corev1.Container{ |
| 337 | Ports: []corev1.ContainerPort{{ |
| 338 | ContainerPort: 3000, |
| 339 | }}, |
| 340 | } |
| 341 | |
| 342 | var testCases = []struct { |
| 343 | name string |
| 344 | networkConf map[string]conf.Severity |
| 345 | container *corev1.Container |
| 346 | expectedResults []ResultMessage |
| 347 | }{ |
| 348 | { |
| 349 | name: "empty ports + empty validation config", |
| 350 | networkConf: emptyConf, |
| 351 | container: emptyContainer, |
| 352 | expectedResults: []ResultMessage{}, |
| 353 | }, |
| 354 | { |
| 355 | name: "empty ports + standard validation config", |
| 356 | networkConf: standardConf, |
| 357 | container: emptyContainer, |
| 358 | expectedResults: []ResultMessage{{ |
| 359 | ID: "hostPortSet", |
| 360 | Message: "Host port is not configured", |
| 361 | Success: true, |
| 362 | Severity: "warning", |
| 363 | Category: "Security", |
| 364 | }}, |
| 365 | }, |
| 366 | { |
| 367 | name: "empty ports + strong validation config", |
| 368 | networkConf: standardConf, |
| 369 | container: emptyContainer, |
| 370 | expectedResults: []ResultMessage{{ |
| 371 | ID: "hostPortSet", |
| 372 | Message: "Host port is not configured", |
| 373 | Success: true, |
| 374 | Severity: "warning", |
| 375 | Category: "Security", |
| 376 | }}, |
nothing calls this directly
no test coverage detected