Skip to content

Instantly share code, notes, and snippets.

@ngw

ngw/test.ex Secret

Last active June 23, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngw/4e01c1338027bf36ec41d1fc9c9bfffc to your computer and use it in GitHub Desktop.
Save ngw/4e01c1338027bf36ec41d1fc9c9bfffc to your computer and use it in GitHub Desktop.
defmodule UeberauthFitzyTest do
use ExUnit.Case
use Plug.Test
alias Plug.Session
@session_opts [
store: :cookie,
key: "foobar",
encryption_salt: "encrypted cookie salt",
signing_salt: "signing salt",
log: false,
encrypt: false
]
setup(%{path: path} = context) do
conn =
conn(:get, path)
|> Map.put(:client_id, "abcd1234")
|> Map.put(:client_secret, "abcdefghi0123456789")
|> Session.call(Session.init(@session_opts))
|> fetch_session
|> fetch_query_params
|> Ueberauth.call(Ueberauth.init([]))
[conn: conn]
end
@tag path: "/auth/fitzy"
test "handle request", %{conn: conn} do
assert conn.status == 302
assert conn.resp_body ==
"<html><body>You are being <a href=\"https://spreads.XXXXXX.net.XXXXXXX.XXXXXXX.net/oauth/authorize?client_id=appid&amp;redirect_uri=http%3A%2F%2Fwww.example.com%2Fauth%2Ffitzy%2Fcallback&amp;response_type=code&amp;scope=\">redirected</a>.</body></html>"
end
@tag path: "/auth/fitzy/callback?code=VERIFER", request: %Plug.Conn{}
test "handle callback", %{conn: %{assigns: %{ueberauth_auth: auth}}} do
IO.inspect auth
end
end
#####
1) test handle callback (UeberauthFitzyTest)
test/strategy/fitzy_test.exs:36
** (ArgumentError) raise/1 expects an alias, string or exception as the first argument, got: %OAuth2.Response{body: %{"error" => "invalid_client", "error_description" => "Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method."}, headers: [{"cache-control", "no-store"}, {"content-type", "application/json; charset=utf-8"}, {"date", "Fri, 23 Jun 2017 14:44:03 GMT"}, {"pragma", "no-cache"}, {"server", "Apache"}, {"status", "401 Unauthorized"}, {"vary", "Accept-Encoding,User-Agent"}, {"www-authenticate", "Bearer realm=\"Doorkeeper\", error=\"invalid_client\", error_description=\"Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method.\""}, {"x-content-type-options", "nosniff"}, {"x-frame-options", "SAMEORIGIN"}, {"x-request-id", "8f35732f-a3fc-400c-bb15-075a6c668fc8"}, {"x-runtime", "0.004919"}, {"x-xss-protection", "1; mode=block"}, {"content-length", "173"}, {"connection", "keep-alive"}], status_code: 401}
stacktrace:
(oauth2) lib/oauth2/client.ex:248: OAuth2.Client.get_token!/4
(ueberauth_fitzy) lib/ueberauth/strategy/fitzy/oauth.ex:38: Ueberauth.Strategy.Fitzy.OAuth.get_token!/2
(ueberauth_fitzy) lib/ueberauth/strategy/fitzy.ex:21: Ueberauth.Strategy.Fitzy.handle_callback!/1
(ueberauth) lib/ueberauth/strategy.ex:299: Ueberauth.Strategy.run_callback/2
test/strategy/fitzy_test.exs:24: UeberauthFitzyTest.__ex_unit_setup_0/1
test/strategy/fitzy_test.exs:1: UeberauthFitzyTest.__ex_unit__/2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment