mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Fix whitelist tests
Followups to [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=121993530
This commit is contained in:
parent
fc936ec2b0
commit
d1f34776d2
7 changed files with 109 additions and 15 deletions
|
@ -282,7 +282,9 @@ public class DomainFlowUtils {
|
||||||
|
|
||||||
/** Return a foreign key for a {@link ReferenceUnion} from memory or datastore as needed. */
|
/** Return a foreign key for a {@link ReferenceUnion} from memory or datastore as needed. */
|
||||||
private static String resolveForeignKey(ReferenceUnion<?> ref) {
|
private static String resolveForeignKey(ReferenceUnion<?> ref) {
|
||||||
return Optional.fromNullable(ref.getForeignKey()).or(ref.getLinked().get().getForeignKey());
|
return ref.getForeignKey() != null
|
||||||
|
? ref.getForeignKey()
|
||||||
|
: ref.getLinked().get().getForeignKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validateNameservers(String tld, Set<ReferenceUnion<HostResource>> nameservers)
|
static void validateNameservers(String tld, Set<ReferenceUnion<HostResource>> nameservers)
|
||||||
|
@ -293,7 +295,7 @@ public class DomainFlowUtils {
|
||||||
}
|
}
|
||||||
ImmutableSet<String> whitelist = Registry.get(tld).getAllowedFullyQualifiedHostNames();
|
ImmutableSet<String> whitelist = Registry.get(tld).getAllowedFullyQualifiedHostNames();
|
||||||
if (!whitelist.isEmpty()) { // Empty whitelists are ignored.
|
if (!whitelist.isEmpty()) { // Empty whitelists are ignored.
|
||||||
for (ReferenceUnion<HostResource> nameserver : nameservers) {
|
for (ReferenceUnion<HostResource> nameserver : nullToEmpty(nameservers)) {
|
||||||
String foreignKey = resolveForeignKey(nameserver);
|
String foreignKey = resolveForeignKey(nameserver);
|
||||||
if (!whitelist.contains(foreignKey)) {
|
if (!whitelist.contains(foreignKey)) {
|
||||||
throw new NameserverNotAllowedException(foreignKey);
|
throw new NameserverNotAllowedException(foreignKey);
|
||||||
|
@ -336,7 +338,7 @@ public class DomainFlowUtils {
|
||||||
ImmutableSet<String> whitelist = Registry.get(tld).getAllowedRegistrantContactIds();
|
ImmutableSet<String> whitelist = Registry.get(tld).getAllowedRegistrantContactIds();
|
||||||
// Empty whitelists are ignored.
|
// Empty whitelists are ignored.
|
||||||
if (!whitelist.isEmpty() && !whitelist.contains(resolveForeignKey(registrant))) {
|
if (!whitelist.isEmpty() && !whitelist.contains(resolveForeignKey(registrant))) {
|
||||||
throw new RegistrantNotAllowedException(registrant.toString());
|
throw new RegistrantNotAllowedException(resolveForeignKey(registrant));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1181,18 +1181,17 @@ public class DomainApplicationCreateFlowTest
|
||||||
persistResource(Registry.get("tld").asBuilder()
|
persistResource(Registry.get("tld").asBuilder()
|
||||||
.setAllowedRegistrantContactIds(ImmutableSet.of("someone"))
|
.setAllowedRegistrantContactIds(ImmutableSet.of("someone"))
|
||||||
.build());
|
.build());
|
||||||
thrown.expect(RegistrantNotAllowedException.class);
|
thrown.expect(RegistrantNotAllowedException.class, "jd1234");
|
||||||
runFlow();
|
runFlow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nameserverNotWhitelisted() throws Exception {
|
public void testFailure_nameserverNotWhitelisted() throws Exception {
|
||||||
persistActiveHost("ns1.example.com");
|
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
persistResource(Registry.get("tld").asBuilder()
|
persistResource(Registry.get("tld").asBuilder()
|
||||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.someone.tld"))
|
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net"))
|
||||||
.build());
|
.build());
|
||||||
thrown.expect(NameserverNotAllowedException.class);
|
thrown.expect(NameserverNotAllowedException.class, "ns1.example.net");
|
||||||
runFlow();
|
runFlow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1209,6 +1208,20 @@ public class DomainApplicationCreateFlowTest
|
||||||
.hasApplicationStatus(ApplicationStatus.VALIDATED);
|
.hasApplicationStatus(ApplicationStatus.VALIDATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_emptyNameserversPassesWhitelist() throws Exception {
|
||||||
|
setEppInput("domain_create_sunrise_encoded_signed_mark_no_hosts.xml");
|
||||||
|
persistResource(Registry.get("tld").asBuilder()
|
||||||
|
.setAllowedRegistrantContactIds(ImmutableSet.of("jd1234"))
|
||||||
|
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("somethingelse.example.net"))
|
||||||
|
.build());
|
||||||
|
persistContactsAndHosts();
|
||||||
|
clock.advanceOneMilli();
|
||||||
|
doSuccessfulTest("domain_create_sunrise_encoded_signed_mark_response.xml", true);
|
||||||
|
assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class))
|
||||||
|
.hasApplicationStatus(ApplicationStatus.VALIDATED);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There is special logic that disallows a failfast for domains in add grace period and sunrush
|
* There is special logic that disallows a failfast for domains in add grace period and sunrush
|
||||||
* add grace period, so make sure that they fail anyways in the actual flow.
|
* add grace period, so make sure that they fail anyways in the actual flow.
|
||||||
|
|
|
@ -629,12 +629,11 @@ public class DomainApplicationUpdateFlowTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_newRegistrantNotWhitelisted() throws Exception {
|
public void testFailure_newRegistrantNotWhitelisted() throws Exception {
|
||||||
setEppInput("domain_update_sunrise_registrant_to_tech.xml");
|
|
||||||
persistReferencedEntities();
|
persistReferencedEntities();
|
||||||
persistApplication();
|
persistApplication();
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("tld").asBuilder()
|
Registry.get("tld").asBuilder()
|
||||||
.setAllowedRegistrantContactIds(ImmutableSet.of("sha8013"))
|
.setAllowedRegistrantContactIds(ImmutableSet.of("contact1234"))
|
||||||
.build());
|
.build());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
thrown.expect(RegistrantNotAllowedException.class);
|
thrown.expect(RegistrantNotAllowedException.class);
|
||||||
|
|
|
@ -1241,21 +1241,30 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
persistResource(Registry.get("tld").asBuilder()
|
persistResource(Registry.get("tld").asBuilder()
|
||||||
.setAllowedRegistrantContactIds(ImmutableSet.of("someone"))
|
.setAllowedRegistrantContactIds(ImmutableSet.of("someone"))
|
||||||
.build());
|
.build());
|
||||||
thrown.expect(RegistrantNotAllowedException.class);
|
thrown.expect(RegistrantNotAllowedException.class, "jd1234");
|
||||||
runFlow();
|
runFlow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_nameserverNotWhitelisted() throws Exception {
|
public void testFailure_nameserverNotWhitelisted() throws Exception {
|
||||||
persistActiveHost("ns1.example.com");
|
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
persistResource(Registry.get("tld").asBuilder()
|
persistResource(Registry.get("tld").asBuilder()
|
||||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.someone.tld"))
|
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net"))
|
||||||
.build());
|
.build());
|
||||||
thrown.expect(NameserverNotAllowedException.class);
|
thrown.expect(NameserverNotAllowedException.class, "ns1.example.net");
|
||||||
runFlow();
|
runFlow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_emptyNameserversPassesWhitelist() throws Exception {
|
||||||
|
setEppInput("domain_create_no_hosts_or_dsdata.xml");
|
||||||
|
persistResource(Registry.get("tld").asBuilder()
|
||||||
|
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("somethingelse.example.net"))
|
||||||
|
.build());
|
||||||
|
persistContactsAndHosts();
|
||||||
|
runFlow(); // This is sufficient, as doSuccessfulTests validates hosts, which will fail here.
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_nameserverAndRegistrantWhitelisted() throws Exception {
|
public void testSuccess_nameserverAndRegistrantWhitelisted() throws Exception {
|
||||||
persistResource(Registry.get("tld").asBuilder()
|
persistResource(Registry.get("tld").asBuilder()
|
||||||
|
|
|
@ -1074,12 +1074,11 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_newRegistrantNotWhitelisted() throws Exception {
|
public void testFailure_newRegistrantNotWhitelisted() throws Exception {
|
||||||
setEppInput("domain_update_registrant_to_tech.xml");
|
|
||||||
persistReferencedEntities();
|
persistReferencedEntities();
|
||||||
persistDomain();
|
persistDomain();
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("tld").asBuilder()
|
Registry.get("tld").asBuilder()
|
||||||
.setAllowedRegistrantContactIds(ImmutableSet.of("sha8013"))
|
.setAllowedRegistrantContactIds(ImmutableSet.of("contact1234"))
|
||||||
.build());
|
.build());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
thrown.expect(RegistrantNotAllowedException.class);
|
thrown.expect(RegistrantNotAllowedException.class);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,42 @@
|
||||||
|
// 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.tools;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import com.google.re2j.Matcher;
|
||||||
|
import com.google.re2j.Pattern;
|
||||||
|
|
||||||
|
import google.registry.model.EntityClasses;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/** Unit tests for {@link GetSchemaTreeCommand}. */
|
||||||
|
public class GetSchemaTreeCommandTest extends CommandTestCase<GetSchemaTreeCommand> {
|
||||||
|
@Test
|
||||||
|
public void testAllClassesPrintedExactlyOnce() throws Exception {
|
||||||
|
runCommand();
|
||||||
|
String stdout = getStdoutAsString();
|
||||||
|
for (Class<?> clazz : EntityClasses.ALL_CLASSES) {
|
||||||
|
String printableName = GetSchemaTreeCommand.getPrintableName(clazz);
|
||||||
|
int count = 0;
|
||||||
|
Matcher matcher = Pattern.compile("(^|\\s)" + printableName + "\\s").matcher(stdout);
|
||||||
|
while (matcher.find()) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
assertThat(count).named(printableName + " occurences").isEqualTo(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue