Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defaultrefererfix #976

Merged
merged 9 commits into from
Apr 23, 2015
Merged

Defaultrefererfix #976

merged 9 commits into from
Apr 23, 2015

Conversation

valeriolopes
Copy link
Collaborator

Relaxing getReferer() visibility to 'protected' in order to unit test it
directly; replacing several test methods for referer check with
redirect/forward with a single method that tests the getReferer()
returned value in various situations

the url host an invalid referer was returned)
the referer host an invalid referer was returned
If the context path string was present in the referer host, the
getReferer() method returned an invalid referer
On proxied app servers is common to have the context path suppressed
from the external URL, although it is still valid within the app server
context. If the request referer path does not start with the internal
context, it should return the entire path.
directly; replacing several test methods for referer check with
redirect/forward with a single method that tests the getReferer()
returned value in various situations
@Turini
Copy link
Member

Turini commented Apr 20, 2015

that sounds nice to me, @valeriolopes! thanks for doing this.
I'll wait a few more time to get more reviews before merge it.


when(request.getHeader("Referer")).thenReturn("/vrap/anything/ok/vrap"); //relative path in the referer (not common but predicted by http spec)
when(request.getContextPath()).thenReturn("/vrap");
assertEquals("/anything/ok/vrap", refererResult.getReferer());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split this test into 4 @Test's, with the appropriate descriptions as the method name instead of the comments.

@valeriolopes
Copy link
Collaborator Author

Done as @lucascs asked, breaking down the test method into more specific tasks.

Besides, added a more safe check on the referer path, because the previous condition doesn't cover all cases:

return refererPath.startsWith(ctxPath) ? refererPath.substring(ctxPath.length()) : refererPath;

If the context path strings appears in the beggining of the url path but it is not the context path (ex: context path = /vrap; url path = /vrapanything/test), this would return anything/test, a wrong path. It's a very specific condition but it can occur.

In order to remove the context path from the url, it should appear in the beggining of the url path in one of those conditions: 1) being followed by a '/' and anything (or nothing) after it; 2) be equal to the url path (nothing should come after it).In this case, we return what's after the context path. This covers all cases:

Context path = /ctx
http://vraptor.com/ctx - return ""
http://vraptor.com/ctx/ - return "/"
http://vraptor.com/ctxtest/tef/ctx/test/ctx - return /ctxtest/tef/ctx/test/ctx
http://vraptor.com/ctx/test/ctx/ok - return /test/ctx/ok

I thought using a regexp to test this - ^/ctx(/.*|$) would do it - but thought again because I would have to compile the regex every time the referer was requested since the context path is not a fixed value (well.. it's a fixed value after the web app is started but I would have to capture that info somewhere and save it to compile it once.. maybe too much work). Ended up staying with plain old string and its fast char array indexing.


@Test
public void whenRefererIsARelativePathRefererShouldBeReturnedCorrectly() throws Exception {
when(request.getHeader("Referer")).thenReturn("/vrap/anything/ok/vrap"); //relative path in the referer (not common but predicted by http spec)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can drop the comments on all tests,

then 🚢

@valeriolopes
Copy link
Collaborator Author

Done

Turini added a commit that referenced this pull request Apr 23, 2015
fixing DefaultRefererResult when context path appears in the URL host
@Turini Turini merged commit 2f1b8f4 into caelum:master Apr 23, 2015
@Turini
Copy link
Member

Turini commented Apr 23, 2015

thanks!

@valeriolopes
Copy link
Collaborator Author

YW -- It was an honor giving this tiny contribution to vraptor. If you guys need more hands to help I'll be around (maybe fixing bug reports or whatever else). Is there any technical documentation of the framework or the code is the only (and prob the best) document?

@Turini
Copy link
Member

Turini commented Apr 23, 2015

that was a nice contribution... not tiny at all 👍

If you guys need more hands to help
I'll be around (maybe fixing bug reports or whatever else)

great! if you want to, you can check our issues

Is there any technical documentation of the framework
or the code is the only (and prob the best) document?

take a look on http://www.vraptor.org/en/docs/one-minute-guide/

@valeriolopes
Copy link
Collaborator Author

From the framework user perspective I have a good knowledge; I meant something about its internals (how it is organized from inside), but since the code is well structured with some study one should learn about it.

BTW, how do you guys organize these issues?You just pick up one issue, branch it, do whatever you want and then submit it for review?

@Turini
Copy link
Member

Turini commented Apr 24, 2015

You can use our test coverage to get into the framework, it's a very effective
way to learn about a project :) About the issues, yes, anyone can choose one
issue that is not assigned, implement it in a fork and send us a PR for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants