parroty / exvcr

HTTP request/response recording library for elixir, inspired by VCR.
MIT License
722 stars 132 forks source link

TLS 1.2 ssl doesn't work for hackney (httpoison) #105

Open joshuataylor opened 7 years ago

joshuataylor commented 7 years ago

Something like:

    data = []
    options = [ssl: [{:versions, [:'tlsv1.2']}]]
    page = HTTPoison.post("https://example.com", {:form, data}, [], options)

Results in:

  1) test Can get an auth token (foo.Test.AuthTest)
     test/auth_test.exs:5
     ** (ArgumentError) cannot convert the given list to a string.

     To be converted to a string, a list must contain only:

       * strings
       * integers representing Unicode codepoints
       * or a list containing one of these three elements

     Please check the given list or call inspect/1 to get the list representation, got:

     [versions: [:"tlsv1.2"]]

     stacktrace:
       (elixir) lib/list.ex:709: List.to_string/1
       (exvcr) lib/exvcr/adapter/hackney/converter.ex:6: ExVCR.Adapter.Hackney.Converter.do_parse_options/2
       (exvcr) lib/exvcr/adapter/hackney/converter.ex:30: ExVCR.Adapter.Hackney.Converter.request_to_string/1
       (exvcr) lib/exvcr/adapter/hackney/converter.ex:6: ExVCR.Adapter.Hackney.Converter.convert_to_string/2
       (exvcr) lib/exvcr/handler.ex:141: ExVCR.Handler.get_response_from_server/2
       (hackney) :hackney.request(:post, "https://example.com/something", [], {:form, []}, [ssl_options: [versions: [:"tlsv1.2"]]])
       (httpoison) lib/httpoison/base.ex:432: HTTPoison.Base.request/
parroty commented 7 years ago

Thanks for the report. The stringify of the option is not handled properly. The above is a trial fix, and I'll be looking some more before pushing to hex. In case if you have chance to verify (wiht the following), that would be great too.

{:exvcr, github: "parroty/exvcr", branch: "fix/issue_105", only: :test}
mpinkston commented 7 years ago

This looks pretty good to me! I'm using the proxy option as well (which was also broken), but this seems to work. The only side-effect is the way it converts charlists. eg: {:socks5, '127.0.0.1', 8157} becomes

"proxy": [
  "socks5",
  [
    49,
    50,
    55,
    46,
    48,
    46,
    48,
    46,
    49
  ],
  8157
]

but considering how lists work, that's probably unavoidable.

parroty commented 7 years ago

Thanks for the confirmation and comment. There has been issues around string(binary) and charlist, but please let me take this as separate item.