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

Test Writer : ResponseHeaders method is not able to resolve when duplicate key found in the response header #293

Closed
krishnan-techconative opened this issue Feb 12, 2024 · 4 comments

Comments

@krishnan-techconative
Copy link

I have test classes generated by TCase, which utilize the default response validator class. In these classes, two assertions responseValidator.assertBodyValid(...) and responseValidator.assertHeadersValid(...) are added. The assertHeaderValid method uses a private method to construct the Map from the response object, where it encounters issues handling duplicate keys.

private static Map<String,String> responseHeaders( Response response) {
        return
            response.getHeaders().asList().stream()
            .collect( toMap( Header::getName, Header::getValue));
}

Please find the sample response header

Vary=Origin
Vary=Access-Control-Request-Method
Vary=Access-Control-Request-Headers
Set-Cookie=JSESSIONID=A53F30B1CAEBCD5C97704EBF24173EEF; Path=/; HttpOnly
X-Content-Type-Options=nosniff
X-XSS-Protection=0
Cache-Control=no-cache, no-store, max-age=0, must-revalidate
Pragma=no-cache
Expires=0
X-Frame-Options=DENY
Content-Type=application/json
Transfer-Encoding=chunked
Date=Fri, 09 Feb 2024 14:52:23 GMT
Keep-Alive=timeout=60
Connection=keep-alive
@krishnan-techconative
Copy link
Author

@kerrykimbrough Can you please help us here?

@kerrykimbrough
Copy link
Contributor

Thanks for reporting this problem. The HTTP specification states that multiple header lines with the same field name MUST be equivalent to a single header line with a comma-separated list of values. For example:

Vary=Origin
Vary=Access-Control-Request-Method
Vary=Access-Control-Request-Headers

must be equivalent to:

Vary=Origin, Access-Control-Request-Method, Access-Control-Request-Headers

Therefore, I propose changing responseHeaders to return a Map that maps "Vary" to "Origin, Access-Control-Request-Method, Access-Control-Request-Headers". Agreed?

@kerrykimbrough
Copy link
Contributor

Correction: I propose changing responseHeaders to return a Map that maps "Vary" to "Origin,Access-Control-Request-Method,Access-Control-Request-Headers". In other words, separating multiple header values with a single comma -- no extra whitespace.

@kerrykimbrough
Copy link
Contributor

Fixed in release 4.0.5

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