Search in sources :

Example 1 with DummyHttpServletRequest

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

the class PluginClassLoaderTest method testFalsePlugin.

@Test
public void testFalsePlugin() {
    PluginClassLoader instance = new PluginClassLoader(pluginDirectory);
    Class<?> clazz = loadClass(instance, "opengrok.auth.plugin.FalsePlugin");
    IAuthorizationPlugin plugin = getNewInstance(clazz);
    Group g = new Group("group1");
    Project p = new Project("project1");
    assertFalse(plugin.isAllowed(new DummyHttpServletRequest(), g));
    assertFalse(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)

Example 2 with DummyHttpServletRequest

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

the class FalsePluginTest method shouldNotAllowRandomUserForAnyProject.

@Test
void shouldNotAllowRandomUserForAnyProject() {
    DummyHttpServletRequest req = new DummyHttpServletRequest();
    req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomStringUtils.randomAlphanumeric(8)));
    Project randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
    boolean projectAllowed = plugin.isAllowed(req, randomProject);
    assertFalse(projectAllowed, "should not allow rando for random project 1");
    randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
    projectAllowed = plugin.isAllowed(req, randomProject);
    assertFalse(projectAllowed, "should not allow rando for random project 2");
}
Also used : Project(org.opengrok.indexer.configuration.Project) User(opengrok.auth.plugin.entity.User) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 3 with DummyHttpServletRequest

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

the class FalsePluginTest method shouldNotAllowRandomUserForAnyGroup.

@Test
void shouldNotAllowRandomUserForAnyGroup() {
    DummyHttpServletRequest req = new DummyHttpServletRequest();
    req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomStringUtils.randomAlphanumeric(8)));
    Group randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10));
    boolean projectAllowed = plugin.isAllowed(req, randomGroup);
    assertFalse(projectAllowed, "should not allow rando for random group 1");
    randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10));
    projectAllowed = plugin.isAllowed(req, randomGroup);
    assertFalse(projectAllowed, "should not allow rando for random group 2");
}
Also used : Group(org.opengrok.indexer.configuration.Group) User(opengrok.auth.plugin.entity.User) DummyHttpServletRequest(org.opengrok.indexer.web.DummyHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 4 with DummyHttpServletRequest

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

the class UserWhiteListPluginTest method shouldNotAllowRandomUserForAnyGroup.

@ParameterizedTest
@MethodSource("parameters")
public void shouldNotAllowRandomUserForAnyGroup(String param) {
    init(param);
    plugin.load(validPluginParameters);
    DummyHttpServletRequest req = new DummyHttpServletRequest();
    req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomStringUtils.randomAlphanumeric(8)));
    Group randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10));
    boolean projectAllowed = plugin.isAllowed(req, randomGroup);
    assertFalse(projectAllowed, "should not allow random group 1");
    randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10));
    projectAllowed = plugin.isAllowed(req, randomGroup);
    assertFalse(projectAllowed, "should not allow random group 2");
}
Also used : Group(org.opengrok.indexer.configuration.Group) 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 5 with DummyHttpServletRequest

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

the class UserWhiteListPluginTest method shouldAllowWhitelistedUserForAnyGroup.

@ParameterizedTest
@MethodSource("parameters")
public void shouldAllowWhitelistedUserForAnyGroup(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);
    Group randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10));
    boolean groupAllowed = plugin.isAllowed(req, randomGroup);
    assertTrue(groupAllowed, "should allow OK entity for random group 1");
    randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10));
    groupAllowed = plugin.isAllowed(req, randomGroup);
    assertTrue(groupAllowed, "should allow OK entity for random group 2");
}
Also used : Group(org.opengrok.indexer.configuration.Group) 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)

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