-
Notifications
You must be signed in to change notification settings - Fork 2k
(fix) Flaky BoxOAuth detector test #4199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9eb8803
moved Generate random Password func to utils to be used by multiple d…
0f99a7e
Merge branch 'main' into hotfix-boxoauth-flaky-test
amanfcp 024b063
Merge branch 'main' into hotfix-boxoauth-flaky-test
abmussani 822c356
fixed spelling issue
0714993
Merge branch 'main' into hotfix-boxoauth-flaky-test
amanfcp d95fb43
Merge branch 'main' into hotfix-boxoauth-flaky-test
abmussani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,66 +3,15 @@ package snowflake | |
import ( | ||
"context" | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/brianvoe/gofakeit/v7" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/trufflesecurity/trufflehog/v3/pkg/common" | ||
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors" | ||
"github.com/trufflesecurity/trufflehog/v3/pkg/engine/ahocorasick" | ||
) | ||
|
||
// GoFakeIt Password generator does not guarantee inclusion of characters. | ||
// Using a custom Password gennerator with guaranteed inclusions (atleast) of lower, upper and numeric characters | ||
func generatePassword(lower, upper, numeric bool, length int) string { | ||
if length < 1 { | ||
return "" | ||
} | ||
|
||
var password []rune | ||
var required []rune | ||
var allowed []rune | ||
|
||
lowerChars := []rune("abcdefghijklmnopqrstuvwxyz") | ||
upperChars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZ") | ||
numberChars := []rune("0123456789") | ||
|
||
// Ensure inclusion from each requested category | ||
if lower { | ||
ch := lowerChars[rand.Intn(len(lowerChars))] | ||
required = append(required, ch) | ||
allowed = append(allowed, lowerChars...) | ||
} | ||
if upper { | ||
ch := upperChars[rand.Intn(len(upperChars))] | ||
required = append(required, ch) | ||
allowed = append(allowed, upperChars...) | ||
} | ||
if numeric { | ||
ch := numberChars[rand.Intn(len(numberChars))] | ||
required = append(required, ch) | ||
allowed = append(allowed, numberChars...) | ||
} | ||
|
||
if len(allowed) == 0 { | ||
return "" // No character sets enabled | ||
} | ||
|
||
// Fill the rest of the password | ||
for i := 0; i < length-len(required); i++ { | ||
ch := allowed[rand.Intn(len(allowed))] | ||
password = append(password, ch) | ||
} | ||
|
||
// Combine required and random characters, then shuffle | ||
password = append(password, required...) | ||
rand.Shuffle(len(password), func(i, j int) { | ||
password[i], password[j] = password[j], password[i] | ||
}) | ||
|
||
return string(password) | ||
} | ||
|
||
func TestSnowflake_Pattern(t *testing.T) { | ||
|
||
validAccount := "tuacoip-zt74995" | ||
|
@@ -71,7 +20,7 @@ func TestSnowflake_Pattern(t *testing.T) { | |
validUsername := gofakeit.Username() | ||
invalidUsername := "[email protected]" // special characters not allowed | ||
|
||
validPassword := generatePassword(true, true, true, 10) | ||
validPassword := common.GenerateRandomPassword(true, true, true, false, 10) | ||
invalidPassword := "!12" // invalid length | ||
|
||
d := Scanner{} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.