Skip to content

Commit

Permalink
Merge pull request #25 from tls-attacker/summarizable-result
Browse files Browse the repository at this point in the history
Implement Summarizable and Detailed Results
  • Loading branch information
mmaehren authored Nov 17, 2023
2 parents 4cad651 + 5e9e368 commit 1704ba1
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Scanner Core - A modular framework for probe definition, execution, and result analysis.
*
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
*
* Licensed under Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package de.rub.nds.scanner.core.probe.result;

import java.io.Serializable;

public class DetailedResult<T extends Serializable> implements SummarizableTestResult {

public static <T extends Serializable> DetailedResult<T> TRUE() {
return new DetailedResult<>(TestResults.TRUE);
}

public static <T extends Serializable> DetailedResult<T> TRUE(T details) {
return new DetailedResult<>(TestResults.TRUE, details);
}

public static <T extends Serializable> DetailedResult<T> FALSE() {
return new DetailedResult<>(TestResults.FALSE);
}

public static <T extends Serializable> DetailedResult<T> FALSE(T details) {
return new DetailedResult<>(TestResults.FALSE, details);
}

private final T details;
private final TestResults summary;

public DetailedResult(TestResults summary, T details) {
this.details = details;
this.summary = summary;
}

public DetailedResult(TestResults summary) {
this(summary, null);
}

public T getDetails() {
return details;
}

@Override
public TestResults getSummarizedResult() {
return summary;
}

@Override
public boolean isExplicitSummary() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Scanner Core - A modular framework for probe definition, execution, and result analysis.
*
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
*
* Licensed under Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package de.rub.nds.scanner.core.probe.result;

/**
* A complex test result that can still be summarized into a single TestResults. This summary might
* be generated on the fly (from the contained details), or set explicitly (e.g. in case of an
* error)
*/
public interface SummarizableTestResult extends TestResult {
TestResults getSummarizedResult();

/**
* @return Whether the summary was explicitly set instead of generated on the fly.
*/
boolean isExplicitSummary();

@Override
default boolean equalsExpectedResult(TestResult other) {
if (other instanceof TestResults) {
return getSummarizedResult().equals(other);
}
return this.equals(other);
}

@Override
default String getName() {
return getSummarizedResult().getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
*/
package de.rub.nds.scanner.core.probe.result;

import java.io.Serializable;

/** The interface for TestResults */
public interface TestResult {
public interface TestResult extends Serializable {

/**
* @return the name of the TestResult.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@JsonIncludeProperties({"type", "value"})
@JsonPropertyOrder({"type", "value"})
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum TestResults implements TestResult {
public enum TestResults implements SummarizableTestResult {
TRUE,
FALSE,
PARTIALLY,
Expand All @@ -48,4 +48,14 @@ public String getName() {
public static TestResults of(boolean value) {
return value ? TRUE : FALSE;
}

@Override
public TestResults getSummarizedResult() {
return this;
}

@Override
public boolean isExplicitSummary() {
return true;
}
}

0 comments on commit 1704ba1

Please sign in to comment.