2017-02-02 20:33:36 +08:00
// Copyright 2017 The Gitea 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 models
import (
2019-08-02 18:06:28 +02:00
"fmt"
2017-02-02 20:33:36 +08:00
"testing"
2021-09-24 19:32:56 +08:00
"code.gitea.io/gitea/models/login"
2021-11-12 22:36:47 +08:00
"code.gitea.io/gitea/models/unittest"
2021-11-11 15:03:30 +08:00
user_model "code.gitea.io/gitea/models/user"
2017-02-14 20:16:00 +08:00
2017-02-02 20:33:36 +08:00
"github.com/stretchr/testify/assert"
)
2021-11-24 17:49:20 +08:00
func TestFollowUser ( t * testing . T ) {
2021-11-12 22:36:47 +08:00
assert . NoError ( t , unittest . PrepareTestDatabase ( ) )
2021-11-24 17:49:20 +08:00
testSuccess := func ( followerID , followedID int64 ) {
assert . NoError ( t , user_model . FollowUser ( followerID , followedID ) )
unittest . AssertExistsAndLoadBean ( t , & user_model . Follow { UserID : followerID , FollowID : followedID } )
}
testSuccess ( 4 , 2 )
testSuccess ( 5 , 2 )
assert . NoError ( t , user_model . FollowUser ( 2 , 2 ) )
unittest . CheckConsistencyFor ( t , & user_model . User { } )
}
func TestUnfollowUser ( t * testing . T ) {
assert . NoError ( t , unittest . PrepareTestDatabase ( ) )
testSuccess := func ( followerID , followedID int64 ) {
assert . NoError ( t , user_model . UnfollowUser ( followerID , followedID ) )
unittest . AssertNotExistsBean ( t , & user_model . Follow { UserID : followerID , FollowID : followedID } )
}
testSuccess ( 4 , 2 )
testSuccess ( 5 , 2 )
testSuccess ( 2 , 2 )
unittest . CheckConsistencyFor ( t , & user_model . User { } )
2021-09-24 19:32:56 +08:00
}
2019-08-02 18:06:28 +02:00
func TestUserIsPublicMember ( t * testing . T ) {
2021-11-12 22:36:47 +08:00
assert . NoError ( t , unittest . PrepareTestDatabase ( ) )
2019-08-02 18:06:28 +02:00
tt := [ ] struct {
uid int64
orgid int64
expected bool
} {
{ 2 , 3 , true } ,
{ 4 , 3 , false } ,
{ 5 , 6 , true } ,
{ 5 , 7 , false } ,
}
for _ , v := range tt {
t . Run ( fmt . Sprintf ( "UserId%dIsPublicMemberOf%d" , v . uid , v . orgid ) , func ( t * testing . T ) {
testUserIsPublicMember ( t , v . uid , v . orgid , v . expected )
} )
}
}
2021-03-15 02:52:12 +08:00
func testUserIsPublicMember ( t * testing . T , uid , orgID int64 , expected bool ) {
2021-11-24 17:49:20 +08:00
user , err := user_model . GetUserByID ( uid )
2019-08-02 18:06:28 +02:00
assert . NoError ( t , err )
2021-11-22 23:21:55 +08:00
is , err := IsPublicMembership ( orgID , user . ID )
assert . NoError ( t , err )
assert . Equal ( t , expected , is )
2019-08-02 18:06:28 +02:00
}
func TestIsUserOrgOwner ( t * testing . T ) {
2021-11-12 22:36:47 +08:00
assert . NoError ( t , unittest . PrepareTestDatabase ( ) )
2019-08-02 18:06:28 +02:00
tt := [ ] struct {
uid int64
orgid int64
expected bool
} {
{ 2 , 3 , true } ,
{ 4 , 3 , false } ,
{ 5 , 6 , true } ,
{ 5 , 7 , true } ,
}
for _ , v := range tt {
t . Run ( fmt . Sprintf ( "UserId%dIsOrgOwnerOf%d" , v . uid , v . orgid ) , func ( t * testing . T ) {
testIsUserOrgOwner ( t , v . uid , v . orgid , v . expected )
} )
}
}
2021-03-15 02:52:12 +08:00
func testIsUserOrgOwner ( t * testing . T , uid , orgID int64 , expected bool ) {
2021-11-24 17:49:20 +08:00
user , err := user_model . GetUserByID ( uid )
2019-08-02 18:06:28 +02:00
assert . NoError ( t , err )
2021-11-22 23:21:55 +08:00
is , err := IsOrganizationOwner ( orgID , user . ID )
assert . NoError ( t , err )
assert . Equal ( t , expected , is )
2019-08-02 18:06:28 +02:00
}
2019-10-09 01:55:16 +08:00
func TestGetOrgRepositoryIDs ( t * testing . T ) {
2021-11-12 22:36:47 +08:00
assert . NoError ( t , unittest . PrepareTestDatabase ( ) )
2021-11-24 17:49:20 +08:00
user2 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 2 } ) . ( * user_model . User )
user4 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 4 } ) . ( * user_model . User )
user5 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 5 } ) . ( * user_model . User )
2019-10-09 01:55:16 +08:00
2021-11-24 17:49:20 +08:00
accessibleRepos , err := GetOrgRepositoryIDs ( user2 )
2019-10-09 01:55:16 +08:00
assert . NoError ( t , err )
// User 2's team has access to private repos 3, 5, repo 32 is a public repo of the organization
assert . Equal ( t , [ ] int64 { 3 , 5 , 23 , 24 , 32 } , accessibleRepos )
2021-11-24 17:49:20 +08:00
accessibleRepos , err = GetOrgRepositoryIDs ( user4 )
2019-10-09 01:55:16 +08:00
assert . NoError ( t , err )
// User 4's team has access to private repo 3, repo 32 is a public repo of the organization
assert . Equal ( t , [ ] int64 { 3 , 32 } , accessibleRepos )
2021-11-24 17:49:20 +08:00
accessibleRepos , err = GetOrgRepositoryIDs ( user5 )
2019-10-09 01:55:16 +08:00
assert . NoError ( t , err )
// User 5's team has no access to any repo
assert . Len ( t , accessibleRepos , 0 )
}
2020-12-18 17:44:18 +00:00
func TestAddLdapSSHPublicKeys ( t * testing . T ) {
2021-11-12 22:36:47 +08:00
assert . NoError ( t , unittest . PrepareTestDatabase ( ) )
2020-12-18 17:44:18 +00:00
2021-11-24 17:49:20 +08:00
user := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 2 } ) . ( * user_model . User )
2021-09-24 19:32:56 +08:00
s := & login . Source { ID : 1 }
2020-12-18 17:44:18 +00:00
testCases := [ ] struct {
keyString string
number int
keyContents [ ] string
} {
{
keyString : "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1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LO2enwjGWWueOO6BodiBgyAOZ / 5 t5nJNMCNuLGT5UIo / RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL + tr1SZi / EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0 / iE9Pb5fkWO9c4AnM1FgI / 8 Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE / jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ + K2 / ioKgXqnXvltu0A9R8 / LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM = nocomment
ssh - dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x / DZuYAz3ibZ2OkQ3S0SqDIa0HXSEJ1zaExQdmbO + Ux / wsytWZmCczWOVsaszBZSl90q8UnWlSH6P + / YA + RWJm5SFtuV9PtGIhyZgoNuz5kBQ7K139wuQsecdKktISwTakzAAAAFQCzKsO2JhNKlL + wwwLGOcLffoAmkwAAAIBpK7 / 3 xvduajLBD / 9 vASqBQIHrgK2J + wiQnIb / Wzy0UsVmvfn8A + udRbBo + csM8xrSnlnlJnjkJS3qiM5g + eTwsLIV1IdKPEwmwB + VcP53Cw6lSyWyJcvhFb0N6s08NZysLzvj0N + ZC / FnhKTLzIyMtkHf / IrPCwlM + pV / M / 96 YgAAAIEAqQcGn9CKgzgPaguIZooTAOQdvBLMI5y0bQjOW6734XOpqQGf / Kra90wpoasLKZjSYKNPjE + FRUOrStLrxcNs4BeVKhy2PYTRnybfYVk1 / dmKgH6P1YSRONsGKvTsH6c5IyCRG0ncCgYeF8tXppyd642982daopE7zQ / NPAnJfag = nocomment ` ,
number : 2 ,
keyContents :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y2PYTRnybfYVk1/dmKgH6P1YSRONsGKvTsH6c5IyCRG0ncCgYeF8tXppyd642982daopE7zQ/NPAnJfag=" ,
} ,
} ,
{
keyString : ` ssh - rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn + iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr / cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ / 5 t5nJNMCNuLGT5UIo / RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL + tr1SZi / EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0 / iE9Pb5fkWO9c4AnM1FgI / 8 Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE / jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ + K2 / ioKgXqnXvltu0A9R8 / LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM = nocomment
# comment asmdna , ndp
ssh - dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x / DZuYAz3ibZ2OkQ3S0SqDIa0HXSEJ1zaExQdmbO + Ux / wsytWZmCczWOVsaszBZSl90q8UnWlSH6P + / YA + RWJm5SFtuV9PtGIhyZgoNuz5kBQ7K139wuQsecdKktISwTakzAAAAFQCzKsO2JhNKlL + wwwLGOcLffoAmkwAAAIBpK7 / 3 xvduajLBD / 9 vASqBQIHrgK2J + wiQnIb / Wzy0UsVmvfn8A + udRbBo + csM8xrSnlnlJnjkJS3qiM5g + eTwsLIV1IdKPEwmwB + VcP53Cw6lSyWyJcvhFb0N6s08NZysLzvj0N + ZC / FnhKTLzIyMt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A+udRbBo+csM8xrSnlnlJnjkJS3qiM5g+eTwsLIV1IdKPEwmwB+VcP53Cw6lSyWyJcvhFb0N6s08NZysLzvj0N+ZC/FnhKTLzIyMtkHf/IrPCwlM+pV/M/96YgAAAIEAqQcGn9CKgzgPaguIZooTAOQdvBLMI5y0bQjOW6734XOpqQGf/Kra90wpoasLKZjSYKNPjE+FRUOrStLrxcNs4BeVKhy2PYTRnybfYVk1/dmKgH6P1YSRONsGKvTsH6c5IyCRG0ncCgYeF8tXppyd642982daopE7zQ/NPAnJfag=" ,
} ,
} ,
{
keyString : ` ssh - rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn + iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr / cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ / 5 t5nJNMCNuLGT5UIo / RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL + tr1SZi / EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0 / iE9Pb5fkWO9c4AnM1FgI / 8 Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE / jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ + K2 / ioKgXqnXvltu0A9R8 / LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM = nocomment
382488320 jasdj1lasmva / vasodifipi4193 - fksma . cm
ssh - dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x / DZuYAz3ibZ2OkQ3S0SqDIa0HXSEJ1zaExQdmbO + Ux / wsytWZmCczWOVsaszBZSl90q8UnWlSH6P + / YA + RWJm5SFtuV9PtGIhyZgoNuz5kBQ7K139wuQsecdKktISwTakzAAAAFQCzKsO2JhNKlL + wwwLGOcLffoAmkwAAAIBpK7 / 3 xvduajLBD / 9 vASqBQIHrgK2J + wiQnIb / Wzy0UsVmvfn8A + udRbBo + csM8xrSnlnlJnjkJS3qiM5g + eTwsLIV1IdKPEwmwB + VcP53Cw6lSyWyJcvhFb0N6s08NZysLzvj0N + ZC / FnhKTLzIyMtkHf / IrPCwlM + pV / M / 96 YgAAAIEAqQcGn9CKgzgPaguIZooTAOQdvBLMI5y0bQjOW6734XOpqQGf / Kra90wpoasLKZjSYKNPjE + FRUOrStLrxcNs4BeVKhy2PYTRnybfYVk1 / dmKgH6P1YSRONsGKvTsH6c5IyCRG0ncCgYeF8tXppyd642982daopE7zQ / NPAnJfag = nocomment ` ,
number : 2 ,
keyContents : [ ] string {
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM=" ,
"ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ibZ2OkQ3S0SqDIa0HXSEJ1zaExQdmbO+Ux/wsytWZmCczWOVsaszBZSl90q8UnWlSH6P+/YA+RWJm5SFtuV9PtGIhyZgoNuz5kBQ7K139wuQsecdKktISwTakzAAAAFQCzKsO2JhNKlL+wwwLGOcLffoAmkwAAAIBpK7/3xvduajLBD/9vASqBQIHrgK2J+wiQnIb/Wzy0UsVmvfn8A+udRbBo+csM8xrSnlnlJnjkJS3qiM5g+eTwsLIV1IdKPEwmwB+VcP53Cw6lSyWyJcvhFb0N6s08NZysLzvj0N+ZC/FnhKTLzIyMtkHf/IrPCwlM+pV/M/96YgAAAIEAqQcGn9CKgzgPaguIZooTAOQdvBLMI5y0bQjOW6734XOpqQGf/Kra90wpoasLKZjSYKNPjE+FRUOrStLrxcNs4BeVKhy2PYTRnybfYVk1/dmKgH6P1YSRONsGKvTsH6c5IyCRG0ncCgYeF8tXppyd642982daopE7zQ/NPAnJfag=" ,
} ,
} ,
}
for i , kase := range testCases {
s . ID = int64 ( i ) + 20
2021-07-24 11:16:34 +01:00
AddPublicKeysBySource ( user , s , [ ] string { kase . keyString } )
keys , err := ListPublicKeysBySource ( user . ID , s . ID )
2020-12-18 17:44:18 +00:00
assert . NoError ( t , err )
if err != nil {
continue
}
2021-06-07 07:27:09 +02:00
assert . Len ( t , keys , kase . number )
2020-12-18 17:44:18 +00:00
for _ , key := range keys {
assert . Contains ( t , kase . keyContents , key . Content )
}
for _ , key := range keys {
DeletePublicKey ( user , key . ID )
}
}
}