feat(mysql): port atomic CLI authentication handoff persistence
This commit is contained in:
1 parent
cbcb8a24b4
commit
3e8a0b6a99
11 files changed
+234
-30
No files matched your search
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestAccountBackendCLIHandoff(t *testing.T) {
|
||||
for _, b := range []storeSQLBackend{storeSQLite, storePostgreSQL} {
|
||||
for _, b := range []storeSQLBackend{storeSQLite, storePostgreSQL, storeMySQL} {
|
||||
t.Run(fmt.Sprint(b), func(t *testing.T) {
|
||||
s, d := accountBackendStore(t, b)
|
||||
p, err := s.BootstrapOwner(d, "owner", "synthetic password for backend tests", "", "")
|
||||
|
||||
+53
-10
@@ -44,7 +44,7 @@ type CLIAuthRequest struct {
|
||||
Remember bool
|
||||
}
|
||||
|
||||
// Admission is serialized on both backends so concurrent unauthenticated
|
||||
// Admission is serialized on all backends so concurrent unauthenticated
|
||||
// requests cannot race the caps. Retain requests for issuance accounting.
|
||||
func (s *Store) StartCLIAuth(ctx context.Context, domain, origin, challenge string) (id, device, code string, err error) {
|
||||
return s.StartCLIAuthForLogin(ctx, domain, origin, challenge, false)
|
||||
@@ -76,6 +76,19 @@ func (s *Store) StartCLIAuthForLogin(ctx context.Context, domain, origin, challe
|
||||
if _, err := tx.ExecContext(ctx, `DELETE FROM auth_cli_requests WHERE expires_ms<`+s.sqlParam(1), now-5*60*1000); err != nil {
|
||||
return err
|
||||
}
|
||||
if s.sqlBackend == storeMySQL {
|
||||
// Read limits under the administrative write lock, avoiding a
|
||||
// target-table subquery in MySQL's INSERT. Admission remains atomic.
|
||||
var total, recent int
|
||||
if err := tx.QueryRowContext(ctx, `SELECT COUNT(*),COALESCE(SUM(domain_uuid=? AND created_ms>?),0) FROM auth_cli_requests`, domain, now-300000).Scan(&total, &recent); err != nil {
|
||||
return err
|
||||
}
|
||||
if total >= 4096 || recent >= 64 {
|
||||
return ErrCLILimit
|
||||
}
|
||||
_, err := tx.ExecContext(ctx, `INSERT INTO auth_cli_requests(id,domain_uuid,origin,device_hash,challenge,code_hash,created_ms,expires_ms,remember) VALUES(?,?,?,?,?,?,?,?,?)`, id, domain, origin, hashAuthToken(device), challenge, hashAuthToken(code), now, now+300000, rememberValue)
|
||||
return err
|
||||
}
|
||||
result, err := tx.ExecContext(ctx, `INSERT INTO auth_cli_requests(id,domain_uuid,origin,device_hash,challenge,code_hash,created_ms,expires_ms,remember)
|
||||
SELECT `+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,`+s.sqlParam(4)+`,`+s.sqlParam(5)+`,`+s.sqlParam(6)+`,`+s.sqlParam(7)+`,`+s.sqlParam(8)+`,`+s.sqlParam(9)+` WHERE (SELECT count(*) FROM auth_cli_requests)<4096
|
||||
AND (SELECT count(*) FROM auth_cli_requests WHERE domain_uuid=`+s.sqlParam(10)+` AND created_ms>`+s.sqlParam(11)+`)<64`,
|
||||
@@ -148,9 +161,14 @@ func (s *Store) DecideCLIAuth(ctx context.Context, domain, origin, id, browser,
|
||||
}
|
||||
now := time.Now().UnixMilli()
|
||||
var expectedCode string
|
||||
err := s.DB.QueryRowContext(ctx, `UPDATE auth_cli_requests SET attempts=attempts+1
|
||||
var err error
|
||||
if s.sqlBackend == storeMySQL {
|
||||
expectedCode, err = s.consumeCLIAuthAttemptMySQL(ctx, domain, origin, id, browser, now)
|
||||
} else {
|
||||
err = s.DB.QueryRowContext(ctx, `UPDATE auth_cli_requests SET attempts=attempts+1
|
||||
WHERE id=`+s.sqlParam(1)+` AND domain_uuid=`+s.sqlParam(2)+` AND origin=`+s.sqlParam(3)+` AND state='pending' AND browser_hash=`+s.sqlParam(4)+` AND attempts<5 AND expires_ms>`+s.sqlParam(5)+`
|
||||
RETURNING code_hash`, id, domain, origin, hashAuthToken(browser), now).Scan(&expectedCode)
|
||||
}
|
||||
if err != nil {
|
||||
return ErrAccessDenied
|
||||
}
|
||||
@@ -192,7 +210,11 @@ func (s *Store) ExchangeCLIAuth(ctx context.Context, domain, origin, device, ver
|
||||
now := time.Now().UnixMilli()
|
||||
lifetime := s.AuthSessionLifetime(domain).Milliseconds()
|
||||
trustedLifetime := s.LoginSessionLifetime(domain, true).Milliseconds()
|
||||
tx, err := s.DB.BeginTx(ctx, nil)
|
||||
var options *sql.TxOptions
|
||||
if s.sqlBackend == storeMySQL {
|
||||
options = &sql.TxOptions{Isolation: sql.LevelReadCommitted}
|
||||
}
|
||||
tx, err := s.DB.BeginTx(ctx, options)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -202,12 +224,21 @@ func (s *Store) ExchangeCLIAuth(ctx context.Context, domain, origin, device, ver
|
||||
if _, err = tx.ExecContext(ctx, `SELECT pg_advisory_xact_lock(1885431653, 1853058931)`); err != nil {
|
||||
return
|
||||
}
|
||||
} else if s.sqlBackend == storeMySQL {
|
||||
// Same lock order as account suspension and membership revocation.
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO namespace_write_lock(id) VALUES(1) ON DUPLICATE KEY UPDATE id=1`); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
var id, state, browser string
|
||||
var remember bool
|
||||
err = tx.QueryRowContext(ctx, `UPDATE auth_cli_requests SET next_poll_ms=`+s.sqlParam(1)+`,state=CASE WHEN state='approved' THEN 'consumed' ELSE state END
|
||||
if s.sqlBackend == storeMySQL {
|
||||
id, state, browser, remember, err = s.pollCLIAuthMySQL(ctx, tx, domain, origin, device, verifier, now)
|
||||
} else {
|
||||
err = tx.QueryRowContext(ctx, `UPDATE auth_cli_requests SET next_poll_ms=`+s.sqlParam(1)+`,state=CASE WHEN state='approved' THEN 'consumed' ELSE state END
|
||||
WHERE device_hash=`+s.sqlParam(2)+` AND challenge=`+s.sqlParam(3)+` AND domain_uuid=`+s.sqlParam(4)+` AND origin=`+s.sqlParam(5)+` AND expires_ms>`+s.sqlParam(6)+` AND next_poll_ms<=`+s.sqlParam(7)+` AND state IN ('pending','approved','denied')
|
||||
RETURNING id,state,browser_hash,remember`, now+5000, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now, now).Scan(&id, &state, &browser, &remember)
|
||||
}
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
var exists int
|
||||
e := tx.QueryRowContext(ctx, `SELECT count(*) FROM auth_cli_requests WHERE device_hash=`+s.sqlParam(1)+` AND challenge=`+s.sqlParam(2)+` AND domain_uuid=`+s.sqlParam(3)+` AND origin=`+s.sqlParam(4)+` AND expires_ms>`+s.sqlParam(5)+` AND state IN ('pending','approved','denied')`, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now).Scan(&exists)
|
||||
@@ -244,16 +275,28 @@ func (s *Store) ExchangeCLIAuth(ctx context.Context, domain, origin, device, ver
|
||||
}
|
||||
token = "pw_api_" + raw
|
||||
minimum, maximum := "min", "max"
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
if s.sqlBackend != storeSQLite {
|
||||
minimum, maximum = "LEAST", "GREATEST"
|
||||
}
|
||||
// A disabled user, removed membership or revoked browser cannot delegate.
|
||||
err = tx.QueryRowContext(ctx, `INSERT INTO auth_sessions(uuid,token_hash,principal_uuid,domain_uuid,auth_time_ms,expires_at_ms,last_seen_at_ms,mfa_level)
|
||||
SELECT `+s.sqlParam(1)+`,`+s.sqlParam(2)+`,p.uuid,a.domain_uuid,a.auth_time_ms,`+minimum+`(`+s.sqlParam(3)+`,a.expires_at_ms),`+s.sqlParam(4)+`,`+maximum+`(a.mfa_level,g.mfa_level)
|
||||
insert := `INSERT INTO auth_sessions(uuid,token_hash,principal_uuid,domain_uuid,auth_time_ms,expires_at_ms,last_seen_at_ms,mfa_level)
|
||||
SELECT ` + s.sqlParam(1) + `,` + s.sqlParam(2) + `,p.uuid,a.domain_uuid,a.auth_time_ms,` + minimum + `(` + s.sqlParam(3) + `,a.expires_at_ms),` + s.sqlParam(4) + `,` + maximum + `(a.mfa_level,g.mfa_level)
|
||||
FROM auth_cli_requests g JOIN auth_sessions a ON a.token_hash=g.browser_hash JOIN principals p ON p.uuid=a.principal_uuid JOIN domain_memberships m ON m.principal_uuid=p.uuid AND m.domain_uuid=a.domain_uuid
|
||||
WHERE a.token_hash=`+s.sqlParam(5)+` AND a.domain_uuid=`+s.sqlParam(6)+` AND a.revoked_at_ms=0 AND a.expires_at_ms>`+s.sqlParam(7)+` AND p.state IN ('active','readonly') AND m.state='active'
|
||||
AND g.id=`+s.sqlParam(8)+`
|
||||
RETURNING principal_uuid,expires_at_ms`, uuid.NewString(), hashAuthToken(token), now+lifetime, now, browser, domain, now, id).Scan(&username, &expires)
|
||||
WHERE a.token_hash=` + s.sqlParam(5) + ` AND a.domain_uuid=` + s.sqlParam(6) + ` AND a.revoked_at_ms=0 AND a.expires_at_ms>` + s.sqlParam(7) + ` AND p.state IN ('active','readonly') AND m.state='active'
|
||||
AND g.id=` + s.sqlParam(8)
|
||||
args := []any{uuid.NewString(), hashAuthToken(token), now + lifetime, now, browser, domain, now, id}
|
||||
if s.sqlBackend == storeMySQL {
|
||||
var result sql.Result
|
||||
result, err = tx.ExecContext(ctx, insert, args...)
|
||||
if err == nil {
|
||||
err = cliChanged(result, nil)
|
||||
}
|
||||
if err == nil {
|
||||
err = tx.QueryRowContext(ctx, `SELECT principal_uuid,expires_at_ms FROM auth_sessions WHERE uuid=?`, args[0]).Scan(&username, &expires)
|
||||
}
|
||||
} else {
|
||||
err = tx.QueryRowContext(ctx, insert+` RETURNING principal_uuid,expires_at_ms`, args...).Scan(&username, &expires)
|
||||
}
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = ErrAccessDenied
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAccountBackendCLIBoundaries(t *testing.T) {
|
||||
for _, backend := range []storeSQLBackend{storeSQLite, storePostgreSQL, storeMySQL} {
|
||||
t.Run(fmt.Sprint(backend), func(t *testing.T) {
|
||||
for _, mode := range []string{"domain", "origin", "verifier", "device", "expired", "denied", "suspended", "membership", "browser-revoked", "attempts", "read-only", "cancelled"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
s, domain := accountBackendStore(t, backend)
|
||||
ctx := context.Background()
|
||||
p, err := s.BootstrapOwner(domain, "owner", "synthetic CLI boundary password", "", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
browser, err := s.CreateBrowserAuthSession(domain, p.UUID, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
verifier := strings.Repeat("b", 43)
|
||||
id, device, code, err := s.StartCLIAuth(ctx, domain, cliTestOrigin, hashAuthToken(verifier))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = s.BindCLIAuth(ctx, domain, cliTestOrigin, id, browser); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mode == "attempts" {
|
||||
for i := 0; i < 5; i++ {
|
||||
if e := s.DecideCLIAuth(ctx, domain, cliTestOrigin, id, browser, "wrong", "", true); !errors.Is(e, ErrAccessDenied) {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
if e := s.DecideCLIAuth(ctx, domain, cliTestOrigin, id, browser, code, "", true); !errors.Is(e, ErrAccessDenied) {
|
||||
t.Fatal("attempt limit bypassed", e)
|
||||
}
|
||||
var attempts int
|
||||
if e := s.DB.QueryRow(`SELECT attempts FROM auth_cli_requests`).Scan(&attempts); e != nil || attempts != 5 {
|
||||
t.Fatal("failed attempts not retained", attempts, e)
|
||||
}
|
||||
} else if err = s.DecideCLIAuth(ctx, domain, cliTestOrigin, id, browser, code, "", mode != "denied"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
origin, query := cliTestOrigin, ""
|
||||
switch mode {
|
||||
case "domain":
|
||||
domain = "outside"
|
||||
case "origin":
|
||||
origin = "https://alias.example.test"
|
||||
case "verifier":
|
||||
verifier = strings.Repeat("c", 43)
|
||||
case "device":
|
||||
device = strings.Repeat("d", 43)
|
||||
case "expired":
|
||||
query = `UPDATE auth_cli_requests SET expires_ms=1`
|
||||
case "suspended":
|
||||
query = `UPDATE principals SET state='suspended'`
|
||||
case "membership":
|
||||
query = `UPDATE domain_memberships SET state='suspended'`
|
||||
case "browser-revoked":
|
||||
query = `UPDATE auth_sessions SET revoked_at_ms=1`
|
||||
case "read-only":
|
||||
s.ReadOnly = true
|
||||
case "cancelled":
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithCancel(ctx)
|
||||
cancel()
|
||||
}
|
||||
if query != "" {
|
||||
if _, err = s.DB.Exec(query); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if token, _, _, e := s.ExchangeCLIAuth(ctx, domain, origin, device, verifier); e == nil || token != "" {
|
||||
t.Fatal("invalid grant issued session", e)
|
||||
}
|
||||
var sessions int
|
||||
if e := s.DB.QueryRow(`SELECT COUNT(*) FROM auth_sessions`).Scan(&sessions); e != nil || sessions != 1 {
|
||||
t.Fatal("session leaked", sessions, e)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// Commit the attempt before checking the approval code. A wrong code must not
|
||||
// roll back its attempt counter. The row lock replaces UPDATE ... RETURNING.
|
||||
func (s *Store) consumeCLIAuthAttemptMySQL(ctx context.Context, domain, origin, id, browser string, now int64) (code string, err error) {
|
||||
err = s.groupWrite(ctx, func(ctx context.Context, tx *sql.Tx) error {
|
||||
if e := tx.QueryRowContext(ctx, `SELECT code_hash FROM auth_cli_requests WHERE id=? AND domain_uuid=? AND origin=? AND state='pending' AND browser_hash=? AND attempts<5 AND expires_ms>? FOR UPDATE`, id, domain, origin, hashAuthToken(browser), now).Scan(&code); e != nil {
|
||||
return e
|
||||
}
|
||||
_, e := tx.ExecContext(ctx, `UPDATE auth_cli_requests SET attempts=attempts+1 WHERE id=?`, id)
|
||||
return e
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// The caller holds the administrative lock and commits polling/consumption
|
||||
// together with session creation. Failed issuance rolls back consumption.
|
||||
func (s *Store) pollCLIAuthMySQL(ctx context.Context, tx *sql.Tx, domain, origin, device, verifier string, now int64) (id, state, browser string, remember bool, err error) {
|
||||
err = tx.QueryRowContext(ctx, `SELECT id,state,browser_hash,remember FROM auth_cli_requests WHERE device_hash=? AND challenge=? AND domain_uuid=? AND origin=? AND expires_ms>? AND next_poll_ms<=? AND state IN ('pending','approved','denied') FOR UPDATE`, hashAuthToken(device), hashAuthToken(verifier), domain, origin, now, now).Scan(&id, &state, &browser, &remember)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if state == "approved" {
|
||||
state = "consumed"
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `UPDATE auth_cli_requests SET next_poll_ms=?,state=? WHERE id=?`, now+5000, state, id)
|
||||
return
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// MUST authenticate and authorize every administrator mutation. It intentionally
|
||||
// exposes neither *Store nor grant-only checks as a complete authorization API.
|
||||
// MFA/provider persistence is internally tested but not exposed as a login API.
|
||||
// Audit/locality policy, CLI handoff and Domain deletion remain unported.
|
||||
// Audit/locality policy and Domain deletion remain unported.
|
||||
type MySQLIdentityRepository struct{ store *Store }
|
||||
|
||||
func NewMySQLIdentityRepository(database *sql.DB) *MySQLIdentityRepository {
|
||||
|
||||
@@ -49,6 +49,17 @@ func mysqlAuthMigrations() []db.MySQLMigration {
|
||||
// Inspect validates the latest contract only, since later versions may
|
||||
// replace older columns. This additive version must retain all v1 checks.
|
||||
steps[1].Assertions = append(append([]string{}, steps[0].Assertions...), steps[1].Assertions...)
|
||||
cli := mysqlAuthTableMigration(3, "CLI authentication handoff", []mysqlAuthTable{
|
||||
{"auth_cli_requests", []mysqlAuthColumn{
|
||||
{"id", "varchar(128)", ""}, {"domain_uuid", id, ""}, {"origin", "varchar(2048)", ""},
|
||||
{"device_hash", "varchar(128)", ""}, {"challenge", "varchar(128)", ""}, {"code_hash", "varchar(128)", ""},
|
||||
{"state", state, "'pending'"}, {"browser_hash", "varchar(128)", "''"}, {"principal_uuid", id, "''"},
|
||||
{"mfa_level", "int", "0"}, {"attempts", "int", "0"}, {"oidc_attempts", "int", "0"},
|
||||
{"created_ms", number, ""}, {"expires_ms", number, ""}, {"next_poll_ms", number, "0"}, {"remember", "int", "0"},
|
||||
}, []string{"id", "device_hash"}, []string{"domain_uuid,created_ms", "expires_ms"}},
|
||||
})
|
||||
cli.Assertions = append(append([]string{}, steps[1].Assertions...), cli.Assertions...)
|
||||
steps = append(steps, cli)
|
||||
return steps
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -206,7 +207,7 @@ func TestMySQLIdentitySchemaAndCancellation(t *testing.T) {
|
||||
database := mysqlTestDatabase(t)
|
||||
r := NewMySQLIdentityRepository(database)
|
||||
ctx := context.Background()
|
||||
if status, e := r.InspectSchema(ctx); e != nil || status.Pending != 5 {
|
||||
if status, e := r.InspectSchema(ctx); e != nil || status.Pending != 6 {
|
||||
t.Fatal(status, e)
|
||||
}
|
||||
if e := r.PrepareSchema(ctx); e != nil {
|
||||
@@ -215,7 +216,7 @@ func TestMySQLIdentitySchemaAndCancellation(t *testing.T) {
|
||||
if e := r.PrepareSchema(ctx); e != nil {
|
||||
t.Fatal("repeat prepare", e)
|
||||
}
|
||||
if _, e := database.Exec(`UPDATE schema_mysql_migrations SET state='running',next_operation=1 WHERE component='store-auth-core' AND version=2`); e != nil {
|
||||
if _, e := database.Exec(`UPDATE schema_mysql_migrations SET state='running',next_operation=1 WHERE component='store-auth-core' AND version=3`); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e := r.PrepareSchema(ctx); !errors.Is(e, db.ErrMySQLMigrationDirty) {
|
||||
@@ -256,37 +257,45 @@ func TestMySQLIdentitySchemaAndCancellation(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMySQLIdentitySchemaUpgradePreservesAccounts(t *testing.T) {
|
||||
for _, version := range []int{1, 2} {
|
||||
t.Run(fmt.Sprint(version), func(t *testing.T) {
|
||||
testMySQLIdentitySchemaUpgrade(t, version)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testMySQLIdentitySchemaUpgrade(t *testing.T, version int) {
|
||||
database := mysqlTestDatabase(t)
|
||||
ctx := context.Background()
|
||||
if err := NewMySQLNamespaceRepository(database).PrepareSchema(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
plan := mysqlAuthMigrations()
|
||||
if err := db.ApplyMySQLMigrations(ctx, database, "store-auth-core", plan[:1]); err != nil {
|
||||
if err := db.ApplyMySQLMigrations(ctx, database, "store-auth-core", plan[:version]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var before string
|
||||
if err := database.QueryRow(`SELECT checksum FROM schema_mysql_migrations WHERE component='store-auth-core' AND version=1`).Scan(&before); err != nil {
|
||||
if err := database.QueryRow(`SELECT GROUP_CONCAT(checksum ORDER BY version) FROM schema_mysql_migrations WHERE component='store-auth-core' AND version<=?`, version).Scan(&before); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := database.Exec(`INSERT INTO principals(uuid,display_name,created_at_ms,updated_at_ms) VALUES('upgrade-user','既存の利用者',1,1)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := NewMySQLIdentityRepository(database)
|
||||
if status, err := r.InspectSchema(ctx); err != nil || status.Pending != 1 || status.Applied != 4 {
|
||||
if status, err := r.InspectSchema(ctx); err != nil || status.Pending != 3-version || status.Applied != 3+version {
|
||||
t.Fatal(status, err)
|
||||
}
|
||||
if err := r.PrepareSchema(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var after, title string
|
||||
if err := database.QueryRow(`SELECT checksum FROM schema_mysql_migrations WHERE component='store-auth-core' AND version=1`).Scan(&after); err != nil || after != before {
|
||||
if err := database.QueryRow(`SELECT GROUP_CONCAT(checksum ORDER BY version) FROM schema_mysql_migrations WHERE component='store-auth-core' AND version<=?`, version).Scan(&after); err != nil || after != before {
|
||||
t.Fatal("historical checksum changed", err)
|
||||
}
|
||||
if err := database.QueryRow(`SELECT display_name FROM principals WHERE uuid='upgrade-user'`).Scan(&title); err != nil || title != "既存の利用者" {
|
||||
t.Fatal("existing principal changed", err)
|
||||
}
|
||||
if status, err := r.InspectSchema(ctx); err != nil || status.Pending != 0 || status.Applied != 5 {
|
||||
if status, err := r.InspectSchema(ctx); err != nil || status.Pending != 0 || status.Applied != 6 {
|
||||
t.Fatal(status, err)
|
||||
}
|
||||
if _, err := database.Exec(`ALTER TABLE auth_providers DROP INDEX uq_0`); err != nil {
|
||||
|
||||
@@ -23,7 +23,7 @@ func mysqlStoreError(operation string, err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
for _, known := range []error{sql.ErrNoRows, context.Canceled, context.DeadlineExceeded, ErrReadOnly, ErrBackendFeatureUnavailable, ErrAccessDenied} {
|
||||
for _, known := range []error{sql.ErrNoRows, context.Canceled, context.DeadlineExceeded, ErrReadOnly, ErrBackendFeatureUnavailable, ErrAccessDenied, ErrCLIPending, ErrCLISlowDown, ErrCLIExpired, ErrCLILimit} {
|
||||
if errors.Is(err, known) {
|
||||
return known
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user