Sanitized error messages.

This commit is contained in:
Erik C. Thauvin 2020-02-10 23:01:50 -08:00
parent 5a39d3ee23
commit fffc51ca15
3 changed files with 17 additions and 21 deletions

View file

@ -80,7 +80,7 @@ public class GoogleSearchTest extends LocalProperties {
} catch (ModuleException e) { } catch (ModuleException e) {
// Avoid displaying api keys in CI logs. // Avoid displaying api keys in CI logs.
if ("true".equals(System.getenv("CI"))) { if ("true".equals(System.getenv("CI"))) {
throw new ModuleException(e.getDebugMessage(), e.getSanitizedMessage()); throw new ModuleException(e.getDebugMessage(), e.getSanitizedMessage(apiKey, cseKey));
} else { } else {
throw e; throw e;
} }

View file

@ -53,14 +53,13 @@ public class ModuleExceptionTest {
@DataProvider(name = "dp") @DataProvider(name = "dp")
Object[][] createData(final Method m) { Object[][] createData(final Method m) {
return new Object[][]{new Object[]{new ModuleException(debugMessage, message, return new Object[][]{new Object[]{new ModuleException(debugMessage,
new IOException("Secret URL http://foo.com?apiKey=sec&userID=me"))}, message,
new Object[]{new ModuleException(debugMessage, message,
new IOException("URL http://foobar.com"))}, new IOException("URL http://foobar.com"))},
new Object[]{new ModuleException(debugMessage, message, new Object[]{new ModuleException(debugMessage,
message,
new IOException("URL http://foobar.com?"))}, new IOException("URL http://foobar.com?"))},
new Object[]{new ModuleException(debugMessage, message)} new Object[]{new ModuleException(debugMessage, message)}};
};
} }
@Test(dataProvider = "dp") @Test(dataProvider = "dp")
@ -73,16 +72,13 @@ public class ModuleExceptionTest {
assertThat(e.getMessage()).as("get message").isEqualTo(message); assertThat(e.getMessage()).as("get message").isEqualTo(message);
} }
@Test(dataProvider = "dp") @Test
final void testGetSanitizedMessage(final ModuleException e) { final void testGetSanitizedMessage() {
if (e.hasCause()) { final String apiKey = "1234567890";
if (e.getSanitizedMessage().contains("Secret")) { final ModuleException e = new ModuleException(debugMessage,
assertThat(e.getSanitizedMessage()).as("get sanitized url") message,
.contains("http://foo.com?apiKey=[3]&userID=[2]"); new IOException(
} else { "URL http://foo.com?apiKey=" + apiKey + "&userID=me"));
assertThat(e.getSanitizedMessage()).as("get sanitized url") assertThat(e.getSanitizedMessage(apiKey)).as("sanitized url").contains("xxxxxxxxxx").doesNotContain(apiKey);
.contains("http://foobar.com");
}
}
} }
} }

View file

@ -75,7 +75,7 @@ public class StockQuoteTest extends LocalProperties {
} catch (ModuleException e) { } catch (ModuleException e) {
// Avoid displaying api keys in CI logs. // Avoid displaying api keys in CI logs.
if ("true".equals(System.getenv("CI"))) { if ("true".equals(System.getenv("CI"))) {
throw new ModuleException(e.getDebugMessage(), e.getSanitizedMessage()); throw new ModuleException(e.getDebugMessage(), e.getSanitizedMessage(apiKey));
} else { } else {
throw e; throw e;
} }