@ -69,7 +69,7 @@ func TestAPISearchRepo(t *testing.T) {
user := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 15 } )
user2 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 16 } )
user 3 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 18 } )
org 3 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 18 } )
user4 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 20 } )
orgUser := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 17 } )
@ -140,11 +140,11 @@ func TestAPISearchRepo(t *testing.T) {
} ,
} ,
{
name : "RepositoriesAccessibleAndRelatedToUser3" , requestURL : fmt . Sprintf ( "/api/v1/repos/search?uid=%d" , user 3. ID ) , expectedResults : expectedResults {
name : "RepositoriesAccessibleAndRelatedToUser3" , requestURL : fmt . Sprintf ( "/api/v1/repos/search?uid=%d" , org 3. ID ) , expectedResults : expectedResults {
nil : { count : 1 } ,
user : { count : 4 , includesPrivate : true } ,
user2 : { count : 3 , includesPrivate : true } ,
user3 : { count : 4 , includesPrivate : true } ,
org3 : { count : 4 , includesPrivate : true } ,
} ,
} ,
{
@ -289,8 +289,8 @@ func TestAPIOrgRepos(t *testing.T) {
defer tests . PrepareTestEnv ( t ) ( )
user := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 2 } )
user2 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 1 } )
user 3 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 5 } )
// User 3 is an Org. Check their repos.
org 3 := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 5 } )
// org 3 is an Org. Check their repos.
sourceOrg := unittest . AssertExistsAndLoadBean ( t , & user_model . User { ID : 3 } )
expectedResults := map [ * user_model . User ] struct {
@ -300,7 +300,7 @@ func TestAPIOrgRepos(t *testing.T) {
user : { count : 1 } ,
user : { count : 3 , includesPrivate : true } ,
user2 : { count : 3 , includesPrivate : true } ,
user3 : { count : 1 } ,
org3 : { count : 1 } ,
}
for userToLogin , expected := range expectedResults {
@ -438,11 +438,11 @@ func TestAPIOrgRepoCreate(t *testing.T) {
orgName , repoName string
expectedStatus int
} {
{ ctxUserID : 1 , orgName : "user 3" , repoName : "repo-admin" , expectedStatus : http . StatusCreated } ,
{ ctxUserID : 2 , orgName : "user 3" , repoName : "repo-own" , expectedStatus : http . StatusCreated } ,
{ ctxUserID : 2 , orgName : "user 6" , repoName : "repo-bad-org" , expectedStatus : http . StatusForbidden } ,
{ ctxUserID : 28 , orgName : "user 3" , repoName : "repo-creator" , expectedStatus : http . StatusCreated } ,
{ ctxUserID : 28 , orgName : "user 6" , repoName : "repo-not-creator" , expectedStatus : http . StatusForbidden } ,
{ ctxUserID : 1 , orgName : "org 3" , repoName : "repo-admin" , expectedStatus : http . StatusCreated } ,
{ ctxUserID : 2 , orgName : "org 3" , repoName : "repo-own" , expectedStatus : http . StatusCreated } ,
{ ctxUserID : 2 , orgName : "org 6" , repoName : "repo-bad-org" , expectedStatus : http . StatusForbidden } ,
{ ctxUserID : 28 , orgName : "org 3" , repoName : "repo-creator" , expectedStatus : http . StatusCreated } ,
{ ctxUserID : 28 , orgName : "org 6" , repoName : "repo-not-creator" , expectedStatus : http . StatusForbidden } ,
}
defer tests . PrepareTestEnv ( t ) ( )
@ -491,21 +491,21 @@ func TestAPIRepoTransfer(t *testing.T) {
teams * [ ] int64
expectedStatus int
} {
// Disclaimer for test story: "user1" is an admin, "user2" is normal user and part of in owner team of org "user 3"
// Disclaimer for test story: "user1" is an admin, "user2" is normal user and part of in owner team of org "org 3"
// Transfer to a user with teams in another org should fail
{ ctxUserID : 1 , newOwner : "user 3" , teams : & [ ] int64 { 5 } , expectedStatus : http . StatusForbidden } ,
{ ctxUserID : 1 , newOwner : "org 3" , teams : & [ ] int64 { 5 } , expectedStatus : http . StatusForbidden } ,
// Transfer to a user with non-existent team IDs should fail
{ ctxUserID : 1 , newOwner : "user2" , teams : & [ ] int64 { 2 } , expectedStatus : http . StatusUnprocessableEntity } ,
// Transfer should go through
{ ctxUserID : 1 , newOwner : "user 3" , teams : & [ ] int64 { 2 } , expectedStatus : http . StatusAccepted } ,
{ ctxUserID : 1 , newOwner : "org 3" , teams : & [ ] int64 { 2 } , expectedStatus : http . StatusAccepted } ,
// Let user transfer it back to himself
{ ctxUserID : 2 , newOwner : "user2" , expectedStatus : http . StatusAccepted } ,
// And revert transfer
{ ctxUserID : 2 , newOwner : "user 3" , teams : & [ ] int64 { 2 } , expectedStatus : http . StatusAccepted } ,
{ ctxUserID : 2 , newOwner : "org 3" , teams : & [ ] int64 { 2 } , expectedStatus : http . StatusAccepted } ,
// Cannot start transfer to an existing repo
{ ctxUserID : 2 , newOwner : "user 3" , teams : nil , expectedStatus : http . StatusUnprocessableEntity } ,
{ ctxUserID : 2 , newOwner : "org 3" , teams : nil , expectedStatus : http . StatusUnprocessableEntity } ,
// Start transfer, repo is now in pending transfer mode
{ ctxUserID : 2 , newOwner : "user 6" , teams : nil , expectedStatus : http . StatusCreated } ,
{ ctxUserID : 2 , newOwner : "org 6" , teams : nil , expectedStatus : http . StatusCreated } ,
}
defer tests . PrepareTestEnv ( t ) ( )
@ -648,7 +648,7 @@ func TestAPIGenerateRepo(t *testing.T) {
// org
req = NewRequestWithJSON ( t , "POST" , fmt . Sprintf ( "/api/v1/repos/%s/%s/generate?token=%s" , templateRepo . OwnerName , templateRepo . Name , token ) , & api . GenerateRepoOption {
Owner : "user 3" ,
Owner : "org 3" ,
Name : "new-repo" ,
Description : "test generate repo" ,
Private : false ,