Skip to content

Commit a391a9c

Browse files
committed
Remove httpclient_error_response_test.go
1 parent f01812d commit a391a9c

File tree

2 files changed

+49
-161
lines changed

2 files changed

+49
-161
lines changed

httpclient/httpclient_auth_validation_test.go

Lines changed: 49 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package httpclient
33

44
import (
5-
"errors"
65
"testing"
76

87
"github.com/stretchr/testify/assert"
@@ -12,21 +11,28 @@ import (
1211
// It verifies that valid UUIDs are correctly identified as such, and invalid formats
1312
// are appropriately flagged with an error message. Additionally, it checks that empty
1413
// client IDs are considered valid according to the updated logic.
14+
// TestIsValidClientID tests the IsValidClientID function for both valid and invalid UUIDs.
1515
func TestIsValidClientID(t *testing.T) {
1616
tests := []struct {
17-
clientID string
18-
expected bool
19-
expectedMsg string
17+
name string
18+
clientID string
19+
want bool
20+
errMsg string
2021
}{
21-
{"123e4567-e89b-12d3-a456-426614174000", true, ""},
22-
{"invalid-uuid", false, "Client ID is not a valid UUID format."},
23-
{"", true, ""}, // Empty client ID should be considered valid as per your updated logic
22+
{"Valid UUID", "123e4567-e89b-12d3-a456-426614174000", true, ""},
23+
{"Invalid UUID - Wrong Length", "123e4567", false, "Client ID is not a valid UUID format."},
24+
{"Invalid UUID - Invalid Characters", "G23e4567-e89b-12d3-a456-426614174000", false, "Client ID is not a valid UUID format."},
25+
// Add more cases as needed...
2426
}
2527

2628
for _, tt := range tests {
27-
valid, msg := IsValidClientID(tt.clientID)
28-
assert.Equal(t, tt.expected, valid)
29-
assert.Equal(t, tt.expectedMsg, msg)
29+
t.Run(tt.name, func(t *testing.T) {
30+
valid, errMsg := IsValidClientID(tt.clientID)
31+
assert.Equal(t, tt.want, valid)
32+
if !tt.want {
33+
assert.Equal(t, tt.errMsg, errMsg)
34+
}
35+
})
3036
}
3137
}
3238

@@ -36,88 +42,52 @@ func TestIsValidClientID(t *testing.T) {
3642
// flagged appropriately, and that empty client secrets are considered valid as per the updated logic.
3743
func TestIsValidClientSecret(t *testing.T) {
3844
tests := []struct {
45+
name string
3946
clientSecret string
40-
expected bool
41-
expectedMsg string
47+
want bool
48+
errMsg string
4249
}{
43-
{"ValidSecret123!", true, ""},
44-
{"short", false, "Client secret must be at least 16 characters long."},
45-
{"", true, ""}, // Empty client secret should be considered valid as per your updated logic
50+
{"Valid Secret", "Aa1!Aa1!Aa1!Aa1!", true, ""},
51+
{"Too Short", "Aa1!", false, "Client secret must be at least 16 characters long."},
52+
{"No Lowercase", "AAAAAAAAAAAAAA1!", false, "Client secret must contain at least one lowercase letter."},
53+
{"No Uppercase", "aaaaaaaaaaaaaa1!", false, "Client secret must contain at least one uppercase letter."},
54+
{"No Digit", "Aa!Aa!Aa!Aa!Aa!Aa!", false, "Client secret must contain at least one digit."},
55+
// Add more cases as needed...
4656
}
4757

4858
for _, tt := range tests {
49-
valid, msg := IsValidClientSecret(tt.clientSecret)
50-
assert.Equal(t, tt.expected, valid)
51-
assert.Equal(t, tt.expectedMsg, msg)
59+
t.Run(tt.name, func(t *testing.T) {
60+
valid, errMsg := IsValidClientSecret(tt.clientSecret)
61+
assert.Equal(t, tt.want, valid)
62+
if !tt.want {
63+
assert.Equal(t, tt.errMsg, errMsg)
64+
}
65+
})
5266
}
5367
}
5468

55-
// 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.
5970
func TestIsValidUsername(t *testing.T) {
6071
tests := []struct {
61-
username string
62-
expected bool
63-
expectedMsg string
72+
name string
73+
username string
74+
want bool
75+
errMsg string
6476
}{
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.
6882
}
6983

7084
for _, tt := range tests {
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-
func TestIsValidPassword(t *testing.T) {
81-
tests := []struct {
82-
password string
83-
expected bool
84-
expectedMsg string
85-
}{
86-
{"Password1", true, ""},
87-
{"short", false, "Password must be at least 8 characters long."},
88-
}
89-
90-
for _, tt := range tests {
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.
102-
func TestDetermineAuthMethod(t *testing.T) {
103-
tests := []struct {
104-
authConfig AuthConfig
105-
expected string
106-
expectedErr error
107-
}{
108-
{AuthConfig{ClientID: "123e4567-e89b-12d3-a456-426614174000", ClientSecret: "ValidSecret123!"}, "oauth", nil},
109-
{AuthConfig{Username: "user123", Password: "Password1"}, "bearer", nil},
110-
{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
112-
}
113-
114-
for _, tt := range tests {
115-
method, err := DetermineAuthMethod(tt.authConfig)
116-
assert.Equal(t, tt.expected, method)
117-
if tt.expectedErr != nil {
118-
assert.EqualError(t, err, tt.expectedErr.Error())
119-
} else {
120-
assert.NoError(t, err)
121-
}
85+
t.Run(tt.name, func(t *testing.T) {
86+
valid, errMsg := IsValidUsername(tt.username)
87+
assert.Equal(t, tt.want, valid)
88+
if !tt.want {
89+
assert.Equal(t, tt.errMsg, errMsg)
90+
}
91+
})
12292
}
12393
}

httpclient/httpclient_error_response_test.go

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)