Error cleanup and minor fixes

This commit is contained in:
Andrew Morgan (https://amorgan.xyz) 2018-02-07 19:17:09 -08:00
parent 6b5ee76a56
commit 2936c49b0b
No known key found for this signature in database
GPG key ID: 174BEAB009FD176D
4 changed files with 14 additions and 13 deletions

View file

@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS account_accounts (
created_ts BIGINT NOT NULL,
-- The password hash for this account. Can be NULL if this is a passwordless account.
password_hash TEXT,
-- Identifies which Application Service this account belongs to.
-- Identifies which Application Service this account belongs to, if any.
appservice_id TEXT
-- TODO:
-- is_guest, is_admin, upgraded_ts, devices, any email reset stuff?
@ -84,7 +84,7 @@ func (s *accountsStatements) insertAccount(
) (*authtypes.Account, error) {
createdTimeMS := time.Now().UnixNano() / 1000000
stmt := s.insertAccountStmt
if _, err := stmt.ExecContext(ctx, localpart, createdTimeMS, hash, appserviceID); err != nil {
if _, err := stmt.ExecContext(ctx, localpart, createdTimeMS, hash, appserviceID ? appserviceID : nil); err != nil {
return nil, err
}
return &authtypes.Account{

View file

@ -127,7 +127,7 @@ func (d *Database) CreateAccount(
// Generate a password hash if this is not a password-less user
hash := ""
if appserviceID == "" && plaintextPassword != "" {
if plaintextPassword != "" {
hash, err = hashPassword(plaintextPassword)
if err != nil {
return nil, err

View file

@ -86,7 +86,7 @@ func MissingToken(msg string) *MatrixError {
}
// UnknownToken is an error when the client tries to access a resource which
// requires authentication and supplies a valid, but out-of-date token.
// requires authentication and supplies an unrecognized token
func UnknownToken(msg string) *MatrixError {
return &MatrixError{"M_UNKNOWN_TOKEN", msg}
}
@ -109,9 +109,10 @@ func UserInUse(msg string) *MatrixError {
return &MatrixError{"M_USER_IN_USE", msg}
}
// Exclusive is an error returned when an application service tries to register
// an username that is outside of its registered namespace
func Exclusive(msg string) *MatrixError {
// ASExclusive is an error returned when an application service tries to
// register an username that is outside of its registered namespace, or if a
// user attempts to register a username within an exclusive namespace
func ASExclusive(msg string) *MatrixError {
return &MatrixError{"M_EXCLUSIVE", msg}
}

View file

@ -312,7 +312,7 @@ func validateApplicationService(
if matchedApplicationService != nil {
return "", &util.JSONResponse{
Code: 401,
JSON: jsonerror.BadJSON("Supplied access_token does not match any known application service"),
JSON: jsonerror.UnknownToken("Supplied access_token does not match any known application service"),
}
}
@ -321,8 +321,8 @@ func validateApplicationService(
// If we didn't find any matches, return M_EXCLUSIVE
return "", &util.JSONResponse{
Code: 401,
JSON: jsonerror.Exclusive("Supplied username " + username +
" did not match any namespaces for application service ID: " + matchedApplicationService.ID),
JSON: jsonerror.ASExclusive(fmt.Sprintf(
"Supplied username %s did not match any namespaces for application service ID: %s", username, matchedApplicationService.ID)),
}
}
@ -330,8 +330,8 @@ func validateApplicationService(
if UsernameMatchesMultipleExclusiveNamespaces(cfg, username) {
return "", &util.JSONResponse{
Code: 401,
JSON: jsonerror.Exclusive("Supplied username " + username +
" matches multiple exclusive application service namespaces. Only 1 match allowed"),
JSON: jsonerror.ASExclusive(fmt.Sprintf(
"Supplied username %s matches multiple exclusive application service namespaces. Only 1 match allowed", username)),
}
}
@ -386,7 +386,7 @@ func Register(
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp.MatchString(r.Username) {
return util.JSONResponse{
Code: 400,
JSON: jsonerror.Exclusive("This username is registered by an application service."),
JSON: jsonerror.ASExclusive("This username is reserved by an application service."),
}
}