swagger-test-templates
swagger-test-templates copied to clipboard
Support for JSON api which use json-vulnerability protrection
One for the list: I have endpoints that use JSON-vulnerability protection. That means it adds )]}, before the start of the response-json, making it invalid. (this protection is widely used, among others, angular supports parsing these responses).
When encountered with this response node doesn't view this as JSON, but just returnes the string. This might actually be the behaviour noticed in #94 :-)
I did not find a way to solve this with request-options, so we probably would need to parse the string. (if anyone knows of a way to solve this with request: plz comment)
I see to other ways to solve this:
- add a config options: useJSONvulnerability (or something shorter ;-)) and then do this in the response-handler:
function(error, res, body) {
if (error) return done(error);
body = JSON.parse(body.substring(5));
// test your stuff
}
- Assume what's reasonable: If using JSON-request, simply check if
typeof body === 'string'
and then do the above.
Please share your thoughts on this, I will do this right after test-refactoring