You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TestIsValidUsername tests the IsValidUsername function with various username inputs.
56
-
// This function verifies that usernames consisting of alphanumeric characters and password safe
57
-
// special characters are considered valid. It also checks that usernames with unsafe characters
58
-
// are correctly identified as invalid.
69
+
// TestIsValidUsername tests the IsValidUsername function to ensure it enforces the defined criteria for usernames.
59
70
funcTestIsValidUsername(t*testing.T) {
60
71
tests:= []struct {
61
-
usernamestring
62
-
expectedbool
63
-
expectedMsgstring
72
+
namestring
73
+
usernamestring
74
+
wantbool
75
+
errMsgstring
64
76
}{
65
-
{"user123", true, ""},
66
-
{"user!@#", true, ""},
67
-
{"<script>", false, "Username must contain only alphanumeric characters and password safe special characters (!@#$%^&*()_-+=[{]}\\|;:'\",<.>/?)."},
77
+
{"Valid Username", "User123!", true, ""},
78
+
{"Valid Special Characters", "User_@#1$", true, ""},
79
+
{"Invalid Characters", " InvalidUsername", false, "Username must contain only alphanumeric characters and password safe special characters (!@#$%^&*()_-+=[{]}\\|;:'\",<.>/?)."},
80
+
{"Empty Username", "", false, "Username must contain only alphanumeric characters and password safe special characters (!@#$%^&*()_-+=[{]}\\|;:'\",<.>/?)."},
81
+
// You can add more cases here to test additional scenarios, such as extremely long usernames or usernames with only special characters.
68
82
}
69
83
70
84
for_, tt:=rangetests {
71
-
valid, msg:=IsValidUsername(tt.username)
72
-
assert.Equal(t, tt.expected, valid)
73
-
assert.Equal(t, tt.expectedMsg, msg)
74
-
}
75
-
}
76
-
77
-
// TestIsValidPassword tests the IsValidPassword function with various password inputs.
78
-
// It ensures that passwords meeting the minimum length requirement are validated correctly,
79
-
// and that short passwords are appropriately flagged as invalid.
80
-
funcTestIsValidPassword(t*testing.T) {
81
-
tests:= []struct {
82
-
passwordstring
83
-
expectedbool
84
-
expectedMsgstring
85
-
}{
86
-
{"Password1", true, ""},
87
-
{"short", false, "Password must be at least 8 characters long."},
88
-
}
89
-
90
-
for_, tt:=rangetests {
91
-
valid, msg:=IsValidPassword(tt.password)
92
-
assert.Equal(t, tt.expected, valid)
93
-
assert.Equal(t, tt.expectedMsg, msg)
94
-
}
95
-
}
96
-
97
-
// TestDetermineAuthMethod tests the DetermineAuthMethod function with various authentication configurations.
98
-
// It checks that the function correctly identifies the authentication method to be used based on the provided
99
-
// credentials. Scenarios include valid OAuth credentials, valid bearer token credentials, and various combinations
100
-
// of invalid or missing credentials. The function should return "oauth" for valid OAuth credentials, "bearer" for
101
-
// valid bearer token credentials, and "unknown" with an error message for invalid or incomplete credentials.
{AuthConfig{ClientID: "invalid-uuid", ClientSecret: "ValidSecret123!"}, "unknown", errors.New("No valid credentials provided. Client ID is not a valid UUID format.")},
111
-
{AuthConfig{}, "unknown", errors.New("No valid credentials provided.")}, // No credentials provided
0 commit comments