use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method fetchUserBranch.
@Test
public void fetchUserBranch() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
requestScopeOperations.setApiUser(user.id());
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, user);
String userRefName = RefNames.refsUsers(user.id());
// remove default READ permissions
try (ProjectConfigUpdate u = updateProject(allUsers)) {
u.getConfig().upsertAccessSection(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", as -> {
as.remove(Permission.builder(Permission.READ));
});
u.save();
}
// deny READ permission that is inherited from All-Projects
projectOperations.project(allUsers).forUpdate().add(deny(Permission.READ).ref(RefNames.REFS + "*").group(ANONYMOUS_USERS)).update();
// fetching user branch without READ permission fails
assertThrows(TransportException.class, () -> fetch(allUsersRepo, userRefName + ":userRef"));
// allow each user to read its own user branch
projectOperations.project(allUsers).forUpdate().add(allow(Permission.READ).ref(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}").group(REGISTERED_USERS)).update();
// fetch user branch using refs/users/YY/XXXXXXX
fetch(allUsersRepo, userRefName + ":userRef");
Ref userRef = allUsersRepo.getRepository().exactRef("userRef");
assertThat(userRef).isNotNull();
// fetch user branch using refs/users/self
fetch(allUsersRepo, RefNames.REFS_USERS_SELF + ":userSelfRef");
Ref userSelfRef = allUsersRepo.getRepository().getRefDatabase().exactRef("userSelfRef");
assertThat(userSelfRef).isNotNull();
assertThat(userSelfRef.getObjectId()).isEqualTo(userRef.getObjectId());
accountIndexedCounter.assertNoReindex();
// fetching user branch of another user fails
String otherUserRefName = RefNames.refsUsers(admin.id());
TransportException thrown = assertThrows(TransportException.class, () -> fetch(allUsersRepo, otherUserRefName + ":otherUserRef"));
assertThat(thrown).hasMessageThat().contains("Remote does not have " + otherUserRefName + " available for fetch.");
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method create.
@Test
public void create() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
AccountInput input = new AccountInput();
input.username = "foo";
input.name = "Foo";
input.email = "foo@example.com";
AccountInfo accountInfo = gApi.accounts().create(input).get();
assertThat(accountInfo._accountId).isNotNull();
assertThat(accountInfo.username).isEqualTo(input.username);
assertThat(accountInfo.name).isEqualTo(input.name);
assertThat(accountInfo.email).isEqualTo(input.email);
assertThat(accountInfo.status).isNull();
assertThat(accountInfo.tags).isNull();
Account.Id accountId = Account.id(accountInfo._accountId);
accountIndexedCounter.assertReindexOf(accountId, 1);
assertThat(externalIds.byAccount(accountId)).containsExactly(externalIdFactory.createUsername(input.username, accountId, null), externalIdFactory.createEmail(accountId, input.email));
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method addEmailAndSetPreferred.
@Test
public void addEmailAndSetPreferred() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String email = "foo.bar@example.com";
EmailInput input = new EmailInput();
input.email = email;
input.noConfirmation = true;
input.preferred = true;
gApi.accounts().self().addEmail(input);
// Account is reindexed twice; once on adding the new email,
// and then again on setting the email preferred.
accountIndexedCounter.assertReindexOf(admin, 2);
String preferred = gApi.accounts().self().get().email;
assertThat(preferred).isEqualTo(email);
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method deleteEmailOfOtherUser.
@Test
public void deleteEmailOfOtherUser() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String email = "foo.bar@example.com";
EmailInput input = new EmailInput();
input.email = email;
input.noConfirmation = true;
gApi.accounts().id(user.id().get()).addEmail(input);
accountIndexedCounter.assertReindexOf(user);
requestScopeOperations.setApiUser(user.id());
assertThat(getEmails()).contains(email);
// admin can delete email of user
requestScopeOperations.setApiUser(admin.id());
gApi.accounts().id(user.id().get()).deleteEmail(email);
accountIndexedCounter.assertReindexOf(user);
requestScopeOperations.setApiUser(user.id());
assertThat(getEmails()).doesNotContain(email);
// user cannot delete email of admin
AuthException thrown = assertThrows(AuthException.class, () -> gApi.accounts().id(admin.id().get()).deleteEmail(admin.email()));
assertThat(thrown).hasMessageThat().contains("modify account not permitted");
}
}
use of com.google.gerrit.acceptance.AccountIndexedCounter in project gerrit by GerritCodeReview.
the class AccountIT method getByIntId.
@Test
public void getByIntId() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
AccountInfo info = gApi.accounts().id("admin").get();
AccountInfo infoByIntId = gApi.accounts().id(info._accountId).get();
assertThat(info.name).isEqualTo(infoByIntId.name);
accountIndexedCounter.assertNoReindex();
}
}
Aggregations