mardi 15 novembre 2016

Headers disappear in integration test on REST service

I have an integration test in my Grails 3.2.2 application that is supposed to check that CORS support is operational. When I start the application and use something like Paw or Postman to do a request, the breakpoint I have set in CorsFilter shows that my headers are set properly. But when I do the same request from an integration test using RestBuilder with the following code:

void "Test request http OPTIONS"() {
    given: "JSON content request"

    when: "OPTIONS are requested"
    def rest = new RestBuilder()
    def optionsUrl = url(path)
    def resp = rest.options(optionsUrl) {
        header 'Origin', 'http://localhost:4200'
        header 'Access-Control-Request-Method', 'GET'
    }

    then: "they are returned"
    resp.status == HttpStatus.SC_OK
    !resp.json
}

The breakpoint in CorsFilter shows that both headers are null:

enter image description here

And the weird thing is that when I put a breakpoint in RestTemplate, right before the request is executed, the headers are there:

enter image description here

I don't get how those headers can disappear. Any idea?

Aucun commentaire:

Enregistrer un commentaire