elixir-wallaby / wallaby

Concurrent browser tests for your Elixir web apps.
https://twitter.com/elixir_wallaby
MIT License
1.65k stars 197 forks source link

Authentication cookie-session setting? #268

Closed GeorgeKaraszi closed 7 years ago

GeorgeKaraszi commented 7 years ago

Hello,

I'm in the process of learning elixir, phoenix, and wallaby for feature testing. But there is one consistent issue that I cannot find any answers to.

Its setting a session variable to login or to keep a user logged in.

Right now I have UeberAuth Github as my authentication package.

The way that I can ensure the user is still logged in, is that I set a session as

...
conn
|> put_session(:user_id, user.id)
|> ...

Later this is resolved throughout the application to create the current user.

Since most of my application is behind lock and key, having the ability to set this session key on the connection would be most ideal.

So how can I set my cookie-session key, so that my application can retrieve it later conn |> get_session(:user_id) |> ... ?

PragTob commented 7 years ago

Hey you can use set_cookie/3 to set a cookie. Alternatively, you can also provide a specific controller end point that just exists in the test and development environment that logs you in as whoever you want without a password check. I use that in one of my apps.

The Wallaby session is different from the connection/session you have in Phoenix itself.