projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'feature/federator-behaviours' into 'develop'
[akkoma]
/
test
/
web
/
salmon
/
salmon_test.exs
diff --git
a/test/web/salmon/salmon_test.exs
b/test/web/salmon/salmon_test.exs
index 65d81e44fc923bb024571d5ea2adac2894419afe..232082779fd8f13de9768c8363efbcbb0779b2b6 100644
(file)
--- a/
test/web/salmon/salmon_test.exs
+++ b/
test/web/salmon/salmon_test.exs
@@
-1,13
+1,28
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Salmon.SalmonTest do
use Pleroma.DataCase
defmodule Pleroma.Web.Salmon.SalmonTest do
use Pleroma.DataCase
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Web.Federator.Publisher
alias Pleroma.Web.Salmon
alias Pleroma.Web.Salmon
- alias Pleroma.{Repo, Activity, User}
+ import Mock
import Pleroma.Factory
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
@wrong_magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAA"
import Pleroma.Factory
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
@wrong_magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAA"
+ @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)
test "decodes a salmon" do
{:ok, salmon} = File.read("test/fixtures/salmon.xml")
{:ok, doc} = Salmon.decode_and_validate(@magickey, salmon)
@@
-20,7
+35,7
@@
defmodule Pleroma.Web.Salmon.SalmonTest do
end
test "generates an RSA private key pem" 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
assert is_binary(key)
assert Regex.match?(~r/RSA/, key)
end
@@
-32,6
+47,10
@@
defmodule Pleroma.Web.Salmon.SalmonTest do
assert @magickey == magic_key
end
assert @magickey == magic_key
end
+ test "it decodes a friendica public key" do
+ _key = Salmon.decode_key(@magickey_friendica)
+ end
+
test "returns a public and private key from a pem" do
pem = File.read!("test/fixtures/private_key.pem")
{:ok, private, public} = Salmon.keys_from_pem(pem)
test "returns a public and private key from a pem" do
pem = File.read!("test/fixtures/private_key.pem")
{:ok, private, public} = Salmon.keys_from_pem(pem)
@@
-53,40
+72,43
@@
defmodule Pleroma.Web.Salmon.SalmonTest do
end
test "it gets a magic key" do
end
test "it gets a magic key" do
- # TODO: Make test local
salmon = File.read!("test/fixtures/salmon2.xml")
{:ok, key} = Salmon.fetch_magic_key(salmon)
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
end
- test "it pushes an activity to remote accounts it's addressed to" do
+ test_with_mock "it pushes an activity to remote accounts it's addressed to",
+ Publisher,
+ [:passthrough],
+ [] do
user_data = %{
info: %{
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)
},
local: false
}
mentioned_user = insert(:user, user_data)
note = insert(:note)
+
activity_data = %{
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,
"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"]
}
"context" => note.data["context"]
}
- {:ok, activity} = Repo.insert(%Activity{data: activity_data})
- user =
Repo.get_by(User, ap_id:
activity.data["actor"])
+ {:ok, activity} = Repo.insert(%Activity{data: activity_data
, recipients: activity_data["to"]
})
+ user =
User.get_cached_by_ap_id(
activity.data["actor"])
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
- poster = fn (url, data, headers) ->
- assert url == "http://example.org/salmon"
- end
- Salmon.publish(user, activity, poster)
+ Salmon.publish(user, activity)
+
+ assert called(Publisher.enqueue_one(Salmon, %{recipient: mentioned_user}))
end
end
end
end