Fix a bug when updating a domain without changing its registrant

When updating a filed other than the registrant for a domain, a null
registratantContactId is passed to the registrant whitelist validator, causing
an excpetion because null is not an element in the whitelist (if it exists).
Added logic to handle null registrantContactId.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=126817310
This commit is contained in:
Ben McIlwain 2016-07-07 10:07:28 -07:00
parent 32e8e8fdb0
commit 1ed77d5572
2 changed files with 21 additions and 2 deletions

View file

@ -318,8 +318,9 @@ public class DomainFlowUtils {
static void validateRegistrantAllowedOnTld(String tld, String registrantContactId)
throws RegistrantNotAllowedException {
ImmutableSet<String> whitelist = Registry.get(tld).getAllowedRegistrantContactIds();
// Empty whitelists are ignored.
if (!whitelist.isEmpty() && !whitelist.contains(registrantContactId)) {
// Empty whitelists or null registrantContactId are ignored.
if (registrantContactId != null && !whitelist.isEmpty()
&& !whitelist.contains(registrantContactId)) {
throw new RegistrantNotAllowedException(registrantContactId);
}
}

View file

@ -1094,6 +1094,24 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
runFlow();
}
@Test
public void testSuccess_newNameserverWhitelisted() throws Exception {
setEppInput("domain_update_add_nameserver.xml");
persistReferencedEntities();
persistDomain();
// No registrant is given but both nameserver and registrant whitelist exist.
persistResource(
Registry.get("tld").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("sh8013"))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.foo"))
.build());
assertThat(reloadResourceByUniqueId().getNameservers()).doesNotContain(
Ref.create(loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc())));
runFlow();
assertThat(reloadResourceByUniqueId().getNameservers()).contains(
Ref.create(loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc())));
}
@Test
public void testSuccess_nameserverAndRegistrantWhitelisted() throws Exception {
persistReferencedEntities();