diff --git a/src/main/java/testingbot/TestingBotReportFactory.java b/src/main/java/testingbot/TestingBotReportFactory.java index f97d974..fd1c4b1 100644 --- a/src/main/java/testingbot/TestingBotReportFactory.java +++ b/src/main/java/testingbot/TestingBotReportFactory.java @@ -24,7 +24,7 @@ public TestingBotReportFactory(TestingBotCredentials credentials) { this.credentials = credentials; } - private static final Pattern SESSION_PATTERN = Pattern.compile("TestingBotSessionID=([A-Za-z0-9]+)"); + private static final Pattern SESSION_PATTERN = Pattern.compile("TestingBotSessionID=([A-Za-z0-9_-]+)"); public static List findSessionIDs(CaseResult testResult) { List sessions = new ArrayList<>(); diff --git a/src/test/java/testingbot/TestingBotSessionIdParsingTest.java b/src/test/java/testingbot/TestingBotSessionIdParsingTest.java new file mode 100644 index 0000000..9285a97 --- /dev/null +++ b/src/test/java/testingbot/TestingBotSessionIdParsingTest.java @@ -0,0 +1,46 @@ +package testingbot; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; + +/** + * Verifies the {@code TestingBotSessionID=} token parser accepts the full session + * id, including the hyphens present in modern WebDriver session ids. A truncated id + * would 404 against the TestingBot REST API and break every embedded report. + */ +public class TestingBotSessionIdParsingTest { + + @Test + public void capturesHyphenatedSessionId() { + String sid = "b0dbacacfa63-342d529ca760-2f981532f469-178429199039-61532530"; + List found = new ArrayList<>(); + TestingBotReportFactory.collectSessionIDs("TestingBotSessionID=" + sid, found); + assertThat(found).containsExactly(sid); + } + + @Test + public void capturesPlainHexSessionId() { + List found = new ArrayList<>(); + TestingBotReportFactory.collectSessionIDs("log TestingBotSessionID=abc123DEF more", found); + assertThat(found).containsExactly("abc123DEF"); + } + + @Test + public void capturesMultipleSessionIds() { + List found = new ArrayList<>(); + TestingBotReportFactory.collectSessionIDs( + "TestingBotSessionID=aaa-111\nTestingBotSessionID=bbb-222\nTestingBotSessionID=abc_def-123", + found); + assertThat(found).containsExactly("aaa-111", "bbb-222", "abc_def-123"); + } + + @Test + public void ignoresTextWithoutToken() { + List found = new ArrayList<>(); + TestingBotReportFactory.collectSessionIDs("no session here", found); + assertThat(found).isEmpty(); + } +}