[OLINGO-659] fix for URI parser to disallow anything after actions

Change-Id: I578ee4562d13b220cec7fb05f1b6c9d69c0b25e4

Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
Klaus Straubinger 2015-06-19 11:17:38 +02:00 committed by Christian Amend
parent 971deb5539
commit fd513e22f1
7 changed files with 41 additions and 21 deletions

View File

@ -24,7 +24,12 @@ import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.server.api.uri.UriResourceAction;
import org.apache.olingo.server.api.uri.UriResourceKind;
public class UriResourceActionImpl extends UriResourceTypedImpl implements UriResourceAction {
/**
* Implementation of the {@link UriResourceAction} interface. This class does not extend
* {@link org.apache.olingo.server.core.uri.UriResourceTypedImpl UriResourceTypedImpl}
* since that would allow type filters and subsequent path segments.
*/
public class UriResourceActionImpl extends UriResourceImpl implements UriResourceAction {
protected EdmAction action;
protected EdmActionImport actionImport;
@ -71,8 +76,12 @@ public class UriResourceActionImpl extends UriResourceTypedImpl implements UriRe
}
@Override
public String toString() {
public String toString(final boolean includeFilters) {
return actionImport == null ? (action == null ? "" : action.getName()) : actionImport.getName();
}
@Override
public String toString() {
return toString(false);
}
}

View File

@ -20,7 +20,6 @@ package org.apache.olingo.server.core.uri;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
@ -45,16 +44,11 @@ public abstract class UriResourceTypedImpl extends UriResourceImpl implements Ur
public String toString(final boolean includeFilters) {
if (includeFilters) {
if (typeFilter != null) {
return toString() + "/" + getFQN(typeFilter).toString();
return toString() + "/" + typeFilter.getFullQualifiedName().toString();
} else {
return toString();
}
}
return toString();
}
private FullQualifiedName getFQN(final EdmType type) {
return new FullQualifiedName(type.getNamespace(), type.getName());
}
}

View File

@ -25,6 +25,7 @@ import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitEx
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitor;
import org.apache.olingo.server.api.uri.queryoption.expression.Member;
import org.apache.olingo.server.core.uri.UriInfoImpl;
import org.apache.olingo.server.core.uri.UriResourceActionImpl;
import org.apache.olingo.server.core.uri.UriResourceImpl;
import org.apache.olingo.server.core.uri.UriResourceTypedImpl;
import org.apache.olingo.server.core.uri.UriResourceWithKeysImpl;
@ -69,6 +70,8 @@ public class MemberImpl extends ExpressionImpl implements Member {
return type;
}
return lastTyped.getType();
} else if (lastResourcePart instanceof UriResourceActionImpl) {
return ((UriResourceActionImpl) lastResourcePart).getType();
} else {
return null;
}
@ -81,6 +84,8 @@ public class MemberImpl extends ExpressionImpl implements Member {
if (lastResourcePart instanceof UriResourceTypedImpl) {
UriResourceTypedImpl lastTyped = (UriResourceTypedImpl) lastResourcePart;
return lastTyped.isCollection();
} else if (lastResourcePart instanceof UriResourceActionImpl) {
return ((UriResourceActionImpl) lastResourcePart).isCollection();
}
return false;
}

View File

@ -40,7 +40,6 @@ import org.apache.olingo.server.core.uri.parser.Parser;
import org.apache.olingo.server.core.uri.parser.UriParserException;
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@ -180,7 +179,6 @@ public class PreconditionsValidatorTest {
runException("SINav/NavPropertyETKeyNavOne/Namespace1_Alias.BAETTwoKeyNavRTETTwoKeyNav");
}
@Ignore
@Test(expected = UriParserSemanticException.class)
public void resourceSegmentAfterActionMustLeadToUriParserException() throws Exception {
validate("ESKeyNav(1)/Namespace1_Alias.BAETTwoKeyNavRTETTwoKeyNav/PropertyInt16", "ESKeyNav", "*", "*");

View File

@ -38,6 +38,7 @@ import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
import org.apache.olingo.server.core.uri.testutil.FilterValidator;
import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
import org.apache.olingo.server.core.uri.validator.UriValidationException;
import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
@ -5201,6 +5202,17 @@ public class TestFullResourcePath {
.isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_ENTITY_TYPES);
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$count")
.isExSemantic(UriParserSemanticException.MessageKeys.ONLY_FOR_COLLECTIONS);
// Actions must not be followed by anything.
testUri.runEx(ContainerProvider.AIRT_STRING + "/$value")
.isExValidation(UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_VALUE);
testUri.runEx(ContainerProvider.AIRTCT_TWO_PRIM_PARAM + "/PropertyInt16")
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/"
+ "olingo.odata.test1.BAETTwoKeyNavRTETTwoKeyNav/olingo.odata.test1.ETTwoKeyNav")
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
testUri.runEx("ESTwoKeyNav/olingo.odata.test1.BAESTwoKeyNavRTESTwoKeyNav/$count")
.isExValidation(UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_COUNT);
}
@Test

View File

@ -193,7 +193,7 @@ public class TestUriParserImpl {
.isType(EntityTypeProvider.nameETTwoKeyTwoPrim, false);
testUri.runEx(ContainerProvider.AIRT_STRING + "/invalidElement")
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE);
.isExSemantic(UriParserSemanticException.MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
}
@Test

View File

@ -19,7 +19,9 @@
package org.apache.olingo.server.core.uri.queryoption.expression;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
@ -134,7 +136,7 @@ public class ExpressionTest {
MemberImpl expression = new MemberImpl();
EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav);
// UriResourceImplTyped
// UriResourceImpl
EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTString);
UriInfoResource uriInfo = new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
new UriResourceActionImpl().setAction(action)).asUriInfoResource();
@ -146,24 +148,24 @@ public class ExpressionTest {
assertEquals("<UARTString>", expression.accept(new FilterTreeToText()));
// UriResourceImplTyped check collection = false case
assertEquals(false, expression.isCollection());
assertFalse(expression.isCollection());
// UriResourceImplTyped check collection = true case
action = edm.getUnboundAction(ActionProvider.nameUARTCollStringTwoParam);
expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
new UriResourceActionImpl().setAction(action))
expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource)
.addResourcePart(new UriResourceActionImpl().setAction(action))
.asUriInfoResource());
assertEquals(true, expression.isCollection());
assertTrue(expression.isCollection());
// UriResourceImplTyped with filter
action = edm.getUnboundAction(ActionProvider.nameUARTString);
EdmFunction function = edm.getUnboundFunction(FunctionProvider.nameUFCRTETKeyNav, null);
expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
new UriResourceActionImpl().setAction(action).setTypeFilter(entityType))
new UriResourceFunctionImpl().setFunction(function).setEntryTypeFilter(entityType))
.asUriInfoResource());
assertEquals(entityType, expression.getType());
// UriResourceImplKeyPred
EdmFunction function = edm.getUnboundFunction(FunctionProvider.nameUFCRTETKeyNav, null);
function = edm.getUnboundFunction(FunctionProvider.nameUFCRTETKeyNav, null);
expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
new UriResourceFunctionImpl().setFunction(function))
.asUriInfoResource());
@ -192,7 +194,7 @@ public class ExpressionTest {
assertEquals(null, expression.getType());
// no typed collection else case
assertEquals(false, expression.isCollection());
assertFalse(expression.isCollection());
}
@Test