1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Add socket authentication tests

This commit is contained in:
Daniel Barber 2018-08-15 14:58:40 -04:00
parent 95b565231a
commit b500ac5068
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
2 changed files with 21 additions and 0 deletions

View File

@ -29,6 +29,7 @@ defmodule ChessWeb.UserSocket do
:error
end
end
def connect(%{}, socket), do: :error
# Socket id's are topics that allow you to identify all sockets for a given user:
#

View File

@ -0,0 +1,20 @@
defmodule ChessWeb.UserSocketTest do
use ChessWeb.ChannelCase, async: true
alias ChessWeb.UserSocket
test "authenticate with valid token" do
token = Phoenix.Token.sign(@endpoint, "game socket", 42)
assert {:ok, socket} = connect(UserSocket, %{"token" => token})
assert socket.assigns.current_user_id == 42
end
test "cannot authenticate with invalid token" do
assert :error = connect(UserSocket, %{"token" => "invalid-token"})
end
test "cannot authenticate with no token" do
assert :error = connect(UserSocket, %{})
end
end