trenpixster / addict

User management lib for Phoenix Framework
MIT License
645 stars 99 forks source link

Backdoor authentication for testing suites? #45

Closed jontonsoup closed 8 years ago

jontonsoup commented 9 years ago

Is there a way to have backdoor auth for a testing suite?

trenpixster commented 9 years ago

Not sure I understood correctly. Do you mean having a way to log the user in automatically?

jontonsoup commented 9 years ago

@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.

trenpixster commented 9 years ago

I believe Addict.SessionInteractor.login/2would do the trick. Something like Addict.SessionInteractor.login({:ok, user}, conn).

jontonsoup commented 9 years ago

@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)?

trenpixster commented 9 years ago

One way to go is maybe to try using the same strategy that is used here.

jontonsoup commented 9 years ago

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}
jontonsoup commented 9 years ago

@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?

trenpixster commented 8 years ago

@jontonsoup sorry for not replying sooner. Can you supply the code you're using for the test?

jontonsoup commented 8 years ago

@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 :).

trenpixster commented 8 years ago

Thanks @jontonsoup :+1: