ueberauth_openstreetmap/test/strategy/twitter/oauth_test.exs
Jeff Browning 97435e8643 Improve OAuth error handling (#10)
* Fixes a crash on network error in access_token!/2 and request_token!/2
* Fixes a crash when an API request results in a non-200 status
2016-10-27 09:35:12 -06:00

37 lines
1.1 KiB
Elixir

defmodule Ueberauth.Strategy.Twitter.OAuthTest do
use ExUnit.Case, async: true
alias Ueberauth.Strategy.Twitter.OAuth
setup do
Application.put_env :ueberauth, OAuth,
consumer_key: "consumer_key",
consumer_secret: "consumer_secret"
:ok
end
test "access_token!/2: raises an appropriate error on auth failure" do
assert_raise RuntimeError, ~r/401/i, fn ->
OAuth.access_token! {"badtoken", "badsecret"}, "badverifier"
end
end
test "access_token!/2 raises an appropriate error on network failure" do
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
OAuth.access_token! {"token", "secret"}, "verifier", site: "https://bogusapi.twitter.com"
end
end
test "request_token!/2: raises an appropriate error on auth failure" do
assert_raise RuntimeError, ~r/401/i, fn ->
OAuth.request_token! [], redirect_uri: "some/uri"
end
end
test "request_token!/2: raises an appropriate error on network failure" do
assert_raise RuntimeError, ~r/nxdomain/i, fn ->
OAuth.request_token! [], site: "https://bogusapi.twitter.com", redirect_uri: "some/uri"
end
end
end