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

Pact JVM: Pact Broker token must be passed in as JVM system property #1521

Open davidvc opened 2 years ago

davidvc commented 2 years ago

In the Pact JVM documentation, it says that the system property pactbroker.auth.token can be passed in as an environment variable as well as a JVM system property.

But when we try using just an environment variable, the token is not picked up and when we talk to the broker we get a 401 unauthorized.

We have to explicitly pass it in to the maven command using -Dpactbroker.auth.token=<token>, and then it works.

davidvc commented 2 years ago

We're using version 4.2.9 of the JVM libraries from Pact:

            <dependency>
            <groupId>au.com.dius.pact.consumer</groupId>
            <artifactId>junit</artifactId>
            <version>4.2.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>au.com.dius.pact.provider</groupId>
            <artifactId>junit5</artifactId>
            <version>4.2.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>au.com.dius.pact.provider</groupId>
            <artifactId>spring</artifactId>
            <version>4.2.9</version>
            <scope>test</scope>
        </dependency>
davidvc commented 2 years ago

For example here's some output during mvn test:

21:25:28 [ERROR] Failed to fetch the root HAL document: Request to path '/' failed with response 'HTTP/1.1 401 Unauthorized' -> [Help 1]