Skip to content

Find, verify, and analyze leaked credentials

(fix) Auth0 Management token flaky test (#4179)

Abdul Basit7f115911ce3c
diff --git a/pkg/detectors/auth0managementapitoken/auth0managementapitoken_test.go b/pkg/detectors/auth0managementapitoken/auth0managementapitoken_test.go
index 0077e52cb..897f8580d 100644
--- a/pkg/detectors/auth0managementapitoken/auth0managementapitoken_test.go
+++ b/pkg/detectors/auth0managementapitoken/auth0managementapitoken_test.go
@@ -97,18 +97,23 @@ func makeFakeTokenString(token, domain string) string {
// generateRandomString generates exactly 2001 char string for a fake token to by pass the check in detector for testing
func generateRandomString() string {
const length = 2001
- const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-"
+ const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
+ const charsetWithBoundaryChars = charset + ".-"
random := rand.New(rand.NewSource(time.Now().UnixNano()))
var builder strings.Builder
builder.Grow(length)
- for i := 0; i < length; i++ {
- randomChar := charset[random.Intn(len(charset))]
+ for i := 0; i < length-1; i++ {
+ randomChar := charsetWithBoundaryChars[random.Intn(len(charset))]
builder.WriteByte(randomChar)
}
+ // ensure last character is not boundary character
+ lastChar := charset[random.Intn(len(charset))]
+ builder.WriteByte(lastChar)
+
// append ey in start as the token must start with 'ey'
return fmt.Sprintf("ey%s", builder.String())
}