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);
}
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");
}
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");
}
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));
}
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));
}
Aggregations