summaryrefslogtreecommitdiffstats
path: root/models/access_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2018-11-28 19:26:14 +0800
committerGitHub <noreply@github.com>2018-11-28 19:26:14 +0800
commiteabbddcd98717ef20d8475e819f403c50f4a9787 (patch)
treeefc525e7ec60d56d3bec72019febfa088a128b89 /models/access_test.go
parent0222623be9fa4a56d870213f77b92139cefc2518 (diff)
downloadgitea-eabbddcd98717ef20d8475e819f403c50f4a9787.tar.gz
gitea-eabbddcd98717ef20d8475e819f403c50f4a9787.zip
Restrict permission check on repositories and fix some problems (#5314)
* fix units permission problems * fix some bugs and merge LoadUnits to repoAssignment * refactor permission struct and add some copyright heads * remove unused codes * fix routes units check * improve permission check * add unit tests for permission * fix typo * fix tests * fix some routes * fix api permission check * improve permission check * fix some permission check * fix tests * fix tests * improve some permission check * fix some permission check * refactor AccessLevel * fix bug * fix tests * fix tests * fix tests * fix AccessLevel * rename CanAccess * fix tests * fix comment * fix bug * add missing unit for test repos * fix bug * rename some functions * fix routes check
Diffstat (limited to 'models/access_test.go')
-rw-r--r--models/access_test.go41
1 files changed, 18 insertions, 23 deletions
diff --git a/models/access_test.go b/models/access_test.go
index 46d6f723ea..d6a1c92b90 100644
--- a/models/access_test.go
+++ b/models/access_test.go
@@ -20,28 +20,28 @@ var accessModes = []AccessMode{
func TestAccessLevel(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
- user1 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
- user2 := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
+ user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ user5 := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
// A public repository owned by User 2
repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
assert.False(t, repo1.IsPrivate)
// A private repository owned by Org 3
- repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
- assert.True(t, repo2.IsPrivate)
+ repo3 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
+ assert.True(t, repo3.IsPrivate)
- level, err := AccessLevel(user1.ID, repo1)
+ level, err := AccessLevel(user2, repo1)
assert.NoError(t, err)
assert.Equal(t, AccessModeOwner, level)
- level, err = AccessLevel(user1.ID, repo2)
+ level, err = AccessLevel(user2, repo3)
assert.NoError(t, err)
- assert.Equal(t, AccessModeWrite, level)
+ assert.Equal(t, AccessModeOwner, level)
- level, err = AccessLevel(user2.ID, repo1)
+ level, err = AccessLevel(user5, repo1)
assert.NoError(t, err)
assert.Equal(t, AccessModeRead, level)
- level, err = AccessLevel(user2.ID, repo2)
+ level, err = AccessLevel(user5, repo3)
assert.NoError(t, err)
assert.Equal(t, AccessModeNone, level)
}
@@ -58,23 +58,18 @@ func TestHasAccess(t *testing.T) {
repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
assert.True(t, repo2.IsPrivate)
- for _, accessMode := range accessModes {
- has, err := HasAccess(user1.ID, repo1, accessMode)
- assert.NoError(t, err)
- assert.True(t, has)
+ has, err := HasAccess(user1.ID, repo1)
+ assert.NoError(t, err)
+ assert.True(t, has)
- has, err = HasAccess(user1.ID, repo2, accessMode)
- assert.NoError(t, err)
- assert.Equal(t, accessMode <= AccessModeWrite, has)
+ has, err = HasAccess(user1.ID, repo2)
+ assert.NoError(t, err)
- has, err = HasAccess(user2.ID, repo1, accessMode)
- assert.NoError(t, err)
- assert.Equal(t, accessMode <= AccessModeRead, has)
+ has, err = HasAccess(user2.ID, repo1)
+ assert.NoError(t, err)
- has, err = HasAccess(user2.ID, repo2, accessMode)
- assert.NoError(t, err)
- assert.Equal(t, accessMode <= AccessModeNone, has)
- }
+ has, err = HasAccess(user2.ID, repo2)
+ assert.NoError(t, err)
}
func TestUser_GetRepositoryAccesses(t *testing.T) {