You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/06/19 13:05:54 UTC

olingo-odata4 git commit: [OLINGO-659] fix for URI parser to disallow anything after actions

Repository: olingo-odata4
Updated Branches:
  refs/heads/master 971deb553 -> fd513e22f


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

Change-Id: I578ee4562d13b220cec7fb05f1b6c9d69c0b25e4

Signed-off-by: Christian Amend <ch...@sap.com>


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/fd513e22
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/fd513e22
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/fd513e22

Branch: refs/heads/master
Commit: fd513e22f1d1a63f014702e3b07b929bdece707f
Parents: 971deb5
Author: Klaus Straubinger <kl...@sap.com>
Authored: Fri Jun 19 11:17:38 2015 +0200
Committer: Christian Amend <ch...@sap.com>
Committed: Fri Jun 19 13:05:28 2015 +0200

----------------------------------------------------------------------
 .../server/core/uri/UriResourceActionImpl.java  | 13 +++++++++++--
 .../server/core/uri/UriResourceTypedImpl.java   |  8 +-------
 .../uri/queryoption/expression/MemberImpl.java  |  5 +++++
 .../server/core/PreconditionsValidatorTest.java |  2 --
 .../core/uri/antlr/TestFullResourcePath.java    | 12 ++++++++++++
 .../core/uri/antlr/TestUriParserImpl.java       |  2 +-
 .../queryoption/expression/ExpressionTest.java  | 20 +++++++++++---------
 7 files changed, 41 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd513e22/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
index a78d79f..6acb6ea 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceActionImpl.java
@@ -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);
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd513e22/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java
index d5f01ea..cef7098 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriResourceTypedImpl.java
@@ -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());
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd513e22/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MemberImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MemberImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MemberImpl.java
index 8940bcf..5f6162f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MemberImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/expression/MemberImpl.java
@@ -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;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd513e22/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
index a70bbc7..fae780d 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/PreconditionsValidatorTest.java
@@ -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", "*", "*");

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd513e22/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index f5e625a..db58288 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -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

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd513e22/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
index 068edd7..0d333f3 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
@@ -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

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/fd513e22/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java
index e466f2d..98abf20 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java
@@ -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