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

Karate as Proxy Server? #640

Closed
nycjoker opened this issue Jan 7, 2019 · 16 comments
Closed

Karate as Proxy Server? #640

nycjoker opened this issue Jan 7, 2019 · 16 comments
Labels

Comments

@nycjoker
Copy link

nycjoker commented Jan 7, 2019

I have an application that consumes 3rd party services? Is it possible to utilize Karate as a true HTTP proxy server such that request to a 3rd party service are intercepted and my mocks are returned in the response? I would like a seamless way to enable and disable mocking.

@ptrthomas
Copy link
Member

yes, look at the last row in this table: https://github.com/intuit/karate/tree/master/karate-netty#consumer-provider-example

the limitation currently is that it does not support HTTPS. typically not an issue since you have control over your environment (and config / property files). so to enable and disable, just set a system HTTP proxy that points to your karate instance

@nycjoker
Copy link
Author

nycjoker commented Jan 8, 2019

That worked, thank you! When you say it does not support HTTPS, what exactly do you mean?

I tried to proxy to an https endpoint and was unsuccessful. I did set ssl to true in the feature file but the request was forwarded on HTTP, not HTTPS.

@ptrthomas
Copy link
Member

@nycjoker that you can't "unpack" HTTPS in the feature file.

you should be able to forward to HTTPS - keep in mind that it is not just the ssl = true that matters, it is the full URL, so if you write some logic to use https://blah it should work

@nycjoker
Copy link
Author

nycjoker commented Jan 9, 2019

@ptrthomas I'm trying to have Karate Proxy Server act as a pass-through for HTTPS URLs that are not mocked. However, when I use karate.proceed() it does not forward to the incoming HTTPS URL. Is this what you mean by "unpack"?

Example
When I curl to https://www.google.com through the Karate Proxy with the attempt to have Karate forward the request, the following error is present:

09:03:35.160 [nioEventLoopGroup-3-1] DEBUG com.intuit.karate - handling method: CONNECT, uri: www.google.com:443
09:03:36.739 [nioEventLoopGroup-3-1] ERROR com.intuit.karate - org.apache.http.NoHttpResponseException: www.google.com:443 failed to respond, http call failed after 62 milliseconds for URL: http://www.google.com:443

@ptrthomas
Copy link
Member

@nycjoker yes, we haven't implemented handling of CONNECT as an HTTPS proxy. so HTTP works and then you can proceed() to anything. proceed() takes the incoming URL by default - but you can override it e.g. proceed('https://someurl.com')

@nycjoker
Copy link
Author

nycjoker commented Jan 9, 2019

@ptrthomas thanks for the quick reply. Is support planned on the roadmap?

@ptrthomas
Copy link
Member

@nycjoker we really want to do this, just that is a little complex ! take a look at https://github.com/adamfisk/LittleProxy

@nycjoker
Copy link
Author

nycjoker commented Jan 9, 2019

@ptrthomas LittleProxy looks great. Would be awesome for Karate to have this ability.

@nycjoker
Copy link
Author

@ptrthomas Been working with mock server as an HTTP PROXY a bit more. I've encountered several HTTPS endpoints at my company that need to be mocked. Unfortunately, HTTP endpoints are unavailable.

What is your recommendation in mocking these HTTPS endpoints? Setup LittleProxy to handle HTTPS endpoints by intercepting them and then forward on to Karate mock server via HTTP?

@ptrthomas
Copy link
Member

yes LittleProxy. but I would first explore if I can re-wire the "callers" to use HTTP, and then Karate can intercept and forward on to HTTPS. typically in pre-prod environments, you would have this level of control

@nycjoker
Copy link
Author

@ptrthomas thanks for the feedback.

@ptrthomas
Copy link
Member

@nycjoker I've had some success implementing an HTTPS proxy. are you interested in joining the slack channel and discuss more / do some early testing - please send an e-mail to ptrthomas at gmail dot com

@prernad0903
Copy link

Hi,

As suggested, i have been trying to intercept the 3rd party APIs being consumed in my spring boot application, using karate as a proxy server, and return mock responses, but it is still executing the actual API and not the mock.
Attached files for reference.
Please advise what is the issue here.

Thanks
ThirdPartyMock.zip

@ptrthomas
Copy link
Member

@prernad0903 this is of no use. see if this answer helps: https://stackoverflow.com/a/61414022/143475 else follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

@prernad0903
Copy link

@ptrthomas Thank you! This helps..

@ptrthomas
Copy link
Member

an update HTTPS is not yet possible because we need a change in the underlying Armeria server we use. details here: https://stackoverflow.com/q/64755992/143475

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

No branches or pull requests

3 participants