Search in sources :

Example 46 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ChangeIT method pushCommitWithFooterOfOtherUserThatCannotSeeChange.

@Test
public void pushCommitWithFooterOfOtherUserThatCannotSeeChange() throws Exception {
    // create hidden project that is only visible to administrators
    Project.NameKey p = createProject("p");
    ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
    Util.allow(cfg, Permission.READ, groupCache.get(new AccountGroup.NameKey("Administrators")).getGroupUUID(), "refs/*");
    Util.block(cfg, Permission.READ, REGISTERED_USERS, "refs/*");
    saveProjectConfig(p, cfg);
    // admin pushes commit that references 'user' in a footer
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo, PushOneCommit.SUBJECT + "\n\n" + FooterConstants.REVIEWED_BY.getName() + ": " + user.getIdent().toExternalString(), PushOneCommit.FILE_NAME, PushOneCommit.FILE_CONTENT);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    // check that 'user' cannot see the change
    setApiUser(user);
    try {
        gApi.changes().id(result.getChangeId()).get();
        fail("Expected ResourceNotFoundException");
    } catch (ResourceNotFoundException e) {
    // Expected.
    }
    // check that 'user' was NOT added as cc ('user' can't see the change)
    setApiUser(admin);
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.reviewers.get(REVIEWER)).isNull();
    assertThat(change.reviewers.get(CC)).isNull();
    assertThat(sender.getMessages()).isEmpty();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 47 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ChangeIT method createNewDraftPatchSetOnDraftChange.

@Test
public void createNewDraftPatchSetOnDraftChange() throws Exception {
    // Create new project with clean permissions
    Project.NameKey p = createProject("addPatchSet4");
    // Clone separate repositories of the same project as admin and as user
    TestRepository<?> adminTestRepo = cloneProject(p, admin);
    TestRepository<?> userTestRepo = cloneProject(p, user);
    // Block default permission
    block(p, "refs/for/*", Permission.ADD_PATCH_SET, REGISTERED_USERS);
    // Create change as admin
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), adminTestRepo);
    PushOneCommit.Result r1 = push.to("refs/drafts/master");
    r1.assertOkStatus();
    // Add user as reviewer
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r1.getChangeId()).addReviewer(in);
    // Fetch change
    GitUtil.fetch(userTestRepo, r1.getPatchSet().getRefName() + ":ps");
    userTestRepo.reset("ps");
    // Amend change as user
    PushOneCommit.Result r2 = amendChange(r1.getChangeId(), "refs/drafts/master", user, userTestRepo);
    r2.assertErrorStatus("cannot add patch set to " + r1.getChange().getId().id + ".");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 48 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ChangeIT method createNewPatchSetWithoutPermission.

@Test
public void createNewPatchSetWithoutPermission() throws Exception {
    // Create new project with clean permissions
    Project.NameKey p = createProject("addPatchSet1");
    // Clone separate repositories of the same project as admin and as user
    TestRepository<InMemoryRepository> adminTestRepo = cloneProject(p, admin);
    TestRepository<InMemoryRepository> userTestRepo = cloneProject(p, user);
    // Block default permission
    block(p, "refs/for/*", Permission.ADD_PATCH_SET, REGISTERED_USERS);
    // Create change as admin
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), adminTestRepo);
    PushOneCommit.Result r1 = push.to("refs/for/master");
    r1.assertOkStatus();
    // Fetch change
    GitUtil.fetch(userTestRepo, r1.getPatchSet().getRefName() + ":ps");
    userTestRepo.reset("ps");
    // Amend change as user
    PushOneCommit.Result r2 = amendChange(r1.getChangeId(), "refs/for/master", user, userTestRepo);
    r2.assertErrorStatus("cannot add patch set to " + r1.getChange().getId().id + ".");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 49 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class AbstractSubmit method onlySelfSubmit.

@Test
public void onlySelfSubmit() throws Exception {
    // create project where only the change owner can submit
    Project.NameKey p = createProject("p");
    ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
    Util.block(cfg, Permission.SUBMIT, REGISTERED_USERS, "refs/*");
    Util.allow(cfg, Permission.SUBMIT, CHANGE_OWNER, "refs/*");
    Util.allow(cfg, Permission.forLabel("Code-Review"), -2, +2, REGISTERED_USERS, "refs/*");
    saveProjectConfig(p, cfg);
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id.get());
    setApiUser(user);
    submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
    setApiUser(admin);
    submit(result.getChangeId());
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 50 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class AbstractSubmit method noSelfSubmit.

@Test
public void noSelfSubmit() throws Exception {
    // create project where submit is blocked for the change owner
    Project.NameKey p = createProject("p");
    ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
    Util.block(cfg, Permission.SUBMIT, CHANGE_OWNER, "refs/*");
    Util.allow(cfg, Permission.SUBMIT, REGISTERED_USERS, "refs/heads/*");
    Util.allow(cfg, Permission.forLabel("Code-Review"), -2, +2, REGISTERED_USERS, "refs/*");
    saveProjectConfig(p, cfg);
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id.get());
    submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
    setApiUser(user);
    submit(result.getChangeId());
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Project (com.google.gerrit.reviewdb.client.Project)145 Test (org.junit.Test)73 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)47 Change (com.google.gerrit.reviewdb.client.Change)32 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)29 Branch (com.google.gerrit.reviewdb.client.Branch)25 Account (com.google.gerrit.reviewdb.client.Account)23 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)22 Config (org.eclipse.jgit.lib.Config)20 Repository (org.eclipse.jgit.lib.Repository)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)20 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)19 SubmoduleSubscription (com.google.gerrit.reviewdb.client.SubmoduleSubscription)17 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)16 IOException (java.io.IOException)16 ObjectId (org.eclipse.jgit.lib.ObjectId)16 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)15 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)14 SubmoduleSectionParser (com.google.gerrit.server.util.SubmoduleSectionParser)14