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