Search in sources :

Example 81 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class ChangeIT method pushCommitOfOtherUserThatCannotSeeChange.

@Test
public void pushCommitOfOtherUserThatCannotSeeChange() throws Exception {
    // create hidden project that is only visible to administrators
    Project.NameKey p = projectOperations.newProject().create();
    projectOperations.project(p).forUpdate().add(allow(Permission.READ).ref("refs/*").group(adminGroupUuid())).add(block(Permission.READ).ref("refs/*").group(REGISTERED_USERS)).update();
    // admin pushes commit of user
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(user.newIdent(), 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());
    CommitInfo commit = change.revisions.get(change.currentRevision).commit;
    assertThat(commit.author.email).isEqualTo(user.email());
    assertThat(commit.committer.email).isEqualTo(user.email());
    // check the user cannot see the change
    requestScopeOperations.setApiUser(user.id());
    assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(result.getChangeId()).get());
    // check that the author/committer was NOT added as reviewer (he can't see
    // the change)
    assertThat(change.reviewers.get(REVIEWER)).isNull();
    assertThat(change.reviewers.get(CC)).isNull();
    assertThat(sender.getMessages()).isEmpty();
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 82 with Project

use of com.google.gerrit.entities.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 = projectOperations.newProject().create();
    projectOperations.project(p).forUpdate().add(allow(Permission.READ).ref("refs/*").group(adminGroupUuid())).add(block(Permission.READ).ref("refs/*").group(REGISTERED_USERS)).update();
    // admin pushes commit that references 'user' in a footer
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(admin.newIdent(), repo, PushOneCommit.SUBJECT + "\n\n" + FooterConstants.REVIEWED_BY.getName() + ": " + user.newIdent().toExternalString(), PushOneCommit.FILE_NAME, PushOneCommit.FILE_CONTENT);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    // check that 'user' cannot see the change
    requestScopeOperations.setApiUser(user.id());
    assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(result.getChangeId()).get());
    // check that 'user' was NOT added as cc ('user' can't see the change)
    requestScopeOperations.setApiUser(admin.id());
    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 : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 83 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byHasDraftExcludesZombieDrafts.

/**
 * This test does not have a test about drafts computed from All-Users Repository because zombie
 * drafts can't be filtered when computing from All-Users repository. TODO(paiking): During
 * rollout, we should find a way to fix zombie drafts.
 */
public void byHasDraftExcludesZombieDrafts() throws Exception {
    Project.NameKey project = Project.nameKey("repo");
    TestRepository<Repo> repo = createProject(project.get());
    Change change = insert(repo, newChange(repo));
    Change.Id id = change.getId();
    DraftInput in = new DraftInput();
    in.line = 1;
    in.message = "nit: trailing whitespace";
    in.path = Patch.COMMIT_MSG;
    gApi.changes().id(id.get()).current().createDraft(in);
    assertQuery("has:draft", change);
    assertQuery("commentby:" + userId);
    try (TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName))) {
        Ref draftsRef = allUsers.getRepository().exactRef(RefNames.refsDraftComments(id, userId));
        assertThat(draftsRef).isNotNull();
        ReviewInput rin = ReviewInput.dislike();
        rin.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
        gApi.changes().id(id.get()).current().review(rin);
        assertQuery("has:draft");
        assertQuery("commentby:" + userId, change);
        assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNull();
        // Re-add drafts ref and ensure it gets filtered out during indexing.
        allUsers.update(draftsRef.getName(), draftsRef.getObjectId());
        assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNotNull();
    }
    indexer.index(project, id);
    assertQuery("has:draft");
}
Also used : Project(com.google.gerrit.entities.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) Ref(org.eclipse.jgit.lib.Ref) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.entities.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput)

Example 84 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method reviewerAndCcByEmail.

@Test
public void reviewerAndCcByEmail() throws Exception {
    Project.NameKey project = Project.nameKey("repo");
    TestRepository<Repo> repo = createProject(project.get());
    ConfigInput conf = new ConfigInput();
    conf.enableReviewerByEmail = InheritableBoolean.TRUE;
    gApi.projects().name(project.get()).config(conf);
    String userByEmail = "un.registered@reviewer.com";
    String userByEmailWithName = "John Doe <" + userByEmail + ">";
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChange(repo));
    insert(repo, newChange(repo));
    ReviewerInput rin = new ReviewerInput();
    rin.reviewer = userByEmailWithName;
    rin.state = ReviewerState.REVIEWER;
    gApi.changes().id(change1.getId().get()).addReviewer(rin);
    rin = new ReviewerInput();
    rin.reviewer = userByEmailWithName;
    rin.state = ReviewerState.CC;
    gApi.changes().id(change2.getId().get()).addReviewer(rin);
    assertQuery("reviewer:\"" + userByEmailWithName + "\"", change1);
    assertQuery("cc:\"" + userByEmailWithName + "\"", change2);
    // Omitting the name:
    assertQuery("reviewer:\"" + userByEmail + "\"", change1);
    assertQuery("cc:\"" + userByEmail + "\"", change2);
}
Also used : Project(com.google.gerrit.entities.Project) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) Change(com.google.gerrit.entities.Change) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test)

Example 85 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byLabelMulti.

@Test
public void byLabelMulti() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Project.NameKey project = Project.nameKey(repo.getRepository().getDescription().getRepositoryName());
    LabelType verified = label(LabelId.VERIFIED, value(1, "Passes"), value(0, "No score"), value(-1, "Failed"));
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        ProjectConfig cfg = projectConfigFactory.create(project);
        cfg.load(md);
        cfg.upsertLabelType(verified);
        cfg.commit(md);
    }
    projectCache.evictAndReindex(project);
    String heads = RefNames.REFS_HEADS + "*";
    projectOperations.project(project).forUpdate().add(allowLabel(verified.getName()).ref(heads).group(REGISTERED_USERS).range(-1, 1)).update();
    ReviewInput reviewVerified = new ReviewInput().label(LabelId.VERIFIED, 1);
    ChangeInserter ins = newChange(repo);
    ChangeInserter ins2 = newChange(repo);
    ChangeInserter ins3 = newChange(repo);
    ChangeInserter ins4 = newChange(repo);
    ChangeInserter ins5 = newChange(repo);
    // CR+1
    Change reviewCRplus1 = insert(repo, ins);
    gApi.changes().id(reviewCRplus1.getId().get()).current().review(ReviewInput.recommend());
    // CR+2
    Change reviewCRplus2 = insert(repo, ins2);
    gApi.changes().id(reviewCRplus2.getId().get()).current().review(ReviewInput.approve());
    // CR+1 VR+1
    Change reviewCRplus1VRplus1 = insert(repo, ins3);
    gApi.changes().id(reviewCRplus1VRplus1.getId().get()).current().review(ReviewInput.recommend());
    gApi.changes().id(reviewCRplus1VRplus1.getId().get()).current().review(reviewVerified);
    // CR+2 VR+1
    Change reviewCRplus2VRplus1 = insert(repo, ins4);
    gApi.changes().id(reviewCRplus2VRplus1.getId().get()).current().review(ReviewInput.approve());
    gApi.changes().id(reviewCRplus2VRplus1.getId().get()).current().review(reviewVerified);
    // VR+1
    Change reviewVRplus1 = insert(repo, ins5);
    gApi.changes().id(reviewVRplus1.getId().get()).current().review(reviewVerified);
    assertQuery("label:Code-Review=+1", reviewCRplus1VRplus1, reviewCRplus1);
    assertQuery("label:Code-Review>=+1", reviewCRplus2VRplus1, reviewCRplus1VRplus1, reviewCRplus2, reviewCRplus1);
    assertQuery("label:Code-Review>=+2", reviewCRplus2VRplus1, reviewCRplus2);
    assertQuery("label:Code-Review>=+1 label:Verified=+1", reviewCRplus2VRplus1, reviewCRplus1VRplus1);
    assertQuery("label:Code-Review>=+2 label:Verified=+1", reviewCRplus2VRplus1);
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Project(com.google.gerrit.entities.Project) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) LabelType(com.google.gerrit.entities.LabelType) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.entities.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Test(org.junit.Test)

Aggregations

Project (com.google.gerrit.entities.Project)184 Test (org.junit.Test)109 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)67 Change (com.google.gerrit.entities.Change)43 Repository (org.eclipse.jgit.lib.Repository)34 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)33 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)32 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)31 BranchNameKey (com.google.gerrit.entities.BranchNameKey)30 Config (org.eclipse.jgit.lib.Config)26 ObjectId (org.eclipse.jgit.lib.ObjectId)26 IOException (java.io.IOException)25 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)24 ProjectState (com.google.gerrit.server.project.ProjectState)23 Inject (com.google.inject.Inject)23 List (java.util.List)23 AuthException (com.google.gerrit.extensions.restapi.AuthException)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)22 PatchSet (com.google.gerrit.entities.PatchSet)20