X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fsalmon%2Fsalmon_test.exs;h=c539a28b263e8ba159daba0652ce62ed7767f2a2;hb=bf5b1c7f06c9f8882c40cf2385439bee3b74522c;hp=cf70c908f364181779c3a68b20e07845e791382b;hpb=460062f2b04220ffcd8f20aa842cc95582d1f849;p=akkoma diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs index cf70c908f..c539a28b2 100644 --- a/test/web/salmon/salmon_test.exs +++ b/test/web/salmon/salmon_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.Salmon.SalmonTest do use Pleroma.DataCase alias Pleroma.Web.Salmon @@ -10,6 +14,11 @@ defmodule Pleroma.Web.Salmon.SalmonTest do @magickey_friendica "RSA.AMwa8FUs2fWEjX0xN7yRQgegQffhBpuKNC6fa5VNSVorFjGZhRrlPMn7TQOeihlc9lBz2OsHlIedbYn2uJ7yCs0.AQAB" + setup_all do + Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) + :ok + end + test "decodes a salmon" do {:ok, salmon} = File.read("test/fixtures/salmon.xml") {:ok, doc} = Salmon.decode_and_validate(@magickey, salmon) @@ -22,7 +31,7 @@ defmodule Pleroma.Web.Salmon.SalmonTest do end test "generates an RSA private key pem" do - {:ok, key} = Salmon.generate_rsa_pem + {:ok, key} = Salmon.generate_rsa_pem() assert is_binary(key) assert Regex.match?(~r/RSA/, key) end @@ -62,26 +71,28 @@ defmodule Pleroma.Web.Salmon.SalmonTest do salmon = File.read!("test/fixtures/salmon2.xml") {:ok, key} = Salmon.fetch_magic_key(salmon) - assert key == "RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB" + assert key == + "RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB" end test "it pushes an activity to remote accounts it's addressed to" do user_data = %{ info: %{ - "salmon" => "http://example.org/salmon" + salmon: "http://test-example.org/salmon" }, local: false } mentioned_user = insert(:user, user_data) note = insert(:note) + activity_data = %{ - "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id, + "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(), "type" => "Create", "actor" => note.data["actor"], "to" => note.data["to"] ++ [mentioned_user.ap_id], "object" => note.data, - "published_at" => DateTime.utc_now() |> DateTime.to_iso8601, + "published_at" => DateTime.utc_now() |> DateTime.to_iso8601(), "context" => note.data["context"] } @@ -89,9 +100,10 @@ defmodule Pleroma.Web.Salmon.SalmonTest do user = Repo.get_by(User, ap_id: activity.data["actor"]) {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user) - poster = fn (url, _data, _headers, _options) -> - assert url == "http://example.org/salmon" + poster = fn url, _data, _headers -> + assert url == "http://test-example.org/salmon" end + Salmon.publish(user, activity, poster) end end