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 JVM with Gradle: Authorization issue, getting response as 400 #1795

Open
muhammad-arham643 opened this issue May 6, 2024 · 1 comment
Labels
question Indicates that an issue, pull request, or discussion needs more information

Comments

@muhammad-arham643
Copy link

muhammad-arham643 commented May 6, 2024

Hi! I am new to Pact JVM and I am trying to write the test on the provider side. I am getting the error 400 as a return code instead of 200. I am using the gradle tool to test the functionality. Can someone please guide me to this issue?

I am using the correct token and the header and the content-type.

Thanks in advance.

@Provider("ABC")
@PactFolder("pacts")
public class ProviderTest {

private String token; // Declare the token variable
@BeforeEach
void before(PactVerificationContext context){
    token = "1234567"
    context.setTarget(new HttpsTestTarget("testing.ABC.", 443, "/..));
}

@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void verifyPact(PactVerificationContext context, HttpRequest request) {

    request.addHeader("Authorization", "Bearer " + token);
    context.verifyInteraction();
}

@State("my test does not exists")
void testdoesnotexists() {
    /* Set up the token as needed for this provider state */
}
}
@rholshausen
Copy link
Contributor

400 error code means your provider did not get the request it was expecting. You will need to enable debug logging to work out what the error is.

@rholshausen rholshausen added the question Indicates that an issue, pull request, or discussion needs more information label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Indicates that an issue, pull request, or discussion needs more information
Projects
None yet
Development

No branches or pull requests

2 participants