Fall back to icannReferralEmail when creating registrars through the command line

This is if the separate email field isn't specified.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=239504636
This commit is contained in:
gbrodman 2019-03-20 16:55:59 -07:00 committed by jianglai
parent 86968e004f
commit 36fd13f8e0
3 changed files with 44 additions and 20 deletions

View file

@ -92,12 +92,8 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
String registrarName; String registrarName;
@Nullable @Nullable
@Parameter( @Parameter(names = "--email", description = "Email address of registrar")
names = "--email", String email;
description = "Email address of registrar",
converter = OptionalStringParameter.class,
validateWith = OptionalStringParameter.class)
Optional<String> email;
@Nullable @Nullable
@Parameter( @Parameter(
@ -280,8 +276,11 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
if (!isNullOrEmpty(registrarName)) { if (!isNullOrEmpty(registrarName)) {
builder.setRegistrarName(registrarName); builder.setRegistrarName(registrarName);
} }
if (email != null) { if (!isNullOrEmpty(email)) {
builder.setEmailAddress(email.orElse(null)); builder.setEmailAddress(email);
} else if (!isNullOrEmpty(
icannReferralEmail)) { // fall back to ICANN referral email if present
builder.setEmailAddress(icannReferralEmail);
} }
if (url != null) { if (url != null) {
builder.setUrl(url.orElse(null)); builder.setUrl(url.orElse(null));

View file

@ -89,6 +89,7 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
assertThat(registrar.getLastUpdateTime()).isEqualTo(registrar.getCreationTime()); assertThat(registrar.getLastUpdateTime()).isEqualTo(registrar.getCreationTime());
assertThat(registrar.getBlockPremiumNames()).isFalse(); assertThat(registrar.getBlockPremiumNames()).isFalse();
assertThat(registrar.getPoNumber()).isEmpty(); assertThat(registrar.getPoNumber()).isEmpty();
assertThat(registrar.getIcannReferralEmail()).isEqualTo("foo@bar.test");
verify(connection) verify(connection)
.sendPostRequest( .sendPostRequest(
@ -563,6 +564,27 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
assertThat(registrar.get().getEmailAddress()).isEqualTo("foo@foo.foo"); assertThat(registrar.get().getEmailAddress()).isEqualTo("foo@foo.foo");
} }
@Test
public void testSuccess_fallBackToIcannReferralEmail() throws Exception {
runCommandForced(
"--name=blobio",
"--password=some_password",
"--registrar_type=REAL",
"--iana_id=8",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"--street=\"123 Fake St\"",
"--city Fakington",
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
Optional<Registrar> registrar = Registrar.loadByClientId("clientz");
assertThat(registrar).isPresent();
assertThat(registrar.get().getEmailAddress()).isEqualTo("foo@bar.test");
}
@Test @Test
public void testSuccess_url() throws Exception { public void testSuccess_url() throws Exception {
runCommandForced( runCommandForced(
@ -618,7 +640,6 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--billing_id=null", "--billing_id=null",
"--phone=null", "--phone=null",
"--fax=null", "--fax=null",
"--email=null",
"--url=null", "--url=null",
"--drive_folder_id=null", "--drive_folder_id=null",
"--street=\"123 Fake St\"", "--street=\"123 Fake St\"",
@ -635,7 +656,6 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
assertThat(registrar.getBillingIdentifier()).isNull(); assertThat(registrar.getBillingIdentifier()).isNull();
assertThat(registrar.getPhoneNumber()).isNull(); assertThat(registrar.getPhoneNumber()).isNull();
assertThat(registrar.getFaxNumber()).isNull(); assertThat(registrar.getFaxNumber()).isNull();
assertThat(registrar.getEmailAddress()).isNull();
assertThat(registrar.getUrl()).isNull(); assertThat(registrar.getUrl()).isNull();
assertThat(registrar.getDriveFolderId()).isNull(); assertThat(registrar.getDriveFolderId()).isNull();
@ -651,7 +671,6 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--billing_id=", "--billing_id=",
"--phone=", "--phone=",
"--fax=", "--fax=",
"--email=",
"--url=", "--url=",
"--drive_folder_id=", "--drive_folder_id=",
"--icann_referral_email=foo@bar.test", "--icann_referral_email=foo@bar.test",
@ -669,7 +688,6 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
assertThat(registrar.getBillingIdentifier()).isNull(); assertThat(registrar.getBillingIdentifier()).isNull();
assertThat(registrar.getPhoneNumber()).isNull(); assertThat(registrar.getPhoneNumber()).isNull();
assertThat(registrar.getFaxNumber()).isNull(); assertThat(registrar.getFaxNumber()).isNull();
assertThat(registrar.getEmailAddress()).isNull();
assertThat(registrar.getUrl()).isNull(); assertThat(registrar.getUrl()).isNull();
assertThat(registrar.getDriveFolderId()).isNull(); assertThat(registrar.getDriveFolderId()).isNull();
} }

View file

@ -346,7 +346,6 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
.setBillingIdentifier(1L) .setBillingIdentifier(1L)
.setPhoneNumber("+1.2125555555") .setPhoneNumber("+1.2125555555")
.setFaxNumber("+1.2125555556") .setFaxNumber("+1.2125555556")
.setEmailAddress("registrar@example.tld")
.setUrl("http://www.example.tld") .setUrl("http://www.example.tld")
.setDriveFolderId("id") .setDriveFolderId("id")
.build()); .build());
@ -355,7 +354,6 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
assertThat(registrar.getBillingIdentifier()).isNotNull(); assertThat(registrar.getBillingIdentifier()).isNotNull();
assertThat(registrar.getPhoneNumber()).isNotNull(); assertThat(registrar.getPhoneNumber()).isNotNull();
assertThat(registrar.getFaxNumber()).isNotNull(); assertThat(registrar.getFaxNumber()).isNotNull();
assertThat(registrar.getEmailAddress()).isNotNull();
assertThat(registrar.getUrl()).isNotNull(); assertThat(registrar.getUrl()).isNotNull();
assertThat(registrar.getDriveFolderId()).isNotNull(); assertThat(registrar.getDriveFolderId()).isNotNull();
@ -365,7 +363,6 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
"--billing_id=null", "--billing_id=null",
"--phone=null", "--phone=null",
"--fax=null", "--fax=null",
"--email=null",
"--url=null", "--url=null",
"--drive_folder_id=null", "--drive_folder_id=null",
"--force", "--force",
@ -376,7 +373,6 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
assertThat(registrar.getBillingIdentifier()).isNull(); assertThat(registrar.getBillingIdentifier()).isNull();
assertThat(registrar.getPhoneNumber()).isNull(); assertThat(registrar.getPhoneNumber()).isNull();
assertThat(registrar.getFaxNumber()).isNull(); assertThat(registrar.getFaxNumber()).isNull();
assertThat(registrar.getEmailAddress()).isNull();
assertThat(registrar.getUrl()).isNull(); assertThat(registrar.getUrl()).isNull();
assertThat(registrar.getDriveFolderId()).isNull(); assertThat(registrar.getDriveFolderId()).isNull();
} }
@ -390,7 +386,6 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
.setBillingIdentifier(1L) .setBillingIdentifier(1L)
.setPhoneNumber("+1.2125555555") .setPhoneNumber("+1.2125555555")
.setFaxNumber("+1.2125555556") .setFaxNumber("+1.2125555556")
.setEmailAddress("registrar@example.tld")
.setUrl("http://www.example.tld") .setUrl("http://www.example.tld")
.setDriveFolderId("id") .setDriveFolderId("id")
.build()); .build());
@ -399,7 +394,6 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
assertThat(registrar.getBillingIdentifier()).isNotNull(); assertThat(registrar.getBillingIdentifier()).isNotNull();
assertThat(registrar.getPhoneNumber()).isNotNull(); assertThat(registrar.getPhoneNumber()).isNotNull();
assertThat(registrar.getFaxNumber()).isNotNull(); assertThat(registrar.getFaxNumber()).isNotNull();
assertThat(registrar.getEmailAddress()).isNotNull();
assertThat(registrar.getUrl()).isNotNull(); assertThat(registrar.getUrl()).isNotNull();
assertThat(registrar.getDriveFolderId()).isNotNull(); assertThat(registrar.getDriveFolderId()).isNotNull();
@ -409,7 +403,6 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
"--billing_id=", "--billing_id=",
"--phone=", "--phone=",
"--fax=", "--fax=",
"--email=",
"--url=", "--url=",
"--drive_folder_id=", "--drive_folder_id=",
"--force", "--force",
@ -420,11 +413,25 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
assertThat(registrar.getBillingIdentifier()).isNull(); assertThat(registrar.getBillingIdentifier()).isNull();
assertThat(registrar.getPhoneNumber()).isNull(); assertThat(registrar.getPhoneNumber()).isNull();
assertThat(registrar.getFaxNumber()).isNull(); assertThat(registrar.getFaxNumber()).isNull();
assertThat(registrar.getEmailAddress()).isNull();
assertThat(registrar.getUrl()).isNull(); assertThat(registrar.getUrl()).isNull();
assertThat(registrar.getDriveFolderId()).isNull(); assertThat(registrar.getDriveFolderId()).isNull();
} }
@Test
public void testSuccess_setIcannEmail() throws Exception {
runCommand("--icann_referral_email=foo@bar.test", "--force", "TheRegistrar");
Registrar registrar = loadRegistrar("TheRegistrar");
assertThat(registrar.getIcannReferralEmail()).isEqualTo("foo@bar.test");
assertThat(registrar.getEmailAddress()).isEqualTo("foo@bar.test");
}
@Test
public void testSuccess_setEmail() throws Exception {
runCommand("--email=foo@bar.baz", "--force", "TheRegistrar");
Registrar registrar = loadRegistrar("TheRegistrar");
assertThat(registrar.getEmailAddress()).isEqualTo("foo@bar.baz");
}
@Test @Test
public void testSuccess_setWhoisServer_works() throws Exception { public void testSuccess_setWhoisServer_works() throws Exception {
runCommand("--whois=whois.goth.black", "--force", "NewRegistrar"); runCommand("--whois=whois.goth.black", "--force", "NewRegistrar");