Skip to content

Commit 45bf325

Browse files
Accept hyphens in TestingBotSessionID so modern session ids resolve (#39)
* Accept hyphens in TestingBotSessionID so modern session ids resolve Modern TestingBot / W3C WebDriver session ids are hyphenated (e.g. b0dbacacfa63-342d529ca760-...). The extraction pattern was TestingBotSessionID=([A-Za-z0-9]+), which stopped at the first hyphen and captured only the leading segment. That truncated id 404s against the TestingBot REST API (the full id maps to an internal test id) and, because getAuthenticationHash() then hashes the wrong string, the embedded mini iframe and share links break too. Net effect: every embedded report, Build page and GitHub-checks summary silently failed for real sessions. Widen the character class to [A-Za-z0-9_-]+ and add TestingBotSessionIdParsingTest covering hyphenated, plain, multiple and no-match inputs. * Cover underscore in session-id parsing test The pattern allows [A-Za-z0-9_-]+; add an underscore-containing id (abc_def-123) to capturesMultipleSessionIds so the underscore branch of the character class is exercised alongside the hyphenated ids.
1 parent b8923cb commit 45bf325

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

src/main/java/testingbot/TestingBotReportFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public TestingBotReportFactory(TestingBotCredentials credentials) {
2424
this.credentials = credentials;
2525
}
2626

27-
private static final Pattern SESSION_PATTERN = Pattern.compile("TestingBotSessionID=([A-Za-z0-9]+)");
27+
private static final Pattern SESSION_PATTERN = Pattern.compile("TestingBotSessionID=([A-Za-z0-9_-]+)");
2828

2929
public static List<String> findSessionIDs(CaseResult testResult) {
3030
List<String> sessions = new ArrayList<>();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package testingbot;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import org.junit.Test;
8+
9+
/**
10+
* Verifies the {@code TestingBotSessionID=} token parser accepts the full session
11+
* id, including the hyphens present in modern WebDriver session ids. A truncated id
12+
* would 404 against the TestingBot REST API and break every embedded report.
13+
*/
14+
public class TestingBotSessionIdParsingTest {
15+
16+
@Test
17+
public void capturesHyphenatedSessionId() {
18+
String sid = "b0dbacacfa63-342d529ca760-2f981532f469-178429199039-61532530";
19+
List<String> found = new ArrayList<>();
20+
TestingBotReportFactory.collectSessionIDs("TestingBotSessionID=" + sid, found);
21+
assertThat(found).containsExactly(sid);
22+
}
23+
24+
@Test
25+
public void capturesPlainHexSessionId() {
26+
List<String> found = new ArrayList<>();
27+
TestingBotReportFactory.collectSessionIDs("log TestingBotSessionID=abc123DEF more", found);
28+
assertThat(found).containsExactly("abc123DEF");
29+
}
30+
31+
@Test
32+
public void capturesMultipleSessionIds() {
33+
List<String> found = new ArrayList<>();
34+
TestingBotReportFactory.collectSessionIDs(
35+
"TestingBotSessionID=aaa-111\nTestingBotSessionID=bbb-222\nTestingBotSessionID=abc_def-123",
36+
found);
37+
assertThat(found).containsExactly("aaa-111", "bbb-222", "abc_def-123");
38+
}
39+
40+
@Test
41+
public void ignoresTextWithoutToken() {
42+
List<String> found = new ArrayList<>();
43+
TestingBotReportFactory.collectSessionIDs("no session here", found);
44+
assertThat(found).isEmpty();
45+
}
46+
}

0 commit comments

Comments
 (0)