mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 01:47:14 +02:00
Add option to registrar_contact command to modify the visible_in_domain_whois_as_abuse flag
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=157588734
This commit is contained in:
parent
009522d078
commit
6cc3ee5e15
2 changed files with 130 additions and 6 deletions
|
@ -110,7 +110,7 @@ final class RegistrarContactCommand extends MutatingCommand {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = "--visible_in_whois_as_admin",
|
names = "--visible_in_whois_as_admin",
|
||||||
description = " Whether this contact is publically visible in WHOIS results as an "
|
description = " Whether this contact is publicly visible in WHOIS results as an "
|
||||||
+ "Admin contact.",
|
+ "Admin contact.",
|
||||||
arity = 1)
|
arity = 1)
|
||||||
private Boolean visibleInWhoisAsAdmin;
|
private Boolean visibleInWhoisAsAdmin;
|
||||||
|
@ -118,11 +118,20 @@ final class RegistrarContactCommand extends MutatingCommand {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = "--visible_in_whois_as_tech",
|
names = "--visible_in_whois_as_tech",
|
||||||
description = " Whether this contact is publically visible in WHOIS results as a "
|
description = " Whether this contact is publicly visible in WHOIS results as a "
|
||||||
+ "Tech contact.",
|
+ "Tech contact.",
|
||||||
arity = 1)
|
arity = 1)
|
||||||
private Boolean visibleInWhoisAsTech;
|
private Boolean visibleInWhoisAsTech;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Parameter(
|
||||||
|
names = "--visible_in_domain_whois_as_abuse",
|
||||||
|
description = " Whether this contact is publicly visible in WHOIS domain results as the "
|
||||||
|
+ "registry abuse phone and email. If this flag is set, it will be cleared from all "
|
||||||
|
+ "other contacts for the same registrar.",
|
||||||
|
arity = 1)
|
||||||
|
private Boolean visibleInDomainWhoisAsAbuse;
|
||||||
|
|
||||||
@Parameter(
|
@Parameter(
|
||||||
names = {"-o", "--output"},
|
names = {"-o", "--output"},
|
||||||
description = "Output file when --mode=LIST",
|
description = "Output file when --mode=LIST",
|
||||||
|
@ -160,6 +169,7 @@ final class RegistrarContactCommand extends MutatingCommand {
|
||||||
break;
|
break;
|
||||||
case CREATE:
|
case CREATE:
|
||||||
stageEntityChange(null, createContact(registrar));
|
stageEntityChange(null, createContact(registrar));
|
||||||
|
unsetOtherWhoisAbuseFlags(contacts, null);
|
||||||
break;
|
break;
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
oldContact =
|
oldContact =
|
||||||
|
@ -168,7 +178,13 @@ final class RegistrarContactCommand extends MutatingCommand {
|
||||||
"No contact with the given email: %s",
|
"No contact with the given email: %s",
|
||||||
email);
|
email);
|
||||||
RegistrarContact newContact = updateContact(oldContact, registrar);
|
RegistrarContact newContact = updateContact(oldContact, registrar);
|
||||||
|
checkArgument(
|
||||||
|
!oldContact.getVisibleInDomainWhoisAsAbuse()
|
||||||
|
|| newContact.getVisibleInDomainWhoisAsAbuse(),
|
||||||
|
"Cannot clear visible_in_domain_whois_as_abuse flag, as that would leave no domain"
|
||||||
|
+ " WHOIS abuse contacts; instead, set the flag on another contact");
|
||||||
stageEntityChange(oldContact, newContact);
|
stageEntityChange(oldContact, newContact);
|
||||||
|
unsetOtherWhoisAbuseFlags(contacts, oldContact.getEmailAddress());
|
||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
oldContact =
|
oldContact =
|
||||||
|
@ -176,6 +192,9 @@ final class RegistrarContactCommand extends MutatingCommand {
|
||||||
contactsMap.get(checkNotNull(email, "--email is required when --mode=DELETE")),
|
contactsMap.get(checkNotNull(email, "--email is required when --mode=DELETE")),
|
||||||
"No contact with the given email: %s",
|
"No contact with the given email: %s",
|
||||||
email);
|
email);
|
||||||
|
checkArgument(
|
||||||
|
!oldContact.getVisibleInDomainWhoisAsAbuse(),
|
||||||
|
"Cannot delete the domain WHOIS abuse contact; set the flag on another contact first");
|
||||||
stageEntityChange(oldContact, null);
|
stageEntityChange(oldContact, null);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -220,6 +239,9 @@ final class RegistrarContactCommand extends MutatingCommand {
|
||||||
if (visibleInWhoisAsTech != null) {
|
if (visibleInWhoisAsTech != null) {
|
||||||
builder.setVisibleInWhoisAsTech(visibleInWhoisAsTech);
|
builder.setVisibleInWhoisAsTech(visibleInWhoisAsTech);
|
||||||
}
|
}
|
||||||
|
if (visibleInDomainWhoisAsAbuse != null) {
|
||||||
|
builder.setVisibleInDomainWhoisAsAbuse(visibleInDomainWhoisAsAbuse);
|
||||||
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +271,9 @@ final class RegistrarContactCommand extends MutatingCommand {
|
||||||
if (visibleInWhoisAsTech != null) {
|
if (visibleInWhoisAsTech != null) {
|
||||||
builder.setVisibleInWhoisAsTech(visibleInWhoisAsTech);
|
builder.setVisibleInWhoisAsTech(visibleInWhoisAsTech);
|
||||||
}
|
}
|
||||||
|
if (visibleInDomainWhoisAsAbuse != null) {
|
||||||
|
builder.setVisibleInDomainWhoisAsAbuse(visibleInDomainWhoisAsAbuse);
|
||||||
|
}
|
||||||
if (allowConsoleAccess != null) {
|
if (allowConsoleAccess != null) {
|
||||||
if (allowConsoleAccess.equals(Boolean.TRUE)) {
|
if (allowConsoleAccess.equals(Boolean.TRUE)) {
|
||||||
builder.setGaeUserId(checkArgumentNotNull(
|
builder.setGaeUserId(checkArgumentNotNull(
|
||||||
|
@ -260,4 +285,17 @@ final class RegistrarContactCommand extends MutatingCommand {
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void unsetOtherWhoisAbuseFlags(
|
||||||
|
ImmutableSet<RegistrarContact> contacts, @Nullable String emailAddressNotToChange) {
|
||||||
|
for (RegistrarContact contact : contacts) {
|
||||||
|
if (((emailAddressNotToChange == null)
|
||||||
|
|| !contact.getEmailAddress().equals(emailAddressNotToChange))
|
||||||
|
&& contact.getVisibleInDomainWhoisAsAbuse()) {
|
||||||
|
RegistrarContact newContact =
|
||||||
|
contact.asBuilder().setVisibleInDomainWhoisAsAbuse(false).build();
|
||||||
|
stageEntityChange(contact, newContact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
||||||
.setTypes(ImmutableSet.of(WHOIS))
|
.setTypes(ImmutableSet.of(WHOIS))
|
||||||
.setVisibleInWhoisAsAdmin(true)
|
.setVisibleInWhoisAsAdmin(true)
|
||||||
.setVisibleInWhoisAsTech(true)
|
.setVisibleInWhoisAsTech(true)
|
||||||
|
.setVisibleInDomainWhoisAsAbuse(false)
|
||||||
.build());
|
.build());
|
||||||
persistSimpleResources(contacts);
|
persistSimpleResources(contacts);
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
|
@ -88,7 +89,8 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
||||||
"--fax=+1.2125650001",
|
"--fax=+1.2125650001",
|
||||||
"--contact_type=WHOIS",
|
"--contact_type=WHOIS",
|
||||||
"--visible_in_whois_as_admin=true",
|
"--visible_in_whois_as_admin=true",
|
||||||
"--visible_in_whois_as_tech=true",
|
"--visible_in_whois_as_tech=false",
|
||||||
|
"--visible_in_domain_whois_as_abuse=false",
|
||||||
"NewRegistrar");
|
"NewRegistrar");
|
||||||
RegistrarContact registrarContact =
|
RegistrarContact registrarContact =
|
||||||
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
||||||
|
@ -101,7 +103,8 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
||||||
.setFaxNumber("+1.2125650001")
|
.setFaxNumber("+1.2125650001")
|
||||||
.setTypes(ImmutableSet.of(WHOIS))
|
.setTypes(ImmutableSet.of(WHOIS))
|
||||||
.setVisibleInWhoisAsAdmin(true)
|
.setVisibleInWhoisAsAdmin(true)
|
||||||
.setVisibleInWhoisAsTech(true)
|
.setVisibleInWhoisAsTech(false)
|
||||||
|
.setVisibleInDomainWhoisAsAbuse(false)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +147,67 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
||||||
assertThat(registrarContact.getGaeUserId()).isNull();
|
assertThat(registrarContact.getGaeUserId()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdate_unsetOtherWhoisAbuseFlags() throws Exception {
|
||||||
|
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
||||||
|
persistSimpleResource(
|
||||||
|
new RegistrarContact.Builder()
|
||||||
|
.setParent(registrar)
|
||||||
|
.setName("John Doe")
|
||||||
|
.setEmailAddress("john.doe@example.com")
|
||||||
|
.setGaeUserId("11111")
|
||||||
|
.build());
|
||||||
|
persistSimpleResource(
|
||||||
|
new RegistrarContact.Builder()
|
||||||
|
.setParent(registrar)
|
||||||
|
.setName("Johnna Doe")
|
||||||
|
.setEmailAddress("johnna.doe@example.com")
|
||||||
|
.setGaeUserId("11112")
|
||||||
|
.setVisibleInDomainWhoisAsAbuse(true)
|
||||||
|
.build());
|
||||||
|
runCommandForced(
|
||||||
|
"--mode=UPDATE",
|
||||||
|
"--email=john.doe@example.com",
|
||||||
|
"--visible_in_domain_whois_as_abuse=true",
|
||||||
|
"NewRegistrar");
|
||||||
|
ImmutableList<RegistrarContact> registrarContacts =
|
||||||
|
Registrar.loadByClientId("NewRegistrar").getContacts().asList();
|
||||||
|
for (RegistrarContact registrarContact : registrarContacts) {
|
||||||
|
if (registrarContact.getName().equals("John Doe")) {
|
||||||
|
assertThat(registrarContact.getVisibleInDomainWhoisAsAbuse()).isTrue();
|
||||||
|
} else {
|
||||||
|
assertThat(registrarContact.getVisibleInDomainWhoisAsAbuse()).isFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdate_cannotUnsetOnlyWhoisAbuseContact() throws Exception {
|
||||||
|
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
||||||
|
persistSimpleResource(
|
||||||
|
new RegistrarContact.Builder()
|
||||||
|
.setParent(registrar)
|
||||||
|
.setName("John Doe")
|
||||||
|
.setEmailAddress("john.doe@example.com")
|
||||||
|
.setGaeUserId("11111")
|
||||||
|
.setVisibleInDomainWhoisAsAbuse(true)
|
||||||
|
.build());
|
||||||
|
try {
|
||||||
|
runCommandForced(
|
||||||
|
"--mode=UPDATE",
|
||||||
|
"--email=john.doe@example.com",
|
||||||
|
"--visible_in_domain_whois_as_abuse=false",
|
||||||
|
"NewRegistrar");
|
||||||
|
throw new Exception(
|
||||||
|
"Expected IllegalArgumentException: Cannot clear visible_in_domain_whois_as_abuse flag");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
assertThat(e).hasMessageThat().contains("Cannot clear visible_in_domain_whois_as_abuse flag");
|
||||||
|
}
|
||||||
|
RegistrarContact registrarContact =
|
||||||
|
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
||||||
|
assertThat(registrarContact.getVisibleInDomainWhoisAsAbuse()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_withAdminType() throws Exception {
|
public void testCreate_withAdminType() throws Exception {
|
||||||
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
Registrar registrar = Registrar.loadByClientId("NewRegistrar");
|
||||||
|
@ -153,7 +217,8 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
||||||
"--email=jim.doe@example.com",
|
"--email=jim.doe@example.com",
|
||||||
"--contact_type=ADMIN,ABUSE",
|
"--contact_type=ADMIN,ABUSE",
|
||||||
"--visible_in_whois_as_admin=true",
|
"--visible_in_whois_as_admin=true",
|
||||||
"--visible_in_whois_as_tech=true",
|
"--visible_in_whois_as_tech=false",
|
||||||
|
"--visible_in_domain_whois_as_abuse=true",
|
||||||
"NewRegistrar");
|
"NewRegistrar");
|
||||||
RegistrarContact registrarContact =
|
RegistrarContact registrarContact =
|
||||||
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(1);
|
||||||
|
@ -164,13 +229,15 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
||||||
.setEmailAddress("jim.doe@example.com")
|
.setEmailAddress("jim.doe@example.com")
|
||||||
.setTypes(ImmutableSet.of(ADMIN, ABUSE))
|
.setTypes(ImmutableSet.of(ADMIN, ABUSE))
|
||||||
.setVisibleInWhoisAsAdmin(true)
|
.setVisibleInWhoisAsAdmin(true)
|
||||||
.setVisibleInWhoisAsTech(true)
|
.setVisibleInWhoisAsTech(false)
|
||||||
|
.setVisibleInDomainWhoisAsAbuse(true)
|
||||||
.build());
|
.build());
|
||||||
assertThat(registrarContact.getGaeUserId()).isNull();
|
assertThat(registrarContact.getGaeUserId()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception {
|
public void testDelete() throws Exception {
|
||||||
|
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isNotEmpty();
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
"--mode=DELETE",
|
"--mode=DELETE",
|
||||||
"--email=janedoe@theregistrar.com",
|
"--email=janedoe@theregistrar.com",
|
||||||
|
@ -178,6 +245,25 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
|
||||||
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isEmpty();
|
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDelete_failsOnDomainWhoisAbuseContact() throws Exception {
|
||||||
|
RegistrarContact registrarContact =
|
||||||
|
Registrar.loadByClientId("NewRegistrar").getContacts().asList().get(0);
|
||||||
|
persistSimpleResource(
|
||||||
|
registrarContact.asBuilder().setVisibleInDomainWhoisAsAbuse(true).build());
|
||||||
|
try {
|
||||||
|
runCommandForced(
|
||||||
|
"--mode=DELETE",
|
||||||
|
"--email=janedoe@theregistrar.com",
|
||||||
|
"NewRegistrar");
|
||||||
|
throw new Exception(
|
||||||
|
"Expected IllegalArgumentException: Cannot delete the domain WHOIS abuse contact");
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
assertThat(e).hasMessageThat().contains("Cannot delete the domain WHOIS abuse contact");
|
||||||
|
}
|
||||||
|
assertThat(Registrar.loadByClientId("NewRegistrar").getContacts()).isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreate_withConsoleAccessEnabled() throws Exception {
|
public void testCreate_withConsoleAccessEnabled() throws Exception {
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue