Skip to content

Commit 22ca4e3

Browse files
authored
Disable old fee extensions in non-prod envs (#2933)
The primary annoyance with this is that it means we need (or at least, should) split all tests that use the fee extension into two separate tests -- one that simulates non-prod environments, and one that simulates prod environments. This leads to duplication of many tests but that's fine since this is theoretically temporary.
1 parent f271364 commit 22ca4e3

File tree

134 files changed

+7188
-2793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+7188
-2793
lines changed

config/presubmits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def fails(self, file):
9898
"File did not include the license header.",
9999

100100
# Files must end in a newline
101-
PresubmitCheck(r".*\n$", ("java", "js", "soy", "sql", "py", "sh", "gradle", "ts"),
102-
{"node_modules/"}, REQUIRED):
101+
PresubmitCheck(r".*\n$", ("java", "js", "soy", "sql", "py", "sh", "gradle", "ts", "xml"),
102+
{"node_modules/", ".idea"}, REQUIRED):
103103
"Source files must end in a newline.",
104104

105105
# System.(out|err).println should only appear in tools/ or load-testing/

core/src/main/java/google/registry/model/eppcommon/EppXmlTransformer.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import google.registry.model.ImmutableObject;
2424
import google.registry.model.eppinput.EppInput;
2525
import google.registry.model.eppoutput.EppOutput;
26+
import google.registry.util.NonFinalForTesting;
2627
import google.registry.util.RegistryEnvironment;
2728
import google.registry.xml.ValidationMode;
2829
import google.registry.xml.XmlException;
@@ -60,20 +61,35 @@ public class EppXmlTransformer {
6061
// XML schemas that should not be used in production (yet)
6162
private static final ImmutableSet<String> NON_PROD_SCHEMAS = ImmutableSet.of("fee-std-v1.xsd");
6263

63-
private static final XmlTransformer INPUT_TRANSFORMER =
64+
// XML schemas that should only be used in production (for backcompat)
65+
private static final ImmutableSet<String> ONLY_PROD_SCHEMAS =
66+
ImmutableSet.of("fee06.xsd", "fee11.xsd", "fee12.xsd");
67+
68+
// TODO(gbrodman): make this final when we can actually remove the old fee extensions and aren't
69+
// relying on switching by environment
70+
@NonFinalForTesting
71+
private static XmlTransformer INPUT_TRANSFORMER =
6472
new XmlTransformer(getSchemas(), EppInput.class);
6573

66-
private static final XmlTransformer OUTPUT_TRANSFORMER =
74+
// TODO(gbrodman): make this final when we can actually remove the old fee extensions and aren't
75+
// relying on switching by environment
76+
@NonFinalForTesting
77+
private static XmlTransformer OUTPUT_TRANSFORMER =
6778
new XmlTransformer(getSchemas(), EppOutput.class);
6879

6980
@VisibleForTesting
7081
public static ImmutableList<String> getSchemas() {
71-
if (RegistryEnvironment.get().equals(RegistryEnvironment.PRODUCTION)) {
72-
return ALL_SCHEMAS.stream()
73-
.filter(s -> !NON_PROD_SCHEMAS.contains(s))
74-
.collect(toImmutableList());
75-
}
76-
return ALL_SCHEMAS;
82+
ImmutableSet<String> schemasToSkip =
83+
RegistryEnvironment.get().equals(RegistryEnvironment.PRODUCTION)
84+
? NON_PROD_SCHEMAS
85+
: ONLY_PROD_SCHEMAS;
86+
return ALL_SCHEMAS.stream().filter(s -> !schemasToSkip.contains(s)).collect(toImmutableList());
87+
}
88+
89+
@VisibleForTesting
90+
public static void reloadTransformers() {
91+
INPUT_TRANSFORMER = new XmlTransformer(getSchemas(), EppInput.class);
92+
OUTPUT_TRANSFORMER = new XmlTransformer(getSchemas(), EppOutput.class);
7793
}
7894

7995
public static void validateOutput(String xml) throws XmlException {

core/src/main/java/google/registry/model/eppcommon/ProtocolDefinition.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static com.google.common.collect.ImmutableSet.toImmutableSet;
1818
import static com.google.common.collect.Maps.uniqueIndex;
1919

20+
import com.google.common.annotations.VisibleForTesting;
2021
import com.google.common.collect.ImmutableMap;
2122
import com.google.common.collect.ImmutableSet;
2223
import google.registry.model.domain.fee06.FeeCheckCommandExtensionV06;
@@ -33,6 +34,7 @@
3334
import google.registry.model.domain.secdns.SecDnsCreateExtension;
3435
import google.registry.model.eppinput.EppInput.CommandExtension;
3536
import google.registry.model.eppoutput.EppResponse.ResponseExtension;
37+
import google.registry.util.NonFinalForTesting;
3638
import google.registry.util.RegistryEnvironment;
3739
import jakarta.xml.bind.annotation.XmlSchema;
3840
import java.util.EnumSet;
@@ -62,15 +64,15 @@ public enum ServiceExtension {
6264
FEE_0_6(
6365
FeeCheckCommandExtensionV06.class,
6466
FeeCheckResponseExtensionV06.class,
65-
ServiceExtensionVisibility.ALL),
67+
ServiceExtensionVisibility.ONLY_IN_PRODUCTION),
6668
FEE_0_11(
6769
FeeCheckCommandExtensionV11.class,
6870
FeeCheckResponseExtensionV11.class,
69-
ServiceExtensionVisibility.ALL),
71+
ServiceExtensionVisibility.ONLY_IN_PRODUCTION),
7072
FEE_0_12(
7173
FeeCheckCommandExtensionV12.class,
7274
FeeCheckResponseExtensionV12.class,
73-
ServiceExtensionVisibility.ALL),
75+
ServiceExtensionVisibility.ONLY_IN_PRODUCTION),
7476
FEE_1_00(
7577
FeeCheckCommandExtensionStdV1.class,
7678
FeeCheckResponseExtensionStdV1.class,
@@ -109,7 +111,7 @@ public static String getCommandExtensionUri(Class<? extends CommandExtension> cl
109111
return clazz.getPackage().getAnnotation(XmlSchema.class).namespace();
110112
}
111113

112-
private boolean isVisible() {
114+
public boolean isVisible() {
113115
return switch (visibility) {
114116
case ALL -> true;
115117
case ONLY_IN_PRODUCTION -> RegistryEnvironment.get().equals(RegistryEnvironment.PRODUCTION);
@@ -134,14 +136,25 @@ public static ServiceExtension getServiceExtensionFromUri(String uri) {
134136
}
135137

136138
/** A set of all the visible extension URIs. */
137-
private static final ImmutableSet<String> visibleServiceExtensionUris =
138-
EnumSet.allOf(ServiceExtension.class).stream()
139-
.filter(ServiceExtension::isVisible)
140-
.map(ServiceExtension::getUri)
141-
.collect(toImmutableSet());
139+
// TODO(gbrodman): make this final when we can actually remove the old fee extensions and aren't
140+
// relying on switching by environment
141+
@NonFinalForTesting private static ImmutableSet<String> visibleServiceExtensionUris;
142+
143+
static {
144+
reloadServiceExtensionUris();
145+
}
142146

143147
/** Return the set of all visible service extension URIs. */
144148
public static ImmutableSet<String> getVisibleServiceExtensionUris() {
145149
return visibleServiceExtensionUris;
146150
}
151+
152+
@VisibleForTesting
153+
public static void reloadServiceExtensionUris() {
154+
visibleServiceExtensionUris =
155+
EnumSet.allOf(ServiceExtension.class).stream()
156+
.filter(ServiceExtension::isVisible)
157+
.map(ServiceExtension::getUri)
158+
.collect(toImmutableSet());
159+
}
147160
}

core/src/test/java/google/registry/flows/FlowTestCase.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,28 +135,6 @@ protected String loadFile(String filename, Map<String, String> substitutions) {
135135
return TestDataHelper.loadFile(getClass(), filename, substitutions);
136136
}
137137

138-
/**
139-
* Converts an input or response EPP message with draft fee extension v12 to std v1.
140-
*
141-
* <p>There is no practical changes between draft v12 and the v1 standard. This method allows us
142-
* to reuse v12 test data.
143-
*/
144-
protected String loadFeeV12FileAsStdV1(String filename) {
145-
String content = loadFile(filename);
146-
return content.replace("urn:ietf:params:xml:ns:fee-0.12", "urn:ietf:params:xml:ns:epp:fee-1.0");
147-
}
148-
149-
/**
150-
* Converts an input or response EPP message with draft fee extension v12 to std v1.
151-
*
152-
* <p>There is no practical changes between draft v12 and the v1 standard. This method allows us
153-
* to reuse v12 test data.
154-
*/
155-
protected String loadFeeV12FileAsStdV1(String filename, Map<String, String> substitutions) {
156-
String content = loadFile(filename, substitutions);
157-
return content.replace("urn:ietf:params:xml:ns:fee-0.12", "urn:ietf:params:xml:ns:epp:fee-1.0");
158-
}
159-
160138
@Nullable
161139
protected String getClientTrid() throws Exception {
162140
return eppLoader.getEpp().getCommandWrapper().getClTrid().orElse(null);

0 commit comments

Comments
 (0)