mirror of
https://github.com/VibedByKaKi/forgejo-11-secure.git
synced 2026-10-19 00:38:06 +02:00
- Currently during external login (such as OAuth2), if the user is enrolled into Webauthn and not enrolled into TOTP then no 2FA is being done during external login and when account linking is set to `auto` then also during automatic linking. This results in bypassing the 2FA of the user. - Create a new unified function that checks if the user is enrolled into 2FA and use this when necessary. Rename the old `HasTwoFactorByUID` function to `HasTOTPByUID` which is a more appropiate naming. (cherry picked from commit df5d65682737fee8e215e9f7dc6b369bba3bf313) Conflicts: the original commit was trimmed down to be fit for backport
34 lines
780 B
Go
34 lines
780 B
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package auth
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"forgejo.org/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(t.Context(), 2)
|
|
require.NoError(t, err)
|
|
assert.False(t, ok)
|
|
})
|
|
|
|
t.Run("WebAuthn credential", func(t *testing.T) {
|
|
ok, err := HasTwoFactorByUID(t.Context(), 32)
|
|
require.NoError(t, err)
|
|
assert.True(t, ok)
|
|
})
|
|
|
|
t.Run("TOTP", func(t *testing.T) {
|
|
ok, err := HasTwoFactorByUID(t.Context(), 24)
|
|
require.NoError(t, err)
|
|
assert.True(t, ok)
|
|
})
|
|
}
|