diff --git a/core/src/main/java/google/registry/beam/spec11/ThreatMatch.java b/core/src/main/java/google/registry/beam/spec11/ThreatMatch.java index c509a8a45..e88a3c3df 100644 --- a/core/src/main/java/google/registry/beam/spec11/ThreatMatch.java +++ b/core/src/main/java/google/registry/beam/spec11/ThreatMatch.java @@ -24,22 +24,10 @@ import org.json.JSONObject; public abstract class ThreatMatch implements Serializable { private static final String THREAT_TYPE_FIELD = "threatType"; - private static final String PLATFORM_TYPE_FIELD = "platformType"; - private static final String METADATA_FIELD = "threatEntryMetadata"; private static final String DOMAIN_NAME_FIELD = "fullyQualifiedDomainName"; /** Returns what kind of threat it is (malware, phishing etc.) */ public abstract String threatType(); - /** Returns what platforms it affects (Windows, Linux etc.) */ - abstract String platformType(); - /** - * Returns a String representing a JSON Object containing arbitrary metadata associated with this - * threat, or "NONE" if there is no metadata to retrieve. - * - *
This ideally would be a {@link JSONObject} type, but can't be due to serialization
- * requirements.
- */
- abstract String metadata();
/** Returns the fully qualified domain name [SLD].[TLD] of the matched threat. */
public abstract String fullyQualifiedDomainName();
@@ -52,29 +40,19 @@ public abstract class ThreatMatch implements Serializable {
static ThreatMatch create(JSONObject threatMatchJSON, String fullyQualifiedDomainName)
throws JSONException {
return new AutoValue_ThreatMatch(
- threatMatchJSON.getString(THREAT_TYPE_FIELD),
- threatMatchJSON.getString(PLATFORM_TYPE_FIELD),
- threatMatchJSON.has(METADATA_FIELD)
- ? threatMatchJSON.getJSONObject(METADATA_FIELD).toString()
- : "NONE",
- fullyQualifiedDomainName);
+ threatMatchJSON.getString(THREAT_TYPE_FIELD), fullyQualifiedDomainName);
}
/** Returns a {@link JSONObject} representing a subset of this object's data. */
JSONObject toJSON() throws JSONException {
return new JSONObject()
.put(THREAT_TYPE_FIELD, threatType())
- .put(PLATFORM_TYPE_FIELD, platformType())
- .put(METADATA_FIELD, metadata())
.put(DOMAIN_NAME_FIELD, fullyQualifiedDomainName());
}
/** Parses a {@link JSONObject} and returns an equivalent {@link ThreatMatch}. */
public static ThreatMatch fromJSON(JSONObject threatMatch) throws JSONException {
return new AutoValue_ThreatMatch(
- threatMatch.getString(THREAT_TYPE_FIELD),
- threatMatch.getString(PLATFORM_TYPE_FIELD),
- threatMatch.getString(METADATA_FIELD),
- threatMatch.getString(DOMAIN_NAME_FIELD));
+ threatMatch.getString(THREAT_TYPE_FIELD), threatMatch.getString(DOMAIN_NAME_FIELD));
}
}
diff --git a/core/src/test/java/google/registry/beam/spec11/Spec11PipelineTest.java b/core/src/test/java/google/registry/beam/spec11/Spec11PipelineTest.java
index 6bc25fef0..5e27cef67 100644
--- a/core/src/test/java/google/registry/beam/spec11/Spec11PipelineTest.java
+++ b/core/src/test/java/google/registry/beam/spec11/Spec11PipelineTest.java
@@ -195,14 +195,10 @@ public class Spec11PipelineTest {
new JSONObject()
.put("fullyQualifiedDomainName", "111.com")
.put("threatType", "MALWARE")
- .put("threatEntryMetadata", "NONE")
- .put("platformType", "WINDOWS")
.toString(),
new JSONObject()
.put("fullyQualifiedDomainName", "222.com")
.put("threatType", "MALWARE")
- .put("threatEntryMetadata", "NONE")
- .put("platformType", "WINDOWS")
.toString());
}
diff --git a/core/src/test/java/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java b/core/src/test/java/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java
index 4849f4d69..2b40195d7 100644
--- a/core/src/test/java/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java
+++ b/core/src/test/java/google/registry/reporting/spec11/Spec11RegistrarThreatMatchesParserTest.java
@@ -77,6 +77,26 @@ public class Spec11RegistrarThreatMatchesParserTest {
.hasValue(LocalDate.parse("2018-07-14"));
}
+ @Test
+ public void testSuccess_ignoreExtraFields() throws Exception {
+ ThreatMatch objectWithExtraFields =
+ ThreatMatch.fromJSON(
+ new JSONObject(
+ ImmutableMap.of(
+ "threatType", "MALWARE",
+ "platformType", "ANY_PLATFORM",
+ "threatEntryMetaData", "NONE",
+ "fullyQualifiedDomainName", "c.com")));
+ ThreatMatch objectWithoutExtraFields =
+ ThreatMatch.fromJSON(
+ new JSONObject(
+ ImmutableMap.of(
+ "threatType", "MALWARE",
+ "fullyQualifiedDomainName", "c.com")));
+
+ assertThat(objectWithExtraFields).isEqualTo(objectWithoutExtraFields);
+ }
+
/** The expected contents of the sample spec11 report file */
static ImmutableSet