pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

How to prevent 443 port adding to url with proxy environment #710

Open valera7979 opened 6 years ago

valera7979 commented 6 years ago

Hi, I have simple provider test


@Provider("OpenApi")
@PactFolder("target/pacts")
public class OpenAPIProviderTest {
    public OpenAPIProviderTest() throws MalformedURLException {
    }

    private URL url = new URL("https://jsonplaceholder.typicode.com"); // open API

    @TestTarget
    public final Target target = new HttpTarget(url);

    @State({"OpenApiTest"})
    public void getPacts() {
        System.out.println("OpenApiTest pacts accepted.");
    }`

It`s passed when I test it in environment where is no proxy. 
but where is proxy I get next error

java.lang.AssertionError: 
0 - Connect to jsonplaceholder.typicode.com:443 [jsonplaceholder.typicode.com/104.18.55.183, jsonplaceholder.typicode.com/104.18.54.183] failed: Connection timed out: connect

Full path is https://jsonplaceholder.typicode.com/posts/5
Why the port is added and how to make it not added, or how to run tests with proxy environment?
Thanks.
uglyog commented 6 years ago

The port is the default one for HTTPS. The issue is that the HttpTarget does not work with HTTP proxies, it is designed to connect to locally running services.

One way to fix it is to create a new target that supports using proxies. See https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-junit#custom-test-target

Hidayath-S commented 5 years ago

i am new to PACT, and facing the above problem. Any resolution?

Hidayath-S commented 5 years ago

Hi, I have simple provider test

@Provider("OpenApi")
@PactFolder("target/pacts")
public class OpenAPIProviderTest {
  public OpenAPIProviderTest() throws MalformedURLException {
  }

  private URL url = new URL("https://jsonplaceholder.typicode.com"); // open API

  @TestTarget
  public final Target target = new HttpTarget(url);

  @State({"OpenApiTest"})
  public void getPacts() {
      System.out.println("OpenApiTest pacts accepted.");
  }`

It`s passed when I test it in environment where is no proxy. 
but where is proxy I get next error

java.lang.AssertionError: 
0 - Connect to jsonplaceholder.typicode.com:443 [jsonplaceholder.typicode.com/104.18.55.183, jsonplaceholder.typicode.com/104.18.54.183] failed: Connection timed out: connect

Full path is https://jsonplaceholder.typicode.com/posts/5
Why the port is added and how to make it not added, or how to run tests with proxy environment?
Thanks.

HI,

Did you get any resolution for this problem?.

valera7979 commented 5 years ago

No