From 75107f98d99148d2eee39acfae6417330fd62763 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 30 Dec 2023 21:49:30 +0100 Subject: [PATCH] oauth: Increase the max size of Provider to 255 There are legit reasons why a Provider ("Authentication Name") can be longer than 25 characters, so lets increase that limit substantially to 255. To do so, we need a migration too, and `AuthenticationForm` needs to have the maximum size of its `Name` field increased similarly. Fixes #24891, at least for the Provider case. Signed-off-by: Gergely Nagy --- models/migrations/migrations.go | 2 ++ models/migrations/v1_22/v284.go | 16 ++++++++++++++++ models/user/external_login_user.go | 2 +- services/forms/auth_form.go | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 models/migrations/v1_22/v284.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 578cbca035d85..7136222139e02 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -552,6 +552,8 @@ var migrations = []Migration{ NewMigration("Add Index to pull_auto_merge.doer_id", v1_22.AddIndexToPullAutoMergeDoerID), // v283 -> v284 NewMigration("Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser), + // v284 -> v285 + NewMigration("Incrase external_login_user.provider size to 255", v1_22.UpdateExternalLoginUserProvider), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_22/v284.go b/models/migrations/v1_22/v284.go new file mode 100644 index 0000000000000..8d9d6745ec7a3 --- /dev/null +++ b/models/migrations/v1_22/v284.go @@ -0,0 +1,16 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "xorm.io/xorm" +) + +func UpdateExternalLoginUserProvider(x *xorm.Engine) error { + type ExternalLoginUser struct { + Provider string `xorm:"index VARCHAR(255)"` + } + + return x.Sync(new(ExternalLoginUser)) +} diff --git a/models/user/external_login_user.go b/models/user/external_login_user.go index 965b7a5ed1dfd..43fe850ef2ded 100644 --- a/models/user/external_login_user.go +++ b/models/user/external_login_user.go @@ -61,7 +61,7 @@ type ExternalLoginUser struct { UserID int64 `xorm:"INDEX NOT NULL"` LoginSourceID int64 `xorm:"pk NOT NULL"` RawData map[string]any `xorm:"TEXT JSON"` - Provider string `xorm:"index VARCHAR(25)"` + Provider string `xorm:"index VARCHAR(255)"` Email string Name string FirstName string diff --git a/services/forms/auth_form.go b/services/forms/auth_form.go index 25acbbb99e877..8f4198d393fd4 100644 --- a/services/forms/auth_form.go +++ b/services/forms/auth_form.go @@ -16,7 +16,7 @@ import ( type AuthenticationForm struct { ID int64 Type int `binding:"Range(2,7)"` - Name string `binding:"Required;MaxSize(30)"` + Name string `binding:"Required;MaxSize(255)"` Host string Port int BindDN string