mirror of
https://github.com/google/nomulus.git
synced 2025-07-26 04:28:34 +02:00
Add fallback for Spec11 ThreatMatch parser (#1806)
This commit is contained in:
parent
fe3472d31d
commit
b83c970af4
2 changed files with 25 additions and 1 deletions
|
@ -26,6 +26,7 @@ public abstract class ThreatMatch implements Serializable {
|
||||||
|
|
||||||
private static final String THREAT_TYPE_FIELD = "threatType";
|
private static final String THREAT_TYPE_FIELD = "threatType";
|
||||||
private static final String DOMAIN_NAME_FIELD = "domainName";
|
private static final String DOMAIN_NAME_FIELD = "domainName";
|
||||||
|
private static final String OUTDATED_NAME_FIELD = "fullyQualifiedDomainName";
|
||||||
|
|
||||||
/** Returns what kind of threat it is (malware, phishing etc.) */
|
/** Returns what kind of threat it is (malware, phishing etc.) */
|
||||||
public abstract String threatType();
|
public abstract String threatType();
|
||||||
|
@ -46,7 +47,12 @@ public abstract class ThreatMatch implements Serializable {
|
||||||
|
|
||||||
/** Parses a {@link JSONObject} and returns an equivalent {@link ThreatMatch}. */
|
/** Parses a {@link JSONObject} and returns an equivalent {@link ThreatMatch}. */
|
||||||
public static ThreatMatch fromJSON(JSONObject threatMatch) throws JSONException {
|
public static ThreatMatch fromJSON(JSONObject threatMatch) throws JSONException {
|
||||||
|
// TODO: delete OUTDATED_NAME_FIELD once we no longer process reports saved with
|
||||||
|
// fullyQualifiedDomainName in them, likely 2023
|
||||||
return new AutoValue_ThreatMatch(
|
return new AutoValue_ThreatMatch(
|
||||||
threatMatch.getString(THREAT_TYPE_FIELD), threatMatch.getString(DOMAIN_NAME_FIELD));
|
threatMatch.getString(THREAT_TYPE_FIELD),
|
||||||
|
threatMatch.has(OUTDATED_NAME_FIELD)
|
||||||
|
? threatMatch.getString(OUTDATED_NAME_FIELD)
|
||||||
|
: threatMatch.getString(DOMAIN_NAME_FIELD));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,24 @@ public class Spec11RegistrarThreatMatchesParserTest {
|
||||||
assertThat(objectWithExtraFields).isEqualTo(objectWithoutExtraFields);
|
assertThat(objectWithExtraFields).isEqualTo(objectWithoutExtraFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSuccess_worksWithOutdatedField() throws Exception {
|
||||||
|
ThreatMatch objectWithOutdatedField =
|
||||||
|
ThreatMatch.fromJSON(
|
||||||
|
new JSONObject(
|
||||||
|
ImmutableMap.of(
|
||||||
|
"threatType", "MALWARE",
|
||||||
|
"fullyQualifiedDomainName", "c.com")));
|
||||||
|
ThreatMatch objectWithoutOutdatedFields =
|
||||||
|
ThreatMatch.fromJSON(
|
||||||
|
new JSONObject(
|
||||||
|
ImmutableMap.of(
|
||||||
|
"threatType", "MALWARE",
|
||||||
|
"domainName", "c.com")));
|
||||||
|
|
||||||
|
assertThat(objectWithOutdatedField).isEqualTo(objectWithoutOutdatedFields);
|
||||||
|
}
|
||||||
|
|
||||||
/** The expected contents of the sample spec11 report file */
|
/** The expected contents of the sample spec11 report file */
|
||||||
public static ImmutableSet<RegistrarThreatMatches> sampleThreatMatches() throws Exception {
|
public static ImmutableSet<RegistrarThreatMatches> sampleThreatMatches() throws Exception {
|
||||||
return ImmutableSet.of(getMatchA(), getMatchB());
|
return ImmutableSet.of(getMatchA(), getMatchB());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue