Search in sources :

Example 26 with InMemoryRepository

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

the class AccountIT method pushToUserBranchForReview.

@Test
public void pushToUserBranchForReview() throws Exception {
    String userRefName = RefNames.refsUsers(admin.id);
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    fetch(allUsersRepo, userRefName + ":userRef");
    allUsersRepo.reset("userRef");
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), allUsersRepo);
    PushOneCommit.Result r = push.to(MagicBranch.NEW_CHANGE + userRefName);
    r.assertOkStatus();
    accountIndexedCounter.assertNoReindex();
    assertThat(r.getChange().change().getDest().get()).isEqualTo(userRefName);
    gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
    gApi.changes().id(r.getChangeId()).current().submit();
    accountIndexedCounter.assertReindexOf(admin);
    push = pushFactory.create(db, admin.getIdent(), allUsersRepo);
    r = push.to(MagicBranch.NEW_CHANGE + RefNames.REFS_USERS_SELF);
    r.assertOkStatus();
    accountIndexedCounter.assertNoReindex();
    assertThat(r.getChange().change().getDest().get()).isEqualTo(userRefName);
    gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
    gApi.changes().id(r.getChangeId()).current().submit();
    accountIndexedCounter.assertReindexOf(admin);
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 27 with InMemoryRepository

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

the class AccountIT method fetchUserBranch.

@Test
@Sandboxed
public void fetchUserBranch() throws Exception {
    setApiUser(user);
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers, user);
    String userRefName = RefNames.refsUsers(user.id);
    // remove default READ permissions
    ProjectConfig cfg = projectCache.checkedGet(allUsers).getConfig();
    cfg.getAccessSection(RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", true).remove(new Permission(Permission.READ));
    saveProjectConfig(allUsers, cfg);
    // deny READ permission that is inherited from All-Projects
    deny(allUsers, RefNames.REFS + "*", Permission.READ, ANONYMOUS_USERS);
    // fetching user branch without READ permission fails
    try {
        fetch(allUsersRepo, userRefName + ":userRef");
        Assert.fail("user branch is visible although no READ permission is granted");
    } catch (TransportException e) {
    // expected because no READ granted on user branch
    }
    // allow each user to read its own user branch
    grant(allUsers, RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", Permission.READ, false, REGISTERED_USERS);
    // 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);
    exception.expect(TransportException.class);
    exception.expectMessage("Remote does not have " + otherUserRefName + " available for fetch.");
    fetch(allUsersRepo, otherUserRefName + ":otherUserRef");
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) GitUtil.deleteRef(com.google.gerrit.acceptance.GitUtil.deleteRef) Ref(org.eclipse.jgit.lib.Ref) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Permission(com.google.gerrit.common.data.Permission) 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) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

Example 28 with InMemoryRepository

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

the class GitUtil method cloneProject.

public static TestRepository<InMemoryRepository> cloneProject(Project.NameKey project, String uri) throws Exception {
    DfsRepositoryDescription desc = new DfsRepositoryDescription("clone of " + project.get());
    FS fs = FS.detect();
    // Avoid leaking user state into our tests.
    fs.setUserHome(null);
    InMemoryRepository dest = new InMemoryRepository.Builder().setRepositoryDescription(desc).setFS(fs).build();
    Config cfg = dest.getConfig();
    cfg.setString("remote", "origin", "url", uri);
    cfg.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    TestRepository<InMemoryRepository> testRepo = newTestRepository(dest);
    FetchResult result = testRepo.git().fetch().setRemote("origin").call();
    String originMaster = "refs/remotes/origin/master";
    if (result.getTrackingRefUpdate(originMaster) != null) {
        testRepo.reset(originMaster);
    }
    return testRepo;
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) FetchResult(org.eclipse.jgit.transport.FetchResult) Config(org.eclipse.jgit.lib.Config) DfsRepositoryDescription(org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription) FS(org.eclipse.jgit.util.FS)

Example 29 with InMemoryRepository

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

the class AccountIT method pushToUserBranch.

@Test
public void pushToUserBranch() throws Exception {
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    fetch(allUsersRepo, RefNames.refsUsers(admin.id) + ":userRef");
    allUsersRepo.reset("userRef");
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), allUsersRepo);
    push.to(RefNames.refsUsers(admin.id)).assertOkStatus();
    accountIndexedCounter.assertReindexOf(admin);
    push = pushFactory.create(db, admin.getIdent(), allUsersRepo);
    push.to(RefNames.REFS_USERS_SELF).assertOkStatus();
    accountIndexedCounter.assertReindexOf(admin);
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 30 with InMemoryRepository

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

the class AccountIT method deleteUserBranchWithAccessDatabaseCapability.

@Test
@Sandboxed
public void deleteUserBranchWithAccessDatabaseCapability() throws Exception {
    allowGlobalCapabilities(REGISTERED_USERS, GlobalCapability.ACCESS_DATABASE);
    grant(allUsers, RefNames.REFS_USERS + "${" + RefPattern.USERID_SHARDED + "}", Permission.DELETE, true, REGISTERED_USERS);
    TestRepository<InMemoryRepository> allUsersRepo = cloneProject(allUsers);
    String userRef = RefNames.refsUsers(admin.id);
    PushResult r = deleteRef(allUsersRepo, userRef);
    RemoteRefUpdate refUpdate = r.getRemoteUpdate(userRef);
    assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.OK);
    try (Repository repo = repoManager.openRepository(allUsers)) {
        assertThat(repo.exactRef(userRef)).isNull();
    }
// TODO(ekempin): assert that account was deleted from cache and index
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

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