Search in sources :

Example 21 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class AbstractSubmit method onlySelfSubmit.

@Test
public void onlySelfSubmit() throws Exception {
    // create project where only the change owner can submit
    Project.NameKey p = createProject("p");
    ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
    Util.block(cfg, Permission.SUBMIT, REGISTERED_USERS, "refs/*");
    Util.allow(cfg, Permission.SUBMIT, CHANGE_OWNER, "refs/*");
    Util.allow(cfg, Permission.forLabel("Code-Review"), -2, +2, REGISTERED_USERS, "refs/*");
    saveProjectConfig(p, cfg);
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id.get());
    setApiUser(user);
    submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
    setApiUser(admin);
    submit(result.getChangeId());
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 22 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class AbstractSubmit method noSelfSubmit.

@Test
public void noSelfSubmit() throws Exception {
    // create project where submit is blocked for the change owner
    Project.NameKey p = createProject("p");
    ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
    Util.block(cfg, Permission.SUBMIT, CHANGE_OWNER, "refs/*");
    Util.allow(cfg, Permission.SUBMIT, REGISTERED_USERS, "refs/heads/*");
    Util.allow(cfg, Permission.forLabel("Code-Review"), -2, +2, REGISTERED_USERS, "refs/*");
    saveProjectConfig(p, cfg);
    TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id.get());
    submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
    setApiUser(user);
    submit(result.getChangeId());
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class ExternalIdIT method pushToExternalIdsBranchRejectsExternalIdWithInvalidConfig.

@Test
public void pushToExternalIdsBranchRejectsExternalIdWithInvalidConfig() throws Exception {
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    fetch(allUsersRepo, RefNames.REFS_EXTERNAL_IDS + ":" + RefNames.REFS_EXTERNAL_IDS);
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    insertExternalIdWithInvalidConfig(allUsersRepo.getRepository(), allUsersRepo.getRevWalk(), "foo:bar");
    allUsersRepo.reset(RefNames.REFS_EXTERNAL_IDS);
    allowPushOfExternalIds();
    PushResult r = pushHead(allUsersRepo, RefNames.REFS_EXTERNAL_IDS);
    assertRefUpdateFailure(r.getRemoteUpdate(RefNames.REFS_EXTERNAL_IDS), "invalid external IDs");
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 24 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class GerritPublicKeyCheckerTest method setUpInjector.

@Before
public void setUpInjector() throws Exception {
    Config cfg = InMemoryModule.newDefaultConfig();
    cfg.setInt("receive", null, "maxTrustDepth", 2);
    cfg.setStringList("receive", null, "trustedKey", ImmutableList.of(Fingerprint.toString(keyB().getPublicKey().getFingerprint()), Fingerprint.toString(keyD().getPublicKey().getFingerprint())));
    Injector injector = Guice.createInjector(new InMemoryModule(cfg, new TestNotesMigration()));
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    injector.injectMembers(this);
    lifecycle.start();
    db = schemaFactory.open();
    schemaCreator.create(db);
    userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    Account userAccount = db.accounts().get(userId);
    // Note: does not match any key in TestKeys.
    userAccount.setPreferredEmail("user@example.com");
    db.accounts().update(ImmutableList.of(userAccount));
    user = reloadUser();
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
    storeRepo = new InMemoryRepository(new DfsRepositoryDescription("repo"));
    store = new PublicKeyStore(storeRepo);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) CurrentUser(com.google.gerrit.server.CurrentUser) Config(org.eclipse.jgit.lib.Config) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) TestNotesMigration(com.google.gerrit.testutil.TestNotesMigration) DfsRepositoryDescription(org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription) Provider(com.google.inject.Provider) Injector(com.google.inject.Injector) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) RequestContext(com.google.gerrit.server.util.RequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) Before(org.junit.Before)

Example 25 with InMemoryRepository

use of org.eclipse.jgit.internal.storage.dfs.InMemoryRepository in project gerrit by GerritCodeReview.

the class PublicKeyStoreTest method setUp.

@Before
public void setUp() throws Exception {
    tr = new TestRepository<>(new InMemoryRepository(new DfsRepositoryDescription("pubkeys")));
    store = new PublicKeyStore(tr.getRepository());
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) DfsRepositoryDescription(org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription) Before(org.junit.Before)

Aggregations

InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)54 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)37 Test (org.junit.Test)37 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)30 Project (com.google.gerrit.reviewdb.client.Project)21 DfsRepositoryDescription (org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription)12 Before (org.junit.Before)12 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)8 Message (com.google.gerrit.testutil.FakeEmailSender.Message)8 PushResult (org.eclipse.jgit.transport.PushResult)8 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)6 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 CurrentUser (com.google.gerrit.server.CurrentUser)4 Config (org.eclipse.jgit.lib.Config)4 Sandboxed (com.google.gerrit.acceptance.Sandboxed)3 SubmitInput (com.google.gerrit.extensions.api.changes.SubmitInput)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 LifecycleManager (com.google.gerrit.lifecycle.LifecycleManager)3