mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 01:47:14 +02:00
Sort the Spec11 pipeline test output by string length
The JSON object toString isn't necessarily deterministic in its ordering of the keys, so we can only rely on length ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=241003060
This commit is contained in:
parent
d5fbdea37d
commit
315be3eab0
1 changed files with 27 additions and 23 deletions
|
@ -35,6 +35,7 @@ import java.io.InputStreamReader;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import org.apache.beam.runners.direct.DirectRunner;
|
import org.apache.beam.runners.direct.DirectRunner;
|
||||||
import org.apache.beam.sdk.options.PipelineOptions;
|
import org.apache.beam.sdk.options.PipelineOptions;
|
||||||
|
@ -142,11 +143,34 @@ public class Spec11PipelineTest {
|
||||||
.isEqualTo("Map from registrar email to detected subdomain threats:");
|
.isEqualTo("Map from registrar email to detected subdomain threats:");
|
||||||
|
|
||||||
// The output file can put the registrar emails and bad URLs in any order.
|
// The output file can put the registrar emails and bad URLs in any order.
|
||||||
// Sort lexicographically to have a stable ordering
|
// We cannot rely on the JSON toString to sort because the keys are not always in the same
|
||||||
ImmutableList<String> sortedLines = ImmutableList.sortedCopyOf(generatedReport.subList(1, 4));
|
// order, so we must rely on length even though that's not ideal.
|
||||||
|
ImmutableList<String> sortedLines =
|
||||||
|
ImmutableList.sortedCopyOf(
|
||||||
|
Comparator.comparingInt(String::length), generatedReport.subList(1, 4));
|
||||||
|
|
||||||
|
JSONObject noEmailRegistrarJSON = new JSONObject(sortedLines.get(0));
|
||||||
|
assertThat(noEmailRegistrarJSON.get("registrarEmailAddress")).isEqualTo("");
|
||||||
|
assertThat(noEmailRegistrarJSON.has("threatMatches")).isTrue();
|
||||||
|
JSONArray noEmailThreatMatch = noEmailRegistrarJSON.getJSONArray("threatMatches");
|
||||||
|
assertThat(noEmailThreatMatch.length()).isEqualTo(1);
|
||||||
|
assertThat(noEmailThreatMatch.getJSONObject(0).get("fullyQualifiedDomainName"))
|
||||||
|
.isEqualTo("no-email.com");
|
||||||
|
assertThat(noEmailThreatMatch.getJSONObject(0).get("threatType"))
|
||||||
|
.isEqualTo("MALWARE");
|
||||||
|
|
||||||
|
JSONObject someRegistrarJSON = new JSONObject(sortedLines.get(1));
|
||||||
|
assertThat(someRegistrarJSON.get("registrarEmailAddress")).isEqualTo("fake@someRegistrar.com");
|
||||||
|
assertThat(someRegistrarJSON.has("threatMatches")).isTrue();
|
||||||
|
JSONArray someThreatMatch = someRegistrarJSON.getJSONArray("threatMatches");
|
||||||
|
assertThat(someThreatMatch.length()).isEqualTo(1);
|
||||||
|
assertThat(someThreatMatch.getJSONObject(0).get("fullyQualifiedDomainName"))
|
||||||
|
.isEqualTo("444.com");
|
||||||
|
assertThat(someThreatMatch.getJSONObject(0).get("threatType"))
|
||||||
|
.isEqualTo("MALWARE");
|
||||||
|
|
||||||
// theRegistrar has two ThreatMatches, we have to parse it explicitly
|
// theRegistrar has two ThreatMatches, we have to parse it explicitly
|
||||||
JSONObject theRegistrarJSON = new JSONObject(sortedLines.get(0));
|
JSONObject theRegistrarJSON = new JSONObject(sortedLines.get(2));
|
||||||
assertThat(theRegistrarJSON.get("registrarEmailAddress")).isEqualTo("fake@theRegistrar.com");
|
assertThat(theRegistrarJSON.get("registrarEmailAddress")).isEqualTo("fake@theRegistrar.com");
|
||||||
assertThat(theRegistrarJSON.has("threatMatches")).isTrue();
|
assertThat(theRegistrarJSON.has("threatMatches")).isTrue();
|
||||||
JSONArray theThreatMatches = theRegistrarJSON.getJSONArray("threatMatches");
|
JSONArray theThreatMatches = theRegistrarJSON.getJSONArray("threatMatches");
|
||||||
|
@ -169,26 +193,6 @@ public class Spec11PipelineTest {
|
||||||
.put("threatEntryMetadata", "NONE")
|
.put("threatEntryMetadata", "NONE")
|
||||||
.put("platformType", "WINDOWS")
|
.put("platformType", "WINDOWS")
|
||||||
.toString());
|
.toString());
|
||||||
|
|
||||||
JSONObject someRegistrarJSON = new JSONObject(sortedLines.get(1));
|
|
||||||
assertThat(someRegistrarJSON.get("registrarEmailAddress")).isEqualTo("fake@someRegistrar.com");
|
|
||||||
assertThat(someRegistrarJSON.has("threatMatches")).isTrue();
|
|
||||||
JSONArray someThreatMatch = someRegistrarJSON.getJSONArray("threatMatches");
|
|
||||||
assertThat(someThreatMatch.length()).isEqualTo(1);
|
|
||||||
assertThat(someThreatMatch.getJSONObject(0).get("fullyQualifiedDomainName"))
|
|
||||||
.isEqualTo("444.com");
|
|
||||||
assertThat(someThreatMatch.getJSONObject(0).get("threatType"))
|
|
||||||
.isEqualTo("MALWARE");
|
|
||||||
|
|
||||||
JSONObject noEmailRegistrarJSON = new JSONObject(sortedLines.get(2));
|
|
||||||
assertThat(noEmailRegistrarJSON.get("registrarEmailAddress")).isEqualTo("");
|
|
||||||
assertThat(noEmailRegistrarJSON.has("threatMatches")).isTrue();
|
|
||||||
JSONArray noEmailThreatMatch = noEmailRegistrarJSON.getJSONArray("threatMatches");
|
|
||||||
assertThat(noEmailThreatMatch.length()).isEqualTo(1);
|
|
||||||
assertThat(noEmailThreatMatch.getJSONObject(0).get("fullyQualifiedDomainName"))
|
|
||||||
.isEqualTo("no-email.com");
|
|
||||||
assertThat(noEmailThreatMatch.getJSONObject(0).get("threatType"))
|
|
||||||
.isEqualTo("MALWARE");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue