diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2022-05-31 14:36:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 14:36:51 +0200 |
commit | ae7b6dd5164eb34cc65b5e43e576c6fcd9779351 (patch) | |
tree | 459b7137b75572a5e2fc0694d6c4b7873ab83ef7 | |
parent | beed39a8f4c613388eddea8ebf95d93f4380196c (diff) |
Fix #2498 (#2506)
-rw-r--r-- | userapi/storage/postgres/accounts_table.go | 2 | ||||
-rw-r--r-- | userapi/storage/storage_test.go | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/userapi/storage/postgres/accounts_table.go b/userapi/storage/postgres/accounts_table.go index 268889ac..e3cab56e 100644 --- a/userapi/storage/postgres/accounts_table.go +++ b/userapi/storage/postgres/accounts_table.go @@ -65,7 +65,7 @@ const selectPasswordHashSQL = "" + "SELECT password_hash FROM account_accounts WHERE localpart = $1 AND is_deactivated = FALSE" const selectNewNumericLocalpartSQL = "" + - "SELECT COALESCE(MAX(localpart::integer), 0) FROM account_accounts WHERE localpart ~ '^[0-9]{1,}$'" + "SELECT COALESCE(MAX(localpart::bigint), 0) FROM account_accounts WHERE localpart ~ '^[0-9]{1,}$'" type accountsStatements struct { insertAccountStmt *sql.Stmt diff --git a/userapi/storage/storage_test.go b/userapi/storage/storage_test.go index 66c15454..a2609733 100644 --- a/userapi/storage/storage_test.go +++ b/userapi/storage/storage_test.go @@ -133,6 +133,14 @@ func Test_Accounts(t *testing.T) { // test getting a numeric localpart, with an existing user without a localpart _, err = db.CreateAccount(ctx, "", "", "", api.AccountTypeGuest) assert.NoError(t, err) + + // Create a user with a high numeric localpart, out of range for the Postgres integer (2147483647) type + _, err = db.CreateAccount(ctx, "2147483650", "", "", api.AccountTypeUser) + assert.NoError(t, err) + + // Now try to create a new guest user + _, err = db.CreateAccount(ctx, "", "", "", api.AccountTypeGuest) + assert.NoError(t, err) }) } |