use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method deleteExternalIdsOfOtherUserNotAllowed.
@Test
public void deleteExternalIdsOfOtherUserNotAllowed() throws Exception {
List<AccountExternalIdInfo> extIds = gApi.accounts().self().getExternalIds();
requestScopeOperations.setApiUser(user.id());
AuthException thrown = assertThrows(AuthException.class, () -> gApi.accounts().id(admin.id().get()).deleteExternalIds(extIds.stream().map(e -> e.identity).collect(toList())));
assertThat(thrown).hasMessageThat().contains("modify account not permitted");
}
use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method deleteExternalIds.
@Test
public void deleteExternalIds() throws Exception {
requestScopeOperations.setApiUser(user.id());
List<AccountExternalIdInfo> externalIds = gApi.accounts().self().getExternalIds();
List<String> toDelete = new ArrayList<>();
List<AccountExternalIdInfo> expectedIds = new ArrayList<>();
for (AccountExternalIdInfo id : externalIds) {
if (id.canDelete != null && id.canDelete) {
toDelete.add(id.identity);
continue;
}
expectedIds.add(id);
}
assertThat(toDelete).hasSize(1);
RestResponse response = userRestSession.post("/accounts/self/external.ids:delete", toDelete);
response.assertNoContent();
List<AccountExternalIdInfo> results = gApi.accounts().self().getExternalIds();
// The external ID in WebSession will not be set for tests, resulting that
// "mailto:user@example.com" can be deleted while "username:user" can't.
assertThat(results).hasSize(1);
assertThat(results).containsExactlyElementsIn(expectedIds);
}
use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method deleteExternalIdOfUsernameByAdmin.
@Test
public void deleteExternalIdOfUsernameByAdmin() throws Exception {
List<String> toDelete = new ArrayList<>();
String externalIdStr = "username:" + user.username();
toDelete.add(externalIdStr);
RestResponse response = adminRestSession.post("/accounts/" + user.id() + "/external.ids:delete", toDelete);
response.assertNoContent();
List<AccountExternalIdInfo> results = gApi.accounts().id(user.id().get()).getExternalIds();
assertThat(results).hasSize(1);
assertThat(results.get(0).identity).isEqualTo("mailto:user1@example.com");
}
use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method pushToExternalIdsBranch.
@Test
public void pushToExternalIdsBranch() throws Exception {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS + ":" + RefNames.REFS_EXTERNAL_IDS);
allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
// different case email is allowed
ExternalId newExtId = createExternalIdWithOtherCaseEmail("foo:bar");
addExtId(allUsersRepo, newExtId);
allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
List<AccountExternalIdInfo> extIdsBefore = gApi.accounts().self().getExternalIds();
allowPushOfExternalIds();
PushResult r = pushHead(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
assertThat(r.getRemoteUpdate(RefNames.REFS_EXTERNAL_IDS).getStatus()).isEqualTo(Status.OK);
List<AccountExternalIdInfo> extIdsAfter = gApi.accounts().self().getExternalIds();
assertThat(extIdsAfter).containsExactlyElementsIn(Iterables.concat(extIdsBefore, ImmutableSet.of(toExternalIdInfo(newExtId))));
}
use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method deleteExternalIdsOfOtherUserWithModifyAccount.
@Test
public void deleteExternalIdsOfOtherUserWithModifyAccount() throws Exception {
projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.MODIFY_ACCOUNT).group(REGISTERED_USERS)).update();
List<AccountExternalIdInfo> externalIds = gApi.accounts().self().getExternalIds();
List<String> toDelete = new ArrayList<>();
List<AccountExternalIdInfo> expectedIds = new ArrayList<>();
for (AccountExternalIdInfo id : externalIds) {
if (id.canDelete != null && id.canDelete) {
toDelete.add(id.identity);
continue;
}
expectedIds.add(id);
}
assertThat(toDelete).hasSize(1);
requestScopeOperations.setApiUser(user.id());
RestResponse response = userRestSession.post("/accounts/" + admin.id() + "/external.ids:delete", toDelete);
response.assertNoContent();
List<AccountExternalIdInfo> results = gApi.accounts().id(admin.id().get()).getExternalIds();
// The external ID in WebSession will not be set for tests, resulting that
// "mailto:user@example.com" can be deleted while "username:user" can't.
assertThat(results).hasSize(1);
assertThat(results).containsExactlyElementsIn(expectedIds);
}
Aggregations