File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ // Copyright 2019 The Gitea Authors. All rights reserved.
2+ // SPDX-License-Identifier: MIT
3+
4+ package asymkey
5+
6+ import (
7+ "testing"
8+
9+ "code.gitea.io/gitea/models/unittest"
10+
11+ user_model "code.gitea.io/gitea/models/user"
12+
13+ "github.com/stretchr/testify/assert"
14+ )
15+
16+ func TestUserHasPubkeys (t * testing.T ) {
17+ ctx := t .Context ()
18+
19+ t .Run ("AllowUserWithGPGKey" , func (t * testing.T ) {
20+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 36 }) // user has GPG key
21+ hasKeys , err := userHasPubkeys (ctx , user )
22+ assert .NoError (t , err )
23+ assert .True (t , hasKeys )
24+ })
25+
26+ t .Run ("AllowUserWithSSHKey" , func (t * testing.T ) {
27+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 }) // user has SSH key
28+ hasKeys , err := userHasPubkeys (ctx , user )
29+ assert .NoError (t , err )
30+ assert .True (t , hasKeys )
31+ })
32+
33+ t .Run ("DenyUserWithNoKeys" , func (t * testing.T ) {
34+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 1 })
35+ hasKeys , err := userHasPubkeys (ctx , user )
36+ assert .NoError (t , err )
37+ assert .False (t , hasKeys )
38+ })
39+ }
You can’t perform that action at this time.
0 commit comments