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

Added a test to answer responses with content or to redirect. #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ganskef
Copy link
Collaborator

@ganskef ganskef commented Jul 29, 2015

It's a simple trick to add a web interface to a proxy application.

@jekh Do you think, the web driver based test can run within Travis-CI?

It's a simple trick to add a web interface to a proxy application.
@jekh
Copy link
Collaborator

jekh commented Jul 31, 2015

For some reason I didn't get a notification that this PR had been opened. Sorry for the delay. (I assume this is the test for the client hang you mentioned in #222?)

Do you think, the web driver based test can run within Travis-CI?

The answer is yes, Selenium tests technically can run in Travis CI, but it's often not a good idea. Travis CI containers have Firefox, and it's also possible to use PhantomJS (and probably others). But I wouldn't recommend it, because Selenium tests often break due to changes in the Selenium driver/FF version/any number of other issues that are beyond our control. For unit tests, I recommend seeing if there's a way to test the functionality without a browser.

For example, if you're trying to verify that the proxy responds with a 302, you could use Apache HTTP Client (as in other unit tests), and disable the "follow redirects" option on the request. (I can provide an example of this if you like.) Then you will be able to verify that the proxy returned a 302, and that the Location header matched the value set in the filter.

return new HttpFiltersAdapter(originalRequest) {
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
HttpResponse answer = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.FOUND);
Copy link
Collaborator

Choose a reason for hiding this comment

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

One thing to note here is that this method will return a new HTTP response when the client sends the HttpRequest, then return a new HttpResponse when the client sends the first HttpContent (if the request is a POST, for example). If the request is a GET, I believe Netty still sends an EmptyLastHttpContent through the pipeline after the HttpRequest, so this filter method would still return a duplicate HttpResponse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test is very simplified to show the trick. I use it with an UI in
my proxy. Three lists, some error/message pages and some actions which
needs to load modified content after redirect. It's like block/unblock,
delete/undelete, empty trash, rebuild index, such things... My use case
is a caching proxy for offline use (without an internet connection). The
search form uses the GET method. I haven't tried a POST request.

Am 31.07.2015 um 17:19 schrieb Jason Hoetger:

In src/test/java/org/littleshoot/proxy/ProxyWebUiTest.java
#224 (comment):

+import org.junit.Test;
+import org.littleshoot.proxy.impl.DefaultHttpProxyServer;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+public class ProxyWebUiTest {
+

  • private static final String REDIRECT_PATH = "/";
  • private HttpFiltersAdapter answerRedirectFilter(HttpRequest originalRequest) {
  •    return new HttpFiltersAdapter(originalRequest) {
    
  •        @Override
    
  •        public HttpResponse clientToProxyRequest(HttpObject httpObject) {
    
  •            HttpResponse answer = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.FOUND);
    

One thing to note here is that this method will return a new HTTP
response when the client sends the HttpRequest, then return a new
HttpResponse when the client sends the first HttpContent (if the request
is a POST, for example). If the request is a GET, I believe Netty still
sends an EmptyLastHttpContent through the pipeline after the
HttpRequest, so this filter method would still return a duplicate
HttpResponse.


Reply to this email directly or view it on GitHub
https://github.com/adamfisk/LittleProxy/pull/224/files#r35983395.

@ganskef
Copy link
Collaborator Author

ganskef commented Jul 31, 2015

Don't worry with the delay. But, may I am on your spam filters list? :-/

Please add an independent client somewhere. I've found inherited base
classes only. There's more than once implementation in. Some of them was
failing with my https requirements. I've tried Netty based and then
URLConnection to get success. I spend a lot of time with this. I could
add a test-jar dependency to LP simply, but I have removed it, since it
had no value for me. Please have a look at
https://github.com/ganskef/LittleProxy-mitm/tree/netty_proxy_client#issue-netty-client-via-proxy-fails-with-littleproxy-if-mitm-enabled
sometime. This branch should describe the misery effects I've seen.

I'll try to reproduce the blocking behavior with this client. Then I'm
happy to replace Selenium.

Am 31.07.2015 um 17:15 schrieb Jason Hoetger:

For some reason I didn't get a notification that this PR had been
opened. Sorry for the delay. (I assume this is the test for the client
hang you mentioned in #222
#222?)

Do you think, the web driver based test can run within Travis-CI?

The answer is yes, Selenium tests technically /can/ run in Travis CI,
but it's often not a good idea. Travis CI containers have Firefox, and
it's also possible to use PhantomJS (and probably others). But I
wouldn't recommend it, because Selenium tests often break due to changes
in the Selenium driver/FF version/any number of other issues that are
beyond our control. For unit tests, I recommend seeing if there's a way
to test the functionality without a browser.

For example, if you're trying to verify that the proxy responds with a
302, you could use Apache HTTP Client (as in other unit tests), and
disable the "follow redirects" option on the request. (I can provide an
example of this if you like.) Then you will be able to verify that the
proxy returned a 302, and that the Location header matched the value set
in the filter.


Reply to this email directly or view it on GitHub
#224 (comment).

@jekh
Copy link
Collaborator

jekh commented Aug 2, 2015

Please add an independent client somewhere. I've found inherited base classes only. There's more than once implementation in.

@ganskef - I'm not quite sure what you're requesting here. Is there a specific test or scenario that is failing?

@ganskef
Copy link
Collaborator Author

ganskef commented Aug 3, 2015

@jekh LittleProxy-mitm (#174) was exciting PR after using LittleProxy as an caching proxy for offline use for years. Now, it works for me with HTTPS too, great (depends on #230), in every day use. But, it was hard for me to create automated tests for MITM'ing. LittleProxy tests wasn't usable for me, since I have to check special cases. Now I have three interfaces for client, server and proxy and implementations to composite in my tests. One unresolved problem is described in the README.md of this branch.

@ganskef
Copy link
Collaborator Author

ganskef commented Mar 16, 2016

This test is an example how to implement an UI like it's used in https://ganskef.github.io/MoCuishle/.

Just try it out. Any concerns with it?

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

Successfully merging this pull request may close these issues.

2 participants