Skip to content

Commit

Permalink
Added fuzzing tests for authentication (#4503)
Browse files Browse the repository at this point in the history
Signed-off-by: Saranya-jena <saranya.jena@harness.io>
  • Loading branch information
Saranya-jena authored Mar 12, 2024
1 parent c7b7d29 commit 9fbbef4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions chaoscenter/authentication/pkg/utils/utils_fuzz_test.go
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
}

0 comments on commit 9fbbef4

Please sign in to comment.