(t *testing.T)
| 1444 | } |
| 1445 | |
| 1446 | func TestRedactSecrets(t *testing.T) { |
| 1447 | ansi.DisableColors(true) |
| 1448 | |
| 1449 | t.Run("redactSecrets with valid base64 data", func(t *testing.T) { |
| 1450 | old := &manifest.MappingResult{ |
| 1451 | Name: "default, foo, Secret (v1)", |
| 1452 | Kind: "Secret", |
| 1453 | Content: ` |
| 1454 | apiVersion: v1 |
| 1455 | kind: Secret |
| 1456 | metadata: |
| 1457 | name: foo |
| 1458 | type: Opaque |
| 1459 | data: |
| 1460 | key1: dmFsdWUx |
| 1461 | key2: dmFsdWUy |
| 1462 | `, |
| 1463 | } |
| 1464 | new := &manifest.MappingResult{ |
| 1465 | Name: "default, foo, Secret (v1)", |
| 1466 | Kind: "Secret", |
| 1467 | Content: ` |
| 1468 | apiVersion: v1 |
| 1469 | kind: Secret |
| 1470 | metadata: |
| 1471 | name: foo |
| 1472 | type: Opaque |
| 1473 | data: |
| 1474 | key1: bmV3dmFsdWUx |
| 1475 | key2: dmFsdWUy |
| 1476 | `, |
| 1477 | } |
| 1478 | redactSecrets(old, new) |
| 1479 | require.Contains(t, old.Content, "key1: '-------- # (6 bytes)'") |
| 1480 | require.Contains(t, old.Content, "key2: 'REDACTED # (6 bytes)'") |
| 1481 | require.Contains(t, new.Content, "key1: '++++++++ # (9 bytes)'") |
| 1482 | require.Contains(t, new.Content, "key2: 'REDACTED # (6 bytes)'") |
| 1483 | }) |
| 1484 | |
| 1485 | t.Run("redactSecrets with stringData", func(t *testing.T) { |
| 1486 | old := &manifest.MappingResult{ |
| 1487 | Name: "default, foo, Secret (v1)", |
| 1488 | Kind: "Secret", |
| 1489 | Content: ` |
| 1490 | apiVersion: v1 |
| 1491 | kind: Secret |
| 1492 | metadata: |
| 1493 | name: foo |
| 1494 | type: Opaque |
| 1495 | stringData: |
| 1496 | key1: value1 |
| 1497 | key2: value2 |
| 1498 | `, |
| 1499 | } |
| 1500 | new := &manifest.MappingResult{ |
| 1501 | Name: "default, foo, Secret (v1)", |
| 1502 | Kind: "Secret", |
| 1503 | Content: ` |
nothing calls this directly
no test coverage detected