Search in sources :

Example 11 with User

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

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

Example 13 with User

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

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

the class OSSODecoderTest method testGetTimeouted.

/**
 * Test of getTimeoutExceeded method, of class User.
 */
@Test
public void testGetTimeouted() {
    String[] tests = { "false", "true", "FALSE", "TRUE", "abcd" };
    boolean[] expected = { false, true, false, true, false };
    for (int i = 0; i < tests.length; i++) {
        dummyRequest.setHeader(OSSO_TIMEOUT_EXCEEDED_HEADER, tests[i]);
        User result = decoder.fromRequest(dummyRequest);
        if (expected[i]) {
            assertNull(result);
        } else {
            assertNotNull(result);
        }
    }
}
Also used : DummyHttpServletRequestUser(opengrok.auth.plugin.util.DummyHttpServletRequestUser) User(opengrok.auth.plugin.entity.User) Test(org.junit.jupiter.api.Test)

Example 15 with User

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

the class OSSODecoderTest method testGetUserDn.

/**
 * Test of getUserDn method, of class User.
 */
@Test
public void testGetUserDn() {
    String[] tests = { "123456", "sd45gfgf5sd4g5ffd54g", "ě5 1g56ew1tč6516re5g1g65d1g65d" };
    for (String test : tests) {
        dummyRequest.setHeader(OSSO_USER_DN_HEADER, test);
        User result = decoder.fromRequest(dummyRequest);
        assertNotNull(result);
        assertEquals(test, result.getUsername());
    }
}
Also used : DummyHttpServletRequestUser(opengrok.auth.plugin.util.DummyHttpServletRequestUser) User(opengrok.auth.plugin.entity.User) 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