[keycloak-dev] Trailing slash
slaskawi at redhat.com
Wed Feb 20 08:47:59 EST 2019
I'm working on migrating Jetty adapters to our base testsuite at the moment
and I noticed an interesting problem.
The URLProvider is responsible for adjusting injected URLs into the Page
objects. One of the things it does is trimming the trailing slash out, so
that "http://localhost:8280/client-secret-jwt-secure-portal/" becomes "
http://localhost:8280/client-secret-jwt-secure-portal". We depend on this
functionality a lot in our testsuite when constructing all kind of
assertions that include myPage.getInjectedUrl().toString(). In other words,
if we inject a URL with a trailing slash, there will be quite a lot of test
Trailing space at the end is not meaningless unfortunately. It is being
used by the container to find proper context. Here's one of the best
explanations I found so far .
Jetty enforces trailing slashes for Servlets deployed in the container. If
you hit a Servlet without a slash (
http://localhost:8280/client-secret-jwt-secure-portal for example), you
will be redirected (with HTTP 302) to a version that has it (
http://localhost:8280/client-secret-jwt-secure-portal/). This of course
breaks some of the tests in our testsuite (since the Resteasy HTTP Engine
doesn't follow redirects by default). It is also worth to mention, that
Arquillian also adds trailing slash at the end of the Servlet context .
So by default, it injects all URLs with trailing space.
My take on this is that we should not trim the trailing slash. Moreover, we
should never manipulate a raw string representation of a URL. What we
should do instead is to use URI#resolve method if we need to query
sub-contexts. Using URI instead of URL is extremely important when it comes
to equality (if you're interested more in this, please read ).
If you agree with me, I'll go ahead and create a JIRA for it.
More information about the keycloak-dev