Search in sources :

Example 11 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class UserWhiteListPluginTest method shouldAllowWhitelistedUserForAnyProject.

@ParameterizedTest
@MethodSource("parameters")
public void shouldAllowWhitelistedUserForAnyProject(String param) {
    init(param);
    plugin.load(validPluginParameters);
    DummyHttpServletRequest req = new DummyHttpServletRequest();
    User user;
    if (param.equals(UserWhiteListPlugin.USERNAME_FIELD)) {
        user = new User(OK_USER);
    } else {
        user = new User("blurb", OK_ID);
    }
    req.setAttribute(UserPlugin.REQUEST_ATTR, user);
    Project randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
    boolean projectAllowed = plugin.isAllowed(req, randomProject);
    assertTrue(projectAllowed, "should allow OK entity for random project 1");
    randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
    projectAllowed = plugin.isAllowed(req, randomProject);
    assertTrue(projectAllowed, "should allow OK entity for random project 2");
}
Also used : Project(org.opengrok.indexer.configuration.Project) User(opengrok.auth.plugin.entity.User) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class IndexerTest method testDefaultProjectsSingleProject.

/**
 * Should include the existing project.
 * @throws Exception
 */
@Test
void testDefaultProjectsSingleProject() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    env.setHistoryEnabled(false);
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, null);
    env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
    assertEquals(1, env.getDefaultProjects().size());
    assertEquals(new TreeSet<>(Collections.singletonList("c")), env.getDefaultProjects().stream().map(Project::getName).collect(Collectors.toSet()));
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Test(org.junit.jupiter.api.Test)

Example 13 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class IndexerTest method testBug11896.

/**
 * Test that named pipes are not indexed.
 * @throws Exception
 */
@Test
@EnabledIf("mkfifoInPath")
void testBug11896() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    Executor executor;
    executor = new Executor(new String[] { "mkdir", "-p", repository.getSourceRoot() + "/testBug11896" });
    executor.exec(true);
    executor = new Executor(new String[] { "mkfifo", repository.getSourceRoot() + "/testBug11896/FIFO" });
    executor.exec(true);
    Project project = new Project("testBug11896");
    project.setPath("/testBug11896");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    MyIndexChangeListener listener = new MyIndexChangeListener();
    idb.addIndexChangedListener(listener);
    System.out.println("Trying to index a special file - FIFO in this case.");
    idb.update();
    assertEquals(0, listener.files.size());
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Executor(org.opengrok.indexer.util.Executor) Test(org.junit.jupiter.api.Test) EnabledIf(org.junit.jupiter.api.condition.EnabledIf)

Example 14 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class IndexerTest method testBug3430.

@Test
void testBug3430() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setSourceRoot(repository.getSourceRoot());
    env.setDataRoot(repository.getDataRoot());
    Project project = new Project("bug3430");
    project.setPath("/bug3430");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    MyIndexChangeListener listener = new MyIndexChangeListener();
    idb.addIndexChangedListener(listener);
    idb.update();
    assertEquals(1, listener.files.size());
}
Also used : Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) Test(org.junit.jupiter.api.Test)

Example 15 with Project

use of org.opengrok.indexer.configuration.Project in project OpenGrok by OpenGrok.

the class IndexerRepoTest method testPerProjectHistory.

private void testPerProjectHistory(boolean globalOn) throws IndexerException, IOException, HistoryException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    // Make sure we start from scratch.
    Path dataRoot = Files.createTempDirectory("dataForPerProjectHistoryTest");
    env.setDataRoot(dataRoot.toString());
    env.setProjectsEnabled(true);
    env.setHistoryEnabled(globalOn);
    Project proj = new Project("mercurial", "/mercurial");
    proj.setHistoryEnabled(!globalOn);
    env.getProjects().clear();
    env.getProjects().put("mercurial", proj);
    Indexer.getInstance().prepareIndexer(env, // search for repositories
    true, // scan and add projects
    true, // don't create dictionary
    false, // subFiles - not needed since we don't list files
    null, // repositories - not needed when not refreshing history
    null);
    File repoRoot = new File(env.getSourceRootFile(), "git");
    File fileInRepo = new File(repoRoot, "main.c");
    assertTrue(fileInRepo.exists());
    if (globalOn) {
        assertNotNull(HistoryGuru.getInstance().getHistory(fileInRepo));
    } else {
        assertNull(HistoryGuru.getInstance().getHistory(fileInRepo));
    }
    repoRoot = new File(env.getSourceRootFile(), "mercurial");
    fileInRepo = new File(repoRoot, "main.c");
    assertTrue(fileInRepo.exists());
    if (globalOn) {
        assertNull(HistoryGuru.getInstance().getHistory(fileInRepo));
    } else {
        assertNotNull(HistoryGuru.getInstance().getHistory(fileInRepo));
    }
    IOUtils.removeRecursive(dataRoot);
}
Also used : Path(java.nio.file.Path) Project(org.opengrok.indexer.configuration.Project) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) File(java.io.File)

Aggregations

Project (org.opengrok.indexer.configuration.Project)88 Test (org.junit.jupiter.api.Test)42 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)27 File (java.io.File)22 Group (org.opengrok.indexer.configuration.Group)20 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)17 ArrayList (java.util.ArrayList)16 TreeSet (java.util.TreeSet)11 IOException (java.io.IOException)10 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)10 List (java.util.List)8 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)7 Path (jakarta.ws.rs.Path)7 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)7 Path (java.nio.file.Path)6 Map (java.util.Map)6 Paths (java.nio.file.Paths)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 MercurialRepositoryTest (org.opengrok.indexer.history.MercurialRepositoryTest)5