Skip to content

Commit

Permalink
Fix failures in IAM tests (#691)
Browse files Browse the repository at this point in the history
The test is expecting an `AWSException` with code `"InvalidAction"` but
the caught exception had code 404. It appears to be because the response
body is XML but AWS didn't set the `Content-Type` header nor did it
begin the response body with a clear indicator of the content type, so
the body doesn't get properly parsed. To fix this, we can expand the set
of things we look for to determine when to parse as XML. Previously we
were only looking for `/xml` at the end of the content or `<?xml` at the
beginning of the body, but the error response has neither, so here I've
added a check for `<\w+ xmlns=` at the beginning of the body. This seems
to be the expected format of an XML response when the `<?xml` line is
absent. Documentation suggests that `<?xml` would only be absent in the
case of an `ErrorResponse` but that the `Content-Type` header would be
set to `text/xml`. Evidently not true in practice...
  • Loading branch information
ararslan authored Jul 8, 2024
1 parent 51b3b0d commit 7e92bcf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/AWSExceptions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ function AWSException(e::HTTP.StatusError, body::AbstractString)
end

# Extract API error code from XML error message...
if endswith(content_type, "/xml") || startswith(body, "<?xml")
if (
endswith(content_type, "/xml") ||
startswith(body, "<?xml") ||
startswith(body, r"<\w+ xmlns=")
)
info = parse_xml(body)
end
elseif parse(Int, HTTP.header(e.response, "Content-Length", "0")) > 0
Expand Down

0 comments on commit 7e92bcf

Please sign in to comment.