-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test mode #70
Comments
Howdy @Papipo! This is definitely something everyone on the @ueberauth/developers team has wanted though I fear we've never come to consensus on the best way to do so. If you're interested in pursuing this feature we can use this issue to discuss the different approaches and hopefully decide on one to take. |
#69 is great. I copy a couple of feature requests I put there:
|
We should allow swapping the implementation based on the environment. We shouldn't mock or come out with an implementation that leaks abstraction. In my opinion, the issue is that Ueberauth needs to embrace an adapter pattern. |
Can we re-open this since it isn't actually fixed? (as far as I can tell) |
@axelson done |
If it helps anyone, I used this idea to test various paths. It is not generally applicable to every situation, but it is easily adaptable (pun intended 😄): # in test/support/test_ueberauth_strategy.ex
defmodule Experiment.TestUeberauthStrategy do
alias Ueberauth.Auth
alias Ueberauth.Failure
use Ueberauth.Strategy,
uid_field: :id,
ignores_csrf_attack: true
def handle_request!(conn), do: aliased_strategy(conn).handle_request!(conn)
def handle_callback!(%{assigns: %{ueberauth_auth: %Auth{}}} = conn), do: conn
def handle_callback!(%{assigns: %{ueberauth_failure: %Failure{}}} = conn), do: conn
def handle_callback!(conn), do: aliased_strategy(conn).handle_callback!(conn)
defp aliased_strategy(%{private: %{ueberauth_request_options: %{options: opts}}} = conn) do
Keyword.fetch!(opts, :aliased_strategy)
end
end
# in config/test.exs
config :ueberauth, Ueberauth,
providers: [microsoft: {Experiment.TestUeberauthStrategy, [aliased_strategy: Ueberauth.Strategy.Microsoft]}]
# in some test, e.g. test/experiment_web/controllers/auth_controller_test.exs
defmodule ExperimentWeb.AuthControllerTest do
alias Ueberauth.Auth
test "uses mock", %{conn: conn} do
# request login
conn = get(conn, ~p"/auth/microsoft")
assert redirected_to(conn, 302) =~ "https://login.microsoftonline.com"
# callback from provider with successfully logged in user
conn =
conn
|> recycle()
|> assign(:ueberauth_auth, %Auth{provider: :microsoft, info: %{email: "some.email@domain.com"}})
conn =
get(conn, ~p"/auth/microsoft/callback", %{
code: UUID.generate(),
session_state: UUID.generate(),
state: UUID.generate()
})
# whatever further assertions you might need
end
end |
Hi!
I've been lost for two days trying to find a proper way of doing testing like you would do with Omniauth.
As a workaround I've set up Bypass, but I find the process clumsy and verbose, since I need to configure each Strategy host to map to different Bypass ports, etc.
So I am willing to tackle the feature but I would like some pointers about how to implement it so we can get a mergeable pull requests.
Thanks.
The text was updated successfully, but these errors were encountered: