Closed jontonsoup closed 8 years ago
Not sure I understood correctly. Do you mean having a way to log the user in automatically?
@trestrantham If I'm writing a feature test (using the library https://github.com/HashNuke/hound, for example) that requires a user, I'd love to be able to write something like:
log_in(user)
and have addict create a session for me.
I believe Addict.SessionInteractor.login/2
would do the trick. Something like Addict.SessionInteractor.login({:ok, user}, conn)
.
@trenpixster how would I use this if I don't have access to the conn (Maybe my tests do have access, but it doesn't seem so)?
One way to go is maybe to try using the same strategy that is used here.
Correction -- I do have a conn, but I think its misconfigured. I'll post more after I investigate.
%Plug.Conn{adapter: {Plug.Adapters.Test.Conn, :...}, assigns: %{},
before_send: [], body_params: %Plug.Conn.Unfetched{aspect: :body_params},
cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false,
host: "www.example.com", method: "GET", owner: #PID<0.335.0>,
params: %Plug.Conn.Unfetched{aspect: :params}, path_info: [],
peer: {{127, 0, 0, 1}, 111317}, port: 80,
private: %{phoenix_recycled: true, plug_skip_csrf_protection: true},
query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: "",
remote_ip: {127, 0, 0, 1},
req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: [],
resp_body: nil, resp_cookies: %{},
resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}],
scheme: :http, script_name: [], secret_key_base: nil, state: :unset,
status: nil}
@trenpixster It seems like https://github.com/phoenixframework/phoenix/blob/master/lib/phoenix/test/conn_test.ex conn doesn't work properly with the addict library. Do you have any insight?
@jontonsoup sorry for not replying sooner. Can you supply the code you're using for the test?
@trenpixster apologies -- I've moved off the project and don't have the code anymore. I've been told that the elixir way is to not backdoor the auth -- this is a holdover of bad performance from rubyland :).
Thanks @jontonsoup :+1:
Is there a way to have backdoor auth for a testing suite?