mirror of
https://github.com/google/nomulus
synced 2026-09-18 22:14:23 +00:00
Don't allow a list of the empty string in List<String> fields (#2011)
If the user does, e.g. `--allowed_nameservers=` (or contact ids) that shouldn't mean a list consisting solely of the empty string. Using this parameter / converter allows us to ensure that lists of strings look reasonable.
This commit is contained in:
@@ -321,28 +321,6 @@ class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarCommand>
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_ipAllowListFlagNull() throws Exception {
|
||||
runCommandForced(
|
||||
"--name=blobio",
|
||||
"--password=some_password",
|
||||
"--registrar_type=REAL",
|
||||
"--iana_id=8",
|
||||
"--ip_allow_list=null",
|
||||
"--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.loadByRegistrarId("clientz");
|
||||
assertThat(registrar).isPresent();
|
||||
assertThat(registrar.get().getIpAddressAllowList()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_clientCertFileFlag() throws Exception {
|
||||
fakeClock.setTo(DateTime.parse("2020-11-01T00:00:00Z"));
|
||||
|
||||
@@ -451,6 +451,16 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||
.containsExactly("alice", "bob");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_emptyAllowedRegistrants() throws Exception {
|
||||
runCommandForced(
|
||||
"--allowed_registrants=",
|
||||
"--roid_suffix=Q9JYB4C",
|
||||
"--dns_writers=VoidDnsWriter",
|
||||
"xn--q9jyb4c");
|
||||
assertThat(Tld.get("xn--q9jyb4c").getAllowedRegistrantContactIds()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_setAllowedNameservers() throws Exception {
|
||||
runCommandForced(
|
||||
@@ -462,6 +472,16 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||
.containsExactly("ns1.example.com", "ns2.example.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_emptyAllowedNameservers() throws Exception {
|
||||
runCommandForced(
|
||||
"--allowed_nameservers=",
|
||||
"--roid_suffix=Q9JYB4C",
|
||||
"--dns_writers=FooDnsWriter",
|
||||
"xn--q9jyb4c");
|
||||
assertThat(Tld.get("xn--q9jyb4c").getAllowedFullyQualifiedHostNames()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_setCommonReservedListOnTld() throws Exception {
|
||||
runSuccessfulReservedListsTest("common_abuse");
|
||||
|
||||
@@ -207,21 +207,6 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
|
||||
.inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_clearIpAllowList_useNull() throws Exception {
|
||||
persistResource(
|
||||
loadRegistrar("NewRegistrar")
|
||||
.asBuilder()
|
||||
.setIpAddressAllowList(
|
||||
ImmutableList.of(
|
||||
CidrAddressBlock.create("192.168.1.1"),
|
||||
CidrAddressBlock.create("192.168.0.2/16")))
|
||||
.build());
|
||||
assertThat(loadRegistrar("NewRegistrar").getIpAddressAllowList()).isNotEmpty();
|
||||
runCommand("--ip_allow_list=null", "--force", "NewRegistrar");
|
||||
assertThat(loadRegistrar("NewRegistrar").getIpAddressAllowList()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_clearIpAllowList_useEmpty() throws Exception {
|
||||
persistResource(
|
||||
|
||||
@@ -429,6 +429,17 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
|
||||
.containsExactly("alice", "bob");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_emptyAllowedRegistrants() throws Exception {
|
||||
persistResource(
|
||||
Tld.get("xn--q9jyb4c")
|
||||
.asBuilder()
|
||||
.setAllowedRegistrantContactIds(ImmutableSet.of("jane", "john"))
|
||||
.build());
|
||||
runCommandForced("--allowed_registrants=", "xn--q9jyb4c");
|
||||
assertThat(Tld.get("xn--q9jyb4c").getAllowedRegistrantContactIds()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_addAllowedRegistrants() throws Exception {
|
||||
persistResource(
|
||||
@@ -483,6 +494,17 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
|
||||
.containsExactly("ns1.example.com", "ns2.example.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_emptyAllowedNameservers() throws Exception {
|
||||
persistResource(
|
||||
Tld.get("xn--q9jyb4c")
|
||||
.asBuilder()
|
||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.com"))
|
||||
.build());
|
||||
runCommandForced("--allowed_nameservers=", "xn--q9jyb4c");
|
||||
assertThat(Tld.get("xn--q9jyb4c").getAllowedFullyQualifiedHostNames()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_addAllowedNameservers() throws Exception {
|
||||
persistResource(
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2023 The Nomulus 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.params;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Tests for {@link StringListParameter}. */
|
||||
public class StringListParameterTest {
|
||||
|
||||
private final StringListParameter instance = new StringListParameter();
|
||||
|
||||
@Test
|
||||
void testSingleItem() {
|
||||
assertThat(instance.convert("foo")).containsExactly("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultipleItems() {
|
||||
assertThat(instance.convert("foo,bar")).containsExactly("foo", "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOmitsEmpty() {
|
||||
assertThat(instance.convert("foo,,bar")).containsExactly("foo", "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntirelyEmpty() {
|
||||
assertThat(instance.convert("")).isEmpty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user