Search in sources :

Example 21 with Registration

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

the class PushAccountIT method pushAccountConfigToUserBranchForReviewIsRejectedOnSubmitIfOwnAccountIsDeactivated.

@Test
public void pushAccountConfigToUserBranchForReviewIsRejectedOnSubmitIfOwnAccountIsDeactivated() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String userRef = RefNames.refsUsers(admin.id());
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
        fetch(allUsersRepo, userRef + ":userRef");
        allUsersRepo.reset("userRef");
        Config ac = getAccountConfig(allUsersRepo);
        ac.setBoolean(AccountProperties.ACCOUNT, null, AccountProperties.KEY_ACTIVE, false);
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(MagicBranch.NEW_CHANGE + userRef);
        r.assertOkStatus();
        accountIndexedCounter.assertNoReindex();
        assertThat(r.getChange().change().getDest().branch()).isEqualTo(userRef);
        gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
        ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(r.getChangeId()).current().submit());
        assertThat(thrown).hasMessageThat().contains("invalid account configuration: cannot deactivate own account");
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Config(org.eclipse.jgit.lib.Config) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 22 with Registration

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

the class PushAccountIT method pushWatchConfigToUserBranch.

@Test
public void pushWatchConfigToUserBranch() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
        fetch(allUsersRepo, RefNames.refsUsers(admin.id()) + ":userRef");
        allUsersRepo.reset("userRef");
        Config wc = new Config();
        wc.setString(ProjectWatches.PROJECT, project.get(), ProjectWatches.KEY_NOTIFY, ProjectWatches.NotifyValue.create(null, EnumSet.of(NotifyType.ALL_COMMENTS)).toString());
        PushOneCommit push = pushFactory.create(admin.newIdent(), allUsersRepo, "Add project watch", ProjectWatches.WATCH_CONFIG, wc.toText());
        push.to(RefNames.REFS_USERS_SELF).assertOkStatus();
        accountIndexedCounter.assertReindexOf(admin);
        String invalidNotifyValue = "]invalid[";
        wc.setString(ProjectWatches.PROJECT, project.get(), ProjectWatches.KEY_NOTIFY, invalidNotifyValue);
        push = pushFactory.create(admin.newIdent(), allUsersRepo, "Add invalid project watch", ProjectWatches.WATCH_CONFIG, wc.toText());
        PushOneCommit.Result r = push.to(RefNames.REFS_USERS_SELF);
        r.assertErrorStatus("invalid account configuration");
        r.assertMessage(String.format("%s: Invalid project watch of account %d for project %s: %s", ProjectWatches.WATCH_CONFIG, admin.id().get(), project.get(), invalidNotifyValue));
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Config(org.eclipse.jgit.lib.Config) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 23 with Registration

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

the class PushAccountIT method pushAccountConfigToUserBranch.

@Test
public void pushAccountConfigToUserBranch() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestAccount oooUser = accountCreator.create("away", "away@mail.invalid", "Ambrose Way", null);
        requestScopeOperations.setApiUser(oooUser.id());
        // Must clone as oooUser to ensure the push is allowed.
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, oooUser);
        fetch(allUsersRepo, RefNames.refsUsers(oooUser.id()) + ":userRef");
        allUsersRepo.reset("userRef");
        Config ac = getAccountConfig(allUsersRepo);
        ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_STATUS, "out-of-office");
        accountIndexedCounter.clear();
        pushFactory.create(oooUser.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(RefNames.refsUsers(oooUser.id())).assertOkStatus();
        accountIndexedCounter.assertReindexOf(oooUser);
        AccountInfo info = gApi.accounts().self().get();
        assertThat(info.email).isEqualTo(oooUser.email());
        assertThat(info.name).isEqualTo(oooUser.fullName());
        assertThat(info.status).isEqualTo("out-of-office");
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Config(org.eclipse.jgit.lib.Config) TestAccount(com.google.gerrit.acceptance.TestAccount) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 24 with Registration

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

the class PushAccountIT method pushAccountConfigToUserBranchIsRejectedIfConfigIsInvalid.

@Test
public void pushAccountConfigToUserBranchIsRejectedIfConfigIsInvalid() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
        String userRef = RefNames.refsUsers(admin.id());
        fetch(allUsersRepo, userRef + ":userRef");
        allUsersRepo.reset("userRef");
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, "invalid config").to(RefNames.REFS_USERS_SELF);
        r.assertErrorStatus("invalid account configuration");
        r.assertMessage(String.format("commit '%s' has an invalid '%s' file for account '%s':" + " Invalid config file %s in project %s in branch %s in commit %s", r.getCommit().name(), AccountProperties.ACCOUNT_CONFIG, admin.id(), AccountProperties.ACCOUNT_CONFIG, allUsers.get(), userRef, r.getCommit().name()));
        accountIndexedCounter.assertNoReindex();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 25 with Registration

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

the class PushAccountIT method pushAccountConfigToUserBranchIsRejectedIfPreferredEmailIsInvalid.

@Test
public void pushAccountConfigToUserBranchIsRejectedIfPreferredEmailIsInvalid() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
        fetch(allUsersRepo, RefNames.refsUsers(admin.id()) + ":userRef");
        allUsersRepo.reset("userRef");
        String noEmail = "no.email";
        Config ac = getAccountConfig(allUsersRepo);
        ac.setString(AccountProperties.ACCOUNT, null, AccountProperties.KEY_PREFERRED_EMAIL, noEmail);
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), allUsersRepo, "Update account config", AccountProperties.ACCOUNT_CONFIG, ac.toText()).to(RefNames.REFS_USERS_SELF);
        r.assertErrorStatus("invalid account configuration");
        r.assertMessage(String.format("invalid preferred email '%s' for account '%s'", noEmail, admin.id()));
        accountIndexedCounter.assertNoReindex();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Config(org.eclipse.jgit.lib.Config) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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