use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class GetBranchIT method getChangeEditRef.
@Test
public void getChangeEditRef() throws Exception {
TestAccount user2 = accountCreator.user2();
// create a change
Change.Id changeId = changeOperations.newChange().project(project).create();
// create a change edit by 'user'
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(changeId.get()).edit().create();
// every user can see their own change edit refs
String changeEditRef = RefNames.refsEdit(user.id(), changeId, PatchSet.id(changeId, 1));
assertBranchFound(project, changeEditRef);
// a user without the 'Access Database' capability cannot see the change edit ref of another
// user
requestScopeOperations.setApiUser(user2.id());
assertBranchNotFound(project, changeEditRef);
// a user with the 'Access Database' capability can see the change edit ref of another user
testGetRefWithAccessDatabase(project, changeEditRef);
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class GetAccountIT method getServiceUserAccount.
@Test
public void getServiceUserAccount() throws Exception {
TestAccount serviceUser = accountCreator.create("robot1", "robot1@example.com", "Ro Bot", "Ro", ServiceUserClassifier.SERVICE_USERS);
assertThat(serviceUser.tags()).containsExactly("SERVICE_USER");
testGetAccount(serviceUser.id().toString(), serviceUser);
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ExternalIdIT method deleteExternalIdOfUsernameMaintainServer.
@Test
public void deleteExternalIdOfUsernameMaintainServer() throws Exception {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.MAINTAIN_SERVER).group(REGISTERED_USERS)).add(allowCapability(GlobalCapability.MODIFY_ACCOUNT).group(REGISTERED_USERS)).update();
List<String> toDelete = new ArrayList<>();
TestAccount user2 = accountCreator.user2();
String externalIdStr = "username:" + user2.username();
toDelete.add(externalIdStr);
RestResponse response = userRestSession.post("/accounts/" + user2.id() + "/external.ids:delete", toDelete);
response.assertNoContent();
List<AccountExternalIdInfo> results = gApi.accounts().id(user2.id().get()).getExternalIds();
assertThat(results).hasSize(1);
assertThat(results.get(0).identity).isEqualTo("mailto:user2@example.com");
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class GroupsIT method reindexPermissions.
// reindex is tested by {@link AbstractQueryGroupsTest#reindex}
@Test
public void reindexPermissions() throws Exception {
TestAccount groupOwner = accountCreator.user2();
GroupInput in = new GroupInput();
in.name = name("group");
in.members = Stream.of(groupOwner).map(u -> u.id().toString()).collect(toList());
in.visibleToAll = true;
GroupInfo group = gApi.groups().create(in).get();
// admin can reindex any group
requestScopeOperations.setApiUser(admin.id());
gApi.groups().id(group.id).index();
// group owner can reindex own group (group is owned by itself)
requestScopeOperations.setApiUser(groupOwner.id());
gApi.groups().id(group.id).index();
// user cannot reindex any group
requestScopeOperations.setApiUser(user.id());
AuthException thrown = assertThrows(AuthException.class, () -> gApi.groups().id(group.id).index());
assertThat(thrown).hasMessageThat().contains("not allowed to index group");
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchFileAllProjects.
@Test
public void watchFileAllProjects() throws Exception {
String anyProject = projectOperations.newProject().create().get();
requestScopeOperations.setApiUser(user.id());
// watch file in All-Projects project as user to watch the file in all
// projects
watch(allProjects.get(), "file:a.txt");
// push a change to watched file in any project -> should trigger email
// notification for user
requestScopeOperations.setApiUser(admin.id());
TestRepository<InMemoryRepository> anyRepo = cloneProject(Project.nameKey(anyProject), admin);
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), anyRepo, "TRIGGER", "a.txt", "a1").to("refs/for/master");
r.assertOkStatus();
// assert email notification for user
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
sender.clear();
// watch project as user2
TestAccount user2 = accountCreator.create("user2", "user2@example.com", "User2", null);
requestScopeOperations.setApiUser(user2.id());
watch(anyProject);
// push a change to non-watched file in any project -> should not trigger
// email notification for user, only for user2
r = pushFactory.create(admin.newIdent(), anyRepo, "TRIGGER_USER2", "b.txt", "b1").to("refs/for/master");
r.assertOkStatus();
// assert email notification
messages = sender.getMessages();
assertThat(messages).hasSize(1);
m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user2.getNameEmail());
assertThat(m.body()).contains("Change subject: TRIGGER_USER2\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Aggregations