use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class AuthUtilTest method test_isRedirectValid_resource_resolver_root_context.
@Test
public void test_isRedirectValid_resource_resolver_root_context() {
context.checking(new Expectations() {
{
allowing(resolver).resolve(with(any(HttpServletRequest.class)), with(equal("/absolute/path")));
will(returnValue(new SyntheticResource(resolver, "/absolute/path", "test")));
allowing(resolver).resolve(with(any(HttpServletRequest.class)), with(equal("relative/path")));
will(returnValue(new NonExistingResource(resolver, "relative/path")));
allowing(resolver).resolve(with(any(HttpServletRequest.class)), with(any(String.class)));
will(returnValue(new NonExistingResource(resolver, "/absolute/missing")));
allowing(request).getAttribute(with(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER));
will(returnValue(resolver));
allowing(request).getAttribute(with(any(String.class)));
will(returnValue(null));
allowing(request).getContextPath();
will(returnValue(""));
}
});
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "relative/path"));
TestCase.assertTrue(AuthUtil.isRedirectValid(request, "/absolute/path"));
TestCase.assertTrue(AuthUtil.isRedirectValid(request, "/absolute/missing"));
TestCase.assertTrue(AuthUtil.isRedirectValid(request, "/absolute/missing/valid"));
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "/absolute/missing/invalid/<"));
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "/absolute/missing/invalid/>"));
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "/absolute/missing/invalid/'"));
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "/absolute/missing/invalid/\""));
}
use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class AuthUtilTest method test_isRedirectValid_resource_resolver_non_root_context.
@Test
public void test_isRedirectValid_resource_resolver_non_root_context() {
context.checking(new Expectations() {
{
allowing(resolver).resolve(with(any(HttpServletRequest.class)), with(equal("/absolute/path")));
will(returnValue(new SyntheticResource(resolver, "/absolute/path", "test")));
allowing(resolver).resolve(with(any(HttpServletRequest.class)), with(equal("relative/path")));
will(returnValue(new NonExistingResource(resolver, "relative/path")));
allowing(request).getAttribute(with(AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER));
will(returnValue(resolver));
allowing(request).getAttribute(with(any(String.class)));
will(returnValue(null));
allowing(request).getContextPath();
will(returnValue("/ctx"));
}
});
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "relative/path"));
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "/absolute/path"));
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "ctx/relative/path"));
TestCase.assertTrue(AuthUtil.isRedirectValid(request, "/ctx/absolute/path"));
TestCase.assertFalse(AuthUtil.isRedirectValid(request, "/ctxrelative/path"));
}
use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class ValidationServiceImplTest method testSyntheticResource.
// see https://issues.apache.org/jira/browse/SLING-5749
@Test
public void testSyntheticResource() throws Exception {
// accept any digits
propertyBuilder.validator(REGEX_VALIDATOR_ID, 0, RegexValidator.REGEX_PARAM, "\\d");
ResourceProperty property = propertyBuilder.build("field1");
modelBuilder.resourceProperty(property);
ChildResource modelChild = new ChildResourceImpl("child", null, true, Collections.singletonList(property), Collections.emptyList());
modelBuilder.childResource(modelChild);
modelChild = new ChildResourceImpl("optionalChild", null, false, Collections.singletonList(property), Collections.emptyList());
modelBuilder.childResource(modelChild);
ValidationModel vm = modelBuilder.build("sometype", "some source");
ResourceResolver rr = context.resourceResolver();
Resource nonExistingResource = new SyntheticResource(rr, "someresource", "resourceType");
ValidationResult vr = validationService.validate(nonExistingResource, vm);
Assert.assertFalse("resource should have been considered invalid", vr.isValid());
Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>containsInAnyOrder(new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"), new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME, "child")));
}
use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class ValidationServiceImplTest method testValidateResourceRecursivelyOnNonExistingResource.
// see https://issues.apache.org/jira/browse/SLING-5674
@Test
public void testValidateResourceRecursivelyOnNonExistingResource() throws Exception {
ResourceResolver rr = context.resourceResolver();
Resource nonExistingResource = new NonExistingResource(rr, "non-existing-resource");
ValidationResult vr = validationService.validateResourceRecursively(nonExistingResource, true, null, true);
Assert.assertTrue("resource should have been considered valid", vr.isValid());
}
use of org.apache.sling.api.resource.NonExistingResource in project sling by apache.
the class ValidationServiceImplTest method testNonExistingResource.
// see https://issues.apache.org/jira/browse/SLING-5674
@Test
public void testNonExistingResource() throws Exception {
// accept any digits
propertyBuilder.validator(REGEX_VALIDATOR_ID, 0, RegexValidator.REGEX_PARAM, "\\d");
ResourceProperty property = propertyBuilder.build("field1");
modelBuilder.resourceProperty(property);
ChildResource modelChild = new ChildResourceImpl("child", null, true, Collections.singletonList(property), Collections.emptyList());
modelBuilder.childResource(modelChild);
modelChild = new ChildResourceImpl("optionalChild", null, false, Collections.singletonList(property), Collections.emptyList());
modelBuilder.childResource(modelChild);
ValidationModel vm = modelBuilder.build("sometype", "some source");
ResourceResolver rr = context.resourceResolver();
Resource nonExistingResource = new NonExistingResource(rr, "non-existing-resource");
ValidationResult vr = validationService.validate(nonExistingResource, vm);
Assert.assertFalse("resource should have been considered invalid", vr.isValid());
Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>containsInAnyOrder(new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field1"), new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME, "child")));
}
Aggregations