Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/org/labkey/test/tests/elispotassay/ElispotAssayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ public void testMeanAndMedian()
List<String> expected4FMedians = Arrays.asList("0.0", "0.0", "6666.7", "0.0");
List<String> expected6FMeans = Arrays.asList("0.0", "0.0", "0.0", "0.0");
List<String> expected6FMedians = Arrays.asList("0.0", "0.0", "0.0", "0.0");
Bag<List<String>> expectedRows = new HashBag<>(DataRegionTable.collateColumnsIntoRows(
MultiSet<List<String>> expectedRows = new HashMultiSet<>(DataRegionTable.collateColumnsIntoRows(
expectedPtids,
expected2FMeans,
expected2FMedians,
Expand All @@ -766,7 +766,7 @@ public void testMeanAndMedian()
expected6FMeans,
expected6FMedians));

Bag<List<String>> actualRows = new HashBag<>(table.getRows(
MultiSet<List<String>> actualRows = new HashMultiSet<>(table.getRows(
"ParticipantID",
"Atg2FMean",
"Atg2FMedian",
Expand Down
47 changes: 29 additions & 18 deletions src/org/labkey/test/util/CspLogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
public class CspLogUtil
{
private static final List<String> ignoredViolations = List.of(
"/_rstudio/",
"/_rstudioReport/"
"/_rstudio/",
"/_rstudioReport/"
);
private static final Set<String> ignoredDirectives = Collections.emptySet();

Expand Down Expand Up @@ -123,8 +123,8 @@ public static void checkNewCspWarnings(ArtifactCollector artifactCollector)
throw new RuntimeException("Failed to read recent CSP violations.", e);
}

boolean foundVioloation = false;
MultiValuedMap<Crawler.ControllerActionId, String> violoations = new HashSetValuedHashMap<>();
boolean foundViolation = false;
MultiValuedMap<Crawler.ControllerActionId, String> violations = new HashSetValuedHashMap<>();
List<CspReport> cspReports = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (String line : warningLines)
Expand All @@ -137,18 +137,18 @@ public static void checkNewCspWarnings(ArtifactCollector artifactCollector)
{
cspReports.add(new CspReport(sb.toString()));
sb = new StringBuilder();
foundVioloation = true;
foundViolation = true;
}
}

if (!foundVioloation)
if (!foundViolation)
{
throw new AssertionError("Detected CSP violations but unable to parse log file: " + recentWarningsFile.getAbsolutePath());
}

for (CspReport cspReport : cspReports)
{
String url = cspReport.getDocumentUri();
String url = cspReport.getDocumentUrl();
String violatedDirective = cspReport.getViolatedDirective();
if (ignoredViolations.stream().anyMatch(url::contains) || ignoredDirectives.contains(violatedDirective))
{
Expand All @@ -157,20 +157,20 @@ public static void checkNewCspWarnings(ArtifactCollector artifactCollector)
else
{
Crawler.ControllerActionId actionId = new Crawler.ControllerActionId(url);
violoations.put(actionId, cspReport.toString());
violations.put(actionId, cspReport.toString());
}
}

if (!violoations.isEmpty())
if (!violations.isEmpty())
{
StringBuilder errorMessage = new StringBuilder()
.append("Detected CSP violations on the following actions (See log for more detail: ")
.append(recentWarningsFile.getAbsolutePath())
.append("):");
for (Crawler.ControllerActionId actionId : violoations.keySet())
for (Crawler.ControllerActionId actionId : violations.keySet())
{
errorMessage.append("\n\t");
Collection<String> urls = violoations.get(actionId);
Collection<String> urls = violations.get(actionId);
errorMessage.append(actionId);
if (urls.size() > 1)
{
Expand Down Expand Up @@ -221,28 +221,39 @@ public CspWarningDetectedException(Object detailMessage)
class CspReport
{
private final String _violatedDirective;
private final String _documentUri;
private final String _documentUrl;

CspReport(String reportStr)
{
JSONObject report = new JSONObject(reportStr).getJSONObject("csp-report");
_violatedDirective = report.getString("violated-directive");
_documentUri = report.getString("document-uri");
// Support report-uri and report-to reports
JSONObject json = new JSONObject(reportStr);
JSONObject report = json.optJSONObject("body");
if (report != null)
{
_violatedDirective = report.getString("effectiveDirective");
_documentUrl = report.getString("documentURL");
}
else
{
report = json.getJSONObject("csp-report");
_violatedDirective = report.getString("violated-directive");
_documentUrl = report.getString("document-uri");
}
}

public String getViolatedDirective()
{
return _violatedDirective;
}

public String getDocumentUri()
public String getDocumentUrl()
{
return _documentUri;
return _documentUrl;
}

@Override
public String toString()
{
return getViolatedDirective() + ": " + getDocumentUri();
return getViolatedDirective() + ": " + getDocumentUrl();
}
}