Skip to content

Commit 49befa3

Browse files
author
TLS Scanner Developer
committed
Fix toString() method that could return null in NamedGroupsGuidelineCheckResult
Changed toString() to return a default message instead of null when no specific named groups information is available. This prevents potential NullPointerException when the toString() result is used. Added comprehensive unit tests to verify toString() never returns null for all possible states of the NamedGroupsGuidelineCheckResult object.
1 parent aa0f4f4 commit 49befa3

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

TLS-Server-Scanner/src/main/java/de/rub/nds/tlsscanner/serverscanner/guideline/results/NamedGroupsGuidelineCheckResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public String toString() {
6969
if (groupCount != null) {
7070
return "Server only supports " + groupCount + " groups.";
7171
}
72-
return null;
72+
return "No specific named groups information available.";
7373
}
7474

7575
public Set<NamedGroup> getNotRecommendedGroups() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* TLS-Scanner - A TLS configuration and analysis tool based on TLS-Attacker
3+
*
4+
* Copyright 2017-2023 Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
5+
*
6+
* Licensed under Apache License, Version 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0.txt
8+
*/
9+
package de.rub.nds.tlsscanner.serverscanner.guideline.results;
10+
11+
import static org.junit.jupiter.api.Assertions.assertNotNull;
12+
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
14+
import de.rub.nds.scanner.core.guideline.GuidelineAdherence;
15+
import de.rub.nds.tlsattacker.core.constants.NamedGroup;
16+
import java.util.Arrays;
17+
import java.util.HashSet;
18+
import java.util.Set;
19+
import org.junit.jupiter.api.Test;
20+
21+
class NamedGroupsGuidelineCheckResultTest {
22+
23+
@Test
24+
void testToStringNeverReturnsNull() {
25+
// Test with CHECK_FAILED adherence
26+
NamedGroupsGuidelineCheckResult result1 =
27+
new NamedGroupsGuidelineCheckResult("test1", GuidelineAdherence.CHECK_FAILED);
28+
assertNotNull(result1.toString());
29+
assertTrue(result1.toString().contains("Missing information"));
30+
31+
// Test with ADHERED adherence
32+
NamedGroupsGuidelineCheckResult result2 =
33+
new NamedGroupsGuidelineCheckResult("test2", GuidelineAdherence.ADHERED);
34+
assertNotNull(result2.toString());
35+
assertTrue(result2.toString().contains("Server passed"));
36+
37+
// Test with not recommended groups
38+
Set<NamedGroup> notRecommended = new HashSet<>();
39+
notRecommended.add(NamedGroup.SECP224R1);
40+
NamedGroupsGuidelineCheckResult result3 =
41+
new NamedGroupsGuidelineCheckResult(
42+
"test3", GuidelineAdherence.VIOLATED, notRecommended);
43+
assertNotNull(result3.toString());
44+
assertTrue(result3.toString().contains("not recommended"));
45+
46+
// Test with missing required groups
47+
NamedGroupsGuidelineCheckResult result4 =
48+
new NamedGroupsGuidelineCheckResult(
49+
"test4", GuidelineAdherence.VIOLATED, Arrays.asList(NamedGroup.SECP256R1));
50+
assertNotNull(result4.toString());
51+
assertTrue(result4.toString().contains("missing one of required"));
52+
53+
// Test with group count
54+
NamedGroupsGuidelineCheckResult result5 =
55+
new NamedGroupsGuidelineCheckResult("test5", GuidelineAdherence.VIOLATED, 3);
56+
assertNotNull(result5.toString());
57+
assertTrue(result5.toString().contains("only supports 3 groups"));
58+
59+
// Test default case - this is the case that was returning null
60+
NamedGroupsGuidelineCheckResult result6 =
61+
new NamedGroupsGuidelineCheckResult("test6", GuidelineAdherence.VIOLATED);
62+
assertNotNull(result6.toString());
63+
assertTrue(result6.toString().contains("No specific named groups information"));
64+
}
65+
}

0 commit comments

Comments
 (0)