|
17 | 17 | package com.example.dlp;
|
18 | 18 |
|
19 | 19 | import static junit.framework.TestCase.assertFalse;
|
| 20 | +import static org.hamcrest.CoreMatchers.containsString; |
| 21 | +import static org.hamcrest.CoreMatchers.not; |
20 | 22 | import static org.junit.Assert.assertNotNull;
|
| 23 | +import static org.junit.Assert.assertThat; |
21 | 24 | import static org.junit.Assert.assertTrue;
|
22 | 25 |
|
23 | 26 | import java.io.ByteArrayOutputStream;
|
@@ -47,36 +50,27 @@ public void setUp() {
|
47 | 50 | }
|
48 | 51 |
|
49 | 52 | @Test
|
50 |
| - public void testInfoTypesInStringAreReplaced() throws Exception { |
51 |
| - String text = |
52 |
| - "\"My phone number is (234) 456-7890 and my email address is [email protected]\""; |
53 |
| - Redact.main(new String[] {"-s", text, "-r", "_REDACTED_"}); |
54 |
| - String output = bout.toString(); |
55 |
| - assertTrue(output.contains("My phone number is _REDACTED_ and my email address is _REDACTED_")); |
56 |
| - } |
57 |
| - |
58 |
| - @Ignore // TODO: b/69461298 |
59 |
| - @Test |
60 |
| - public void testInfoTypesInImageAreReplaced() throws Exception { |
61 |
| - ClassLoader classLoader = getClass().getClassLoader(); |
62 |
| - // confirm that current data contains info types |
63 |
| - File file = new File(classLoader.getResource("test.png").getFile()); |
64 |
| - Inspect.main(new String[] {"-f", file.getAbsolutePath()}); |
65 |
| - String output = bout.toString(); |
66 |
| - assertTrue(output.contains("PHONE_NUMBER")); |
67 |
| - assertTrue(output.contains("EMAIL_ADDRESS")); |
68 |
| - bout.reset(); |
69 |
| - |
70 |
| - String outputFilePath = "output.png"; |
| 53 | + public void testRedactImage() throws Exception { |
| 54 | + // InspectIT Tests verify original has PII present |
| 55 | + String outputFilePath = "src/test/resources/output.png"; |
71 | 56 |
|
| 57 | + // Restrict phone number, but not email |
72 | 58 | Redact.main(
|
73 | 59 | new String[] {
|
74 |
| - "-f", file.getAbsolutePath(), "-infoTypes", "PHONE_NUMBER", "-o", outputFilePath |
| 60 | + "-f", "src/test/resources/test.png", |
| 61 | + "-infoTypes", "PHONE_NUMBER", |
| 62 | + "-o", outputFilePath |
75 | 63 | });
|
76 |
| - Inspect.main(new String[] {"-f", outputFilePath}); |
77 |
| - output = bout.toString(); |
78 |
| - assertFalse(output.contains("PHONE_NUMBER")); |
79 |
| - assertTrue(output.contains("EMAIL_ADDRESS")); |
| 64 | + bout.reset(); |
| 65 | + |
| 66 | + // Verify that phone_number is missing but email is present |
| 67 | + Inspect.main(new String[] { |
| 68 | + "-f", outputFilePath, |
| 69 | + "-infoTypes", "PHONE_NUMBER", "EMAIL_ADDRESS" |
| 70 | + }); |
| 71 | + String output = bout.toString(); |
| 72 | + assertThat(output, not(containsString("PHONE_NUMBER"))); |
| 73 | + assertThat(output, containsString("EMAIL_ADDRESS")); |
80 | 74 | }
|
81 | 75 |
|
82 | 76 | @After
|
|
0 commit comments