public class FilterConfigValidatorTest extends GeoServerMockTestSupport {
@Test
public void testDigestConfigValidation() throws Exception{
DigestAuthenticationFilterConfig config = new DigestAuthenticationFilterConfig();
config.setClassName(GeoServerDigestAuthenticationFilter.class.getName());
config.setName("testDigest");
GeoServerSecurityManager secMgr = getSecurityManager();
FilterConfigValidator validator = new FilterConfigValidator(secMgr);
try {
validator.validateFilterConfig(config);
fail("no user group service should fail");
} catch (FilterConfigException ex){
assertEquals(FilterConfigException.USER_GROUP_SERVICE_NEEDED,ex.getId());
assertEquals(0,ex.getArgs().length);
}
config.setUserGroupServiceName("blabla");
try {
validator.validateFilterConfig(config);
fail("unknown user group service should fail");
} catch (FilterConfigException ex){
assertEquals(FilterConfigException.UNKNOWN_USER_GROUP_SERVICE,ex.getId());
assertEquals(1,ex.getArgs().length);
assertEquals("blabla",ex.getArgs()[0]);
}
config.setUserGroupServiceName(XMLUserGroupService.DEFAULT_NAME);
config.setNonceValiditySeconds(-1);
try {
validator.validateFilterConfig(config);
fail("invalid nonce should fail");
} catch (FilterConfigException ex){
assertEquals(FilterConfigException.INVALID_SECONDS,ex.getId());
assertEquals(0,ex.getArgs().length);
}
config.setNonceValiditySeconds(100);
validator.validateFilterConfig(config);
}