1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-07-21 02:29:41 +02:00
forgejo/models/auth/two_factor_test.go

36 lines
839 B
Go
Raw Normal View History

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package auth
import (
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestHasTwoFactorByUID(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
t.Run("No twofactor", func(t *testing.T) {
ok, err := HasTwoFactorByUID(db.DefaultContext, 2)
require.NoError(t, err)
assert.False(t, ok)
})
t.Run("WebAuthn credential", func(t *testing.T) {
ok, err := HasTwoFactorByUID(db.DefaultContext, 32)
require.NoError(t, err)
assert.True(t, ok)
})
t.Run("TOTP", func(t *testing.T) {
ok, err := HasTwoFactorByUID(db.DefaultContext, 24)
require.NoError(t, err)
assert.True(t, ok)
})
}