Fix medium findings: deletion coords, count SQL, cache startup

This commit is contained in:
2026-03-14 04:15:37 +01:00
parent c7a9f152f9
commit 18e429e05a
12 changed files with 522 additions and 140 deletions

View File

@@ -43,7 +43,7 @@ defmodule Parrhesia.FaultInjectionGroupFlowTest do
payload = JSON.encode!(["EVENT", group_event])
assert {:push, {:text, error_response}, ^state} =
assert {:push, {:text, error_response}, _next_state} =
Connection.handle_in({payload, [opcode: :text]}, state)
assert JSON.decode!(error_response) == ["OK", group_event["id"], false, "error: :db_down"]
@@ -54,7 +54,7 @@ defmodule Parrhesia.FaultInjectionGroupFlowTest do
previous_storage |> Keyword.put(:moderation, PermissiveModeration)
)
assert {:push, {:text, ok_response}, ^state} =
assert {:push, {:text, ok_response}, _next_state} =
Connection.handle_in({payload, [opcode: :text]}, state)
assert JSON.decode!(ok_response) == ["OK", group_event["id"], true, "ok: event stored"]
@@ -87,7 +87,7 @@ defmodule Parrhesia.FaultInjectionGroupFlowTest do
"content" => Base.encode64("newer")
})
assert {:push, {:text, outage_response}, ^state} =
assert {:push, {:text, outage_response}, _next_state} =
Connection.handle_in(
{JSON.encode!(["EVENT", older_event]), [opcode: :text]},
state
@@ -101,7 +101,7 @@ defmodule Parrhesia.FaultInjectionGroupFlowTest do
previous_storage |> Keyword.put(:moderation, PermissiveModeration)
)
assert {:push, {:text, newer_response}, ^state} =
assert {:push, {:text, newer_response}, _next_state} =
Connection.handle_in(
{JSON.encode!(["EVENT", newer_event]), [opcode: :text]},
state
@@ -109,7 +109,7 @@ defmodule Parrhesia.FaultInjectionGroupFlowTest do
assert JSON.decode!(newer_response) == ["OK", newer_event["id"], true, "ok: event stored"]
assert {:push, {:text, older_response}, ^state} =
assert {:push, {:text, older_response}, _next_state} =
Connection.handle_in(
{JSON.encode!(["EVENT", older_event]), [opcode: :text]},
state

View File

@@ -29,7 +29,7 @@ defmodule Parrhesia.FaultInjectionTest do
{:ok, state} = Connection.init(subscription_index: nil)
event = valid_event()
assert {:push, {:text, response}, ^state} =
assert {:push, {:text, response}, _next_state} =
Connection.handle_in({JSON.encode!(["EVENT", event]), [opcode: :text]}, state)
assert JSON.decode!(response) == ["OK", event["id"], false, "error: :db_down"]

View File

@@ -26,6 +26,31 @@ defmodule Parrhesia.Storage.Adapters.Postgres.EventsLifecycleTest do
assert {:ok, nil} = Events.get_event(%{}, target["id"])
end
test "delete_by_request tombstones addressable targets referenced via a tags" do
author = String.duplicate("4", 64)
target =
event(%{
"pubkey" => author,
"kind" => 30_023,
"tags" => [["d", "topic"]],
"content" => "addressable-target"
})
assert {:ok, _event} = Events.put_event(%{}, target)
delete_request =
event(%{
"pubkey" => author,
"kind" => 5,
"tags" => [["a", "30023:#{author}:topic"]],
"content" => "delete-addressable"
})
assert {:ok, 1} = Events.delete_by_request(%{}, delete_request)
assert {:ok, nil} = Events.get_event(%{}, target["id"])
end
test "vanish hard-deletes events authored by pubkey" do
author = String.duplicate("3", 64)

View File

@@ -17,6 +17,12 @@ defmodule Parrhesia.Storage.ArchiverTest do
test "archive_sql builds insert-select statement" do
assert Archiver.archive_sql("events_2026_03", "events_archive") ==
"INSERT INTO events_archive SELECT * FROM events_2026_03;"
~s(INSERT INTO "events_archive" SELECT * FROM "events_2026_03";)
end
test "archive_sql rejects invalid SQL identifiers" do
assert_raise ArgumentError, fn ->
Archiver.archive_sql("events_default; DROP TABLE events", "events_archive")
end
end
end