Search in sources :

Example 6 with DummyHttpServletRequest

use of org.opengrok.indexer.web.DummyHttpServletRequest 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 7 with DummyHttpServletRequest

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

the class PageConfigTest method testRequestAttributes.

@Test
public void testRequestAttributes() {
    HttpServletRequest req = new DummyHttpServletRequest();
    PageConfig cfg = PageConfig.get(req);
    String[] attrs = { "a", "b", "c", "d" };
    Object[] values = { "some object", new DummyHttpServletRequest(), 1, this };
    assertEquals(attrs.length, values.length);
    for (int i = 0; i < attrs.length; i++) {
        cfg.setRequestAttribute(attrs[i], values[i]);
        Object attribute = req.getAttribute(attrs[i]);
        assertNotNull(attribute);
        assertEquals(values[i], attribute);
        attribute = cfg.getRequestAttribute(attrs[i]);
        assertNotNull(attribute);
        assertEquals(values[i], attribute);
    }
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 8 with DummyHttpServletRequest

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

the class PageConfigTest method testCheckSourceRootExistence2.

/**
 * Test the case when source root is empty.
 */
@Test
public void testCheckSourceRootExistence2() {
    assertThrows(FileNotFoundException.class, () -> {
        HttpServletRequest req = new DummyHttpServletRequest();
        PageConfig cfg = PageConfig.get(req);
        String path = RuntimeEnvironment.getInstance().getSourceRootPath();
        RuntimeEnvironment.getInstance().setSourceRoot("");
        try {
            cfg.checkSourceRootExistence();
        } finally {
            RuntimeEnvironment.getInstance().setSourceRoot(path);
            PageConfig.cleanup(req);
        }
    });
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 9 with DummyHttpServletRequest

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

the class PageConfigTest method testGetRevisionLocationNullQuery.

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

        @Override
        public String getPathInfo() {
            return "/git/main.c";
        }

        @Override
        public String getContextPath() {
            return "source";
        }

        @Override
        public String getQueryString() {
            return null;
        }
    };
    PageConfig cfg = PageConfig.get(req1);
    String location = cfg.getRevisionLocation(cfg.getLatestRevision());
    assertNotNull(location);
    assertEquals("source/xref/git/main.c?r=aa35c258", location);
}
Also used : DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 10 with DummyHttpServletRequest

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

the class PageConfigTest method testGetAnnotation.

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

            @Override
            public String getContextPath() {
                return "/source";
            }

            @Override
            public String getServletPath() {
                return "/history";
            }

            @Override
            public String getPathInfo() {
                return "/git/main.c";
            }

            @Override
            public String getParameter(String name) {
                switch(name) {
                    case "r":
                        return revisions[index];
                    case "a":
                        return "true";
                }
                return null;
            }
        };
        PageConfig cfg = PageConfig.get(req);
        Annotation annotation = cfg.getAnnotation();
        assertNotNull(annotation);
        assertEquals("main.c", annotation.getFilename());
        assertEquals(revisions.length - i, annotation.getFileVersionsCount());
        for (int j = 1; j <= annotation.size(); j++) {
            String tmp = annotation.getRevision(j);
            assertTrue(Arrays.asList(revisions).contains(tmp));
        }
        assertEquals(revisions.length - i, annotation.getFileVersion(revisions[i]), "The version should be reflected through the revision");
        PageConfig.cleanup(req);
    }
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Annotation(org.opengrok.indexer.history.Annotation) 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