-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fuzzing tests for authentication (#4503)
Signed-off-by: Saranya-jena <saranya.jena@harness.io>
- Loading branch information
1 parent
c7b7d29
commit 9fbbef4
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func FuzzSanitizeString(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, input string) { | ||
err := ValidateStrictPassword(input) | ||
if err != nil { | ||
if isExpectedError(err) { | ||
fmt.Printf("Expected validation failure for input '%s': %v\n", input, err) | ||
} else { | ||
fmt.Printf("Unexpected validation failure for input '%s': %v\n", input, err) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func isExpectedError(err error) bool { | ||
expectedErrors := []string{ | ||
"password is less than 8 characters", | ||
"password does not contain digits", | ||
"password does not contain lowercase alphabets", | ||
"password does not contain uppercase alphabets", | ||
"password does not contain special characters", | ||
} | ||
|
||
for _, expected := range expectedErrors { | ||
if err.Error() == expected { | ||
return true | ||
} | ||
} | ||
return false | ||
} |