Include TLD in reserved/registered lists too (#2725)

We already do this for premium terms, but it's nice to do it for the
other list types too

https://b.corp.google.com/issues/390053672
This commit is contained in:
gbrodman
2025-03-24 15:52:12 +00:00
committed by GitHub
parent 20fd944e83
commit 967d04efce
4 changed files with 21 additions and 18 deletions
@@ -78,7 +78,7 @@ public class ExportDomainListsAction implements Runnable {
ORDER BY d.domain_name"""; ORDER BY d.domain_name""";
// This may be a CSV, but it is uses a .txt file extension for back-compatibility // This may be a CSV, but it is uses a .txt file extension for back-compatibility
static final String REGISTERED_DOMAINS_FILENAME = "registered_domains.txt"; static final String REGISTERED_DOMAINS_FILENAME_FORMAT = "registered_domains_%s.txt";
@Inject Clock clock; @Inject Clock clock;
@Inject DriveConnection driveConnection; @Inject DriveConnection driveConnection;
@@ -146,7 +146,7 @@ public class ExportDomainListsAction implements Runnable {
} else { } else {
String resultMsg = String resultMsg =
driveConnection.createOrUpdateFile( driveConnection.createOrUpdateFile(
REGISTERED_DOMAINS_FILENAME, String.format(REGISTERED_DOMAINS_FILENAME_FORMAT, tldStr),
MediaType.PLAIN_TEXT_UTF_8, MediaType.PLAIN_TEXT_UTF_8,
tld.getDriveFolderId(), tld.getDriveFolderId(),
domains.getBytes(UTF_8)); domains.getBytes(UTF_8));
@@ -43,7 +43,7 @@ public class ExportReservedTermsAction implements Runnable {
private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
static final MediaType EXPORT_MIME_TYPE = MediaType.PLAIN_TEXT_UTF_8; static final MediaType EXPORT_MIME_TYPE = MediaType.PLAIN_TEXT_UTF_8;
static final String RESERVED_TERMS_FILENAME = "reserved_terms.txt"; static final String RESERVED_TERMS_FILENAME_FORMAT = "reserved_terms_%s.txt";
@Inject DriveConnection driveConnection; @Inject DriveConnection driveConnection;
@Inject ExportUtils exportUtils; @Inject ExportUtils exportUtils;
@@ -79,7 +79,7 @@ public class ExportReservedTermsAction implements Runnable {
} else { } else {
resultMsg = resultMsg =
driveConnection.createOrUpdateFile( driveConnection.createOrUpdateFile(
RESERVED_TERMS_FILENAME, String.format(RESERVED_TERMS_FILENAME_FORMAT, tldStr),
EXPORT_MIME_TYPE, EXPORT_MIME_TYPE,
tld.getDriveFolderId(), tld.getDriveFolderId(),
exportUtils.exportReservedTerms(tld).getBytes(UTF_8)); exportUtils.exportReservedTerms(tld).getBytes(UTF_8));
@@ -15,7 +15,6 @@
package google.registry.export; package google.registry.export;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.export.ExportDomainListsAction.REGISTERED_DOMAINS_FILENAME;
import static google.registry.model.common.FeatureFlag.FeatureName.INCLUDE_PENDING_DELETE_DATE_FOR_DOMAINS; import static google.registry.model.common.FeatureFlag.FeatureName.INCLUDE_PENDING_DELETE_DATE_FOR_DOMAINS;
import static google.registry.model.common.FeatureFlag.FeatureStatus.ACTIVE; import static google.registry.model.common.FeatureFlag.FeatureStatus.ACTIVE;
import static google.registry.model.common.FeatureFlag.FeatureStatus.INACTIVE; import static google.registry.model.common.FeatureFlag.FeatureStatus.INACTIVE;
@@ -83,10 +82,11 @@ class ExportDomainListsActionTest {
persistFeatureFlag(INACTIVE); persistFeatureFlag(INACTIVE);
} }
private void verifyExportedToDrive(String folderId, String domains) throws Exception { private void verifyExportedToDrive(String folderId, String filename, String domains)
throws Exception {
verify(driveConnection) verify(driveConnection)
.createOrUpdateFile( .createOrUpdateFile(
eq(REGISTERED_DOMAINS_FILENAME), eq(filename),
eq(MediaType.PLAIN_TEXT_UTF_8), eq(MediaType.PLAIN_TEXT_UTF_8),
eq(folderId), eq(folderId),
bytesExportedToDrive.capture()); bytesExportedToDrive.capture());
@@ -103,7 +103,7 @@ class ExportDomainListsActionTest {
String tlds = new String(gcsUtils.readBytesFrom(existingFile), UTF_8); String tlds = new String(gcsUtils.readBytesFrom(existingFile), UTF_8);
// Check that it only contains the active domains, not the dead one. // Check that it only contains the active domains, not the dead one.
assertThat(tlds).isEqualTo("onetwo.tld\nrudnitzky.tld"); assertThat(tlds).isEqualTo("onetwo.tld\nrudnitzky.tld");
verifyExportedToDrive("brouhaha", "onetwo.tld\nrudnitzky.tld"); verifyExportedToDrive("brouhaha", "registered_domains_tld.txt", "onetwo.tld\nrudnitzky.tld");
verifyNoMoreInteractions(driveConnection); verifyNoMoreInteractions(driveConnection);
} }
@@ -118,7 +118,7 @@ class ExportDomainListsActionTest {
String tlds = new String(gcsUtils.readBytesFrom(existingFile), UTF_8); String tlds = new String(gcsUtils.readBytesFrom(existingFile), UTF_8);
// Check that it only contains the active domains, not the dead one. // Check that it only contains the active domains, not the dead one.
assertThat(tlds).isEqualTo("onetwo.tld,\nrudnitzky.tld,"); assertThat(tlds).isEqualTo("onetwo.tld,\nrudnitzky.tld,");
verifyExportedToDrive("brouhaha", "onetwo.tld,\nrudnitzky.tld,"); verifyExportedToDrive("brouhaha", "registered_domains_tld.txt", "onetwo.tld,\nrudnitzky.tld,");
verifyNoMoreInteractions(driveConnection); verifyNoMoreInteractions(driveConnection);
} }
@@ -137,7 +137,7 @@ class ExportDomainListsActionTest {
assertThrows(StorageException.class, () -> gcsUtils.readBytesFrom(nonexistentFile)); assertThrows(StorageException.class, () -> gcsUtils.readBytesFrom(nonexistentFile));
ImmutableList<String> ls = gcsUtils.listFolderObjects("outputbucket", ""); ImmutableList<String> ls = gcsUtils.listFolderObjects("outputbucket", "");
assertThat(ls).containsExactly("tld.txt"); assertThat(ls).containsExactly("tld.txt");
verifyExportedToDrive("brouhaha", "onetwo.tld\nrudnitzky.tld"); verifyExportedToDrive("brouhaha", "registered_domains_tld.txt", "onetwo.tld\nrudnitzky.tld");
verifyNoMoreInteractions(driveConnection); verifyNoMoreInteractions(driveConnection);
} }
@@ -157,7 +157,7 @@ class ExportDomainListsActionTest {
assertThrows(StorageException.class, () -> gcsUtils.readBytesFrom(nonexistentFile)); assertThrows(StorageException.class, () -> gcsUtils.readBytesFrom(nonexistentFile));
ImmutableList<String> ls = gcsUtils.listFolderObjects("outputbucket", ""); ImmutableList<String> ls = gcsUtils.listFolderObjects("outputbucket", "");
assertThat(ls).containsExactly("tld.txt"); assertThat(ls).containsExactly("tld.txt");
verifyExportedToDrive("brouhaha", "onetwo.tld,\nrudnitzky.tld,"); verifyExportedToDrive("brouhaha", "registered_domains_tld.txt", "onetwo.tld,\nrudnitzky.tld,");
verifyNoMoreInteractions(driveConnection); verifyNoMoreInteractions(driveConnection);
} }
@@ -189,7 +189,9 @@ class ExportDomainListsActionTest {
action.run(); action.run();
verifyExportedToDrive( verifyExportedToDrive(
"brouhaha", "active.tld,\npendingdelete.tld,2020-02-05T02:02:02.000Z\nredemption.tld,"); "brouhaha",
"registered_domains_tld.txt",
"active.tld,\npendingdelete.tld,2020-02-05T02:02:02.000Z\nredemption.tld,");
} }
@Test @Test
@@ -215,8 +217,9 @@ class ExportDomainListsActionTest {
BlobId thirdTldFile = BlobId.of("outputbucket", "tldthree.txt"); BlobId thirdTldFile = BlobId.of("outputbucket", "tldthree.txt");
String evenMoreTlds = new String(gcsUtils.readBytesFrom(thirdTldFile), UTF_8).trim(); String evenMoreTlds = new String(gcsUtils.readBytesFrom(thirdTldFile), UTF_8).trim();
assertThat(evenMoreTlds).isEqualTo("cupid.tldthree"); assertThat(evenMoreTlds).isEqualTo("cupid.tldthree");
verifyExportedToDrive("brouhaha", "dasher.tld\nprancer.tld"); verifyExportedToDrive("brouhaha", "registered_domains_tld.txt", "dasher.tld\nprancer.tld");
verifyExportedToDrive("hooray", "buddy.tldtwo\nrudolph.tldtwo\nsanta.tldtwo"); verifyExportedToDrive(
"hooray", "registered_domains_tldtwo.txt", "buddy.tldtwo\nrudolph.tldtwo\nsanta.tldtwo");
// tldthree does not have a drive id, so no export to drive is performed. // tldthree does not have a drive id, so no export to drive is performed.
verifyNoMoreInteractions(driveConnection); verifyNoMoreInteractions(driveConnection);
} }
@@ -245,8 +248,9 @@ class ExportDomainListsActionTest {
BlobId thirdTldFile = BlobId.of("outputbucket", "tldthree.txt"); BlobId thirdTldFile = BlobId.of("outputbucket", "tldthree.txt");
String evenMoreTlds = new String(gcsUtils.readBytesFrom(thirdTldFile), UTF_8).trim(); String evenMoreTlds = new String(gcsUtils.readBytesFrom(thirdTldFile), UTF_8).trim();
assertThat(evenMoreTlds).isEqualTo("cupid.tldthree,"); assertThat(evenMoreTlds).isEqualTo("cupid.tldthree,");
verifyExportedToDrive("brouhaha", "dasher.tld,\nprancer.tld,"); verifyExportedToDrive("brouhaha", "registered_domains_tld.txt", "dasher.tld,\nprancer.tld,");
verifyExportedToDrive("hooray", "buddy.tldtwo,\nrudolph.tldtwo,\nsanta.tldtwo,"); verifyExportedToDrive(
"hooray", "registered_domains_tldtwo.txt", "buddy.tldtwo,\nrudolph.tldtwo,\nsanta.tldtwo,");
// tldthree does not have a drive id, so no export to drive is performed. // tldthree does not have a drive id, so no export to drive is performed.
verifyNoMoreInteractions(driveConnection); verifyNoMoreInteractions(driveConnection);
} }
@@ -16,7 +16,6 @@ package google.registry.export;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.export.ExportReservedTermsAction.EXPORT_MIME_TYPE; import static google.registry.export.ExportReservedTermsAction.EXPORT_MIME_TYPE;
import static google.registry.export.ExportReservedTermsAction.RESERVED_TERMS_FILENAME;
import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistReservedList; import static google.registry.testing.DatabaseHelper.persistReservedList;
import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.testing.DatabaseHelper.persistResource;
@@ -77,7 +76,7 @@ public class ExportReservedTermsActionTest {
runAction("tld"); runAction("tld");
byte[] expected = "# This is a disclaimer.\ncat\nlol\n".getBytes(UTF_8); byte[] expected = "# 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_tld.txt", EXPORT_MIME_TYPE, "brouhaha", expected);
assertThat(response.getStatus()).isEqualTo(SC_OK); assertThat(response.getStatus()).isEqualTo(SC_OK);
assertThat(response.getPayload()).isEqualTo("1001"); assertThat(response.getPayload()).isEqualTo("1001");
} }