X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fostatus%2Fostatus_test.exs;h=b4b19ab05351167166f31598b30317b13ca94986;hb=833161b5d21f85e2276cd0cee3e148ecbe6e1f05;hp=f095e41dd1e26514603396682cee77a32269e380;hpb=c2dcd767cf4abaa88da946e12ca643840b65e184;p=akkoma diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index f095e41dd..b4b19ab05 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -1,11 +1,24 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.OStatusTest do use Pleroma.DataCase alias Pleroma.Web.OStatus alias Pleroma.Web.XML - alias Pleroma.{Object, Repo, User, Activity} + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Activity + alias Pleroma.Instances import Pleroma.Factory import ExUnit.CaptureLog + setup_all do + Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end + test "don't insert create notes twice" do incoming = File.read!("test/fixtures/incoming_note_activity.xml") {:ok, [activity]} = OStatus.handle_incoming(incoming) @@ -17,7 +30,7 @@ defmodule Pleroma.Web.OStatusTest do {:ok, [activity]} = OStatus.handle_incoming(incoming) user = User.get_by_ap_id(activity.data["actor"]) - assert user.info["note_count"] == 1 + assert user.info.note_count == 1 assert activity.data["type"] == "Create" assert activity.data["object"]["type"] == "Note" @@ -302,6 +315,22 @@ defmodule Pleroma.Web.OStatusTest do refute User.following?(follower, followed) end + test "it clears `unreachable` federation status of the sender" do + incoming_reaction_xml = File.read!("test/fixtures/share-gs.xml") + doc = XML.parse_document(incoming_reaction_xml) + actor_uri = XML.string_from_xpath("//author/uri[1]", doc) + reacted_to_author_uri = XML.string_from_xpath("//author/uri[2]", doc) + + Instances.set_consistently_unreachable(actor_uri) + Instances.set_consistently_unreachable(reacted_to_author_uri) + refute Instances.reachable?(actor_uri) + refute Instances.reachable?(reacted_to_author_uri) + + {:ok, _} = OStatus.handle_incoming(incoming_reaction_xml) + assert Instances.reachable?(actor_uri) + refute Instances.reachable?(reacted_to_author_uri) + end + describe "new remote user creation" do test "returns local users" do local_user = insert(:user) @@ -319,7 +348,7 @@ defmodule Pleroma.Web.OStatusTest do assert user.name == "Constance Variable" assert user.nickname == "lambadalambda@social.heldscal.la" assert user.local == false - assert user.info["uri"] == uri + assert user.info.uri == uri assert user.ap_id == uri assert user.bio == "Call me Deacon Blues." assert user.avatar["type"] == "Image" @@ -329,6 +358,38 @@ defmodule Pleroma.Web.OStatusTest do assert user == user_again end + test "find_or_make_user sets all the nessary input fields" do + uri = "https://social.heldscal.la/user/23211" + {:ok, user} = OStatus.find_or_make_user(uri) + + assert user.info == + %Pleroma.User.Info{ + id: user.info.id, + ap_enabled: false, + background: %{}, + banner: %{}, + blocks: [], + deactivated: false, + default_scope: "public", + domain_blocks: [], + follower_count: 0, + is_admin: false, + is_moderator: false, + keys: nil, + locked: false, + no_rich_text: false, + note_count: 0, + settings: nil, + source_data: %{}, + hub: "https://social.heldscal.la/main/push/hub", + magic_key: + "RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB", + salmon: "https://social.heldscal.la/main/salmon/user/23211", + topic: "https://social.heldscal.la/api/statuses/user_timeline/23211.atom", + uri: "https://social.heldscal.la/user/23211" + } + end + test "find_make_or_update_user takes an author element and returns an updated user" do uri = "https://social.heldscal.la/user/23211" @@ -447,7 +508,7 @@ defmodule Pleroma.Web.OStatusTest do end end - test "it doesn't add nil in the do field" do + test "it doesn't add nil in the to field" do incoming = File.read!("test/fixtures/nil_mention_entry.xml") {:ok, [activity]} = OStatus.handle_incoming(incoming) @@ -456,4 +517,30 @@ defmodule Pleroma.Web.OStatusTest do "https://www.w3.org/ns/activitystreams#Public" ] end + + describe "is_representable?" do + test "Note objects are representable" do + note_activity = insert(:note_activity) + + assert OStatus.is_representable?(note_activity) + end + + test "Article objects are not representable" do + note_activity = insert(:note_activity) + + note_object = Object.normalize(note_activity.data["object"]) + + note_data = + note_object.data + |> Map.put("type", "Article") + + Cachex.clear(:object_cache) + + cs = Object.change(note_object, %{data: note_data}) + {:ok, _article_object} = Repo.update(cs) + + # the underlying object is now an Article instead of a note, so this should fail + refute OStatus.is_representable?(note_activity) + end + end end