2019-08-02 21:36:28 +05:30
|
|
|
// Copyright 2019 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 (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2019-08-02 21:36:28 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserListIsPublicMember(t *testing.T) {
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2019-08-02 21:36:28 +05:30
|
|
|
tt := []struct {
|
|
|
|
orgid int64
|
|
|
|
expected map[int64]bool
|
|
|
|
}{
|
2019-11-20 16:57:49 +05:30
|
|
|
{3, map[int64]bool{2: true, 4: false, 28: true}},
|
|
|
|
{6, map[int64]bool{5: true, 28: true}},
|
2019-08-02 21:36:28 +05:30
|
|
|
{7, map[int64]bool{5: false}},
|
|
|
|
{25, map[int64]bool{24: true}},
|
|
|
|
{22, map[int64]bool{}},
|
|
|
|
}
|
|
|
|
for _, v := range tt {
|
|
|
|
t.Run(fmt.Sprintf("IsPublicMemberOfOrdIg%d", v.orgid), func(t *testing.T) {
|
|
|
|
testUserListIsPublicMember(t, v.orgid, v.expected)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-03-15 00:22:12 +05:30
|
|
|
|
2019-08-02 21:36:28 +05:30
|
|
|
func testUserListIsPublicMember(t *testing.T, orgID int64, expected map[int64]bool) {
|
|
|
|
org, err := GetUserByID(orgID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, org.GetMembers())
|
|
|
|
assert.Equal(t, expected, org.MembersIsPublic)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserListIsUserOrgOwner(t *testing.T) {
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2019-08-02 21:36:28 +05:30
|
|
|
tt := []struct {
|
|
|
|
orgid int64
|
|
|
|
expected map[int64]bool
|
|
|
|
}{
|
2019-11-20 16:57:49 +05:30
|
|
|
{3, map[int64]bool{2: true, 4: false, 28: false}},
|
|
|
|
{6, map[int64]bool{5: true, 28: false}},
|
2019-08-02 21:36:28 +05:30
|
|
|
{7, map[int64]bool{5: true}},
|
|
|
|
{25, map[int64]bool{24: false}}, // ErrTeamNotExist
|
|
|
|
{22, map[int64]bool{}}, // No member
|
|
|
|
}
|
|
|
|
for _, v := range tt {
|
|
|
|
t.Run(fmt.Sprintf("IsUserOrgOwnerOfOrdIg%d", v.orgid), func(t *testing.T) {
|
|
|
|
testUserListIsUserOrgOwner(t, v.orgid, v.expected)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testUserListIsUserOrgOwner(t *testing.T, orgID int64, expected map[int64]bool) {
|
|
|
|
org, err := GetUserByID(orgID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, org.GetMembers())
|
|
|
|
assert.Equal(t, expected, org.Members.IsUserOrgOwner(orgID))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserListIsTwoFaEnrolled(t *testing.T) {
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2019-08-02 21:36:28 +05:30
|
|
|
tt := []struct {
|
|
|
|
orgid int64
|
|
|
|
expected map[int64]bool
|
|
|
|
}{
|
2019-11-20 16:57:49 +05:30
|
|
|
{3, map[int64]bool{2: false, 4: false, 28: false}},
|
|
|
|
{6, map[int64]bool{5: false, 28: false}},
|
2019-08-02 21:36:28 +05:30
|
|
|
{7, map[int64]bool{5: false}},
|
|
|
|
{25, map[int64]bool{24: true}},
|
|
|
|
{22, map[int64]bool{}},
|
|
|
|
}
|
|
|
|
for _, v := range tt {
|
|
|
|
t.Run(fmt.Sprintf("IsTwoFaEnrolledOfOrdIg%d", v.orgid), func(t *testing.T) {
|
|
|
|
testUserListIsTwoFaEnrolled(t, v.orgid, v.expected)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testUserListIsTwoFaEnrolled(t *testing.T, orgID int64, expected map[int64]bool) {
|
|
|
|
org, err := GetUserByID(orgID)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, org.GetMembers())
|
|
|
|
assert.Equal(t, expected, org.Members.GetTwoFaStatus())
|
|
|
|
}
|