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

Pact Broker URL defaults to HTTP despite being specified as HTTPS #1853

Open
LinghaoYu opened this issue Jan 31, 2025 · 1 comment
Open

Pact Broker URL defaults to HTTP despite being specified as HTTPS #1853

LinghaoYu opened this issue Jan 31, 2025 · 1 comment

Comments

@LinghaoYu
Copy link

Hello, I am using version 4.1.21 to verify contracts. maven dependency:

<dependency>
	<groupId>au.com.dius.pact.provider</groupId>
	<artifactId>junit5</artifactId>
	<version>4.1.21 </version>
</dependency>

java code snippet:

        @TestTemplate
	@ExtendWith(PactVerificationInvocationContextProvider.class)
	void pactVerificationTestTemplate(final Pact<?> pact, final Interaction interaction, final HttpRequest request,
			final PactVerificationContext context) throws URISyntaxException {
		LOGGER.info("testTemplate called: " + pact.getProvider().getName() + ", " + interaction);
		request.addHeader("X-ContractTest", "true");
		URIBuilder newBuilder = new URIBuilder(request.getRequestLine().getUri());
		List<NameValuePair> params = newBuilder.getQueryParams();
		Map<String, String> mappedParams = params.stream()
				.collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
		assertThat("crn must be provided as query parameter", mappedParams.keySet(), hasItem("crn"));
		context.verifyInteraction();
	}

I specified url within PactBroker annotation @PactBroker(url = "https://pact-broker.apps.mdmdev-ocp-saas-cr1.cp.fyre.ibm.com") or @PactBroker(host = "pact-broker.apps.mdmdev-ocp-saas-cr1.cp.fyre.ibm.com", scheme="https"), but the endpoint to fetch contracts becomes http:

[main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider - provideTestTemplateInvocationContexts called
[main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider - Verifying pacts for provider 'mdm-job-v1' and consumer 'null'
[main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider - Pact sources on test class:
 @au.com.dius.pact.provider.junitsupport.loader.PactSource(au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader.class)
[main] DEBUG au.com.dius.pact.provider.ProviderUtils - Pact source does not have a constructor with one argument of type Class
[main] DEBUG au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader - Loading pacts from pact broker for provider mdm-job-v1 and consumer version selectors []
[main] DEBUG au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader - Authentication: None
[main] DEBUG au.com.dius.pact.core.pactbroker.HalClient - Fetching: /
[main] DEBUG au.com.dius.pact.core.pactbroker.PactBrokerClient - Fetching pacts using the pactsForVerification endpoint
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 17.399 s <<< FAILURE! - in com.ibm.entity.analytics.job.pact.ContractVerificationTest
[ERROR] com.ibm.entity.analytics.job.pact.ContractVerificationTest.pactVerificationTestTemplate(Pact,Interaction,HttpRequest,PactVerificationContext)  Time elapsed: 17.397 s  <<< ERROR!
au.com.dius.pact.core.pactbroker.RequestFailedException: Request to path 'http://pact-broker.apps.mdmdev-ocp-saas-cr1.cp.fyre.ibm.com/pacts/provider/mdm-job-v1/for-verification' failed with response 'HTTP/1.0 503 Service Unavailable'
	at au.com.dius.pact.core.pactbroker.HalClient.handleHalResponse(HalClient.kt:304)
	at au.com.dius.pact.core.pactbroker.HalClient.access$handleHalResponse(HalClient.kt:140)
	at au.com.dius.pact.core.pactbroker.HalClient$postJson$3.invoke(HalClient.kt:476)
	at au.com.dius.pact.core.pactbroker.HalClient$postJson$3.invoke(HalClient.kt:140)
	at au.com.dius.pact.core.support.KotlinLanguageSupportKt.handleWith(KotlinLanguageSupport.kt:38)
	at au.com.dius.pact.core.pactbroker.HalClient.postJson(HalClient.kt:474)
	at au.com.dius.pact.core.pactbroker.PactBrokerClient$fetchPactsUsingNewEndpoint$2.invoke(PactBrokerClient.kt:291)
	at au.com.dius.pact.core.pactbroker.PactBrokerClient$fetchPactsUsingNewEndpoint$2.invoke(PactBrokerClient.kt:173)
	at au.com.dius.pact.core.support.KotlinLanguageSupportKt.handleWith(KotlinLanguageSupport.kt:38)
	at au.com.dius.pact.core.pactbroker.PactBrokerClient.fetchPactsUsingNewEndpoint(PactBrokerClient.kt:290)
	at au.com.dius.pact.core.pactbroker.PactBrokerClient.fetchConsumersWithSelectors(PactBrokerClient.kt:249)
	at au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader.loadPactsForProvider(PactBrokerLoader.kt:219)
	at au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader.load(PactBrokerLoader.kt:117)
	at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider$resolvePactSources$$inlined$flatMap$lambda$1.invoke(PactJUnit5VerificationProvider.kt:80)
	at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider$resolvePactSources$$inlined$flatMap$lambda$1.invoke(PactJUnit5VerificationProvider.kt:37)
	at au.com.dius.pact.core.support.KotlinLanguageSupportKt.handleWith(KotlinLanguageSupport.kt:38)
	at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.resolvePactSources(PactJUnit5VerificationProvider.kt:80)
	at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.provideTestTemplateInvocationContexts(PactJUnit5VerificationProvider.kt:41)

Also tried passing-Dpactbroker.url=https://pact-broker.apps.mdmdev-ocp-saas-cr1.cp.fyre.ibm.com or -Dpactbroker.host=pact-broker.apps.mdmdev-ocp-saas-cr1.cp.fyre.ibm.com -Dpactbroker.scheme=https as maven properties, same result. Could @uglyog please help?

@YOU54F
Copy link
Member

YOU54F commented Feb 4, 2025

it fetches the root url, but fails to follow the relation.

What do the links show in the hal browser? are they http?

[main] DEBUG au.com.dius.pact.core.pactbroker.HalClient - Fetching: /
[main] DEBUG au.com.dius.pact.core.pactbroker.PactBrokerClient - Fetching pacts using the pactsForVerification endpoint

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

No branches or pull requests

2 participants