use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class PushAccountIT method pushAccountConfigToUserBranchDeactivateOtherAccount.
@Test
public void pushAccountConfigToUserBranchDeactivateOtherAccount() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
TestAccount foo = accountCreator.create(name("foo"));
assertThat(gApi.accounts().id(foo.id().get()).getActive()).isTrue();
String userRef = RefNames.refsUsers(foo.id());
accountIndexedCounter.clear();
projectOperations.project(allUsers).forUpdate().add(allow(Permission.PUSH).ref(userRef).group(adminGroupUuid())).update();
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
fetch(allUsersRepo, userRef + ":userRef");
allUsersRepo.reset("userRef");
Config ac = getAccountConfig(allUsersRepo);
ac.setBoolean(AccountProperties.ACCOUNT, null, AccountProperties.KEY_ACTIVE, false);
pushFactory.create(admin.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(userRef).assertOkStatus();
accountIndexedCounter.assertReindexOf(foo);
assertThat(gApi.accounts().id(foo.id().get()).getActive()).isFalse();
}
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class PushAccountIT method pushAccountConfigToUserBranchIfPreferredEmailDoesNotExistAsExtId.
@Test
public void pushAccountConfigToUserBranchIfPreferredEmailDoesNotExistAsExtId() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
TestAccount foo = accountCreator.create(name("foo"), name("foo") + "@example.com", "Foo", null);
String userRef = RefNames.refsUsers(foo.id());
accountIndexedCounter.clear();
projectOperations.project(allUsers).forUpdate().add(allow(Permission.PUSH).ref(userRef).group(adminGroupUuid())).update();
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, foo);
fetch(allUsersRepo, userRef + ":userRef");
allUsersRepo.reset("userRef");
String email = "some.email@example.com";
Config ac = getAccountConfig(allUsersRepo);
ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_PREFERRED_EMAIL, email);
pushFactory.create(foo.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(userRef).assertOkStatus();
accountIndexedCounter.assertReindexOf(foo);
AccountInfo info = gApi.accounts().id(foo.id().get()).get();
assertThat(info.email).isEqualTo(email);
assertThat(info.name).isEqualTo(foo.fullName());
}
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class AttentionSetIT method repliesAddsOwnerAndUploader.
@Test
public void repliesAddsOwnerAndUploader() throws Exception {
// Create change with owner: admin
PushOneCommit.Result r = createChange();
r = amendChangeWithUploader(r, project, user);
TestAccount user2 = accountCreator.user2();
requestScopeOperations.setApiUser(user2.id());
change(r).attention(user.email()).remove(new AttentionSetInput("reason"));
ReviewInput reviewInput = new ReviewInput();
change(r).current().review(reviewInput);
reviewInput = new ReviewInput();
change(r).current().review(reviewInput);
// Uploader added
AttentionSetUpdate attentionSet = Iterables.getOnlyElement(getAttentionSetUpdatesForUser(r, user));
assertThat(attentionSet).hasAccountIdThat().isEqualTo(user.id());
assertThat(attentionSet).hasOperationThat().isEqualTo(AttentionSetUpdate.Operation.ADD);
assertThat(attentionSet).hasReasonThat().isEqualTo("Someone else replied on the change");
// Owner added
attentionSet = Iterables.getOnlyElement(getAttentionSetUpdatesForUser(r, admin));
assertThat(attentionSet).hasAccountIdThat().isEqualTo(admin.id());
assertThat(attentionSet).hasOperationThat().isEqualTo(AttentionSetUpdate.Operation.ADD);
assertThat(attentionSet).hasReasonThat().isEqualTo("Someone else replied on the change");
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method reviewAndAddGroupReviewers.
@Test
public void reviewAndAddGroupReviewers() throws Exception {
int largeGroupSize = ReviewerModifier.DEFAULT_MAX_REVIEWERS + 1;
int mediumGroupSize = ReviewerModifier.DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK + 1;
List<TestAccount> users = createAccounts(largeGroupSize, "reviewAndAddGroupReviewers");
List<String> usernames = new ArrayList<>(largeGroupSize);
for (TestAccount u : users) {
usernames.add(u.username());
}
String largeGroup = groupOperations.newGroup().name("largeGroup").create().get();
String mediumGroup = groupOperations.newGroup().name("mediumGroup").create().get();
gApi.groups().id(largeGroup).addMembers(usernames.toArray(new String[largeGroupSize]));
gApi.groups().id(mediumGroup).addMembers(usernames.subList(0, mediumGroupSize).toArray(new String[mediumGroupSize]));
TestAccount observer = accountCreator.user2();
PushOneCommit.Result r = createChange();
// Attempt to add overly large group as reviewers.
ReviewInput input = ReviewInput.approve().reviewer(user.email()).reviewer(observer.email(), CC, false).reviewer(largeGroup);
ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input, SC_BAD_REQUEST);
assertThat(result.labels).isNull();
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(3);
ReviewerResult reviewerResult = result.reviewers.get(largeGroup);
assertThat(reviewerResult).isNotNull();
assertThat(reviewerResult.confirm).isNull();
assertThat(reviewerResult.error).isNotNull();
assertThat(reviewerResult.error).contains("has too many members to add them all as reviewers");
// No labels should have changed, and no reviewers/CCs should have been added.
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.messages).hasSize(1);
assertThat(c.reviewers.get(REVIEWER)).isNull();
assertThat(c.reviewers.get(CC)).isNull();
// Attempt to add group large enough to require confirmation, without
// confirmation, as reviewers.
input = ReviewInput.approve().reviewer(user.email()).reviewer(observer.email(), CC, false).reviewer(mediumGroup);
result = review(r.getChangeId(), r.getCommit().name(), input, SC_BAD_REQUEST);
assertThat(result.labels).isNull();
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(3);
reviewerResult = result.reviewers.get(mediumGroup);
assertThat(reviewerResult).isNotNull();
assertThat(reviewerResult.confirm).isTrue();
assertThat(reviewerResult.error).contains("has " + mediumGroupSize + " members. Do you want to add them all as reviewers?");
// No labels should have changed, and no reviewers/CCs should have been added.
c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.messages).hasSize(1);
assertThat(c.reviewers.get(REVIEWER)).isNull();
assertThat(c.reviewers.get(CC)).isNull();
// Retrying with confirmation should successfully approve and add reviewers/CCs.
input = ReviewInput.approve().reviewer(user.email()).reviewer(mediumGroup, CC, true);
result = review(r.getChangeId(), r.getCommit().name(), input);
assertThat(result.labels).isNotNull();
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(2);
c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.messages).hasSize(2);
assertReviewers(c, REVIEWER, admin, user);
assertReviewers(c, CC, users.subList(0, mediumGroupSize));
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method addOverlappingGroups.
@Test
public void addOverlappingGroups() throws Exception {
String emailPrefix = "addOverlappingGroups-";
TestAccount user1 = accountCreator.create(name("user1"), emailPrefix + "user1@example.com", "User1", null);
TestAccount user2 = accountCreator.create(name("user2"), emailPrefix + "user2@example.com", "User2", null);
TestAccount user3 = accountCreator.create(name("user3"), emailPrefix + "user3@example.com", "User3", null);
String group1 = groupOperations.newGroup().name("group1").create().get();
String group2 = groupOperations.newGroup().name("group2").create().get();
gApi.groups().id(group1).addMembers(user1.username(), user2.username());
gApi.groups().id(group2).addMembers(user2.username(), user3.username());
PushOneCommit.Result r = createChange();
ReviewInput input = ReviewInput.approve().reviewer(group1).reviewer(group2);
ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input);
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(2);
ReviewerResult reviewerResult = result.reviewers.get(group1);
assertThat(reviewerResult.error).isNull();
assertThat(reviewerResult.reviewers).hasSize(2);
reviewerResult = result.reviewers.get(group2);
assertThat(reviewerResult.error).isNull();
assertThat(reviewerResult.reviewers).hasSize(1);
// Repeat the above for CCs
r = createChange();
input = ReviewInput.approve().reviewer(group1, CC, false).reviewer(group2, CC, false);
result = review(r.getChangeId(), r.getCommit().name(), input);
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(2);
reviewerResult = result.reviewers.get(group1);
assertThat(reviewerResult.error).isNull();
assertThat(reviewerResult.ccs).hasSize(2);
reviewerResult = result.reviewers.get(group2);
assertThat(reviewerResult.error).isNull();
assertThat(reviewerResult.ccs).hasSize(1);
// Repeat again with one group REVIEWER, the other CC. The overlapping
// member should end up as a REVIEWER.
r = createChange();
input = ReviewInput.approve().reviewer(group1, REVIEWER, false).reviewer(group2, CC, false);
result = review(r.getChangeId(), r.getCommit().name(), input);
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(2);
reviewerResult = result.reviewers.get(group1);
assertThat(reviewerResult.error).isNull();
assertThat(reviewerResult.reviewers).hasSize(2);
reviewerResult = result.reviewers.get(group2);
assertThat(reviewerResult.error).isNull();
assertThat(reviewerResult.reviewers).isNull();
assertThat(reviewerResult.ccs).hasSize(1);
}
Aggregations