mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Enforce no logging in production environment
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=199156367
This commit is contained in:
parent
1295882307
commit
61f6e666b1
2 changed files with 23 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
package google.registry.proxy;
|
package google.registry.proxy;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Suppliers.memoizeWithExpiration;
|
import static com.google.common.base.Suppliers.memoizeWithExpiration;
|
||||||
import static google.registry.proxy.ProxyConfig.getProxyConfig;
|
import static google.registry.proxy.ProxyConfig.getProxyConfig;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
@ -79,7 +80,11 @@ public class ProxyModule {
|
||||||
@Parameter(names = "--env", description = "Environment to run the proxy in")
|
@Parameter(names = "--env", description = "Environment to run the proxy in")
|
||||||
private Environment env = Environment.LOCAL;
|
private Environment env = Environment.LOCAL;
|
||||||
|
|
||||||
@Parameter(names = "--log", description = "Whether to log activities for debugging")
|
@Parameter(
|
||||||
|
names = "--log",
|
||||||
|
description =
|
||||||
|
"Whether to log activities for debugging. "
|
||||||
|
+ "This cannot be enabled for production as logs contain PII.")
|
||||||
boolean log;
|
boolean log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,6 +139,9 @@ public class ProxyModule {
|
||||||
jCommander.usage();
|
jCommander.usage();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
checkArgument(
|
||||||
|
!log || env != Environment.PRODUCTION,
|
||||||
|
"Logging cannot be enabled for production environment");
|
||||||
configureLogging();
|
configureLogging();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,20 @@ public class ProxyModuleTest {
|
||||||
assertThat(proxyModule.log).isFalse();
|
assertThat(proxyModule.log).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_parseArgs_loggingInProduction() {
|
||||||
|
String[] args = {"--env", "production", "--log"};
|
||||||
|
IllegalArgumentException e =
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> {
|
||||||
|
proxyModule.parse(args);
|
||||||
|
});
|
||||||
|
assertThat(e)
|
||||||
|
.hasMessageThat()
|
||||||
|
.isEqualTo("Logging cannot be enabled for production environment");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_parseArgs_wrongArguments() {
|
public void testFailure_parseArgs_wrongArguments() {
|
||||||
String[] args = {"--wrong_flag", "some_value"};
|
String[] args = {"--wrong_flag", "some_value"};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue