Introduce support for 3rd-party auth (OAuth2 & LDAP)
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
54
test/web/controllers/auth_controller_test.exs
Normal file
54
test/web/controllers/auth_controller_test.exs
Normal file
@@ -0,0 +1,54 @@
|
||||
defmodule Mobilizon.Web.AuthControllerTest do
|
||||
use Mobilizon.Web.ConnCase
|
||||
alias Mobilizon.Service.Auth.Authenticator
|
||||
alias Mobilizon.Users.User
|
||||
|
||||
@email "someone@somewhere.tld"
|
||||
|
||||
test "login and registration",
|
||||
%{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> assign(:ueberauth_auth, %Ueberauth.Auth{
|
||||
strategy: Ueberauth.Strategy.Twitter,
|
||||
extra: %Ueberauth.Auth.Extra{raw_info: %{user: %{"email" => @email}}}
|
||||
})
|
||||
|> get("/auth/twitter/callback")
|
||||
|
||||
assert html_response(conn, 200) =~ "auth-access-token"
|
||||
|
||||
assert %User{confirmed_at: confirmed_at, email: @email} = Authenticator.fetch_user(@email)
|
||||
|
||||
refute is_nil(confirmed_at)
|
||||
end
|
||||
|
||||
test "on bad provider error", %{
|
||||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> assign(:ueberauth_failure, %{errors: [%{message: "Some error"}]})
|
||||
|> get("/auth/nothing")
|
||||
|
||||
assert "/login?code=Login Provider not found&provider=nothing" =
|
||||
redirection = redirected_to(conn, 302)
|
||||
|
||||
conn = get(recycle(conn), redirection)
|
||||
assert html_response(conn, 200)
|
||||
end
|
||||
|
||||
test "on authentication error", %{
|
||||
conn: conn
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> assign(:ueberauth_failure, %{errors: [%{message: "Some error"}]})
|
||||
|> get("/auth/twitter/callback")
|
||||
|
||||
assert "/login?code=Error with Login Provider&provider=twitter" =
|
||||
redirection = redirected_to(conn, 302)
|
||||
|
||||
conn = get(recycle(conn), redirection)
|
||||
assert html_response(conn, 200)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user