Search in sources :

Example 1 with User

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

the class LdapUserPluginTest method getFilterTest1.

@Test
public void getFilterTest1() {
    Map<String, Object> params = getParamsMap();
    String cl = "posixUser";
    params.put(LdapUserPlugin.OBJECT_CLASS, (Object) cl);
    plugin.load(params);
    String cn = "cn=foo-foo_bar1";
    User user = new User(cn + ",l=EMEA,dc=foobar,dc=com", "id", null, false);
    String filter = plugin.getFilter(user);
    Assert.assertEquals("(&(" + LdapUserPlugin.OBJECT_CLASS + "=" + cl + ")(" + cn + "))", filter);
}
Also used : User(opengrok.auth.plugin.entity.User) Test(org.junit.Test)

Example 2 with User

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

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

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

the class LdapFilterPluginTest method expandFilterTest1.

@Test
void expandFilterTest1() {
    LdapUser ldapUser = new LdapUser();
    ldapUser.setAttribute("mail", new TreeSet<>(Collections.singletonList("james@bond")));
    ldapUser.setAttribute("uid", new TreeSet<>(Collections.singletonList("bondjame")));
    ldapUser.setAttribute("ou", new TreeSet<>(Arrays.asList("MI6", "MI7")));
    User user = new User("007", "123", null, true);
    assertEquals("(objectclass=james@bond)", plugin.expandFilter("(objectclass=%mail%)", ldapUser, user));
    assertEquals("(objectclass=bondjame)", plugin.expandFilter("(objectclass=%uid%)", ldapUser, user));
    assertEquals("(objectclass=007)", plugin.expandFilter("(objectclass=%username%)", ldapUser, user));
    assertEquals("(objectclass=123)", plugin.expandFilter("(objectclass=%guid%)", ldapUser, user));
    ldapUser.setAttribute("role", new TreeSet<>(Collections.singletonList("agent")));
    assertEquals("(objectclass=agent)", plugin.expandFilter("(objectclass=%role%)", ldapUser, user));
    // doesn't work for more than one value
    ldapUser.setAttribute("role", new TreeSet<>(Arrays.asList("agent", "double-agent")));
    assertEquals("(objectclass=%role%)", plugin.expandFilter("(objectclass=%role%)", ldapUser, user));
}
Also used : LdapUser(opengrok.auth.entity.LdapUser) User(opengrok.auth.plugin.entity.User) LdapUser(opengrok.auth.entity.LdapUser) Test(org.junit.jupiter.api.Test)

Example 5 with User

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

the class LdapFilterPluginTest method expandFilterTest2.

@Test
void expandFilterTest2() {
    LdapUser ldapUser = new LdapUser();
    ldapUser.setAttribute("mail", new TreeSet<>(Collections.singletonList("james@bond")));
    ldapUser.setAttribute("uid", new TreeSet<>(Collections.singletonList("bondjame")));
    ldapUser.setAttribute("ou", new TreeSet<>(Arrays.asList("MI6", "MI7")));
    User user = new User("007", "123", null, true);
    assertEquals("(objectclass=%james@bond%)", plugin.expandFilter("(objectclass=%%mail%%)", ldapUser, user));
    assertEquals("(objectclass=%james@bond%)", plugin.expandFilter("(objectclass=\\%%mail%\\%)", ldapUser, user));
    assertEquals("(objectclass=%mail%)", plugin.expandFilter("(objectclass=\\%mail\\%)", ldapUser, user));
    assertEquals("(objectclass=%mail)", plugin.expandFilter("(objectclass=\\%mail)", ldapUser, user));
    assertEquals("(objectclass=mail)", plugin.expandFilter("(objectclass=mail)", ldapUser, user));
    assertEquals("(objectclass=%mail)", plugin.expandFilter("(objectclass=%mail)", ldapUser, user));
    assertEquals("(objectclass=%%%%)", plugin.expandFilter("(objectclass=\\%%\\%\\%)", ldapUser, user));
}
Also used : LdapUser(opengrok.auth.entity.LdapUser) User(opengrok.auth.plugin.entity.User) LdapUser(opengrok.auth.entity.LdapUser) 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