コード例 #1
0
ファイル: ViewFilterTest.java プロジェクト: candylin/gitiles
  private GitilesView getView(String pathAndQuery) throws ServletException, IOException {
    final AtomicReference<GitilesView> view = Atomics.newReference();
    HttpServlet testServlet =
        new HttpServlet() {
          @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse res) {
            view.set(ViewFilter.getView(req));
          }
        };

    ViewFilter vf =
        new ViewFilter(
            new TestGitilesAccess(repo.getRepository()),
            TestGitilesUrls.URLS,
            new VisibilityCache(false));
    MetaFilter mf = new MetaFilter();

    for (Pattern p : ImmutableList.of(ROOT_REGEX, REPO_REGEX, REPO_PATH_REGEX)) {
      mf.serveRegex(p).through(vf).with(testServlet);
    }

    FakeHttpServletRequest req = newRequest(repo.getRepository());
    int q = pathAndQuery.indexOf('?');
    if (q > 0) {
      req.setPathInfo(pathAndQuery.substring(0, q));
      req.setQueryString(pathAndQuery.substring(q + 1));
    } else {
      req.setPathInfo(pathAndQuery);
    }
    new MetaServlet(mf) {}.service(req, new FakeHttpServletResponse());

    return view.get();
  }
コード例 #2
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final TestRepository<Repository> src = createTestRepository();
    final String srcName = src.getRepository().getDirectory().getName();

    ServletContextHandler app = server.addContext("/git");
    GitServlet gs = new GitServlet();
    gs.setRepositoryResolver(
        new RepositoryResolver<HttpServletRequest>() {
          public Repository open(HttpServletRequest req, String name)
              throws RepositoryNotFoundException, ServiceNotEnabledException {
            if (!name.equals(srcName)) throw new RepositoryNotFoundException(name);

            final Repository db = src.getRepository();
            db.incrementOpen();
            return db;
          }
        });
    app.addServlet(new ServletHolder(gs), "/*");

    server.setUp();

    remoteRepository = src.getRepository();
    remoteURI = toURIish(app, srcName);

    A_txt = src.blob("A");
    A = src.commit().add("A_txt", A_txt).create();
    B = src.commit().parent(A).add("A_txt", "C").add("B", "B").create();
    src.update(master, B);
  }
コード例 #3
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final TestRepository<FileRepository> src = createTestRepository();
    final String srcName = src.getRepository().getDirectory().getName();

    ServletContextHandler app = server.addContext("/git");
    GitServlet gs = new GitServlet();
    gs.setRepositoryResolver(
        new RepositoryResolver<HttpServletRequest>() {
          public Repository open(HttpServletRequest req, String name)
              throws RepositoryNotFoundException, ServiceNotEnabledException {
            if (!name.equals(srcName)) throw new RepositoryNotFoundException(name);

            final Repository db = src.getRepository();
            db.incrementOpen();
            return db;
          }
        });
    app.addServlet(new ServletHolder(gs), "/*");

    server.setUp();

    remoteRepository = src.getRepository();
    remoteURI = toURIish(app, srcName);

    FileBasedConfig cfg = remoteRepository.getConfig();
    cfg.setBoolean("http", null, "receivepack", true);
    cfg.save();

    a_blob = src.blob("a");
  }
コード例 #4
0
 @Before
 public void setUp() throws IOException {
   DfsRepositoryDescription desc = new DfsRepositoryDescription("test");
   git = new TestRepository<>(new InMemoryRepository(desc));
   repo = git.getRepository();
   odb = repo.getObjectDatabase();
 }
コード例 #5
0
  private ServletContextHandler dumb(final String path) {
    final File srcGit = remoteRepository.getRepository().getDirectory();
    final URI base = srcGit.getParentFile().toURI();

    ServletContextHandler ctx = server.addContext(path);
    ctx.setResourceBase(base.toString());
    ctx.addServlet(DefaultServlet.class, "/");
    return ctx;
  }
コード例 #6
0
 @Before
 public void setUp() throws Exception {
   repo =
       new TestRepository<DfsRepository>(
           new InMemoryRepository(new DfsRepositoryDescription("test")));
   walk = new RevWalk(repo.getRepository());
   cache = new TimeCache();
   start = repo.getClock().getTime() / 1000;
 }
コード例 #7
0
 private RevCommit writeCommit(String body, PersonIdent author) throws Exception {
   try (ObjectInserter ins = testRepo.getRepository().newObjectInserter()) {
     CommitBuilder cb = new CommitBuilder();
     cb.setAuthor(author);
     cb.setCommitter(new PersonIdent(serverIdent, author.getWhen()));
     cb.setTreeId(testRepo.tree());
     cb.setMessage(body);
     ObjectId id = ins.insert(cb);
     ins.flush();
     RevCommit commit = walk.parseCommit(id);
     walk.parseBody(commit);
     return commit;
   }
 }
コード例 #8
0
 protected Change newPatchSet(TestRepository<Repo> repo, Change c) throws Exception {
   // Add a new file so the patch set is not a trivial rebase, to avoid default
   // Code-Review label copying.
   int n = c.currentPatchSetId().get() + 1;
   RevCommit commit =
       repo.parseBody(repo.commit().message("message").add("file" + n, "contents " + n).create());
   ChangeControl ctl = changeControlFactory.controlFor(c.getId(), user);
   return patchSetFactory
       .create(repo.getRepository(), repo.getRevWalk(), ctl, commit)
       .setSendMail(false)
       .setRunHooks(false)
       .setValidatePolicy(ValidatePolicy.NONE)
       .insert();
 }
コード例 #9
0
ファイル: AbstractSubmit.java プロジェクト: hdost/gerrit
 protected void assertRebase(TestRepository<?> testRepo, boolean contentMerge) throws IOException {
   Repository repo = testRepo.getRepository();
   RevCommit localHead = getHead(repo);
   RevCommit remoteHead = getRemoteHead();
   assert_()
       .withFailureMessage(String.format("%s not equal %s", localHead.name(), remoteHead.name()))
       .that(localHead.getId())
       .isNotEqualTo(remoteHead.getId());
   assertThat(remoteHead.getParentCount()).isEqualTo(1);
   if (!contentMerge) {
     assertThat(getLatestRemoteDiff()).isEqualTo(getLatestDiff(repo));
   }
   assertThat(remoteHead.getShortMessage()).isEqualTo(localHead.getShortMessage());
 }
コード例 #10
0
 @Test
 public void tagMissingTime() throws Exception {
   RevCommit commit = repo.commit().create();
   TagBuilder builder = new TagBuilder();
   builder.setObjectId(commit);
   builder.setTag("tag");
   builder.setMessage("");
   ObjectId id;
   try (ObjectInserter ins = repo.getRepository().newObjectInserter()) {
     id = ins.insert(builder);
     ins.flush();
   }
   assertThat(getTime(commit)).isEqualTo(start + 1);
   assertThat(getTime(id)).isEqualTo(start + 1);
 }
コード例 #11
0
  protected ChangeInserter newChange(
      TestRepository<Repo> repo,
      @Nullable RevCommit commit,
      @Nullable String key,
      @Nullable Integer owner,
      @Nullable String branch)
      throws Exception {
    if (commit == null) {
      commit = repo.parseBody(repo.commit().message("message").create());
    }
    Account.Id ownerId = owner != null ? new Account.Id(owner) : userId;
    branch = MoreObjects.firstNonNull(branch, "refs/heads/master");
    if (!branch.startsWith("refs/heads/")) {
      branch = "refs/heads/" + branch;
    }
    Project.NameKey project =
        new Project.NameKey(repo.getRepository().getDescription().getRepositoryName());

    Change.Id id = new Change.Id(db.nextChangeId());
    if (key == null) {
      key =
          "I"
              + Hashing.sha1()
                  .newHasher()
                  .putInt(id.get())
                  .putString(project.get(), UTF_8)
                  .putString(commit.name(), UTF_8)
                  .putInt(ownerId.get())
                  .putString(branch, UTF_8)
                  .hash()
                  .toString();
    }

    Change change =
        new Change(
            new Change.Key(key),
            id,
            ownerId,
            new Branch.NameKey(project, branch),
            TimeUtil.nowTs());
    IdentifiedUser user = userFactory.create(Providers.of(db), ownerId);
    return changeFactory.create(projectControlFactory.controlFor(project, user), change, commit);
  }
コード例 #12
0
  @Test
  public void testPushNotSupported() throws Exception {
    final TestRepository src = createTestRepository();
    final RevCommit Q = src.commit().create();
    final Repository db = src.getRepository();

    Transport t = Transport.open(db, remoteURI);
    ((TransportHttp) t).setUseSmartHttp(false);
    try {
      try {
        t.push(NullProgressMonitor.INSTANCE, push(src, Q));
        fail("push incorrectly completed against a smart server");
      } catch (NotSupportedException nse) {
        String exp = "smart HTTP push disabled";
        assertEquals(exp, nse.getMessage());
      }
    } finally {
      t.close();
    }
  }
コード例 #13
0
  @Test
  public void testListRemote_Smart_UploadPackDisabled() throws Exception {
    FileRepository src = remoteRepository.getRepository();
    final FileBasedConfig cfg = src.getConfig();
    cfg.setBoolean("http", null, "uploadpack", false);
    cfg.save();

    Repository dst = createBareRepository();
    Transport t = Transport.open(dst, smartAuthNoneURI);
    try {
      try {
        t.openFetch();
        fail("connection opened even though service disabled");
      } catch (TransportException err) {
        String exp = smartAuthNoneURI + ": git-upload-pack not permitted";
        assertEquals(exp, err.getMessage());
      }
    } finally {
      t.close();
    }
  }
コード例 #14
0
  @Test
  public void testListRemote_Dumb_NoHEAD() throws Exception {
    FileRepository src = remoteRepository.getRepository();
    File headref = new File(src.getDirectory(), Constants.HEAD);
    assertTrue("HEAD used to be present", headref.delete());
    assertFalse("HEAD is gone", headref.exists());

    Repository dst = createBareRepository();
    Ref head;
    Transport t = Transport.open(dst, dumbAuthNoneURI);
    try {
      FetchConnection c = t.openFetch();
      try {
        head = c.getRef(Constants.HEAD);
      } finally {
        c.close();
      }
    } finally {
      t.close();
    }
    assertNull("has no " + Constants.HEAD, head);
  }
コード例 #15
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    remoteRepository = createTestRepository();
    remoteRepository.update(master, remoteRepository.commit().create());

    ServletContextHandler dNone = dumb("/dnone");
    ServletContextHandler dBasic = server.authBasic(dumb("/dbasic"));

    ServletContextHandler sNone = smart("/snone");
    ServletContextHandler sBasic = server.authBasic(smart("/sbasic"));

    server.setUp();

    final String srcName = nameOf(remoteRepository.getRepository());
    dumbAuthNoneURI = toURIish(dNone, srcName);
    dumbAuthBasicURI = toURIish(dBasic, srcName);

    smartAuthNoneURI = toURIish(sNone, srcName);
    smartAuthBasicURI = toURIish(sBasic, srcName);
  }
コード例 #16
0
  @Test
  public void testListRemote_Smart_DetachedHEAD() throws Exception {
    Repository src = remoteRepository.getRepository();
    RefUpdate u = src.updateRef(Constants.HEAD, true);
    RevCommit Q = remoteRepository.commit().message("Q").create();
    u.setNewObjectId(Q);
    assertEquals(RefUpdate.Result.FORCED, u.forceUpdate());

    Repository dst = createBareRepository();
    Ref head;
    Transport t = Transport.open(dst, smartAuthNoneURI);
    try {
      FetchConnection c = t.openFetch();
      try {
        head = c.getRef(Constants.HEAD);
      } finally {
        c.close();
      }
    } finally {
      t.close();
    }
    assertNotNull("has " + Constants.HEAD, head);
    assertEquals(Q, head.getObjectId());
  }
コード例 #17
0
 private void serveHttp() throws Exception {
   httpServer = new SimpleHttpServer(src.getRepository());
   httpServer.start();
   uri = httpServer.getUri().toString();
 }
コード例 #18
0
 private void serve() throws IOException {
   d = new Daemon();
   d.exportRepository(REPO_NAME, src.getRepository());
   d.start();
   uri = "git://localhost:" + d.getAddress().getPort() + "/" + REPO_NAME + Constants.DOT_GIT;
 }