Skip to content

Commit

Permalink
Additional test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislaskey committed Oct 5, 2017
1 parent e46dd8d commit fa3c6a0
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions test/oauth2/client_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ defmodule OAuth2.ClientTest do
assert %Client{} = Client.get_token!(client, [code: "code1234"], [{"accept", "application/json"}])
end

test "get_token, get_token! when `:token_method` is `:get`", %{client: client, server: server} do
client = %{client | token_method: :get}

bypass server, "GET", "/oauth/token", fn conn ->
refute conn.query_string == ""
assert conn.query_params["code"] == "code1234"
assert conn.query_params["redirect_uri"]
send_resp(conn, 200, ~s({"access_token":"test1234","token_type":"bearer"}))
end

assert {:ok, %Client{token: token}} = Client.get_token(client, code: "code1234")
assert token.access_token == "test1234"
assert %Client{token: token} = Client.get_token!(client, code: "code1234")
assert token.access_token == "test1234"
end

test "get_token, get_token! when response error", %{client: client, server: server} do
code = [code: "code1234"]
headers = [{"accept", "application/json"}]
Expand All @@ -62,22 +78,6 @@ defmodule OAuth2.ClientTest do
end
end

test "get_token, get_token! when `:token_method` is `:get`", %{client: client, server: server} do
client = %{client | token_method: :get}

bypass server, "GET", "/oauth/token", fn conn ->
refute conn.query_string == ""
assert conn.query_params["code"] == "code1234"
assert conn.query_params["redirect_uri"]
send_resp(conn, 200, ~s({"access_token":"test1234","token_type":"bearer"}))
end

assert {:ok, %Client{token: token}} = Client.get_token(client, code: "code1234")
assert token.access_token == "test1234"
assert %Client{token: token} = Client.get_token!(client, code: "code1234")
assert token.access_token == "test1234"
end

test "refresh_token and refresh_token! with a POST", %{server: server, client_with_token: client} do
bypass server, "POST", "/oauth/token", fn conn ->
assert get_req_header(conn, "authorization") == []
Expand Down Expand Up @@ -143,6 +143,14 @@ defmodule OAuth2.ClientTest do
assert {"content-type", "application/xml"} = List.keyfind(client.headers, "content-type", 0)
end

test "basic_auth", %{client: client} do
%OAuth2.Client{client_id: id, client_secret: secret} = client
client = basic_auth(client)

assert {"authorization", value} = List.keyfind(client.headers, "authorization", 0)
assert value == "Basic " <> Base.encode64(id <> ":" <> secret)
end

## GET

test "GET", %{server: server, client_with_token: client} do
Expand Down

0 comments on commit fa3c6a0

Please sign in to comment.