1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-22 17:34:03 +03:00

Override xorm type mapping for U2F counter (#6232)

This commit is contained in:
Maurizio Porrato 2019-03-05 02:34:52 +00:00 committed by techknowlogick
parent 141c58f5a6
commit 19862699cd
4 changed files with 43 additions and 1 deletions

View File

@ -215,6 +215,8 @@ var migrations = []Migration{
NewMigration("add can close issues via commit in any branch", addCanCloseIssuesViaCommitInAnyBranch), NewMigration("add can close issues via commit in any branch", addCanCloseIssuesViaCommitInAnyBranch),
// v80 -> v81 // v80 -> v81
NewMigration("add is locked to issues", addIsLockedToIssues), NewMigration("add is locked to issues", addIsLockedToIssues),
// v81 -> v82
NewMigration("update U2F counter type", changeU2FCounterType),
} }
// Migrate database to current version // Migrate database to current version

32
models/migrations/v81.go Normal file
View File

@ -0,0 +1,32 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package migrations
import (
"fmt"
"github.com/go-xorm/xorm"
)
func changeU2FCounterType(x *xorm.Engine) error {
var err error
switch x.Dialect().DriverName() {
case "tidb":
fallthrough
case "mysql":
_, err = x.Exec("ALTER TABLE `u2f_registration` MODIFY `counter` BIGINT")
case "postgres":
_, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` SET DATA TYPE bigint")
case "mssql":
_, err = x.Exec("ALTER TABLE `u2f_registration` ALTER COLUMN `counter` BIGINT")
}
if err != nil {
return fmt.Errorf("Error changing u2f_registration counter column type: %v", err)
}
return nil
}

View File

@ -17,7 +17,7 @@ type U2FRegistration struct {
Name string Name string
UserID int64 `xorm:"INDEX"` UserID int64 `xorm:"INDEX"`
Raw []byte Raw []byte
Counter uint32 Counter uint32 `xorm:"BIGINT"`
CreatedUnix util.TimeStamp `xorm:"INDEX created"` CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
} }

View File

@ -40,6 +40,14 @@ func TestU2FRegistration_UpdateCounter(t *testing.T) {
AssertExistsIf(t, true, &U2FRegistration{ID: 1, Counter: 1}) AssertExistsIf(t, true, &U2FRegistration{ID: 1, Counter: 1})
} }
func TestU2FRegistration_UpdateLargeCounter(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
reg := AssertExistsAndLoadBean(t, &U2FRegistration{ID: 1}).(*U2FRegistration)
reg.Counter = 0xffffffff
assert.NoError(t, reg.UpdateCounter())
AssertExistsIf(t, true, &U2FRegistration{ID: 1, Counter: 0xffffffff})
}
func TestCreateRegistration(t *testing.T) { func TestCreateRegistration(t *testing.T) {
assert.NoError(t, PrepareTestDatabase()) assert.NoError(t, PrepareTestDatabase())
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)