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

MessageBuilderSupport should not silently pass a failing check even if isSpringInternalHeader is true #1192

Open
novarx opened this issue Jul 15, 2024 · 0 comments

Comments

@novarx
Copy link

novarx commented Jul 15, 2024

Citrus Version
4.2.1

Expected behavior

The Test should fail.

  • Either because the headers are obviously not the same
  • Or because some headers are explicitly not allowed for testing
@Test
public class OpenApiClientIT extends TestNGCitrusSpringSupport {

    private final int port = SocketUtils.findAvailableTcpPort(8080);

    @BindToRegistry
    private final HttpServer httpServer = new HttpServerBuilder()
            .port(port)
            .timeout(5000L)
            .autoStart(true)
            .defaultStatus(HttpStatus.NO_CONTENT)
            .build();

    @BindToRegistry
    private final HttpClient httpClient = new HttpClientBuilder()
            .requestUrl("http://localhost:%d".formatted(port))
            .build();

    private final OpenApiSpecification petstoreSpec = OpenApiSpecification.from(
            Resources.create("classpath:org/citrusframework/openapi/petstore/petstore-v3.json"));

    @CitrusTest
    public void getPetById() {
        variable("petId", "1001");

        when(openapi(petstoreSpec)
                .client(httpClient)
                .send("getPetById")
                .fork(true)
                .message()
                // ⏩ header is set here
                .header("correlationId", "my-correlation-id")
        );

        then(http().server(httpServer)
                .receive()
                .get("/pet/1001")
                .message()
                // TODO BUG? - cannot check correlationId
                //  see: org/citrusframework/validation/DefaultMessageHeaderValidator.java:68
                //  see: org.citrusframework.message.MessageHeaderUtils.isSpringInternalHeader
                // ⏩ this check should fail, but it does not 😱
                .header("correlationId", "NOT-my-correlation-id")
        );

        then(http().server(httpServer)
                .send()
                .response(HttpStatus.OK)
                .message()
                .body(Resources.create("classpath:org/citrusframework/openapi/petstore/pet.json"))
                .contentType("application/json"));

        then(openapi(petstoreSpec)
                .client(httpClient)
                .receive("getPetById", HttpStatus.OK));
    }
}

Actual behavior

The test does not fail.

Test case sample
See: Expected behaviour

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

No branches or pull requests

2 participants