mirror of
https://github.com/google/nomulus.git
synced 2025-07-23 03:06:01 +02:00
Dagger, meet Flows. Flows, meet Dagger.
Daggerizes all of the EPP flows. This does not change anything yet about the flows themselves, just how they are invoked, but after this CL it's safe to @Inject things into flow classes. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125382478
This commit is contained in:
parent
116bf1f4d6
commit
c9a16f7f11
69 changed files with 973 additions and 292 deletions
|
@ -31,6 +31,7 @@ java_library(
|
|||
"//java/com/google/common/net",
|
||||
"//third_party/java/appengine:appengine-api-testonly",
|
||||
"//third_party/java/appengine:appengine-testing",
|
||||
"//third_party/java/dagger",
|
||||
"//third_party/java/joda_money",
|
||||
"//third_party/java/joda_time",
|
||||
"//third_party/java/json_simple",
|
||||
|
|
|
@ -19,17 +19,16 @@ import static google.registry.testing.DatastoreHelper.createTld;
|
|||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatastoreHelper.persistReservedList;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.flows.EppTestComponent.FakesAndMocksModule;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.monitoring.whitebox.EppMetrics;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.util.SystemClock;
|
||||
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Before;
|
||||
|
@ -66,9 +65,11 @@ public class CheckApiActionTest {
|
|||
action.domain = domain;
|
||||
action.response = new FakeResponse();
|
||||
action.config = RegistryEnvironment.UNITTEST.config();
|
||||
action.eppController = new EppController();
|
||||
action.eppController.clock = new SystemClock();
|
||||
action.eppController.metrics = mock(EppMetrics.class);
|
||||
action.eppController = DaggerEppTestComponent.builder()
|
||||
.fakesAndMocksModule(new FakesAndMocksModule(new FakeClock()))
|
||||
.build()
|
||||
.startRequest()
|
||||
.eppController();
|
||||
action.run();
|
||||
return (Map<String, Object>) JSONValue.parse(((FakeResponse) action.response).getPayload());
|
||||
}
|
||||
|
|
171
javatests/google/registry/flows/EppCommitLogsTest.java
Normal file
171
javatests/google/registry/flows/EppCommitLogsTest.java
Normal file
|
@ -0,0 +1,171 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.EppResourceUtils.loadAtPointInTime;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.joda.time.Duration.standardDays;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
|
||||
import google.registry.flows.EppTestComponent.FakesAndMocksModule;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.EppLoader;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeHttpSession;
|
||||
import google.registry.testing.InjectRule;
|
||||
import google.registry.testing.ShardableTestCase;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Test that domain flows create the commit logs needed to reload at points in the past. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class EppCommitLogsTest extends ShardableTestCase {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withTaskQueue()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExceptionRule thrown = new ExceptionRule();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.now(UTC));
|
||||
private EppLoader eppLoader;
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
createTld("tld");
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
}
|
||||
|
||||
private void runFlow() throws Exception {
|
||||
SessionMetadata sessionMetadata = new HttpSessionMetadata(new FakeHttpSession());
|
||||
sessionMetadata.setClientId("TheRegistrar");
|
||||
DaggerEppTestComponent.builder()
|
||||
.fakesAndMocksModule(new FakesAndMocksModule(clock))
|
||||
.build()
|
||||
.startRequest()
|
||||
.flowComponentBuilder()
|
||||
.flowModule(new FlowModule.Builder()
|
||||
.setSessionMetadata(sessionMetadata)
|
||||
.setCredentials(new PasswordOnlyTransportCredentials())
|
||||
.setEppRequestSource(EppRequestSource.UNIT_TEST)
|
||||
.setIsDryRun(false)
|
||||
.setIsSuperuser(false)
|
||||
.setInputXmlBytes(eppLoader.getEppXml().getBytes(UTF_8))
|
||||
.setEppInput(eppLoader.getEpp())
|
||||
.build())
|
||||
.build()
|
||||
.flowRunner()
|
||||
.run();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAtPointInTime() throws Exception {
|
||||
clock.setTo(DateTime.parse("1984-12-18T12:30Z")); // not midnight
|
||||
|
||||
persistActiveHost("ns1.example.net");
|
||||
persistActiveHost("ns2.example.net");
|
||||
persistActiveContact("jd1234");
|
||||
persistActiveContact("sh8013");
|
||||
|
||||
clock.advanceBy(standardDays(1));
|
||||
DateTime timeAtCreate = clock.nowUtc();
|
||||
clock.setTo(timeAtCreate);
|
||||
eppLoader = new EppLoader(this, "domain_create.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
Key<DomainResource> key = Key.create(ofy().load().type(DomainResource.class).first().now());
|
||||
DomainResource domainAfterCreate = ofy().load().key(key).now();
|
||||
assertThat(domainAfterCreate.getFullyQualifiedDomainName()).isEqualTo("example.tld");
|
||||
|
||||
clock.advanceBy(standardDays(2));
|
||||
DateTime timeAtFirstUpdate = clock.nowUtc();
|
||||
eppLoader = new EppLoader(this, "domain_update_dsdata_add.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
|
||||
DomainResource domainAfterFirstUpdate = ofy().load().key(key).now();
|
||||
assertThat(domainAfterCreate).isNotEqualTo(domainAfterFirstUpdate);
|
||||
|
||||
clock.advanceOneMilli(); // same day as first update
|
||||
DateTime timeAtSecondUpdate = clock.nowUtc();
|
||||
eppLoader = new EppLoader(this, "domain_update_dsdata_rem.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
DomainResource domainAfterSecondUpdate = ofy().load().key(key).now();
|
||||
|
||||
clock.advanceBy(standardDays(2));
|
||||
DateTime timeAtDelete = clock.nowUtc(); // before 'add' grace period ends
|
||||
eppLoader = new EppLoader(this, "domain_delete.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
|
||||
assertThat(domainAfterFirstUpdate).isNotEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
// Point-in-time can only rewind an object from the current version, not roll forward.
|
||||
DomainResource latest = ofy().load().key(key).now();
|
||||
|
||||
// Creation time has millisecond granularity due to isActive() check.
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.minusMillis(1)).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.plusMillis(1)).now()).isNotNull();
|
||||
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.plusDays(1)).now())
|
||||
.isEqualTo(domainAfterCreate);
|
||||
|
||||
// Both updates happened on the same day. Since the revisions field has day granularity, the
|
||||
// reference to the first update should have been overwritten by the second, and its timestamp
|
||||
// rolled forward. So we have to fall back to the last revision before midnight.
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtFirstUpdate).now())
|
||||
.isEqualTo(domainAfterCreate);
|
||||
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtSecondUpdate).now())
|
||||
.isEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtSecondUpdate.plusDays(1)).now())
|
||||
.isEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
// Deletion time has millisecond granularity due to isActive() check.
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.minusMillis(1)).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.plusMillis(1)).now()).isNull();
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
package google.registry.flows;
|
||||
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.createTlds;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -44,7 +45,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
|
||||
@Before
|
||||
public void initTld() {
|
||||
createTld("example");
|
||||
createTlds("example", "tld");
|
||||
}
|
||||
|
||||
/** Create the two administrative contacts and two hosts. */
|
||||
|
@ -129,7 +130,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
"domain_create_response.xml",
|
||||
DateTime.parse("2000-06-01T00:02:00Z"));
|
||||
|
||||
// Delete domain example.com after its add grace period has expired.
|
||||
// Delete domain example.tld after its add grace period has expired.
|
||||
assertCommandAndResponse(
|
||||
"domain_delete.xml",
|
||||
"generic_success_action_pending_response.xml",
|
||||
|
@ -338,7 +339,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
DateTime.parse("2001-01-01T00:01:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "1-A-EXAMPLE-16-20"),
|
||||
ImmutableMap.of("ID", "1-B-EXAMPLE-17-21"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2001-01-01T00:01:00Z"));
|
||||
|
@ -350,7 +351,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
DateTime.parse("2001-01-06T00:01:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "1-A-EXAMPLE-16-22"),
|
||||
ImmutableMap.of("ID", "1-B-EXAMPLE-17-23"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2001-01-06T00:01:00Z"));
|
||||
|
@ -366,7 +367,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
|
|||
DateTime.parse("2001-01-06T00:02:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "1-A-EXAMPLE-16-21"),
|
||||
ImmutableMap.of("ID", "1-B-EXAMPLE-17-22"),
|
||||
"poll_ack_response_empty.xml",
|
||||
null,
|
||||
DateTime.parse("2001-01-06T00:02:00Z"));
|
||||
|
|
|
@ -21,12 +21,11 @@ import static google.registry.xml.XmlTestUtils.assertXmlEqualsWithMessage;
|
|||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.google.common.net.MediaType;
|
||||
|
||||
import google.registry.flows.EppTestComponent.FakesAndMocksModule;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.monitoring.whitebox.EppMetrics;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeHttpSession;
|
||||
import google.registry.testing.FakeResponse;
|
||||
|
@ -100,8 +99,7 @@ public class EppTestCase extends ShardableTestCase {
|
|||
// When a session is invalidated, reset the sessionMetadata field.
|
||||
super.invalidate();
|
||||
EppTestCase.this.sessionMetadata = null;
|
||||
}
|
||||
};
|
||||
}};
|
||||
}
|
||||
String actualOutput = executeXmlCommand(input);
|
||||
assertXmlEqualsWithMessage(
|
||||
|
@ -118,14 +116,16 @@ public class EppTestCase extends ShardableTestCase {
|
|||
EppRequestHandler handler = new EppRequestHandler();
|
||||
FakeResponse response = new FakeResponse();
|
||||
handler.response = response;
|
||||
handler.eppController = new EppController();
|
||||
handler.eppController.clock = clock;
|
||||
handler.eppController.metrics = mock(EppMetrics.class);
|
||||
handler.eppController = DaggerEppTestComponent.builder()
|
||||
.fakesAndMocksModule(new FakesAndMocksModule(clock))
|
||||
.build()
|
||||
.startRequest()
|
||||
.eppController();
|
||||
handler.executeEpp(
|
||||
sessionMetadata,
|
||||
credentials,
|
||||
EppRequestSource.UNIT_TEST,
|
||||
false,
|
||||
false, // Not dryRun.
|
||||
isSuperuser,
|
||||
inputXml.getBytes(UTF_8));
|
||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||
|
|
70
javatests/google/registry/flows/EppTestComponent.java
Normal file
70
javatests/google/registry/flows/EppTestComponent.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.flows;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.Subcomponent;
|
||||
|
||||
import google.registry.monitoring.whitebox.EppMetrics;
|
||||
import google.registry.request.RequestScope;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.util.Clock;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/** Dagger component for running EPP tests. */
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
EppTestComponent.FakesAndMocksModule.class
|
||||
})
|
||||
interface EppTestComponent {
|
||||
|
||||
RequestComponent startRequest();
|
||||
|
||||
/** Module for injecting fakes and mocks. */
|
||||
@Module
|
||||
static class FakesAndMocksModule {
|
||||
final FakeClock clock;
|
||||
final EppMetrics metrics;
|
||||
|
||||
FakesAndMocksModule(FakeClock clock) {
|
||||
this.clock = clock;
|
||||
this.metrics = mock(EppMetrics.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
Clock provideClock() {
|
||||
return clock;
|
||||
}
|
||||
|
||||
@Provides
|
||||
EppMetrics provideMetrics() {
|
||||
return metrics;
|
||||
}
|
||||
}
|
||||
|
||||
/** Subcomponent for request scoped injections. */
|
||||
@RequestScope
|
||||
@Subcomponent
|
||||
interface RequestComponent {
|
||||
EppController eppController();
|
||||
FlowComponent.Builder flowComponentBuilder();
|
||||
}
|
||||
}
|
|
@ -34,13 +34,12 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import google.registry.flows.EppTestComponent.FakesAndMocksModule;
|
||||
import google.registry.flows.picker.FlowPicker;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.domain.GracePeriod;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
import google.registry.model.eppcommon.ProtocolDefinition;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.eppinput.EppInput;
|
||||
import google.registry.model.eppoutput.EppOutput;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
|
@ -86,8 +85,6 @@ public abstract class FlowTestCase<F extends Flow> {
|
|||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private Class<? extends Flow> flowClass;
|
||||
|
||||
protected EppLoader eppLoader;
|
||||
protected SessionMetadata sessionMetadata;
|
||||
protected FakeClock clock = new FakeClock(DateTime.now(UTC));
|
||||
|
@ -120,29 +117,8 @@ public abstract class FlowTestCase<F extends Flow> {
|
|||
return readResourceUtf8(getClass(), "testdata/" + filename);
|
||||
}
|
||||
|
||||
/** Load a flow from an epp object. */
|
||||
private FlowRunner getFlowRunner(CommitMode commitMode, UserPrivileges userPrivileges)
|
||||
throws Exception {
|
||||
EppInput eppInput = eppLoader.getEpp();
|
||||
flowClass = firstNonNull(flowClass, FlowPicker.getFlowClass(eppInput));
|
||||
Class<?> expectedFlowClass = new TypeInstantiator<F>(getClass()){}.getExactType();
|
||||
assertThat(flowClass).isEqualTo(expectedFlowClass);
|
||||
return new FlowRunner(
|
||||
flowClass,
|
||||
eppInput,
|
||||
getTrid(),
|
||||
sessionMetadata,
|
||||
credentials,
|
||||
eppRequestSource,
|
||||
commitMode.equals(CommitMode.DRY_RUN),
|
||||
userPrivileges.equals(UserPrivileges.SUPERUSER),
|
||||
"<xml></xml>".getBytes(),
|
||||
null,
|
||||
clock);
|
||||
}
|
||||
|
||||
protected Trid getTrid() throws Exception {
|
||||
return Trid.create(eppLoader.getEpp().getCommandWrapper().getClTrid(), "server-trid");
|
||||
protected String getClientTrid() throws Exception {
|
||||
return eppLoader.getEpp().getCommandWrapper().getClTrid();
|
||||
}
|
||||
|
||||
/** Gets the client ID that the flow will run as. */
|
||||
|
@ -156,8 +132,15 @@ public abstract class FlowTestCase<F extends Flow> {
|
|||
}
|
||||
|
||||
public void assertTransactionalFlow(boolean isTransactional) throws Exception {
|
||||
assertThat(getFlowRunner(CommitMode.LIVE, UserPrivileges.NORMAL).isTransactional())
|
||||
.isEqualTo(isTransactional);
|
||||
Class<? extends Flow> flowClass = FlowPicker.getFlowClass(eppLoader.getEpp());
|
||||
if (isTransactional) {
|
||||
assertThat(flowClass).isAssignableTo(TransactionalFlow.class);
|
||||
} else {
|
||||
// There's no "isNotAssignableTo" in Truth.
|
||||
assertThat(TransactionalFlow.class.isAssignableFrom(flowClass))
|
||||
.named(flowClass.getSimpleName() + " implements TransactionalFlow")
|
||||
.isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
public void assertNoHistory() throws Exception {
|
||||
|
@ -273,36 +256,67 @@ public abstract class FlowTestCase<F extends Flow> {
|
|||
.containsExactlyElementsIn(FluentIterable.from(asList(expected)).transform(idStripper));
|
||||
}
|
||||
|
||||
/** Run a flow, and attempt to marshal the result to EPP or throw if it doesn't validate. */
|
||||
private EppOutput runFlowInternal(CommitMode commitMode, UserPrivileges userPrivileges)
|
||||
throws Exception {
|
||||
// Assert that the xml triggers the flow we expect.
|
||||
assertThat(FlowPicker.getFlowClass(eppLoader.getEpp()))
|
||||
.isEqualTo(new TypeInstantiator<F>(getClass()){}.getExactType());
|
||||
// Run the flow.
|
||||
return DaggerEppTestComponent.builder()
|
||||
.fakesAndMocksModule(new FakesAndMocksModule(clock))
|
||||
.build()
|
||||
.startRequest()
|
||||
.flowComponentBuilder()
|
||||
.flowModule(new FlowModule.Builder()
|
||||
.setSessionMetadata(sessionMetadata)
|
||||
.setCredentials(credentials)
|
||||
.setEppRequestSource(eppRequestSource)
|
||||
.setIsDryRun(commitMode.equals(CommitMode.DRY_RUN))
|
||||
.setIsSuperuser(userPrivileges.equals(UserPrivileges.SUPERUSER))
|
||||
.setInputXmlBytes(eppLoader.getEppXml().getBytes(UTF_8))
|
||||
.setEppInput(eppLoader.getEpp())
|
||||
.build())
|
||||
.build()
|
||||
.flowRunner()
|
||||
.run();
|
||||
}
|
||||
|
||||
/** Run a flow and marshal the result to EPP, or throw if it doesn't validate. */
|
||||
public EppOutput runFlow(CommitMode commitMode, UserPrivileges userPrivileges) throws Exception {
|
||||
EppOutput output = getFlowRunner(commitMode, userPrivileges).run();
|
||||
EppOutput output = runFlowInternal(commitMode, userPrivileges);
|
||||
marshal(output, ValidationMode.STRICT);
|
||||
return output;
|
||||
}
|
||||
|
||||
/** Shortcut to call {@link #runFlow(CommitMode, UserPrivileges)} as normal user and live run. */
|
||||
public EppOutput runFlow() throws Exception {
|
||||
return runFlow(CommitMode.LIVE, UserPrivileges.NORMAL);
|
||||
}
|
||||
|
||||
/** Run a flow, marshal the result to EPP, and assert that the output is as expected. */
|
||||
public void runFlowAssertResponse(
|
||||
CommitMode commitMode, UserPrivileges userPrivileges, String xml, String... ignoredPaths)
|
||||
throws Exception {
|
||||
EppOutput eppOutput = getFlowRunner(commitMode, userPrivileges).run();
|
||||
if (eppOutput.isResponse()) {
|
||||
assertThat(eppOutput.isSuccess()).isTrue();
|
||||
// Always ignore the server trid, since it's generated and meaningless to flow correctness.
|
||||
String[] ignoredPathsPlusTrid = FluentIterable.from(ignoredPaths)
|
||||
.append("epp.response.trID.svTRID")
|
||||
.toArray(String.class);
|
||||
EppOutput output = runFlowInternal(commitMode, userPrivileges);
|
||||
if (output.isResponse()) {
|
||||
assertThat(output.isSuccess()).isTrue();
|
||||
}
|
||||
try {
|
||||
assertXmlEquals(
|
||||
xml, new String(marshal(eppOutput, ValidationMode.STRICT), UTF_8), ignoredPaths);
|
||||
xml, new String(marshal(output, ValidationMode.STRICT), UTF_8), ignoredPathsPlusTrid);
|
||||
} catch (Throwable e) {
|
||||
assertXmlEquals(
|
||||
xml, new String(marshal(eppOutput, ValidationMode.LENIENT), UTF_8), ignoredPaths);
|
||||
xml, new String(marshal(output, ValidationMode.LENIENT), UTF_8), ignoredPathsPlusTrid);
|
||||
// If it was a marshaling error, augment the output.
|
||||
throw new Exception(
|
||||
String.format(
|
||||
"Invalid xml.\nExpected:\n%s\n\nActual:\n%s\n",
|
||||
xml,
|
||||
marshal(eppOutput, ValidationMode.LENIENT)),
|
||||
marshal(output, ValidationMode.LENIENT)),
|
||||
e);
|
||||
}
|
||||
// Clear the cache so that we don't see stale results in tests.
|
||||
|
|
|
@ -71,7 +71,7 @@ public class ContactTransferRequestFlowTest
|
|||
.hasTransferStatus(TransferStatus.PENDING).and()
|
||||
.hasTransferGainingClientId("NewRegistrar").and()
|
||||
.hasTransferLosingClientId("TheRegistrar").and()
|
||||
.hasTransferRequestTrid(getTrid()).and()
|
||||
.hasTransferRequestClientTrid(getClientTrid()).and()
|
||||
.hasCurrentSponsorClientId("TheRegistrar").and()
|
||||
.hasPendingTransferExpirationTime(afterTransfer).and()
|
||||
.hasOnlyOneHistoryEntryWhich()
|
||||
|
|
|
@ -64,7 +64,6 @@ import google.registry.model.domain.GracePeriod;
|
|||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
|
||||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.poll.PendingActionNotificationResponse;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
|
@ -95,7 +94,7 @@ public class DomainTransferRequestFlowTest
|
|||
.hasTransferStatus(TransferStatus.PENDING).and()
|
||||
.hasTransferGainingClientId("NewRegistrar").and()
|
||||
.hasTransferLosingClientId("TheRegistrar").and()
|
||||
.hasTransferRequestTrid(getTrid()).and()
|
||||
.hasTransferRequestClientTrid(getClientTrid()).and()
|
||||
.hasCurrentSponsorClientId("TheRegistrar").and()
|
||||
.hasPendingTransferExpirationTime(
|
||||
clock.nowUtc().plus(Registry.get("tld").getAutomaticTransferLength())).and()
|
||||
|
@ -228,8 +227,7 @@ public class DomainTransferRequestFlowTest
|
|||
PendingActionNotificationResponse panData = Iterables.getOnlyElement(FluentIterable
|
||||
.from(transferApprovedPollMessage.getResponseData())
|
||||
.filter(PendingActionNotificationResponse.class));
|
||||
assertThat(panData.getTrid())
|
||||
.isEqualTo(Trid.create("ABC-12345", "server-trid"));
|
||||
assertThat(panData.getTrid().getClientTransactionId()).isEqualTo("ABC-12345");
|
||||
assertThat(panData.getActionResult()).isTrue();
|
||||
|
||||
// Two poll messages on the losing registrar's side at the implicit transfer time: a
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<create>
|
||||
<domain:create
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.example</domain:name>
|
||||
<domain:name>example.tld</domain:name>
|
||||
<domain:period unit="y">2</domain:period>
|
||||
<domain:registrant>jd1234</domain:registrant>
|
||||
<domain:contact type="admin">sh8013</domain:contact>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<resData>
|
||||
<domain:creData
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.example</domain:name>
|
||||
<domain:name>example.tld</domain:name>
|
||||
<domain:crDate>2000-06-01T00:02:00.0Z</domain:crDate>
|
||||
<domain:exDate>2002-06-01T00:02:00.0Z</domain:exDate>
|
||||
</domain:creData>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<delete>
|
||||
<domain:delete
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.example</domain:name>
|
||||
<domain:name>example.tld</domain:name>
|
||||
</domain:delete>
|
||||
</delete>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<info>
|
||||
<domain:info
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name hosts="all">example.example</domain:name>
|
||||
<domain:name hosts="all">example.tld</domain:name>
|
||||
</domain:info>
|
||||
</info>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<resData>
|
||||
<domain:infData
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.example</domain:name>
|
||||
<domain:name>example.tld</domain:name>
|
||||
<domain:roid>%ROID%</domain:roid>
|
||||
<domain:status s="inactive"/>
|
||||
<domain:status s="pendingDelete"/>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<update>
|
||||
<domain:update
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.example</domain:name>
|
||||
<domain:name>example.tld</domain:name>
|
||||
<domain:chg/>
|
||||
</domain:update>
|
||||
</update>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-A-EXAMPLE-16-20">
|
||||
<msgQ count="1" id="1-B-EXAMPLE-17-21">
|
||||
<qDate>2001-01-01T00:00:00Z</qDate>
|
||||
<msg>Transfer requested.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-A-EXAMPLE-16-22">
|
||||
<msgQ count="1" id="1-B-EXAMPLE-17-23">
|
||||
<qDate>2001-01-06T00:00:00Z</qDate>
|
||||
<msg>Transfer approved.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="1" id="1-A-EXAMPLE-16-21">
|
||||
<msgQ count="1" id="1-B-EXAMPLE-17-22">
|
||||
<qDate>2001-01-06T00:00:00Z</qDate>
|
||||
<msg>Transfer approved.</msg>
|
||||
</msgQ>
|
||||
|
|
|
@ -15,35 +15,19 @@
|
|||
package google.registry.model;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.flows.picker.FlowPicker.getFlowClass;
|
||||
import static google.registry.model.EppResourceUtils.loadAtPointInTime;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.newHostResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveHost;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistResourceWithCommitLog;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.joda.time.Duration.standardDays;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
|
||||
import google.registry.flows.EppRequestSource;
|
||||
import google.registry.flows.FlowRunner;
|
||||
import google.registry.flows.HttpSessionMetadata;
|
||||
import google.registry.flows.PasswordOnlyTransportCredentials;
|
||||
import google.registry.flows.SessionMetadata;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.EppLoader;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeHttpSession;
|
||||
import google.registry.testing.InjectRule;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -71,7 +55,6 @@ public class EppResourceUtilsTest {
|
|||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.now(UTC));
|
||||
private EppLoader eppLoader;
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
|
@ -79,103 +62,6 @@ public class EppResourceUtilsTest {
|
|||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
}
|
||||
|
||||
private void runFlow() throws Exception {
|
||||
SessionMetadata sessionMetadata = new HttpSessionMetadata(new FakeHttpSession());
|
||||
sessionMetadata.setClientId("TheRegistrar");
|
||||
new FlowRunner(
|
||||
getFlowClass(eppLoader.getEpp()),
|
||||
eppLoader.getEpp(),
|
||||
Trid.create(null, "server-trid"),
|
||||
sessionMetadata,
|
||||
new PasswordOnlyTransportCredentials(),
|
||||
EppRequestSource.UNIT_TEST,
|
||||
false,
|
||||
false,
|
||||
"<xml></xml>".getBytes(),
|
||||
null,
|
||||
clock)
|
||||
.run();
|
||||
}
|
||||
|
||||
/** Test that update flow creates commit logs needed to reload at any arbitrary time. */
|
||||
@Test
|
||||
public void testLoadAtPointInTime() throws Exception {
|
||||
clock.setTo(DateTime.parse("1984-12-18T12:30Z")); // not midnight
|
||||
|
||||
persistActiveHost("ns1.example.net");
|
||||
persistActiveHost("ns2.example.net");
|
||||
persistActiveContact("jd1234");
|
||||
persistActiveContact("sh8013");
|
||||
|
||||
clock.advanceBy(standardDays(1));
|
||||
DateTime timeAtCreate = clock.nowUtc();
|
||||
clock.setTo(timeAtCreate);
|
||||
eppLoader = new EppLoader(this, "domain_create.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
Key<DomainResource> key = Key.create(ofy().load().type(DomainResource.class).first().now());
|
||||
DomainResource domainAfterCreate = ofy().load().key(key).now();
|
||||
assertThat(domainAfterCreate.getFullyQualifiedDomainName()).isEqualTo("example.tld");
|
||||
|
||||
clock.advanceBy(standardDays(2));
|
||||
DateTime timeAtFirstUpdate = clock.nowUtc();
|
||||
eppLoader = new EppLoader(this, "domain_update_dsdata_add.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
|
||||
DomainResource domainAfterFirstUpdate = ofy().load().key(key).now();
|
||||
assertThat(domainAfterCreate).isNotEqualTo(domainAfterFirstUpdate);
|
||||
|
||||
clock.advanceOneMilli(); // same day as first update
|
||||
DateTime timeAtSecondUpdate = clock.nowUtc();
|
||||
eppLoader = new EppLoader(this, "domain_update_dsdata_rem.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
DomainResource domainAfterSecondUpdate = ofy().load().key(key).now();
|
||||
|
||||
clock.advanceBy(standardDays(2));
|
||||
DateTime timeAtDelete = clock.nowUtc(); // before 'add' grace period ends
|
||||
eppLoader = new EppLoader(this, "domain_delete.xml");
|
||||
runFlow();
|
||||
ofy().clearSessionCache();
|
||||
|
||||
assertThat(domainAfterFirstUpdate).isNotEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
// Point-in-time can only rewind an object from the current version, not roll forward.
|
||||
DomainResource latest = ofy().load().key(key).now();
|
||||
|
||||
// Creation time has millisecond granularity due to isActive() check.
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.minusMillis(1)).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.plusMillis(1)).now()).isNotNull();
|
||||
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtCreate.plusDays(1)).now())
|
||||
.isEqualTo(domainAfterCreate);
|
||||
|
||||
// Both updates happened on the same day. Since the revisions field has day granularity, the
|
||||
// reference to the first update should have been overwritten by the second, and its timestamp
|
||||
// rolled forward. So we have to fall back to the last revision before midnight.
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtFirstUpdate).now())
|
||||
.isEqualTo(domainAfterCreate);
|
||||
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtSecondUpdate).now())
|
||||
.isEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtSecondUpdate.plusDays(1)).now())
|
||||
.isEqualTo(domainAfterSecondUpdate);
|
||||
|
||||
// Deletion time has millisecond granularity due to isActive() check.
|
||||
ofy().clearSessionCache();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.minusMillis(1)).now()).isNotNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete).now()).isNull();
|
||||
assertThat(loadAtPointInTime(latest, timeAtDelete.plusMillis(1)).now()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAtPointInTime_beforeCreated_returnsNull() throws Exception {
|
||||
clock.advanceOneMilli();
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<delete>
|
||||
<domain:delete
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.tld</domain:name>
|
||||
</domain:delete>
|
||||
</delete>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -26,7 +26,6 @@ import com.google.common.truth.Subject;
|
|||
|
||||
import google.registry.model.EppResource;
|
||||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.testing.TruthChainer.And;
|
||||
|
@ -205,10 +204,10 @@ abstract class AbstractEppResourceSubject
|
|||
"has transferStatus");
|
||||
}
|
||||
|
||||
public And<S> hasTransferRequestTrid(Trid trid) {
|
||||
public And<S> hasTransferRequestClientTrid(String clTrid) {
|
||||
return hasValue(
|
||||
trid,
|
||||
getSubject().getTransferData().getTransferRequestTrid(),
|
||||
clTrid,
|
||||
getSubject().getTransferData().getTransferRequestTrid().getClientTransactionId(),
|
||||
"has trid");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue