-
Notifications
You must be signed in to change notification settings - Fork 780
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
base: master
Are you sure you want to change the base?
Conversation
It's a simple trick to add a web interface to a proxy application.
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?)
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 I'll try to reproduce the blocking behavior with this client. Then I'm Am 31.07.2015 um 17:15 schrieb Jason Hoetger:
|
@ganskef - I'm not quite sure what you're requesting here. Is there a specific test or scenario that is failing? |
@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. |
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? |
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?