Search in sources :

Example 26 with User

use of opengrok.auth.plugin.entity.User 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 27 with User

use of opengrok.auth.plugin.entity.User in project OpenGrok by OpenGrok.

the class UserWhiteListPluginTest method shouldNotAllowRandomUserForAnyProject.

@ParameterizedTest
@MethodSource("parameters")
public void shouldNotAllowRandomUserForAnyProject(String param) {
    init(param);
    plugin.load(validPluginParameters);
    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 random user for random project 1");
    randomProject = new Project(RandomStringUtils.randomAlphanumeric(10));
    projectAllowed = plugin.isAllowed(req, randomProject);
    assertFalse(projectAllowed, "should not allow random user 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 28 with User

use of opengrok.auth.plugin.entity.User in project OpenGrok by OpenGrok.

the class MellonDecoderTest method testUsername.

@Test
public void testUsername() {
    dummyRequest.setHeader(MELLON_USERNAME_HEADER, "foo");
    User result = decoder.fromRequest(dummyRequest);
    assertNotNull(result);
    assertEquals("foo", result.getUsername());
    assertFalse(result.isTimeouted());
}
Also used : User(opengrok.auth.plugin.entity.User) DummyHttpServletRequestUser(opengrok.auth.plugin.util.DummyHttpServletRequestUser) Test(org.junit.jupiter.api.Test)

Example 29 with User

use of opengrok.auth.plugin.entity.User in project OpenGrok by OpenGrok.

the class MellonDecoderTest method testId.

@Test
public void testId() {
    User result = decoder.fromRequest(dummyRequest);
    assertNotNull(result);
    assertEquals("foo@bar.cz", result.getId());
    assertNull(result.getUsername());
    assertFalse(result.isTimeouted());
}
Also used : User(opengrok.auth.plugin.entity.User) DummyHttpServletRequestUser(opengrok.auth.plugin.util.DummyHttpServletRequestUser) Test(org.junit.jupiter.api.Test)

Example 30 with User

use of opengrok.auth.plugin.entity.User 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

User (opengrok.auth.plugin.entity.User)31 Test (org.junit.jupiter.api.Test)18 DummyHttpServletRequestUser (opengrok.auth.plugin.util.DummyHttpServletRequestUser)9 DummyHttpServletRequest (org.opengrok.indexer.web.DummyHttpServletRequest)8 LdapUser (opengrok.auth.entity.LdapUser)7 Group (org.opengrok.indexer.configuration.Group)5 Project (org.opengrok.indexer.configuration.Project)5 DummyHttpServletRequestLdap (opengrok.auth.plugin.util.DummyHttpServletRequestLdap)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)3 AbstractLdapProvider (opengrok.auth.plugin.ldap.AbstractLdapProvider)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 Date (java.util.Date)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1