Skip to content

Commit 08bad2a

Browse files
committed
Add RST support in Sandbox
Added RST test label files as resources. Added a RstTmchUtils class that loads appropriate labels according to TLD pattern. Temporarily changed label fetching in production to include the TLD string, so that the new class may know which set of labels to use.
1 parent 6f0bc1d commit 08bad2a

File tree

12 files changed

+275
-9
lines changed

12 files changed

+275
-9
lines changed

core/src/main/java/google/registry/flows/domain/DomainClaimsCheckFlow.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public EppResponse run() throws EppException {
108108
verifyClaimsPeriodNotEnded(tld, now);
109109
}
110110
}
111-
Optional<String> claimKey = ClaimsListDao.get().getClaimKey(parsedDomain.parts().get(0));
111+
Optional<String> claimKey =
112+
ClaimsListDao.get(tldStr).getClaimKey(parsedDomain.parts().get(0));
112113
launchChecksBuilder.add(
113114
LaunchCheck.create(
114115
LaunchCheckName.create(claimKey.isPresent(), domainName), claimKey.orElse(null)));

core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public EppResponse run() throws EppException {
280280
checkAllowedAccessToTld(registrarId, tld.getTldStr());
281281
checkHasBillingAccount(registrarId, tld.getTldStr());
282282
boolean isValidReservedCreate = isValidReservedCreate(domainName, allocationToken);
283-
ClaimsList claimsList = ClaimsListDao.get();
283+
ClaimsList claimsList = ClaimsListDao.get(tld.getTldStr());
284284
verifyIsGaOrSpecialCase(
285285
tld,
286286
claimsList,
@@ -312,7 +312,8 @@ public EppResponse run() throws EppException {
312312
// at this point so that we can verify it before the "after validation" extension point.
313313
signedMarkId =
314314
tmchUtils
315-
.verifySignedMarks(launchCreate.get().getSignedMarks(), domainLabel, now)
315+
.verifySignedMarks(
316+
tld.getTldStr(), launchCreate.get().getSignedMarks(), domainLabel, now)
316317
.getId();
317318
}
318319
verifyNotBlockedByBsa(domainName, tld, now, allocationToken);

core/src/main/java/google/registry/flows/domain/DomainFlowTmchUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public DomainFlowTmchUtils(TmchXmlSignature tmchXmlSignature) {
5555
}
5656

5757
public SignedMark verifySignedMarks(
58-
ImmutableList<AbstractSignedMark> signedMarks, String domainLabel, DateTime now)
58+
String tld, ImmutableList<AbstractSignedMark> signedMarks, String domainLabel, DateTime now)
5959
throws EppException {
6060
if (signedMarks.size() > 1) {
6161
throw new TooManySignedMarksException();
@@ -64,7 +64,7 @@ public SignedMark verifySignedMarks(
6464
throw new SignedMarksMustBeEncodedException();
6565
}
6666
SignedMark signedMark =
67-
verifyEncodedSignedMark((EncodedSignedMark) signedMarks.get(0), now);
67+
verifyEncodedSignedMark(tld, (EncodedSignedMark) signedMarks.get(0), now);
6868
return verifySignedMarkValidForDomainLabel(signedMark, domainLabel);
6969
}
7070

@@ -76,8 +76,9 @@ public SignedMark verifySignedMarkValidForDomainLabel(SignedMark signedMark, Str
7676
return signedMark;
7777
}
7878

79-
public SignedMark verifyEncodedSignedMark(EncodedSignedMark encodedSignedMark, DateTime now)
80-
throws EppException {
79+
// TODO(b/412715713): remove the tld parameter when RST completes.
80+
public SignedMark verifyEncodedSignedMark(
81+
String tld, EncodedSignedMark encodedSignedMark, DateTime now) throws EppException {
8182
if (!encodedSignedMark.getEncoding().equals("base64")) {
8283
throw new Base64RequiredForEncodedSignedMarksException();
8384
}
@@ -95,7 +96,7 @@ public SignedMark verifyEncodedSignedMark(EncodedSignedMark encodedSignedMark, D
9596
throw new SignedMarkParsingErrorException();
9697
}
9798

98-
if (SignedMarkRevocationList.get().isSmdRevoked(signedMark.getId(), now)) {
99+
if (SignedMarkRevocationList.get(tld).isSmdRevoked(signedMark.getId(), now)) {
99100
throw new SignedMarkRevokedErrorException();
100101
}
101102

core/src/main/java/google/registry/model/smd/SignedMarkRevocationList.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.common.base.Supplier;
2222
import com.google.common.collect.ImmutableMap;
2323
import google.registry.model.ImmutableObject;
24+
import google.registry.tmch.RstTmchUtils;
2425
import jakarta.persistence.CollectionTable;
2526
import jakarta.persistence.Column;
2627
import jakarta.persistence.ElementCollection;
@@ -71,6 +72,11 @@ public static SignedMarkRevocationList get() {
7172
return CACHE.get();
7273
}
7374

75+
// TODO(b/412715713): remove the tld parameter when RST completes.
76+
public static SignedMarkRevocationList get(String tld) {
77+
return RstTmchUtils.getSmdrList(tld).orElseGet(SignedMarkRevocationList::get);
78+
}
79+
7480
/** Create a new {@link SignedMarkRevocationList} without saving it. */
7581
public static SignedMarkRevocationList create(
7682
DateTime creationTime, ImmutableMap<String, DateTime> revokes) {

core/src/main/java/google/registry/model/tmch/ClaimsListDao.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.annotations.VisibleForTesting;
2323
import com.google.common.collect.ImmutableMap;
2424
import google.registry.model.CacheUtils;
25+
import google.registry.tmch.RstTmchUtils;
2526
import java.time.Duration;
2627
import java.util.Optional;
2728

@@ -72,6 +73,11 @@ public static ClaimsList get() {
7273
return CACHE.get(ClaimsListDao.class);
7374
}
7475

76+
// TODO(b/412715713): remove the tld parameter when RST completes.
77+
public static ClaimsList get(String tld) {
78+
return RstTmchUtils.getClaimsList(tld).orElseGet(ClaimsListDao::get);
79+
}
80+
7581
/**
7682
* Returns the most recent revision of the {@link ClaimsList} in SQL or an empty list if it
7783
* doesn't exist.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2025 The Nomulus Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package google.registry.tmch;
16+
17+
import static com.google.common.base.Suppliers.memoize;
18+
import static com.google.common.io.Resources.getResource;
19+
import static com.google.common.io.Resources.readLines;
20+
import static google.registry.tmch.RstTmchUtils.RstType.OTE;
21+
import static google.registry.tmch.RstTmchUtils.RstType.PROD;
22+
import static google.registry.util.RegistryEnvironment.SANDBOX;
23+
import static java.nio.charset.StandardCharsets.UTF_8;
24+
25+
import com.google.common.base.Supplier;
26+
import com.google.common.collect.ImmutableMap;
27+
import com.google.common.flogger.FluentLogger;
28+
import google.registry.model.smd.SignedMarkRevocationList;
29+
import google.registry.model.tmch.ClaimsList;
30+
import google.registry.util.RegistryEnvironment;
31+
import java.io.IOException;
32+
import java.net.URL;
33+
import java.util.Locale;
34+
import java.util.Optional;
35+
36+
/**
37+
* Utilities supporting TMCH-related RST testing in the Sandbox environment.
38+
*
39+
* <p>For logistic reasons we must conduct RST testing in the Sandbox environments. RST tests
40+
* require the use of special labels hosted on their website. To isolate these labels from regular
41+
* customers conducting onboarding tests, we manually download the test files as resources, and
42+
* serve them up only to RST TLDs.
43+
*/
44+
public class RstTmchUtils {
45+
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
46+
47+
enum RstType {
48+
OTE,
49+
PROD
50+
}
51+
52+
private static final ImmutableMap<RstType, Supplier<Optional<ClaimsList>>> CLAIMS_CACHE =
53+
ImmutableMap.of(
54+
OTE, memoize(() -> getClaimList(OTE)), PROD, memoize(() -> getClaimList(PROD)));
55+
56+
private static final ImmutableMap<RstType, Supplier<Optional<SignedMarkRevocationList>>>
57+
SMDRL_CACHE =
58+
ImmutableMap.of(
59+
OTE, memoize(() -> getSmdrList(OTE)), PROD, memoize(() -> getSmdrList(PROD)));
60+
61+
/**
62+
* Returns appropriate test labels if {@code tld} is for RST testing; otherwise returns {@code
63+
* defaultList}.
64+
*/
65+
public static Optional<ClaimsList> getClaimsList(String tld) {
66+
return getRstType(tld).map(CLAIMS_CACHE::get).flatMap(Supplier::get);
67+
}
68+
69+
/**
70+
* Returns appropriate test labels if {@code tld} is for RST testing; otherwise returns {@code
71+
* defaultList}.
72+
*/
73+
public static Optional<SignedMarkRevocationList> getSmdrList(String tld) {
74+
return getRstType(tld).map(SMDRL_CACHE::get).flatMap(Supplier::get);
75+
}
76+
77+
static Optional<RstType> getRstType(String tld) {
78+
if (!RegistryEnvironment.get().equals(SANDBOX)) {
79+
return Optional.empty();
80+
}
81+
if (tld.startsWith("cc-rst-test-")) {
82+
return Optional.of(OTE);
83+
}
84+
if (tld.startsWith("zz--")) {
85+
return Optional.of(PROD);
86+
}
87+
return Optional.empty();
88+
}
89+
90+
private static Optional<ClaimsList> getClaimList(RstType rstType) {
91+
if (!RegistryEnvironment.get().equals(SANDBOX)) {
92+
return Optional.empty();
93+
}
94+
String resourceName = rstType.name().toLowerCase(Locale.ROOT) + ".rst.dnl.csv";
95+
URL resource = getResource(RstTmchUtils.class, resourceName);
96+
try {
97+
return Optional.of(ClaimsListParser.parse(readLines(resource, UTF_8)));
98+
} catch (IOException fnfe) {
99+
// Do not throw.
100+
logger.atSevere().log("Could not load Claims list for %s in Sandbox.", rstType);
101+
return Optional.empty();
102+
}
103+
}
104+
105+
private static Optional<SignedMarkRevocationList> getSmdrList(RstType rstType) {
106+
if (!RegistryEnvironment.get().equals(SANDBOX)) {
107+
return Optional.empty();
108+
}
109+
String resourceName = rstType.name().toLowerCase(Locale.ROOT) + ".rst.smdrl.csv";
110+
URL resource = getResource(RstTmchUtils.class, resourceName);
111+
try {
112+
return Optional.of(SmdrlCsvParser.parse(readLines(resource, UTF_8)));
113+
} catch (IOException fnfe) {
114+
// Do not throw.
115+
logger.atSevere().log("Could not load Claims list for %s in Sandbox.", rstType);
116+
return Optional.empty();
117+
}
118+
}
119+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1,2024-09-13T02:21:12.0Z
2+
DNL,lookup-key,insertion-datetime
3+
test---validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
4+
test--validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
5+
test-and-validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
6+
test-andvalidate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
7+
test-validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
8+
testand-validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
9+
testandvalidate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
10+
testvalidate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
1,2022-11-22T01:49:36.9Z
2+
smd-id,insertion-datetime
3+
0000001761385117375880-65535,2013-07-15T00:00:00.0Z
4+
0000001751501056761969-65535,2017-07-26T10:12:41.9Z
5+
000000541526299609231-65535,2018-05-14T17:52:23.7Z
6+
000000541602140609520-65535,2020-10-08T07:07:25.0Z
7+
000000541669081776937-65535,2022-11-22T01:49:36.9Z
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
1,2024-09-13T02:21:12.0Z
2+
DNL,lookup-key,insertion-datetime
3+
test---validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
4+
test--validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
5+
test-and-validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
6+
test-andvalidate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
7+
test-validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
8+
testand-validate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
9+
testandvalidate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
10+
testvalidate,2024091300/6/a/b/arJyPPf2CK7f21bVGne0qMgW0000000001,2024-09-13T02:21:12.0Z
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
1,2022-11-22T01:49:36.9Z
2+
smd-id,insertion-datetime
3+
0000001761385117375880-65535,2013-07-15T00:00:00.0Z
4+
0000001751501056761969-65535,2017-07-26T10:12:41.9Z
5+
000000541526299609231-65535,2018-05-14T17:52:23.7Z
6+
000000541602140609520-65535,2020-10-08T07:07:25.0Z
7+
000000541669081776937-65535,2022-11-22T01:49:36.9Z

0 commit comments

Comments
 (0)