Skip to content

Commit 7f11591

Browse files
authored
(fix) Auth0 Management token flaky test (#4179)
* ensure random generated token does not have last character as boundary character * use separate charset for boundary chars
1 parent e02a822 commit 7f11591

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/detectors/auth0managementapitoken/auth0managementapitoken_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,23 @@ func makeFakeTokenString(token, domain string) string {
9797
// generateRandomString generates exactly 2001 char string for a fake token to by pass the check in detector for testing
9898
func generateRandomString() string {
9999
const length = 2001
100-
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-"
100+
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
101+
const charsetWithBoundaryChars = charset + ".-"
101102

102103
random := rand.New(rand.NewSource(time.Now().UnixNano()))
103104

104105
var builder strings.Builder
105106
builder.Grow(length)
106107

107-
for i := 0; i < length; i++ {
108-
randomChar := charset[random.Intn(len(charset))]
108+
for i := 0; i < length-1; i++ {
109+
randomChar := charsetWithBoundaryChars[random.Intn(len(charset))]
109110
builder.WriteByte(randomChar)
110111
}
111112

113+
// ensure last character is not boundary character
114+
lastChar := charset[random.Intn(len(charset))]
115+
builder.WriteByte(lastChar)
116+
112117
// append ey in start as the token must start with 'ey'
113118
return fmt.Sprintf("ey%s", builder.String())
114119
}

0 commit comments

Comments
 (0)