Test that server will disconnect websocket upon token revocation
This commit is contained in:
parent
eb42e90c4f
commit
3522852c61
@ -91,7 +91,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||||||
|
|
||||||
{:ok, token} = OAuth.Token.exchange_token(app, auth)
|
{:ok, token} = OAuth.Token.exchange_token(app, auth)
|
||||||
|
|
||||||
%{user: user, token: token}
|
%{app: app, user: user, token: token}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "accepts valid tokens", state do
|
test "accepts valid tokens", state do
|
||||||
@ -126,5 +126,21 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||||||
Process.sleep(30)
|
Process.sleep(30)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "disconnect when token is revoked", %{app: app, user: user, token: token} do
|
||||||
|
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
|
||||||
|
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
|
||||||
|
|
||||||
|
{:ok, auth} = OAuth.Authorization.create_authorization(app, user)
|
||||||
|
|
||||||
|
{:ok, token2} = OAuth.Token.exchange_token(app, auth)
|
||||||
|
assert {:ok, _} = start_socket("?stream=user&access_token=#{token2.token}")
|
||||||
|
|
||||||
|
OAuth.Token.Strategy.Revoke.revoke(token)
|
||||||
|
|
||||||
|
assert_receive {:close, _}
|
||||||
|
assert_receive {:close, _}
|
||||||
|
refute_receive {:close, _}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -41,6 +41,12 @@ defmodule Pleroma.Integration.WebsocketClient do
|
|||||||
{:ok, state}
|
{:ok, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_disconnect(conn_status, state) do
|
||||||
|
send(state.sender, {:close, conn_status})
|
||||||
|
{:ok, state}
|
||||||
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@impl true
|
@impl true
|
||||||
def handle_info({:text, msg}, state) do
|
def handle_info({:text, msg}, state) do
|
||||||
|
Loading…
Reference in New Issue
Block a user