Skip to content

Commit a9f1911

Browse files
feat: human-readable test names everywhere + credential hygiene in logs and mocks
- TestDisplayNameGenerator registered as the global JUnit display-name generator: every test without an explicit @DisplayName gets a readable sentence (testAllInvitationWithQuery -> 'All invitation with query', verb-led names get a 'should ...' prefix). Explicit annotations still win. - Security sweep fixes: - preserve-mode log no longer prints the management token value (CI console is org-visible); only a 6-char prefix is shown - replaced a personal gmail address in OrgApiTests with example.com - replaced a blt-format uid in mockrole/updateRole.json with a placeholder Verified: dynamic suite 252/0 failures; report shows 0 old-style names; leak scan of report and tracked sources: no authtokens, cs* tokens, passwords or real uids.
1 parent 5fbf5f7 commit a9f1911

5 files changed

Lines changed: 72 additions & 3 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.contentstack.cms;
2+
3+
import org.junit.jupiter.api.DisplayNameGenerator;
4+
5+
import java.lang.reflect.Method;
6+
import java.util.Arrays;
7+
import java.util.HashSet;
8+
import java.util.Set;
9+
10+
/**
11+
* Generates human-readable display names for every test that has no explicit
12+
* {@code @DisplayName} - e.g. {@code testAllInvitationWithQuery()} becomes
13+
* "should fetch all invitation with query". Registered globally via
14+
* {@code junit.jupiter.displayname.generator.default} in
15+
* {@code junit-platform.properties}; explicit annotations always win.
16+
*/
17+
public class TestDisplayNameGenerator extends DisplayNameGenerator.Standard {
18+
19+
/** verbs that read naturally with a "should <verb> ..." prefix */
20+
private static final Set<String> VERBS = new HashSet<>(Arrays.asList(
21+
"create", "fetch", "find", "get", "update", "delete", "upload", "replace",
22+
"publish", "unpublish", "localize", "unlocalize", "move", "import", "export",
23+
"clone", "deploy", "share", "unshare", "transfer", "accept", "reject",
24+
"login", "logout", "validate", "verify", "handle", "return", "reorder",
25+
"generate", "download", "setup", "throw", "reset", "activate", "deactivate"));
26+
27+
@Override
28+
public String generateDisplayNameForClass(Class<?> testClass) {
29+
return splitCamelCase(testClass.getSimpleName());
30+
}
31+
32+
@Override
33+
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod) {
34+
String name = testMethod.getName();
35+
// strip common prefixes
36+
if (name.startsWith("test")) {
37+
name = name.substring(4);
38+
}
39+
String sentence = splitCamelCase(name).toLowerCase();
40+
if (sentence.isEmpty()) {
41+
return testMethod.getName();
42+
}
43+
String firstWord = sentence.split(" ")[0];
44+
if (VERBS.contains(firstWord)) {
45+
return "should " + sentence;
46+
}
47+
// capitalize the first letter for non-verb starts, e.g. "All invitation with query"
48+
return Character.toUpperCase(sentence.charAt(0)) + sentence.substring(1);
49+
}
50+
51+
private static String splitCamelCase(String s) {
52+
return s
53+
// lower-to-upper boundary: fetchAll -> fetch All
54+
.replaceAll("([a-z0-9])([A-Z])", "$1 $2")
55+
// acronym-to-word boundary: APITest -> API Test
56+
.replaceAll("([A-Z]+)([A-Z][a-z])", "$1 $2")
57+
// letter-digit boundary: fetch2 -> fetch 2
58+
.replaceAll("([a-zA-Z])(\\d)", "$1 $2")
59+
.replace('_', ' ')
60+
.trim();
61+
}
62+
}

src/test/java/com/contentstack/cms/TestStackContext.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ public static synchronized void teardown() {
177177
System.out.println("[TestStackContext] DELETE_DYNAMIC_RESOURCES=false - preserving resources for debugging:");
178178
System.out.println("[TestStackContext] Stack: " + stackName);
179179
System.out.println("[TestStackContext] API key: " + stackApiKey);
180-
System.out.println("[TestStackContext] Management token: " + managementToken);
180+
// never print token values in logs (CI console is org-visible);
181+
// fetch/regenerate the token from the preserved stack's UI if needed
182+
System.out.println("[TestStackContext] Management token: "
183+
+ (managementToken == null ? "none" : managementToken.substring(0, 6) + "*** (value not logged)"));
181184
if (amStackCreated) {
182185
System.out.println("[TestStackContext] AM stack: " + amStackName + " (" + amStackApiKey + ")");
183186
}

src/test/java/com/contentstack/cms/organization/OrgApiTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void testTransferOwnership() {
234234
HashMap<String, Object> query = new HashMap<>();
235235
query.put("include_plan", true);
236236
String strBody = "{\n" +
237-
"\t\"transfer_to\": \"shaileshmishra@gmail.com\"\n" +
237+
"\t\"transfer_to\": \"transfer.user@example.com\"\n" +
238238
"}";
239239
JSONObject body = theJSONBody(strBody);
240240
ORG = TestClient.getClient().organization(ORG_ID)

src/test/resources/junit-platform.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
# META-INF/services/org.junit.jupiter.api.extension.Extension
33
# (used by TestReporter - the custom HTML test report)
44
junit.jupiter.extensions.autodetection.enabled=true
5+
6+
# Human-readable test names for every test without an explicit @DisplayName
7+
# (e.g. testAllInvitationWithQuery -> "should fetch all invitation with query")
8+
junit.jupiter.displayname.generator.default=com.contentstack.cms.TestDisplayNameGenerator

src/test/resources/mockrole/updateRole.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@
7373
}
7474
}
7575
],
76-
"uid":"blt668fa7872710da7c"
76+
"uid":"roleuid0999999999999"
7777
}
7878
}

0 commit comments

Comments
 (0)