Skip to content

Commit 124834d

Browse files
committed
Moved tests outside of companion object
1 parent 6099503 commit 124834d

1 file changed

Lines changed: 46 additions & 47 deletions

File tree

agent/src/test/kotlin/com/teamscale/jacoco/agent/options/AgentOptionsTest.kt

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,53 @@ class AgentOptionsTest {
541541
return result
542542
}
543543

544+
/** Tests that [AgentOptions.obfuscateAccessToken] hides the token in a comma-separated options string. */
545+
@Test
546+
fun obfuscateAccessTokenHidesTokenInOptionsString() {
547+
val input =
548+
"config-file=jacocoagent.properties,teamscale-access-token=unlYgehaYYYhbPAegNWV3WgjOzxkmNHn,teamscale-partition=p"
549+
Assertions.assertThat(AgentOptions.obfuscateAccessToken(input))
550+
.isEqualTo("config-file=jacocoagent.properties,teamscale-access-token=************mNHn,teamscale-partition=p")
551+
}
552+
553+
/** Tests that obfuscation also covers tokens in newline-separated input (the format Teamscale returns for config-id). */
554+
@Test
555+
fun obfuscateAccessTokenHidesTokenInNewlineSeparatedString() {
556+
val input = "teamscale-access-token=unlYgehaYYYhbPAegNWV3WgjOzxkmNHn\nteamscale-partition=p"
557+
Assertions.assertThat(AgentOptions.obfuscateAccessToken(input))
558+
.isEqualTo("teamscale-access-token=************mNHn\nteamscale-partition=p")
559+
}
560+
561+
/** Tests that obfuscation hides every `*-access-token=` occurrence, not just the last one. */
562+
@Test
563+
fun obfuscateAccessTokenHidesMultipleTokens() {
564+
val input =
565+
"teamscale-access-token=unlYgehaYYYhbPAegNWV3WgjOzxkmNHn,artifactory-access-token=anotherSecretAbcd"
566+
Assertions.assertThat(AgentOptions.obfuscateAccessToken(input))
567+
.isEqualTo("teamscale-access-token=************mNHn,artifactory-access-token=************Abcd")
568+
}
569+
570+
/** Tests that strings without an access token are returned unchanged. */
571+
@Test
572+
fun obfuscateAccessTokenReturnsInputUnchangedWhenNoTokenPresent() {
573+
val input = "config-file=jacocoagent.properties,teamscale-partition=p"
574+
Assertions.assertThat(AgentOptions.obfuscateAccessToken(input)).isEqualTo(input)
575+
}
576+
577+
/** Tests the null-input contract used by [AgentOptions.obfuscatedOptionsString]. */
578+
@Test
579+
fun obfuscateAccessTokenReturnsEmptyStringForNullInput() {
580+
Assertions.assertThat(AgentOptions.obfuscateAccessToken(null)).isEmpty()
581+
}
582+
583+
/** Tests that a token shorter than 4 characters does not throw and is fully obfuscated. */
584+
@Test
585+
fun obfuscateAccessTokenHandlesShortToken() {
586+
Assertions.assertThat(AgentOptions.obfuscateAccessToken("teamscale-access-token=abc"))
587+
.isEqualTo("teamscale-access-token=************abc")
588+
}
589+
544590
companion object {
545-
@Throws(Exception::class)
546591
private fun parseProxyOptions(
547592
otherOptionsString: String?, protocol: ProxySystemProperties.Protocol?,
548593
expectedHost: String?, expectedPort: Int, expectedUser: String?,
@@ -593,52 +638,6 @@ class AgentOptionsTest {
593638
return AgentOptionsParser(CommandLineLogger(), null, null, credentials, null)
594639
}
595640

596-
/** Tests that [AgentOptions.obfuscateAccessToken] hides the token in a comma-separated options string. */
597-
@Test
598-
fun obfuscateAccessTokenHidesTokenInOptionsString() {
599-
val input =
600-
"config-file=jacocoagent.properties,teamscale-access-token=unlYgehaYYYhbPAegNWV3WgjOzxkmNHn,teamscale-partition=p"
601-
Assertions.assertThat(AgentOptions.obfuscateAccessToken(input))
602-
.isEqualTo("config-file=jacocoagent.properties,teamscale-access-token=************mNHn,teamscale-partition=p")
603-
}
604-
605-
/** Tests that obfuscation also covers tokens in newline-separated input (the format Teamscale returns for config-id). */
606-
@Test
607-
fun obfuscateAccessTokenHidesTokenInNewlineSeparatedString() {
608-
val input = "teamscale-access-token=unlYgehaYYYhbPAegNWV3WgjOzxkmNHn\nteamscale-partition=p"
609-
Assertions.assertThat(AgentOptions.obfuscateAccessToken(input))
610-
.isEqualTo("teamscale-access-token=************mNHn\nteamscale-partition=p")
611-
}
612-
613-
/** Tests that obfuscation hides every `*-access-token=` occurrence, not just the last one. */
614-
@Test
615-
fun obfuscateAccessTokenHidesMultipleTokens() {
616-
val input =
617-
"teamscale-access-token=unlYgehaYYYhbPAegNWV3WgjOzxkmNHn,artifactory-access-token=anotherSecretAbcd"
618-
Assertions.assertThat(AgentOptions.obfuscateAccessToken(input))
619-
.isEqualTo("teamscale-access-token=************mNHn,artifactory-access-token=************Abcd")
620-
}
621-
622-
/** Tests that strings without an access token are returned unchanged. */
623-
@Test
624-
fun obfuscateAccessTokenReturnsInputUnchangedWhenNoTokenPresent() {
625-
val input = "config-file=jacocoagent.properties,teamscale-partition=p"
626-
Assertions.assertThat(AgentOptions.obfuscateAccessToken(input)).isEqualTo(input)
627-
}
628-
629-
/** Tests the null-input contract used by [AgentOptions.obfuscatedOptionsString]. */
630-
@Test
631-
fun obfuscateAccessTokenReturnsEmptyStringForNullInput() {
632-
Assertions.assertThat(AgentOptions.obfuscateAccessToken(null)).isEmpty()
633-
}
634-
635-
/** Tests that a token shorter than 4 characters does not throw and is fully obfuscated. */
636-
@Test
637-
fun obfuscateAccessTokenHandlesShortToken() {
638-
Assertions.assertThat(AgentOptions.obfuscateAccessToken("teamscale-access-token=abc"))
639-
.isEqualTo("teamscale-access-token=************abc")
640-
}
641-
642641
/**
643642
* Delete created coverage folders
644643
*/

0 commit comments

Comments
 (0)