Contact authInfo should not be visible to all registrars in <info> flows

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133960014
This commit is contained in:
cgoldfeder 2016-09-22 09:06:43 -07:00 committed by Ben McIlwain
parent 4813ed392b
commit 740d49e22e
4 changed files with 105 additions and 1 deletions

View file

@ -21,6 +21,7 @@ import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.FlowModule.TargetId; import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.LoggedInFlow; import google.registry.flows.LoggedInFlow;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
@ -33,12 +34,14 @@ import javax.inject.Inject;
* *
* <p>The response includes the contact's postal info, phone numbers, emails, the authInfo which can * <p>The response includes the contact's postal info, phone numbers, emails, the authInfo which can
* be used to request a transfer and the details of the contact's most recent transfer if it has * be used to request a transfer and the details of the contact's most recent transfer if it has
* ever been transferred. Any registrar can see any contact's information. * ever been transferred. Any registrar can see any contact's information, but the authInfo is only
* visible to the registrar that owns the contact or to a registrar that already supplied it.
* *
* @error {@link google.registry.flows.exceptions.ResourceToQueryDoesNotExistException} * @error {@link google.registry.flows.exceptions.ResourceToQueryDoesNotExistException}
*/ */
public final class ContactInfoFlow extends LoggedInFlow { public final class ContactInfoFlow extends LoggedInFlow {
@Inject @ClientId String clientId;
@Inject @TargetId String targetId; @Inject @TargetId String targetId;
@Inject Optional<AuthInfo> authInfo; @Inject Optional<AuthInfo> authInfo;
@Inject ContactInfoFlow() {} @Inject ContactInfoFlow() {}
@ -47,6 +50,9 @@ public final class ContactInfoFlow extends LoggedInFlow {
public final EppOutput run() throws EppException { public final EppOutput run() throws EppException {
ContactResource contact = loadResourceForQuery(ContactResource.class, targetId, now); ContactResource contact = loadResourceForQuery(ContactResource.class, targetId, now);
verifyOptionalAuthInfoForResource(authInfo, contact); verifyOptionalAuthInfoForResource(authInfo, contact);
if (!clientId.equals(contact.getCurrentSponsorClientId()) && !authInfo.isPresent()) {
contact = contact.asBuilder().setAuthInfo(null).build();
}
return createOutput(SUCCESS, cloneResourceWithLinkedStatus(contact, now)); return createOutput(SUCCESS, cloneResourceWithLinkedStatus(contact, now));
} }
} }

View file

@ -118,6 +118,49 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase<ContactInfoFlow, C
assertNoBillingEvents(); assertNoBillingEvents();
} }
@Test
public void testSuccess_owningRegistrarWithoutAuthInfo_seesAuthInfo() throws Exception {
setEppInput("contact_info_no_authinfo.xml");
persistContactResource(true);
// Check that the persisted contact info was returned.
assertTransactionalFlow(false);
runFlowAssertResponse(
readFile("contact_info_response.xml"),
// We use a different roid scheme than the samples so ignore it.
"epp.response.resData.infData.roid");
assertNoHistory();
assertNoBillingEvents();
}
@Test
public void testSuccess_otherRegistrarWithoutAuthInfio_doesNotSeeAuthInfo() throws Exception {
setClientIdForFlow("NewRegistrar");
setEppInput("contact_info_no_authinfo.xml");
persistContactResource(true);
// Check that the persisted contact info was returned.
assertTransactionalFlow(false);
runFlowAssertResponse(
readFile("contact_info_response_no_authinfo.xml"),
// We use a different roid scheme than the samples so ignore it.
"epp.response.resData.infData.roid");
assertNoHistory();
assertNoBillingEvents();
}
@Test
public void testSuccess_otherRegistrarWithAuthInfo_seesAuthInfo() throws Exception {
setClientIdForFlow("NewRegistrar");
persistContactResource(true);
// Check that the persisted contact info was returned.
assertTransactionalFlow(false);
runFlowAssertResponse(
readFile("contact_info_response.xml"),
// We use a different roid scheme than the samples so ignore it.
"epp.response.resData.infData.roid");
assertNoHistory();
assertNoBillingEvents();
}
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect( thrown.expect(

View file

@ -0,0 +1,11 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<info>
<contact:info
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>sh8013</contact:id>
</contact:info>
</info>
<clTRID>ABC-12345</clTRID>
</command>
</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>
<contact:infData
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>sh8013</contact:id>
<contact:roid>SH8013-REP</contact:roid>
<contact:status s="clientDeleteProhibited"/>
<contact:postalInfo type="int">
<contact:name>John Doe</contact:name>
<contact:org>Example Inc.</contact:org>
<contact:addr>
<contact:street>123 Example Dr.</contact:street>
<contact:street>Suite 100</contact:street>
<contact:city>Dulles</contact:city>
<contact:sp>VA</contact:sp>
<contact:pc>20166-6503</contact:pc>
<contact:cc>US</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:voice x="1234">+1.7035555555</contact:voice>
<contact:fax>+1.7035555556</contact:fax>
<contact:email>jdoe@example.com</contact:email>
<contact:clID>TheRegistrar</contact:clID>
<contact:crID>NewRegistrar</contact:crID>
<contact:crDate>1999-04-03T22:00:00.0Z</contact:crDate>
<contact:upID>NewRegistrar</contact:upID>
<contact:upDate>1999-12-03T09:00:00.0Z</contact:upDate>
<contact:trDate>2000-04-08T09:00:00.0Z</contact:trDate>
<contact:disclose flag="1">
<contact:voice/>
<contact:email/>
</contact:disclose>
</contact:infData>
</resData>
<trID>
<clTRID>ABC-12345</clTRID>
<svTRID>server-trid</svTRID>
</trID>
</response>
</epp>