mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-28 07:02:39 +00:00

- Currently the options `pubkey` and `twofa` only consider TOTP and GPG keys respectively. Adjust the code to also consider WebAuthn credentials and SSH keys. - While adding the new unified functions I noticed that certain places also benefited from using these unified functions and took the liberty (where it was either a trivial translation or it was covered under testing) to use the new unified functions. - Resolves forgejo/forgejo#7658 - Adds unit and integration tests. Documentation PR: https://codeberg.org/forgejo/docs/pulls/1166 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7693 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
34 lines
758 B
Go
34 lines
758 B
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package asymkey
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"forgejo.org/models/unittest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestUserHasAsymKey(t *testing.T) {
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
t.Run("No key", func(t *testing.T) {
|
|
ok, err := HasAsymKeyByUID(t.Context(), 1)
|
|
require.NoError(t, err)
|
|
assert.False(t, ok)
|
|
})
|
|
|
|
t.Run("SSH key", func(t *testing.T) {
|
|
ok, err := HasAsymKeyByUID(t.Context(), 2)
|
|
require.NoError(t, err)
|
|
assert.True(t, ok)
|
|
})
|
|
|
|
t.Run("GPG key", func(t *testing.T) {
|
|
ok, err := HasAsymKeyByUID(t.Context(), 36)
|
|
require.NoError(t, err)
|
|
assert.True(t, ok)
|
|
})
|
|
}
|