Comments (6)
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.
from ueberauth.
@axelson done
from ueberauth.
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: "[email protected]"}})
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
from ueberauth.
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.
from ueberauth.
#69 is great. I copy a couple of feature requests I put there:
- Adding mocks at runtime.
- Forcing an authentication failure.
from ueberauth.
Can we re-open this since it isn't actually fixed? (as far as I can tell)
from ueberauth.
Related Issues (20)
- OAuth2 needs new maintainers HOT 4
- State nonce cookie should properly be signed HOT 2
- How can run Ueberauth plug directly? HOT 3
- Custom `callback_port` and `callback_scheme` not used HOT 1
- Callback URL not mounted right when router has nested paths
- Can't set strategy options at runtime HOT 2
- Line Login v2.1 update request which I've done HOT 4
- Gracefully handle unknown providers HOT 10
- callback_port config compiled into plug at compile time HOT 10
- App.Auth.AuthController.request/2 is undefined or private HOT 1
- minor: mix package versions are out of date
- New hex.pm release? HOT 1
- Incorrect callback_url when using Bandit.PhoenixAdapter
- put_session successful, but get_session failed HOT 1
- function MyAppWeb.OAuthController.request/2 is undefined or private HOT 1
- Support for nonces HOT 1
- FR: Support multiple usages of the same strategy in config HOT 13
- Incomplete docs to configure pipeline and check that user is authenticated HOT 3
- Latest release breaks existing paths HOT 6
- Latest version is retired HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ueberauth.