Search in sources :

Example 6 with AbstractLdapProvider

use of opengrok.auth.plugin.ldap.AbstractLdapProvider 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

LdapUser (opengrok.auth.entity.LdapUser)6 AbstractLdapProvider (opengrok.auth.plugin.ldap.AbstractLdapProvider)6 Map (java.util.Map)4 Set (java.util.Set)4 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)3 HashMap (java.util.HashMap)3 User (opengrok.auth.plugin.entity.User)3 LdapException (opengrok.auth.plugin.ldap.LdapException)3 DummyHttpServletRequestLdap (opengrok.auth.plugin.util.DummyHttpServletRequestLdap)3 Test (org.junit.jupiter.api.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 AuthorizationException (org.opengrok.indexer.authorization.AuthorizationException)3 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 HashSet (java.util.HashSet)1 Group (org.opengrok.indexer.configuration.Group)1 Project (org.opengrok.indexer.configuration.Project)1