mirror of
https://github.com/google/nomulus.git
synced 2025-06-27 14:54:51 +02:00
Move FlowRunner ICANN reporting logging to new FlowReporter
Since this reporting is getting more complicated (see b/36599833), it'll be better to have a dedicated class to encapsulate it, which also lets us keep the tests separate and focus FlowRunner more on its core purpose of actually running the flow. Note that this doesn't move the legacy log statement logging because that specifically must be logged from the FlowRunner.run() method to preserve the existing log signature matching in our ICANN activity reporting query. (The new statement is designed to be robust to moves like this since it doesn't use the logging callsite to match log lines, and it's not in use yet anyway.) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=153762008
This commit is contained in:
parent
89b3e9c55b
commit
12f267292a
4 changed files with 228 additions and 102 deletions
|
@ -14,11 +14,11 @@
|
|||
|
||||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.io.BaseEncoding.base64;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.base.Joiner;
|
||||
|
@ -29,11 +29,9 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.testing.TestLogHandler;
|
||||
import google.registry.flows.annotations.ReportingSpec;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.eppoutput.EppOutput.ResponseOrGreeting;
|
||||
import google.registry.model.eppoutput.EppResponse;
|
||||
import google.registry.model.reporting.IcannReportingTypes.ActivityReportField;
|
||||
import google.registry.monitoring.whitebox.EppMetric;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
|
@ -41,15 +39,14 @@ import google.registry.testing.FakeHttpSession;
|
|||
import google.registry.testing.Providers;
|
||||
import google.registry.testing.ShardableTestCase;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/** Unit tests for {@link FlowRunner}. */
|
||||
@RunWith(JUnit4.class)
|
||||
|
@ -71,17 +68,10 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@ReportingSpec(ActivityReportField.CONTACT_CHECK)
|
||||
static class TestReportingSpecCommandFlow implements Flow {
|
||||
@Override
|
||||
public ResponseOrGreeting run() throws EppException {
|
||||
return mock(EppResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
Logger.getLogger(FlowRunner.class.getCanonicalName()).addHandler(handler);
|
||||
Logger.getLogger(FlowReporter.class.getCanonicalName()).addHandler(handler);
|
||||
flowRunner.clientId = "TheRegistrar";
|
||||
flowRunner.credentials = new PasswordOnlyTransportCredentials();
|
||||
flowRunner.eppRequestSource = EppRequestSource.UNIT_TEST;
|
||||
|
@ -94,6 +84,7 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
flowRunner.sessionMetadata =
|
||||
new StatelessRequestSessionMetadata("TheRegistrar", ImmutableSet.<String>of());
|
||||
flowRunner.trid = Trid.create("client-123", "server-456");
|
||||
flowRunner.flowReporter = Mockito.mock(FlowReporter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -123,56 +114,9 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRun_reportingLogStatement_basic() throws Exception {
|
||||
public void testRun_callsFlowReporterOnce() throws Exception {
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(parseJsonMap(findLogMessageByPrefix(handler, "EPP-REPORTING-LOG-SIGNATURE: ")))
|
||||
.containsExactly(
|
||||
"trid", "server-456",
|
||||
"clientId", "TheRegistrar",
|
||||
"xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml/>\n",
|
||||
"xmlBytes", "PHhtbC8+", // Base64-encoding of "<xml/>".
|
||||
"icannActivityReportField", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun_reportingLogStatement_withReportingSpec() throws Exception {
|
||||
flowRunner.flowClass = TestReportingSpecCommandFlow.class;
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(parseJsonMap(findLogMessageByPrefix(handler, "EPP-REPORTING-LOG-SIGNATURE: ")))
|
||||
.containsExactly(
|
||||
"trid", "server-456",
|
||||
"clientId", "TheRegistrar",
|
||||
"xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml/>\n",
|
||||
"xmlBytes", "PHhtbC8+", // Base64-encoding of "<xml/>".
|
||||
"icannActivityReportField", "srs-cont-check");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun_reportingLogStatement_noClientId() throws Exception {
|
||||
flowRunner.clientId = "";
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(parseJsonMap(findLogMessageByPrefix(handler, "EPP-REPORTING-LOG-SIGNATURE: ")))
|
||||
.containsExactly(
|
||||
"trid", "server-456",
|
||||
"clientId", "",
|
||||
"xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml/>\n",
|
||||
"xmlBytes", "PHhtbC8+", // Base64-encoding of "<xml/>".
|
||||
"icannActivityReportField", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun_reportingLogStatement_complexEppInput() throws Exception {
|
||||
String domainCreateXml = loadFileWithSubstitutions(
|
||||
getClass(), "domain_create_prettyprinted.xml", ImmutableMap.<String, String>of());
|
||||
flowRunner.inputXmlBytes = domainCreateXml.getBytes(UTF_8);
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(parseJsonMap(findLogMessageByPrefix(handler, "EPP-REPORTING-LOG-SIGNATURE: ")))
|
||||
.containsExactly(
|
||||
"trid", "server-456",
|
||||
"clientId", "TheRegistrar",
|
||||
"xml", domainCreateXml,
|
||||
"xmlBytes", base64().encode(domainCreateXml.getBytes(UTF_8)),
|
||||
"icannActivityReportField", "");
|
||||
verify(flowRunner.flowReporter).recordToLogs();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -242,11 +186,6 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
assertThat(xml).isEqualTo(domainCreateXml);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Object> parseJsonMap(String json) throws Exception {
|
||||
return (Map<String, Object>) JSONValue.parseWithException(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the first log message stored in the handler that has the provided prefix, and return
|
||||
* that message with the prefix stripped off.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue