Skip to content

Commit

Permalink
Only get certificate when it could be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
ties committed Feb 27, 2024
1 parent 1fcf5d5 commit f1ff083
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public void shouldAcceptCertificateWithResourceExtension(String testCasenumber,
public void shouldRejectCertificateWithInvalidResourceExtension(String testCasenumber, String testCaseFile, String testCaseDescription) throws IOException {

Check notice

Code scanning / CodeQL

Useless parameter Note test

The parameter 'testCasenumber' is never used.
final String fileName = String.format("root/badCert%s.cer", testCaseFile);

assertThatThrownBy(() -> parseCertificate(fileName))
.isInstanceOfAny(IllegalArgumentException.class, IllegalStateException.class)
assertThatThrownBy(() -> assertThat(parseCertificate(fileName)).isFalse())
.isInstanceOfAny(IllegalArgumentException.class, IllegalStateException.class, AssertionError.class)
.withFailMessage("Should reject certificate with " + testCaseDescription + " from " + fileName);
}

Expand All @@ -114,7 +114,9 @@ private boolean certificateHasWarningOrFailure(String certificate) throws IOExce
var parser = new X509ResourceCertificateParser();
parser.parse(result, encoded);
// Trigger some lazy parsing
parser.getCertificate();
if (!result.hasFailures()) {
parser.getCertificate();
}
return result.hasFailures() || result.hasWarnings();
}

Expand All @@ -124,8 +126,9 @@ private boolean parseCertificate(String certificate) throws IOException {
ValidationResult result = ValidationResult.withLocation(file.getName());
var parser = new X509ResourceCertificateParser();
parser.parse(result, encoded);

parser.getCertificate();
if (!result.hasFailures()) {
parser.getCertificate();
}
return result.hasFailures();
}
}

0 comments on commit f1ff083

Please sign in to comment.