use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method getExternalIdsOfOtherUserWithAccessDatabase.
@Test
public void getExternalIdsOfOtherUserWithAccessDatabase() throws Exception {
allowGlobalCapabilities(REGISTERED_USERS, GlobalCapability.ACCESS_DATABASE);
Collection<ExternalId> expectedIds = accountCache.get(admin.getId()).getExternalIds();
List<AccountExternalIdInfo> expectedIdInfos = toExternalIdInfos(expectedIds);
RestResponse response = userRestSession.get("/accounts/" + admin.id + "/external.ids");
response.assertOK();
List<AccountExternalIdInfo> results = newGson().fromJson(response.getReader(), new TypeToken<List<AccountExternalIdInfo>>() {
}.getType());
Collections.sort(expectedIdInfos);
Collections.sort(results);
assertThat(results).containsExactlyElementsIn(expectedIdInfos);
}
use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method toExternalIdInfo.
private AccountExternalIdInfo toExternalIdInfo(ExternalId extId) {
AccountExternalIdInfo info = new AccountExternalIdInfo();
info.identity = extId.key().get();
info.emailAddress = extId.email();
info.canDelete = !extId.isScheme(SCHEME_USERNAME) ? true : null;
info.trusted = extId.isScheme(SCHEME_MAILTO) || extId.isScheme(SCHEME_UUID) || extId.isScheme(SCHEME_USERNAME) ? true : null;
return info;
}
use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method deleteExternalIdOfOtherUserUnderOwnAccount_unprocessableEntity.
@Test
public void deleteExternalIdOfOtherUserUnderOwnAccount_unprocessableEntity() throws Exception {
List<AccountExternalIdInfo> extIds = gApi.accounts().self().getExternalIds();
requestScopeOperations.setApiUser(user.id());
UnprocessableEntityException thrown = assertThrows(UnprocessableEntityException.class, () -> gApi.accounts().self().deleteExternalIds(extIds.stream().map(e -> e.identity).collect(toList())));
assertThat(thrown).hasMessageThat().contains(String.format("External id %s does not exist", extIds.get(0).identity));
}
use of com.google.gerrit.extensions.common.AccountExternalIdInfo in project gerrit by GerritCodeReview.
the class ExternalIdIT method getExternalIds.
@Test
public void getExternalIds() throws Exception {
Collection<ExternalId> expectedIds = getAccountState(user.id()).externalIds();
List<AccountExternalIdInfo> expectedIdInfos = toExternalIdInfos(expectedIds);
RestResponse response = userRestSession.get("/accounts/self/external.ids");
response.assertOK();
List<AccountExternalIdInfo> results = newGson().fromJson(response.getReader(), new TypeToken<List<AccountExternalIdInfo>>() {
}.getType());
assertThat(results).containsExactlyElementsIn(expectedIdInfos);
}
use of com.google.gerrit.extensions.common.AccountExternalIdInfo 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");
}
Aggregations