Search in sources :

Example 11 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class ProjectHelperExtendedTest method setupPageConfigRequest.

private void setupPageConfigRequest(final String cookie) {
    cfg = PageConfig.get(new DummyHttpServletRequest() {

        @Override
        public Cookie[] getCookies() {
            Cookie[] ret = new Cookie[1];
            ret[0] = new Cookie("OpenGrokProject", cookie);
            return ret;
        }
    });
    helper = cfg.getProjectHelper();
}
Also used : Cookie(jakarta.servlet.http.Cookie) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest)

Example 12 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PageConfigTest method testCheckSourceRootExistence5.

/**
 * Test a successful check.
 * @throws IOException I/O exception
 */
@Test
public void testCheckSourceRootExistence5() throws IOException {
    HttpServletRequest req = new DummyHttpServletRequest();
    PageConfig cfg = PageConfig.get(req);
    String path = RuntimeEnvironment.getInstance().getSourceRootPath();
    File temp = File.createTempFile("opengrok", "-test-file.tmp");
    temp.delete();
    temp.mkdirs();
    RuntimeEnvironment.getInstance().setSourceRoot(temp.getAbsolutePath());
    cfg.checkSourceRootExistence();
    RuntimeEnvironment.getInstance().setSourceRoot(path);
    temp.deleteOnExit();
    PageConfig.cleanup(req);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 13 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PageConfigTest method testGetRequestedRevision.

@Test
public void testGetRequestedRevision() {
    final String[] revisions = { "6c5588de", "", "6c5588de", "6c5588de", "6c5588de" };
    for (int i = 0; i < revisions.length; i++) {
        final int index = i;
        DummyHttpServletRequest req = new DummyHttpServletRequest() {

            @Override
            public String getParameter(String name) {
                if (name.equals("r")) {
                    return revisions[index];
                }
                return null;
            }
        };
        PageConfig cfg = PageConfig.get(req);
        String rev = cfg.getRequestedRevision();
        assertNotNull(rev);
        assertEquals(revisions[i], rev);
        assertFalse(rev.contains("r="));
        PageConfig.cleanup(req);
    }
}
Also used : DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 14 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PageConfigTest method testGetLatestRevisionValid.

@Test
public void testGetLatestRevisionValid() {
    DummyHttpServletRequest req1 = new DummyHttpServletRequest() {

        @Override
        public String getPathInfo() {
            return "/git/main.c";
        }
    };
    PageConfig cfg = PageConfig.get(req1);
    String rev = cfg.getLatestRevision();
    assertEquals("aa35c258", rev);
}
Also used : DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 15 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest in project OpenGrok by OpenGrok.

the class PluginClassLoaderTest method testTruePlugin.

@Test
public void testTruePlugin() {
    PluginClassLoader instance = new PluginClassLoader(pluginDirectory);
    Class<?> clazz = loadClass(instance, "opengrok.auth.plugin.TruePlugin");
    IAuthorizationPlugin plugin = getNewInstance(clazz);
    Group g = new Group("group1");
    Project p = new Project("project1");
    assertTrue(plugin.isAllowed(new DummyHttpServletRequest(), g));
    assertTrue(plugin.isAllowed(new DummyHttpServletRequest(), p));
}
Also used : Group(org.opengrok.indexer.configuration.Group) Project(org.opengrok.indexer.configuration.Project) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) PluginClassLoader(org.opengrok.indexer.framework.PluginClassLoader) Test(org.junit.jupiter.api.Test)

Aggregations

DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)27 Test (org.junit.jupiter.api.Test)22 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)8 User (opengrok.auth.plugin.entity.User)8 Project (org.opengrok.indexer.configuration.Project)8 Group (org.opengrok.indexer.configuration.Group)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 File (java.io.File)3 PluginClassLoader (org.opengrok.indexer.framework.PluginClassLoader)2 Cookie (jakarta.servlet.http.Cookie)1 HttpSession (jakarta.servlet.http.HttpSession)1 Response (jakarta.ws.rs.core.Response)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)1 Configuration (org.opengrok.indexer.configuration.Configuration)1 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)1 Annotation (org.opengrok.indexer.history.Annotation)1 PageConfig (org.opengrok.web.PageConfig)1