Search in sources :

Example 16 with Group

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

the class UserPluginTest method testTimeoutedUser.

@Test
public void testTimeoutedUser() {
    HttpServletRequest req;
    assertFalse(plugin.isAllowed(req = createRequest("007", true), new Group()));
    assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
    assertFalse(plugin.isAllowed(req = createRequest("008", true), new Project()));
    assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
    assertFalse(plugin.isAllowed(req = createRequest("009", true), createGroup("some group")));
    assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
    assertFalse(plugin.isAllowed(req = createRequest("00A", true), createProject("some project")));
    assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Group(org.opengrok.indexer.configuration.Group) Project(org.opengrok.indexer.configuration.Project) Test(org.junit.jupiter.api.Test)

Example 17 with Group

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

the class UserPluginTest method createGroup.

protected Group createGroup(String name) {
    Group g = new Group();
    g.setName(name);
    return g;
}
Also used : Group(org.opengrok.indexer.configuration.Group)

Example 18 with Group

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

the class LdapAttrPluginTest method makeGroup.

private Group makeGroup(String name) {
    Group p = new Group();
    p.setName(name);
    return p;
}
Also used : Group(org.opengrok.indexer.configuration.Group)

Example 19 with Group

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

the class TruePluginTest method shouldAllowRandomUserForAnyGroup.

@Test
public void shouldAllowRandomUserForAnyGroup() {
    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);
    assertTrue(projectAllowed, "should allow rando for random group 1");
    randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10));
    projectAllowed = plugin.isAllowed(req, randomGroup);
    assertTrue(projectAllowed, "should 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 20 with Group

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

the class LdapUserPluginTest method testNegativeCache.

@Test
void testNegativeCache() throws LdapException {
    AbstractLdapProvider mockprovider = mock(LdapFacade.class);
    when(mockprovider.lookupLdapContent(isNull(), isNull(), any(String[].class))).thenReturn(null);
    Map<String, Object> params = getParamsMap();
    params.put(LdapUserPlugin.ATTRIBUTES, "mail");
    params.put(LdapUserPlugin.USE_DN, false);
    LdapUserPlugin origPlugin = new LdapUserPlugin();
    LdapUserPlugin plugin = Mockito.spy(origPlugin);
    plugin.load(params, mockprovider);
    assertSame(mockprovider, plugin.getLdapProvider());
    HttpServletRequest dummyRequest = new DummyHttpServletRequestLdap();
    User user = new User("foo@example.com", "id");
    dummyRequest.setAttribute(UserPlugin.REQUEST_ATTR, new User("foo", "123"));
    plugin.fillSession(dummyRequest, user);
    assertNotNull(dummyRequest.getSession().getAttribute(SESSION_ATTR));
    assertFalse(plugin.isAllowed(dummyRequest, new Project("foo")));
    assertFalse(plugin.isAllowed(dummyRequest, new Group("bar")));
    // Make sure that the session was filled so that the second call to isAllowed() did not fill it again.
    verify(plugin, times(2)).updateSession(eq(dummyRequest), anyString(), anyBoolean());
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) DummyHttpServletRequestLdap(opengrok.auth.plugin.util.DummyHttpServletRequestLdap) Project(org.opengrok.indexer.configuration.Project) Group(org.opengrok.indexer.configuration.Group) LdapUser(opengrok.auth.entity.LdapUser) User(opengrok.auth.plugin.entity.User) AbstractLdapProvider(opengrok.auth.plugin.ldap.AbstractLdapProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

Group (org.opengrok.indexer.configuration.Group)33 Test (org.junit.jupiter.api.Test)19 Project (org.opengrok.indexer.configuration.Project)19 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)7 User (opengrok.auth.plugin.entity.User)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 Entity (jakarta.ws.rs.client.Entity)2 GenericType (jakarta.ws.rs.core.GenericType)2 Response (jakarta.ws.rs.core.Response)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2