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();
}
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();
}
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");
}
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);
}
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);
}
Aggregations