Search in sources :

Example 11 with AccountExternalIdInfo

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");
}
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) AuthException(com.google.gerrit.extensions.restapi.AuthException) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with AccountExternalIdInfo

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

Example 13 with AccountExternalIdInfo

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

Example 14 with AccountExternalIdInfo

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))));
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) PushResult(org.eclipse.jgit.transport.PushResult) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with AccountExternalIdInfo

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