Add extra flow logic hooks for info and update

This CL adds the hooks necessary to implement TLD-specific flow info and update flow logic. Usage of the hooks follows in a separate CL.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130108832
This commit is contained in:
mountford 2016-08-12 09:41:48 -07:00 committed by Ben McIlwain
parent e55ed209c5
commit 0066a03709
18 changed files with 397 additions and 16 deletions

View file

@ -39,6 +39,7 @@ 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.eppinput.EppInput;
import google.registry.model.eppoutput.EppOutput;
import google.registry.model.ofy.Ofy;
import google.registry.model.poll.PollMessage;
@ -112,6 +113,11 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
eppLoader = new EppLoader(this, inputFilename, substitutions);
}
/** Returns the EPP data loaded by a previous call to setEppInput. */
protected EppInput getEppInput() throws Exception {
return eppLoader.getEpp();
}
protected String readFile(String filename) {
return readResourceUtf8(getClass(), "testdata/" + filename);
}

View file

@ -17,6 +17,7 @@ package google.registry.flows.domain;
import static com.google.common.io.BaseEncoding.base16;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
@ -42,6 +43,7 @@ import google.registry.model.domain.DesignatedContact.Type;
import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.TestExtraLogicManager;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
@ -67,9 +69,11 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info.xml");
sessionMetadata.setClientId("NewRegistrar");
clock.setTo(DateTime.parse("2005-03-03T22:00:00.000Z"));
createTld("tld");
createTlds("tld", "flags");
persistResource(
AppEngineRule.makeRegistrar1().asBuilder().setClientIdentifier("ClientZ").build());
// For flags extension tests.
RegistryExtraFlowLogicProxy.setOverride("flags", TestExtraLogicManager.class);
}
private void persistTestEntities(String domainName, boolean inactive) {
@ -613,4 +617,20 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
persistTestEntities(false);
runFlow();
}
/** Test registry extra logic manager with no flags. */
@Test
public void testExtraLogicManager_noFlags() throws Exception {
setEppInput("domain_info_flags_none.xml");
persistTestEntities("domain.flags", false);
doSuccessfulTest("domain_info_response_flags_none.xml", false);
}
/** Test registry extra logic manager with two flags. */
@Test
public void testExtraLogicManager_twoFlags() throws Exception {
setEppInput("domain_info_flags_two.xml");
persistTestEntities("domain-flag1-flag2.flags", false);
doSuccessfulTest("domain_info_response_flags_two.xml", false);
}
}

View file

@ -21,6 +21,7 @@ import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.testing.DatastoreHelper.assertBillingEvents;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.getOnlyHistoryEntryOfType;
import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
@ -37,10 +38,8 @@ import static org.joda.money.CurrencyUnit.USD;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Ref;
import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.EppRequestSource;
import google.registry.flows.ResourceCreateOrMutateFlow.OnlyToolCanPassMetadataException;
@ -74,6 +73,7 @@ import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DesignatedContact.Type;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.TestExtraLogicManager;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue;
@ -81,7 +81,6 @@ import google.registry.model.host.HostResource;
import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.Before;
@ -105,7 +104,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
@Before
public void initDomainTest() {
createTld("tld");
createTlds("tld", "flags");
// For flags extension tests.
RegistryExtraFlowLogicProxy.setOverride("flags", TestExtraLogicManager.class);
}
private void persistReferencedEntities() {
@ -1176,4 +1177,13 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
thrown.expect(NameserversNotSpecifiedException.class);
runFlow();
}
@Test
public void testAddAndRemoveFlags() throws Exception {
setEppInput("domain_update_addremove_flags.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(UnimplementedExtensionException.class);
runFlow();
}
}

View file

@ -0,0 +1,11 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<info>
<domain:info
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name hosts="all">domain.flags</domain:name>
</domain:info>
</info>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -0,0 +1,11 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<info>
<domain:info
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name hosts="all">domain-flag1-flag2.flags</domain:name>
</domain:info>
</info>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -0,0 +1,38 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<domain:infData
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>domain.flags</domain:name>
<domain:roid>%ROID%</domain:roid>
<domain:status s="ok"/>
<domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact>
<domain:contact type="tech">sh8013</domain:contact>
<domain:ns>
<domain:hostObj>ns1.example.tld</domain:hostObj>
<domain:hostObj>ns1.example.net</domain:hostObj>
</domain:ns>
<domain:host>ns1.example.tld</domain:host>
<domain:host>ns2.example.tld</domain:host>
<domain:clID>NewRegistrar</domain:clID>
<domain:crID>TheRegistrar</domain:crID>
<domain:crDate>1999-04-03T22:00:00.0Z</domain:crDate>
<domain:upID>NewRegistrar</domain:upID>
<domain:upDate>1999-12-03T09:00:00.0Z</domain:upDate>
<domain:exDate>2005-04-03T22:00:00.0Z</domain:exDate>
<domain:trDate>2000-04-08T09:00:00.0Z</domain:trDate>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:infData>
</resData>
<trID>
<clTRID>ABC-12345</clTRID>
<svTRID>server-trid</svTRID>
</trID>
</response>
</epp>

View file

@ -0,0 +1,44 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<domain:infData
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>domain-flag1-flag2.flags</domain:name>
<domain:roid>%ROID%</domain:roid>
<domain:status s="ok"/>
<domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact>
<domain:contact type="tech">sh8013</domain:contact>
<domain:ns>
<domain:hostObj>ns1.example.tld</domain:hostObj>
<domain:hostObj>ns1.example.net</domain:hostObj>
</domain:ns>
<domain:host>ns1.example.tld</domain:host>
<domain:host>ns2.example.tld</domain:host>
<domain:clID>NewRegistrar</domain:clID>
<domain:crID>TheRegistrar</domain:crID>
<domain:crDate>1999-04-03T22:00:00.0Z</domain:crDate>
<domain:upID>NewRegistrar</domain:upID>
<domain:upDate>1999-12-03T09:00:00.0Z</domain:upDate>
<domain:exDate>2005-04-03T22:00:00.0Z</domain:exDate>
<domain:trDate>2000-04-08T09:00:00.0Z</domain:trDate>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:infData>
</resData>
<extension>
<flags:infData xmlns:flags="urn:google:params:xml:ns:flags-0.1">
<flags:flag>flag1</flags:flag>
<flags:flag>flag2</flags:flag>
</flags:infData>
</extension>
<trID>
<clTRID>ABC-12345</clTRID>
<svTRID>server-trid</svTRID>
</trID>
</response>
</epp>

View file

@ -0,0 +1,23 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.flags</domain:name>
</domain:update>
</update>
<extension>
<flags:update xmlns:flags="urn:google:params:xml:ns:flags-0.1">
<flags:add>
<flags:flag>flag1</flags:flag>
<flags:flag>flag2</flags:flag>
</flags:add>
<flags:rem>
<flags:flag>flag3</flags:flag>
<flags:flag>flag4</flags:flag>
</flags:rem>
</flags:update>
</extension>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -0,0 +1,63 @@
// 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.model.domain;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import google.registry.flows.EppException;
import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.domain.RegistryExtraFlowLogic;
import google.registry.model.domain.flags.FlagsUpdateCommandExtension;
import google.registry.model.eppinput.EppInput;
import java.util.List;
import org.joda.time.DateTime;
/**
* Fake extra logic manager which synthesizes information from the domain name for testing purposes.
*/
public class TestExtraLogicManager implements RegistryExtraFlowLogic {
@Override
public List<String> getFlags(
DomainResource domainResource, String clientIdentifier, DateTime asOfDate) {
// Take the part before the period, split by dashes, and treat each part after the first as
// a flag.
List<String> components =
Splitter.on('-').splitToList(
Iterables.getFirst(
Splitter.on('.').split(domainResource.getFullyQualifiedDomainName()), ""));
return components.subList(1, components.size());
}
@Override
public void performAdditionalDomainUpdateLogic(
DomainResource domainResource,
String clientIdentifier,
DateTime asOfDate,
EppInput eppInput) throws EppException {
FlagsUpdateCommandExtension updateFlags =
eppInput.getSingleExtension(FlagsUpdateCommandExtension.class);
if (updateFlags == null) {
return;
}
// Throw this exception as a signal to the test that we got this far.
throw new UnimplementedExtensionException();
}
@Override
public void commitAdditionalDomainUpdates() {
return;
}
}