Search in sources :

Example 86 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class AccountIT method addOtherUsersGpgKey_Conflict.

@Test
public void addOtherUsersGpgKey_Conflict() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        // Both users have a matching external ID for this key.
        addExternalIdEmail(admin, "test5@example.com");
        accountIndexedCounter.clear();
        accountsUpdateProvider.get().update("Add External ID", user.id(), u -> u.addExternalId(externalIdFactory.create("foo", "myId", user.id())));
        accountIndexedCounter.assertReindexOf(user);
        TestKey key = validKeyWithSecondUserId();
        addGpgKey(key.getPublicKeyArmored());
        requestScopeOperations.setApiUser(user.id());
        ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> addGpgKey(user, key.getPublicKeyArmored()));
        assertThat(thrown).hasMessageThat().contains("GPG key already associated with another account");
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) TestKey(com.google.gerrit.gpg.testing.TestKey) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 87 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class AccountIT method createAnonymousCowardByAccountCreator.

@Test
public void createAnonymousCowardByAccountCreator() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestAccount anonymousCoward = accountCreator.create();
        accountIndexedCounter.assertReindexOf(anonymousCoward);
        assertUserBranchWithoutAccountConfig(anonymousCoward.id());
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) TestAccount(com.google.gerrit.acceptance.TestAccount) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 88 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class AccountIT method addReviewerToIgnoredChange.

@Test
public void addReviewerToIgnoredChange() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        PushOneCommit.Result r = createChange();
        requestScopeOperations.setApiUser(user.id());
        gApi.changes().id(r.getChangeId()).ignore(true);
        sender.clear();
        requestScopeOperations.setApiUser(admin.id());
        ReviewerInput in = new ReviewerInput();
        in.reviewer = user.email();
        gApi.changes().id(r.getChangeId()).addReviewer(in);
        List<Message> messages = sender.getMessages();
        assertThat(messages).hasSize(0);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 89 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class AccountIT method ignoreChange.

@Test
public void ignoreChange() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestAccount user2 = accountCreator.user2();
        accountIndexedCounter.clear();
        PushOneCommit.Result r = createChange();
        ReviewerInput in = new ReviewerInput();
        in.reviewer = user.email();
        gApi.changes().id(r.getChangeId()).addReviewer(in);
        in = new ReviewerInput();
        in.reviewer = user2.email();
        gApi.changes().id(r.getChangeId()).addReviewer(in);
        requestScopeOperations.setApiUser(user.id());
        gApi.changes().id(r.getChangeId()).ignore(true);
        sender.clear();
        requestScopeOperations.setApiUser(admin.id());
        gApi.changes().id(r.getChangeId()).abandon();
        List<Message> messages = sender.getMessages();
        assertThat(messages).hasSize(1);
        assertThat(messages.get(0).rcpt()).containsExactly(user2.getNameEmail());
        accountIndexedCounter.assertNoReindex();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 90 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class AccountIT method fetchUserBranch.

@Test
public void fetchUserBranch() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        requestScopeOperations.setApiUser(user.id());
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, user);
        String userRefName = RefNames.refsUsers(user.id());
        // remove default READ permissions
        try (ProjectConfigUpdate u = updateProject(allUsers)) {
            u.getConfig().upsertAccessSection(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", as -> {
                as.remove(Permission.builder(Permission.READ));
            });
            u.save();
        }
        // deny READ permission that is inherited from All-Projects
        projectOperations.project(allUsers).forUpdate().add(deny(Permission.READ).ref(RefNames.REFS + "*").group(ANONYMOUS_USERS)).update();
        // fetching user branch without READ permission fails
        assertThrows(TransportException.class, () -> fetch(allUsersRepo, userRefName + ":userRef"));
        // allow each user to read its own user branch
        projectOperations.project(allUsers).forUpdate().add(allow(Permission.READ).ref(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}").group(REGISTERED_USERS)).update();
        // fetch user branch using refs/users/YY/XXXXXXX
        fetch(allUsersRepo, userRefName + ":userRef");
        Ref userRef = allUsersRepo.getRepository().exactRef("userRef");
        assertThat(userRef).isNotNull();
        // fetch user branch using refs/users/self
        fetch(allUsersRepo, RefNames.REFS_USERS_SELF + ":userSelfRef");
        Ref userSelfRef = allUsersRepo.getRepository().getRefDatabase().exactRef("userSelfRef");
        assertThat(userSelfRef).isNotNull();
        assertThat(userSelfRef.getObjectId()).isEqualTo(userRef.getObjectId());
        accountIndexedCounter.assertNoReindex();
        // fetching user branch of another user fails
        String otherUserRefName = RefNames.refsUsers(admin.id());
        TransportException thrown = assertThrows(TransportException.class, () -> fetch(allUsersRepo, otherUserRefName + ":otherUserRef"));
        assertThat(thrown).hasMessageThat().contains("Remote does not have " + otherUserRefName + " available for fetch.");
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) GitUtil.deleteRef(com.google.gerrit.acceptance.GitUtil.deleteRef) Ref(org.eclipse.jgit.lib.Ref) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TransportException(org.eclipse.jgit.api.errors.TransportException) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)205 Test (org.junit.Test)200 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)194 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)90 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)47 RestResponse (com.google.gerrit.acceptance.RestResponse)39 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)38 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)31 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)23 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)22 TestAccount (com.google.gerrit.acceptance.TestAccount)19 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)16 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)15 Config (org.eclipse.jgit.lib.Config)14 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)12 CreateProjectArgs (com.google.gerrit.server.project.CreateProjectArgs)11 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 ImmutableList (com.google.common.collect.ImmutableList)10