Skip to content

Commit

Permalink
fixed issue apiman-1227 related to a trailing / being left out in the…
Browse files Browse the repository at this point in the history
… gateway
  • Loading branch information
EricWittmann committed Jan 23, 2017
1 parent f694919 commit 5d8c60a
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 0 deletions.
Expand Up @@ -69,6 +69,8 @@ public static final ApiRequestPathInfo parseApiRequestPath(String apiVersionHead
resource.append('/');
}
info.resource = resource.toString();
} else if (pathInfo.endsWith("/")) {
info.resource = "/";
}
}
}
Expand Down
@@ -0,0 +1,60 @@
/*
* Copyright 2016 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.apiman.common.util;

import org.junit.Assert;
import org.junit.Test;

import io.apiman.common.util.ApimanPathUtils.ApiRequestPathInfo;

public class ApimanPathUtilsTest {

@Test
public void testParseApiRequestPath() {
ApiRequestPathInfo path = ApimanPathUtils.parseApiRequestPath(null, "application/json", "/OrgId/ApiId/VER/path/to/thing");
Assert.assertEquals("OrgId", path.orgId);
Assert.assertEquals("ApiId", path.apiId);
Assert.assertEquals("VER", path.apiVersion);
Assert.assertEquals("/path/to/thing", path.resource);

path = ApimanPathUtils.parseApiRequestPath(null, "application/json", "/OrgId/ApiId/VER");
Assert.assertEquals("OrgId", path.orgId);
Assert.assertEquals("ApiId", path.apiId);
Assert.assertEquals("VER", path.apiVersion);
Assert.assertEquals(null, path.resource);

path = ApimanPathUtils.parseApiRequestPath(null, "application/json", "/OrgId/ApiId/VER/");
Assert.assertEquals("OrgId", path.orgId);
Assert.assertEquals("ApiId", path.apiId);
Assert.assertEquals("VER", path.apiVersion);
Assert.assertEquals("/", path.resource);

path = ApimanPathUtils.parseApiRequestPath("VER", "application/json", "/OrgId/ApiId/path/to/thing");
Assert.assertEquals("OrgId", path.orgId);
Assert.assertEquals("ApiId", path.apiId);
Assert.assertEquals("VER", path.apiVersion);
Assert.assertEquals("/path/to/thing", path.resource);

path = ApimanPathUtils.parseApiRequestPath("VER", "application/json", "/OrgId/ApiId");
Assert.assertEquals("OrgId", path.orgId);
Assert.assertEquals("ApiId", path.apiId);
Assert.assertEquals("VER", path.apiVersion);
Assert.assertEquals(null, path.resource);

}

}
@@ -0,0 +1,32 @@
/*
* Copyright 2014 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.apiman.gateway.test;

import io.apiman.gateway.test.junit.GatewayRestTestPlan;
import io.apiman.gateway.test.junit.GatewayRestTester;

import org.junit.runner.RunWith;

/**
* Make sure the gateway and test echo server are working.
*
* @author eric.wittmann@redhat.com
*/
@RunWith(GatewayRestTester.class)
@GatewayRestTestPlan("test-plans/simple/simple-echo-1227-testPlan.xml")
public class SimpleEcho1227Test {

}
@@ -0,0 +1,14 @@
PUT /apis admin/admin
Content-Type: application/json

{
"organizationId" : "SimpleEcho1227Test",
"apiId" : "echo",
"version" : "1.0",
"publicAPI" : true,
"endpointType" : "REST",
"endpoint" : "${apiman-gateway-test.endpoints.echo}/endpoint/with-trailing-slash/",
"apiPolicies" : [ ]
}
----
204
@@ -0,0 +1,14 @@
GET /SimpleEcho1227Test/echo/1.0/ admin/admin
Accept: application/json

----
200
Content-Type: application/json

{
"method" : "GET",
"resource" : "/endpoint/with-trailing-slash/",
"uri" : "/endpoint/with-trailing-slash/",
"headers" : {
}
}
@@ -0,0 +1,14 @@
GET /SimpleEcho1227Test/echo/1.0 admin/admin
Accept: application/json

----
200
Content-Type: application/json

{
"method" : "GET",
"resource" : "/endpoint/with-trailing-slash",

This comment has been minimized.

Copy link
@msavy

msavy Jan 23, 2017

Member

@EricWittmann Hmm, is this right? As I understand it - we should be using registered API endpoint plus whatever is on the API call path after the /SimpleEcho1227Test/echo/1.0 bit?

So, registered endpoint is:

${apiman-gateway-test.endpoints.echo}/endpoint/with-trailing-slash/

Invoked path is: "" (empty string)

Which would be "/endpoint/with-trailing-slash/" + "" = /endpoint/with-trailing-slash/

Am I misunderstanding?

This comment has been minimized.

Copy link
@EricWittmann

EricWittmann Jan 24, 2017

Author Member

Let's discuss tomorrow via irc or hangout. I think it's a bit trickier than we thought. :) Surprisingly.

This comment has been minimized.

Copy link
@msavy

msavy Jan 24, 2017

Member

👍

"uri" : "/endpoint/with-trailing-slash",
"headers" : {
}
}
@@ -0,0 +1,14 @@
GET /SimpleEcho1227Test/echo/1.0/some/resource admin/admin
Accept: application/json

----
200
Content-Type: application/json

{
"method" : "GET",
"resource" : "/endpoint/with-trailing-slash/some/resource",
"uri" : "/endpoint/with-trailing-slash/some/resource",
"headers" : {
}
}
@@ -0,0 +1,14 @@
GET /SimpleEcho1227Test/echo/1.0/some/resource/ admin/admin
Accept: application/json

----
200
Content-Type: application/json

{
"method" : "GET",
"resource" : "/endpoint/with-trailing-slash/some/resource/",
"uri" : "/endpoint/with-trailing-slash/some/resource/",
"headers" : {
}
}
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<testPlan xmlns="urn:io.apiman.test:2014:02:testPlan">

<!-- Reproducer for APIMAN-1227 -->

<testGroup name="setup" endpoint="api">
<test name="Publish Api">test-plan-data/simple/simple-echo-1227/001-publish-api.resttest</test>
</testGroup>

<testGroup name="test">
<test name="Echo 1">test-plan-data/simple/simple-echo-1227/002-echo.resttest</test>
<test name="Echo 2">test-plan-data/simple/simple-echo-1227/003-echo-2.resttest</test>
<test name="Echo 3">test-plan-data/simple/simple-echo-1227/004-echo-3.resttest</test>
<test name="Echo 4">test-plan-data/simple/simple-echo-1227/005-echo-4.resttest</test>
</testGroup>
</testPlan>

0 comments on commit 5d8c60a

Please sign in to comment.