Skip to content
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

Support login request with leading or trailing whitespace from payload #3496

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/user_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ func getLoginResponse(params authApi.LoginParams) (*models.LoginResponse, *Coded
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
defer cancel()
lr := params.Body
// trim any leading and trailing whitespace from the login request
lr.AccessKey = strings.TrimSpace(lr.AccessKey)
lr.SecretKey = strings.TrimSpace(lr.SecretKey)
lr.Sts = strings.TrimSpace(lr.Sts)

clientIP := getClientIP(params.HTTPRequest)
client := GetConsoleHTTPClient(clientIP)
Expand Down
30 changes: 30 additions & 0 deletions integration/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,36 @@ func TestLogout(t *testing.T) {
assert.Equal(response.StatusCode, 200)
}

func TestLoginExtraSpaces(t *testing.T) {
assert := assert.New(t)

client := &http.Client{
Timeout: 2 * time.Second,
}
requestData := map[string]string{
"accessKey": " minioadmin ",
"secretKey": "minioadmin",
}

requestDataJSON, _ := json.Marshal(requestData)

requestDataBody := bytes.NewReader(requestDataJSON)

request, err := http.NewRequest("POST", "http://localhost:9090/api/v1/login", requestDataBody)
if err != nil {
log.Println(err)
return
}

request.Header.Add("Content-Type", "application/json")

response, err := client.Do(request)

assert.Equal(204, response.StatusCode, "Login request should succeed")
assert.NotNil(response, "Login response is nil")
assert.Nil(err, "Login errored out")
}

func TestBadLogin(t *testing.T) {
assert := assert.New(t)

Expand Down
Loading