Merge branch 'release/2.4.4' into mergeback/2.4.4
This commit is contained in:
commit
dd82fd234f
9 changed files with 172 additions and 10 deletions
|
|
@ -93,7 +93,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
|
||||
{:ok, token} = OAuth.Token.exchange_token(app, auth)
|
||||
|
||||
%{user: user, token: token}
|
||||
%{app: app, user: user, token: token}
|
||||
end
|
||||
|
||||
test "accepts valid tokens", state do
|
||||
|
|
@ -130,5 +130,21 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
Process.sleep(30)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -887,4 +887,105 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
assert last_status["id"] == to_string(create_activity.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "stop streaming if token got revoked" do
|
||||
setup do
|
||||
child_proc = fn start, finalize ->
|
||||
fn ->
|
||||
start.()
|
||||
|
||||
receive do
|
||||
{StreamerTest, :ready} ->
|
||||
assert_receive {:render_with_user, _, "update.json", _}
|
||||
|
||||
receive do
|
||||
{StreamerTest, :revoked} -> finalize.()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
starter = fn user, token ->
|
||||
fn -> Streamer.get_topic_and_add_socket("user", user, token) end
|
||||
end
|
||||
|
||||
hit = fn -> assert_receive :close end
|
||||
miss = fn -> refute_receive :close end
|
||||
|
||||
send_all = fn tasks, thing -> Enum.each(tasks, &send(&1.pid, thing)) end
|
||||
|
||||
%{
|
||||
child_proc: child_proc,
|
||||
starter: starter,
|
||||
hit: hit,
|
||||
miss: miss,
|
||||
send_all: send_all
|
||||
}
|
||||
end
|
||||
|
||||
test "do not revoke other tokens", %{
|
||||
child_proc: child_proc,
|
||||
starter: starter,
|
||||
hit: hit,
|
||||
miss: miss,
|
||||
send_all: send_all
|
||||
} do
|
||||
%{user: user, token: token} = oauth_access(["read"])
|
||||
%{token: token2} = oauth_access(["read"], user: user)
|
||||
%{user: user2, token: user2_token} = oauth_access(["read"])
|
||||
|
||||
post_user = insert(:user)
|
||||
CommonAPI.follow(user, post_user)
|
||||
CommonAPI.follow(user2, post_user)
|
||||
|
||||
tasks = [
|
||||
Task.async(child_proc.(starter.(user, token), hit)),
|
||||
Task.async(child_proc.(starter.(user, token2), miss)),
|
||||
Task.async(child_proc.(starter.(user2, user2_token), miss))
|
||||
]
|
||||
|
||||
{:ok, _} =
|
||||
CommonAPI.post(post_user, %{
|
||||
status: "hi"
|
||||
})
|
||||
|
||||
send_all.(tasks, {StreamerTest, :ready})
|
||||
|
||||
Pleroma.Web.OAuth.Token.Strategy.Revoke.revoke(token)
|
||||
|
||||
send_all.(tasks, {StreamerTest, :revoked})
|
||||
|
||||
Enum.each(tasks, &Task.await/1)
|
||||
end
|
||||
|
||||
test "revoke all streams for this token", %{
|
||||
child_proc: child_proc,
|
||||
starter: starter,
|
||||
hit: hit,
|
||||
send_all: send_all
|
||||
} do
|
||||
%{user: user, token: token} = oauth_access(["read"])
|
||||
|
||||
post_user = insert(:user)
|
||||
CommonAPI.follow(user, post_user)
|
||||
|
||||
tasks = [
|
||||
Task.async(child_proc.(starter.(user, token), hit)),
|
||||
Task.async(child_proc.(starter.(user, token), hit))
|
||||
]
|
||||
|
||||
{:ok, _} =
|
||||
CommonAPI.post(post_user, %{
|
||||
status: "hi"
|
||||
})
|
||||
|
||||
send_all.(tasks, {StreamerTest, :ready})
|
||||
|
||||
Pleroma.Web.OAuth.Token.Strategy.Revoke.revoke(token)
|
||||
|
||||
send_all.(tasks, {StreamerTest, :revoked})
|
||||
|
||||
Enum.each(tasks, &Task.await/1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,6 +41,12 @@ defmodule Pleroma.Integration.WebsocketClient do
|
|||
{:ok, state}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_disconnect(conn_status, state) do
|
||||
send(state.sender, {:close, conn_status})
|
||||
{:ok, state}
|
||||
end
|
||||
|
||||
@doc false
|
||||
@impl true
|
||||
def handle_info({:text, msg}, state) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue