mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Add octothorpes to disclaimer in exported reserved list
There's no real standard for commented lines in a CSV, but this seems to be the most well-supported option, so may as well use it. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=211847395
This commit is contained in:
parent
9436ce6f0e
commit
72bfd43e00
6 changed files with 27 additions and 12 deletions
|
@ -19,6 +19,7 @@ import static google.registry.config.ConfigUtils.makeUrl;
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -33,6 +34,7 @@ import java.lang.annotation.Retention;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Qualifier;
|
import javax.inject.Qualifier;
|
||||||
|
@ -1063,7 +1065,13 @@ public final class RegistryConfig {
|
||||||
@Provides
|
@Provides
|
||||||
@Config("reservedTermsExportDisclaimer")
|
@Config("reservedTermsExportDisclaimer")
|
||||||
public static String provideReservedTermsExportDisclaimer(RegistryConfigSettings config) {
|
public static String provideReservedTermsExportDisclaimer(RegistryConfigSettings config) {
|
||||||
return config.registryPolicy.reservedTermsExportDisclaimer;
|
return Splitter.on('\n')
|
||||||
|
.omitEmptyStrings()
|
||||||
|
.trimResults()
|
||||||
|
.splitToList(config.registryPolicy.reservedTermsExportDisclaimer)
|
||||||
|
.stream()
|
||||||
|
.map(s -> "# " + s)
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the clientId of the registrar used by the {@code CheckApiServlet}. */
|
/** Returns the clientId of the registrar used by the {@code CheckApiServlet}. */
|
||||||
|
@ -1390,7 +1398,8 @@ public final class RegistryConfig {
|
||||||
* <p>Memoizing without cache expiration is used because the app must be re-deployed in order to
|
* <p>Memoizing without cache expiration is used because the app must be re-deployed in order to
|
||||||
* change the contents of the YAML config files.
|
* change the contents of the YAML config files.
|
||||||
*/
|
*/
|
||||||
private static final Supplier<RegistryConfigSettings> CONFIG_SETTINGS =
|
@VisibleForTesting
|
||||||
|
static final Supplier<RegistryConfigSettings> CONFIG_SETTINGS =
|
||||||
memoize(YamlUtils::getConfigSettings);
|
memoize(YamlUtils::getConfigSettings);
|
||||||
|
|
||||||
private RegistryConfig() {}
|
private RegistryConfig() {}
|
||||||
|
|
|
@ -6,6 +6,9 @@ registryPolicy:
|
||||||
- notification@test.example
|
- notification@test.example
|
||||||
- notification2@test.example
|
- notification2@test.example
|
||||||
defaultRegistrarWhoisServer: whois.nic.fakewhois.example
|
defaultRegistrarWhoisServer: whois.nic.fakewhois.example
|
||||||
|
reservedTermsExportDisclaimer: |
|
||||||
|
Disclaimer line 1.
|
||||||
|
Line 2 is this 1.
|
||||||
|
|
||||||
datastore:
|
datastore:
|
||||||
commitLogBucketsNum: 3
|
commitLogBucketsNum: 3
|
||||||
|
|
|
@ -37,7 +37,7 @@ public final class ExportUtils {
|
||||||
|
|
||||||
/** Returns the file contents of the auto-export reserved terms document for the given TLD. */
|
/** Returns the file contents of the auto-export reserved terms document for the given TLD. */
|
||||||
public String exportReservedTerms(Registry registry) {
|
public String exportReservedTerms(Registry registry) {
|
||||||
StringBuilder termsBuilder = new StringBuilder(reservedTermsExportDisclaimer);
|
StringBuilder termsBuilder = new StringBuilder(reservedTermsExportDisclaimer).append("\n");
|
||||||
Set<String> reservedTerms = new TreeSet<>();
|
Set<String> reservedTerms = new TreeSet<>();
|
||||||
for (Key<ReservedList> key : registry.getReservedLists()) {
|
for (Key<ReservedList> key : registry.getReservedLists()) {
|
||||||
ReservedList reservedList = ReservedList.load(key).get();
|
ReservedList reservedList = ReservedList.load(key).get();
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
package google.registry.config;
|
package google.registry.config;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.config.RegistryConfig.CONFIG_SETTINGS;
|
||||||
|
import static google.registry.config.RegistryConfig.ConfigModule.provideReservedTermsExportDisclaimer;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -23,13 +25,16 @@ import org.junit.runners.JUnit4;
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class RegistryConfigTest {
|
public class RegistryConfigTest {
|
||||||
|
|
||||||
public RegistryConfigTest() {}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_clientSecretFilename() {
|
public void test_clientSecretFilename() {
|
||||||
// Verify that we're pulling this from the default.
|
// Verify that we're pulling this from the default.
|
||||||
assertThat(RegistryConfig.getClientSecretFilename()).isEqualTo(
|
assertThat(RegistryConfig.getClientSecretFilename()).isEqualTo(
|
||||||
"/google/registry/tools/resources/client_secret.json");
|
"/google/registry/tools/resources/client_secret.json");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_reservedTermsExportDisclaimer_isPrependedWithOctothorpes() {
|
||||||
|
assertThat(provideReservedTermsExportDisclaimer(CONFIG_SETTINGS.get()))
|
||||||
|
.isEqualTo("# Disclaimer line 1.\n" + "# Line 2 is this 1.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class ExportReservedTermsActionTest {
|
||||||
ExportReservedTermsAction action = new ExportReservedTermsAction();
|
ExportReservedTermsAction action = new ExportReservedTermsAction();
|
||||||
action.response = response;
|
action.response = response;
|
||||||
action.driveConnection = driveConnection;
|
action.driveConnection = driveConnection;
|
||||||
action.exportUtils = new ExportUtils("This is a disclaimer.\n");
|
action.exportUtils = new ExportUtils("# This is a disclaimer.");
|
||||||
action.tld = tld;
|
action.tld = tld;
|
||||||
action.run();
|
action.run();
|
||||||
}
|
}
|
||||||
|
@ -85,9 +85,7 @@ public class ExportReservedTermsActionTest {
|
||||||
@Test
|
@Test
|
||||||
public void test_uploadFileToDrive_succeeds() throws Exception {
|
public void test_uploadFileToDrive_succeeds() throws Exception {
|
||||||
runAction("tld");
|
runAction("tld");
|
||||||
byte[] expected =
|
byte[] expected = "# This is a disclaimer.\ncat\nlol\n".getBytes(UTF_8);
|
||||||
("This is a disclaimer.\ncat\nlol\n")
|
|
||||||
.getBytes(UTF_8);
|
|
||||||
verify(driveConnection)
|
verify(driveConnection)
|
||||||
.createOrUpdateFile(RESERVED_TERMS_FILENAME, EXPORT_MIME_TYPE, "brouhaha", expected);
|
.createOrUpdateFile(RESERVED_TERMS_FILENAME, EXPORT_MIME_TYPE, "brouhaha", expected);
|
||||||
verify(response).setStatus(SC_OK);
|
verify(response).setStatus(SC_OK);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class ExportUtilsTest {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
persistResource(Registry.get("tld").asBuilder().setReservedLists(rl1, rl2, rl3).build());
|
persistResource(Registry.get("tld").asBuilder().setReservedLists(rl1, rl2, rl3).build());
|
||||||
// Should not contain jimmy, tine, or oval.
|
// Should not contain jimmy, tine, or oval.
|
||||||
assertThat(new ExportUtils("This is a disclaimer.\n").exportReservedTerms(Registry.get("tld")))
|
assertThat(new ExportUtils("# This is a disclaimer.").exportReservedTerms(Registry.get("tld")))
|
||||||
.isEqualTo("This is a disclaimer.\ncat\nlol\nsnow\n");
|
.isEqualTo("# This is a disclaimer.\ncat\nlol\nsnow\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue