From badbe2656c9ac33c35976ae8ebdbd6c305300307 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 27 Nov 2018 18:12:03 +0100 Subject: [PATCH] More fixes. --- lib/pleroma/user.ex | 5 ++-- lib/pleroma/user/info.ex | 8 ++++-- test/web/activity_pub/activity_pub_test.exs | 4 +-- test/web/activity_pub/transmogrifier_test.exs | 28 +++++++++---------- .../mastodon_api_controller_test.exs | 2 +- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1bf0f568c..bed8fd1b4 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -112,6 +112,7 @@ def remote_user_creation(params) do end end + # TODO: Check if this still used def update_changeset(struct, params \\ %{}) do struct |> cast(params, [:bio, :name]) @@ -730,7 +731,7 @@ def get_or_create_instance_user do # AP style def public_key_from_info(%{ - "source_data" => %{"publicKey" => %{"publicKeyPem" => public_key_pem}} + source_data: %{"publicKey" => %{"publicKeyPem" => public_key_pem}} }) do key = :public_key.pem_decode(public_key_pem) @@ -741,7 +742,7 @@ def public_key_from_info(%{ end # OStatus Magic Key - def public_key_from_info(%{"magic_key" => magic_key}) do + def public_key_from_info(%{magic_key: magic_key}) do {:ok, Pleroma.Web.Salmon.decode_key(magic_key)} end diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 630e9129a..a11e50022 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -18,6 +18,8 @@ defmodule Pleroma.User.Info do field(:is_moderator, :boolean, default: false) field(:keys, :string, default: nil) field(:settings, :map, default: nil) + field(:magic_key, :string, default: nil) + # topic, subject, salmon, subscribe_address end def set_activation_status(info, deactivated) do @@ -94,7 +96,8 @@ def remote_user_creation(info, params) do :ap_enabled, :source_data, :banner, - :locked + :locked, + :magic_key ]) end @@ -104,7 +107,8 @@ def user_upgrade(info, params) do :ap_enabled, :source_data, :banner, - :locked + :locked, + :magic_key ]) end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 35c381ac3..1d561d38d 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -14,8 +14,8 @@ test "it returns a user" do {:ok, user} = ActivityPub.make_user_from_ap_id(user_id) assert user.ap_id == user_id assert user.nickname == "admin@mastodon.example.org" - assert user.info["source_data"] - assert user.info["ap_enabled"] + assert user.info.source_data + assert user.info.ap_enabled assert user.follower_address == "http://mastodon.example.org/users/admin/followers" end end diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 829da0a65..e74b8f9a1 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -92,7 +92,7 @@ test "it works for incoming notices" do user = User.get_by_ap_id(object["actor"]) - assert user.info["note_count"] == 1 + assert user.info.note_count == 1 end test "it works for incoming notices with hashtags" do @@ -307,7 +307,7 @@ test "it works for incoming update activities" do } ] - assert user.info["banner"]["url"] == [ + assert user.info.banner["url"] == [ %{ "href" => "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png" @@ -337,7 +337,7 @@ test "it works for incoming update activities which lock the account" do {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data) user = User.get_cached_by_ap_id(data["actor"]) - assert user.info["locked"] == true + assert user.info.locked == true end test "it works for incoming deletes" do @@ -543,7 +543,7 @@ test "it works for incoming accepts which were pre-accepted" do test "it works for incoming accepts which were orphaned" do follower = insert(:user) - followed = insert(:user, %{info: %{"locked" => true}}) + followed = insert(:user, %{info: %User.Info{locked: true}}) {:ok, follow_activity} = ActivityPub.follow(follower, followed) @@ -565,7 +565,7 @@ test "it works for incoming accepts which were orphaned" do test "it works for incoming accepts which are referenced by IRI only" do follower = insert(:user) - followed = insert(:user, %{info: %{"locked" => true}}) + followed = insert(:user, %{info: %User.Info{locked: true}}) {:ok, follow_activity} = ActivityPub.follow(follower, followed) @@ -585,7 +585,7 @@ test "it works for incoming accepts which are referenced by IRI only" do test "it fails for incoming accepts which cannot be correlated" do follower = insert(:user) - followed = insert(:user, %{info: %{"locked" => true}}) + followed = insert(:user, %{info: %User.Info{locked: true}}) accept_data = File.read!("test/fixtures/mastodon-accept-activity.json") @@ -604,7 +604,7 @@ test "it fails for incoming accepts which cannot be correlated" do test "it fails for incoming rejects which cannot be correlated" do follower = insert(:user) - followed = insert(:user, %{info: %{"locked" => true}}) + followed = insert(:user, %{info: %User.Info{locked: true}}) accept_data = File.read!("test/fixtures/mastodon-reject-activity.json") @@ -623,7 +623,7 @@ test "it fails for incoming rejects which cannot be correlated" do test "it works for incoming rejects which are orphaned" do follower = insert(:user) - followed = insert(:user, %{info: %{"locked" => true}}) + followed = insert(:user, %{info: %User.Info{locked: true}}) {:ok, follower} = User.follow(follower, followed) {:ok, _follow_activity} = ActivityPub.follow(follower, followed) @@ -648,7 +648,7 @@ test "it works for incoming rejects which are orphaned" do test "it works for incoming rejects which are referenced by IRI only" do follower = insert(:user) - followed = insert(:user, %{info: %{"locked" => true}}) + followed = insert(:user, %{info: %User.Info{locked: true}}) {:ok, follower} = User.follow(follower, followed) {:ok, follow_activity} = ActivityPub.follow(follower, followed) @@ -815,18 +815,18 @@ test "it upgrades a user to activitypub" do assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients user = Repo.get(User, user.id) - assert user.info["note_count"] == 1 + assert user.info.note_count == 1 {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye") - assert user.info["ap_enabled"] - assert user.info["note_count"] == 1 + assert user.info.ap_enabled + assert user.info.note_count == 1 assert user.follower_address == "https://niu.moe/users/rye/followers" # Wait for the background task :timer.sleep(1000) user = Repo.get(User, user.id) - assert user.info["note_count"] == 1 + assert user.info.note_count == 1 activity = Repo.get(Activity, activity.id) assert user.follower_address in activity.recipients @@ -847,7 +847,7 @@ test "it upgrades a user to activitypub" do "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png" } ] - } = user.info["banner"] + } = user.info.banner refute "..." in activity.recipients diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 8577d1b5b..ef9db20cf 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1105,7 +1105,7 @@ test "blocking / unblocking a domain", %{conn: conn} do refute User.blocks?(user, other_user) end - test "getting a list of domain blocks" do + test "getting a list of domain blocks", %{conn: conn} do user = insert(:user) {:ok, user} = User.block_domain(user, "bad.site")