Search in sources :

Example 1 with AccountExternalIdInfo

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);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with AccountExternalIdInfo

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;
}
Also used : AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo)

Example 3 with AccountExternalIdInfo

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));
}
Also used : ExternalIdKeyFactory(com.google.gerrit.server.account.externalids.ExternalIdKeyFactory) Arrays(java.util.Arrays) TypeToken(com.google.gson.reflect.TypeToken) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) ExternalIdTestUtil.insertExternalIdWithEmptyNote(com.google.gerrit.server.account.externalids.testing.ExternalIdTestUtil.insertExternalIdWithEmptyNote) RevWalk(org.eclipse.jgit.revwalk.RevWalk) SCHEME_USERNAME(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) Locale(java.util.Locale) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) SCHEME_UUID(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_UUID) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) CheckAccountExternalIdsInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountExternalIdsInput) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) Account(com.google.gerrit.entities.Account) ConsistencyCheckInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo) Set(java.util.Set) SCHEME_GPGKEY(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GPGKEY) ExternalIds(com.google.gerrit.server.account.externalids.ExternalIds) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) List(java.util.List) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) GitUtil.fetch(com.google.gerrit.acceptance.GitUtil.fetch) ExternalIdTestUtil.insertExternalIdWithoutAccountId(com.google.gerrit.server.account.externalids.testing.ExternalIdTestUtil.insertExternalIdWithoutAccountId) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) ExternalIdTestUtil.insertExternalIdWithKeyThatDoesntMatchNoteId(com.google.gerrit.server.account.externalids.testing.ExternalIdTestUtil.insertExternalIdWithKeyThatDoesntMatchNoteId) Iterables(com.google.common.collect.Iterables) Status(org.eclipse.jgit.transport.RemoteRefUpdate.Status) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExternalIdTestUtil.insertExternalIdWithInvalidConfig(com.google.gerrit.server.account.externalids.testing.ExternalIdTestUtil.insertExternalIdWithInvalidConfig) SCHEME_GERRIT(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GERRIT) ImmutableList(com.google.common.collect.ImmutableList) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) ExternalIdFactory(com.google.gerrit.server.account.externalids.ExternalIdFactory) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ConsistencyCheckInput(com.google.gerrit.extensions.api.config.ConsistencyCheckInput) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) TestProjectUpdate.allowCapability(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) TestRepository(org.eclipse.jgit.junit.TestRepository) ExternalIdReader(com.google.gerrit.server.account.externalids.ExternalIdReader) Permission(com.google.gerrit.entities.Permission) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) SCHEME_MAILTO(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_MAILTO) MutableInteger(org.eclipse.jgit.util.MutableInteger) TransportException(org.eclipse.jgit.api.errors.TransportException) Collectors.toList(java.util.stream.Collectors.toList) Provider(com.google.inject.Provider) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) DuplicateKeyException(com.google.gerrit.exceptions.DuplicateKeyException) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) ServerInitiated(com.google.gerrit.server.ServerInitiated) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) DuplicateExternalIdKeyException(com.google.gerrit.server.account.externalids.DuplicateExternalIdKeyException) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) Repository(org.eclipse.jgit.lib.Repository) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with AccountExternalIdInfo

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);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with AccountExternalIdInfo

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");
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) ArrayList(java.util.ArrayList) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AccountExternalIdInfo (com.google.gerrit.extensions.common.AccountExternalIdInfo)15 Test (org.junit.Test)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 RestResponse (com.google.gerrit.acceptance.RestResponse)10 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)9 ArrayList (java.util.ArrayList)8 TypeToken (com.google.gson.reflect.TypeToken)5 TestAccount (com.google.gerrit.acceptance.TestAccount)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables (com.google.common.collect.Iterables)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)2 GitUtil.fetch (com.google.gerrit.acceptance.GitUtil.fetch)2 GitUtil.pushHead (com.google.gerrit.acceptance.GitUtil.pushHead)2 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)2 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)2 TestProjectUpdate.allow (com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow)2 TestProjectUpdate.allowCapability (com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability)2