|
|
@ -25,19 +25,19 @@ func TestAccessLevel(t *testing.T) { |
|
|
|
repo1 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 2, IsPrivate: false}).(*Repository) |
|
|
|
repo1 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 2, IsPrivate: false}).(*Repository) |
|
|
|
repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository) |
|
|
|
repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository) |
|
|
|
|
|
|
|
|
|
|
|
level, err := AccessLevel(user1, repo1) |
|
|
|
level, err := AccessLevel(user1.ID, repo1) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.Equal(t, AccessModeOwner, level) |
|
|
|
assert.Equal(t, AccessModeOwner, level) |
|
|
|
|
|
|
|
|
|
|
|
level, err = AccessLevel(user1, repo2) |
|
|
|
level, err = AccessLevel(user1.ID, repo2) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.Equal(t, AccessModeWrite, level) |
|
|
|
assert.Equal(t, AccessModeWrite, level) |
|
|
|
|
|
|
|
|
|
|
|
level, err = AccessLevel(user2, repo1) |
|
|
|
level, err = AccessLevel(user2.ID, repo1) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.Equal(t, AccessModeRead, level) |
|
|
|
assert.Equal(t, AccessModeRead, level) |
|
|
|
|
|
|
|
|
|
|
|
level, err = AccessLevel(user2, repo2) |
|
|
|
level, err = AccessLevel(user2.ID, repo2) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.Equal(t, AccessModeNone, level) |
|
|
|
assert.Equal(t, AccessModeNone, level) |
|
|
|
} |
|
|
|
} |
|
|
@ -51,19 +51,19 @@ func TestHasAccess(t *testing.T) { |
|
|
|
repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository) |
|
|
|
repo2 := AssertExistsAndLoadBean(t, &Repository{OwnerID: 3, IsPrivate: true}).(*Repository) |
|
|
|
|
|
|
|
|
|
|
|
for _, accessMode := range accessModes { |
|
|
|
for _, accessMode := range accessModes { |
|
|
|
has, err := HasAccess(user1, repo1, accessMode) |
|
|
|
has, err := HasAccess(user1.ID, repo1, accessMode) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.True(t, has) |
|
|
|
assert.True(t, has) |
|
|
|
|
|
|
|
|
|
|
|
has, err = HasAccess(user1, repo2, accessMode) |
|
|
|
has, err = HasAccess(user1.ID, repo2, accessMode) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.Equal(t, accessMode <= AccessModeWrite, has) |
|
|
|
assert.Equal(t, accessMode <= AccessModeWrite, has) |
|
|
|
|
|
|
|
|
|
|
|
has, err = HasAccess(user2, repo1, accessMode) |
|
|
|
has, err = HasAccess(user2.ID, repo1, accessMode) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.Equal(t, accessMode <= AccessModeRead, has) |
|
|
|
assert.Equal(t, accessMode <= AccessModeRead, has) |
|
|
|
|
|
|
|
|
|
|
|
has, err = HasAccess(user2, repo2, accessMode) |
|
|
|
has, err = HasAccess(user2.ID, repo2, accessMode) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.NoError(t, err) |
|
|
|
assert.Equal(t, accessMode <= AccessModeNone, has) |
|
|
|
assert.Equal(t, accessMode <= AccessModeNone, has) |
|
|
|
} |
|
|
|
} |
|
|
|