// Copyright 2020 The Gogs 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 db import ( "testing" "time" "github.com/jinzhu/gorm" "github.com/stretchr/testify/assert" "gogs.io/gogs/internal/errutil" ) func Test_twoFactors(t *testing.T) { if testing.Short() { t.Skip() } t.Parallel() tables := []interface{}{new(TwoFactor), new(TwoFactorRecoveryCode)} db := &twoFactors{ DB: initTestDB(t, "twoFactors", tables...), } for _, tc := range []struct { name string test func(*testing.T, *twoFactors) }{ {"Create", test_twoFactors_Create}, {"GetByUserID", test_twoFactors_GetByUserID}, {"IsUserEnabled", test_twoFactors_IsUserEnabled}, } { t.Run(tc.name, func(t *testing.T) { t.Cleanup(func() { err := clearTables(t, db.DB, tables...) if err != nil { t.Fatal(err) } }) tc.test(t, db) }) } } func test_twoFactors_Create(t *testing.T, db *twoFactors) { // Create a 2FA token err := db.Create(1, "secure-key", "secure-secret") if err != nil { t.Fatal(err) } // Get it back and check the Created field tf, err := db.GetByUserID(1) if err != nil { t.Fatal(err) } assert.Equal(t, gorm.NowFunc().Format(time.RFC3339), tf.Created.UTC().Format(time.RFC3339)) // Verify there are 10 recover codes generated var count int64 err = db.Model(new(TwoFactorRecoveryCode)).Count(&count).Error if err != nil { t.Fatal(err) } assert.Equal(t, int64(10), count) } func test_twoFactors_GetByUserID(t *testing.T, db *twoFactors) { // Create a 2FA token for user 1 err := db.Create(1, "secure-key", "secure-secret") if err != nil { t.Fatal(err) } // We should be able to get it back _, err = db.GetByUserID(1) if err != nil { t.Fatal(err) } // Try to get a non-existent 2FA token _, err = db.GetByUserID(2) expErr := ErrTwoFactorNotFound{args: errutil.Args{"userID": int64(2)}} assert.Equal(t, expErr, err) } func test_twoFactors_IsUserEnabled(t *testing.T, db *twoFactors) { // Create a 2FA token for user 1 err := db.Create(1, "secure-key", "secure-secret") if err != nil { t.Fatal(err) } assert.True(t, db.IsUserEnabled(1)) assert.False(t, db.IsUserEnabled(2)) } PANIC: session(release): write data/sessions/e/8/e8ad667cb9987f23: no space left on device

PANIC

session(release): write data/sessions/e/8/e8ad667cb9987f23: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)