Re-add password check, remove home_server from response

This commit is contained in:
Till Faelligen 2022-12-19 16:29:37 +01:00
parent f9a08db24d
commit a41a400c91
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
3 changed files with 4 additions and 24 deletions

View file

@ -23,14 +23,12 @@ import (
"github.com/matrix-org/dendrite/clientapi/userutil" "github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
userapi "github.com/matrix-org/dendrite/userapi/api" userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
) )
type loginResponse struct { type loginResponse struct {
UserID string `json:"user_id"` UserID string `json:"user_id"`
AccessToken string `json:"access_token"` AccessToken string `json:"access_token"`
HomeServer gomatrixserverlib.ServerName `json:"home_server"`
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
} }
@ -116,7 +114,6 @@ func completeAuth(
JSON: loginResponse{ JSON: loginResponse{
UserID: performRes.Device.UserID, UserID: performRes.Device.UserID,
AccessToken: performRes.Device.AccessToken, AccessToken: performRes.Device.AccessToken,
HomeServer: serverName,
DeviceID: performRes.Device.ID, DeviceID: performRes.Device.ID,
}, },
} }

View file

@ -322,7 +322,7 @@ func validatePassword(password string) *util.JSONResponse {
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON(fmt.Sprintf("'password' >%d characters", maxPasswordLength)), JSON: jsonerror.BadJSON(fmt.Sprintf("'password' >%d characters", maxPasswordLength)),
} }
} else if len(password) < minPasswordLength { } else if len(password) > 0 && len(password) < minPasswordLength {
return &util.JSONResponse{ return &util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.WeakPassword(fmt.Sprintf("password too weak: min %d chars", minPasswordLength)), JSON: jsonerror.WeakPassword(fmt.Sprintf("password too weak: min %d chars", minPasswordLength)),

View file

@ -350,13 +350,6 @@ func Test_validatePassword(t *testing.T) {
password string password string
want *util.JSONResponse want *util.JSONResponse
}{ }{
{
name: "no password supplied",
want: &util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.WeakPassword(fmt.Sprintf("password too weak: min %d chars", minPasswordLength)),
},
},
{ {
name: "password too short", name: "password too short",
password: "shortpw", password: "shortpw",
@ -462,16 +455,6 @@ func Test_register(t *testing.T) {
JSON: jsonerror.InvalidUsername("Numeric user IDs are reserved"), JSON: jsonerror.InvalidUsername("Numeric user IDs are reserved"),
}, },
}, },
{
name: "can't register without password",
username: "helloworld",
password: "",
forceEmpty: true,
wantResponse: util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.WeakPassword(fmt.Sprintf("password too weak: min %d chars", minPasswordLength)),
},
},
} }
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) { test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {