summaryrefslogtreecommitdiff
path: root/test/web
diff options
context:
space:
mode:
Diffstat (limited to 'test/web')
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs22
-rw-r--r--test/web/activity_pub/relay_test.exs11
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs45
-rw-r--r--test/web/activity_pub/views/object_view_test.exs1
-rw-r--r--test/web/federator_test.exs44
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs56
-rw-r--r--test/web/mastodon_api/status_view_test.exs18
-rw-r--r--test/web/node_info_test.exs32
-rw-r--r--test/web/ostatus/ostatus_test.exs24
-rw-r--r--test/web/plugs/federating_plug_test.exs33
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs130
-rw-r--r--test/web/twitter_api/twitter_api_test.exs2
-rw-r--r--test/web/twitter_api/views/user_view_test.exs7
13 files changed, 421 insertions, 4 deletions
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index e63cd6583..1c24b348c 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -5,6 +5,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
alias Pleroma.{Repo, User}
alias Pleroma.Activity
+ describe "/relay" do
+ test "with the relay active, it returns the relay user", %{conn: conn} do
+ res =
+ conn
+ |> get(activity_pub_path(conn, :relay))
+ |> json_response(200)
+
+ assert res["id"] =~ "/relay"
+ end
+
+ test "with the relay disabled, it returns 404", %{conn: conn} do
+ Pleroma.Config.put([:instance, :allow_relay], false)
+
+ res =
+ conn
+ |> get(activity_pub_path(conn, :relay))
+ |> json_response(404)
+
+ Pleroma.Config.put([:instance, :allow_relay], true)
+ end
+ end
+
describe "/users/:nickname" do
test "it returns a json representation of the user", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs
new file mode 100644
index 000000000..41d13e055
--- /dev/null
+++ b/test/web/activity_pub/relay_test.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Web.ActivityPub.RelayTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.ActivityPub.Relay
+
+ test "gets an actor for the relay" do
+ user = Relay.get_actor()
+
+ assert user.ap_id =~ "/relay"
+ end
+end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6a6f2a44c..0278ef5d1 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -145,6 +145,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert "test" in data["object"]["tag"]
end
+ test "it works for incoming notices with url not being a string (prismo)" do
+ data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!()
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["object"]["url"] == "https://prismo.news/posts/83"
+ end
+
test "it works for incoming follow requests" do
user = insert(:user)
@@ -695,7 +703,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
- assert modified["@context"] == "https://www.w3.org/ns/activitystreams"
+ assert modified["@context"] ==
+ Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"]
+
assert modified["object"]["conversation"] == modified["context"]
end
@@ -733,6 +743,39 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
end
+
+ test "it strips internal hashtag data" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"})
+
+ expected_tag = %{
+ "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
+ "type" => "Hashtag",
+ "name" => "#2hu"
+ }
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert modified["object"]["tag"] == [expected_tag]
+ end
+
+ test "it strips internal fields" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :moominmamma:"})
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert length(modified["object"]["tag"]) == 2
+
+ assert is_nil(modified["object"]["emoji"])
+ assert is_nil(modified["object"]["likes"])
+ assert is_nil(modified["object"]["like_count"])
+ assert is_nil(modified["object"]["announcements"])
+ assert is_nil(modified["object"]["announcement_count"])
+ assert is_nil(modified["object"]["context_id"])
+ end
end
describe "user upgrade" do
diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs
index 6a1311be7..7e08dff5d 100644
--- a/test/web/activity_pub/views/object_view_test.exs
+++ b/test/web/activity_pub/views/object_view_test.exs
@@ -13,5 +13,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
assert result["to"] == note.data["to"]
assert result["content"] == note.data["content"]
assert result["type"] == "Note"
+ assert result["@context"]
end
end
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 09533362a..c709d1181 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -1,6 +1,9 @@
defmodule Pleroma.Web.FederatorTest do
alias Pleroma.Web.Federator
+ alias Pleroma.Web.CommonAPI
use Pleroma.DataCase
+ import Pleroma.Factory
+ import Mock
test "enqueues an element according to priority" do
queue = [%{item: 1, priority: 2}]
@@ -17,4 +20,45 @@ defmodule Pleroma.Web.FederatorTest do
assert {2, [%{item: 1, priority: 2}]} = Federator.queue_pop(queue)
end
+
+ describe "Publish an activity" do
+ setup do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"})
+
+ relay_mock = {
+ Pleroma.Web.ActivityPub.Relay,
+ [],
+ [publish: fn _activity -> send(self(), :relay_publish) end]
+ }
+
+ %{activity: activity, relay_mock: relay_mock}
+ end
+
+ test "with relays active, it publishes to the relay", %{
+ activity: activity,
+ relay_mock: relay_mock
+ } do
+ with_mocks([relay_mock]) do
+ Federator.handle(:publish, activity)
+ end
+
+ assert_received :relay_publish
+ end
+
+ test "with relays deactivated, it does not publish to the relay", %{
+ activity: activity,
+ relay_mock: relay_mock
+ } do
+ Pleroma.Config.put([:instance, :allow_relay], false)
+
+ with_mocks([relay_mock]) do
+ Federator.handle(:publish, activity)
+ end
+
+ refute_received :relay_publish
+
+ Pleroma.Config.put([:instance, :allow_relay], true)
+ end
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e9deae64d..ad67cae6b 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -178,6 +178,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> get("api/v1/timelines/home")
[_s1, _s2] = json_response(res_conn, 200)
+
+ # Test pagination
+ Enum.each(1..20, fn _ ->
+ {:ok, _} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "direct"
+ })
+ end)
+
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("api/v1/timelines/direct")
+
+ statuses = json_response(res_conn, 200)
+ assert length(statuses) == 20
+
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("api/v1/timelines/direct", %{max_id: List.last(statuses)["id"]})
+
+ [status] = json_response(res_conn, 200)
+
+ assert status["url"] != direct.data["id"]
end
test "replying to a status", %{conn: conn} do
@@ -198,6 +224,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert activity.data["object"]["inReplyToStatusId"] == replied_to.id
end
+ test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""})
+
+ assert %{"content" => "xD", "id" => id} = json_response(conn, 200)
+
+ activity = Repo.get(Activity, id)
+
+ assert activity
+ end
+
test "verify_credentials", %{conn: conn} do
user = insert(:user)
@@ -280,6 +321,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert response = json_response(conn, 200)
assert response["phrase"] == filter.phrase
assert response["context"] == filter.context
+ assert response["id"] != nil
+ assert response["id"] != ""
end
test "fetching a list of filters", %{conn: conn} do
@@ -927,11 +970,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, [_activity]} =
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
- conn =
+ nconn =
conn
|> get("/api/v1/timelines/tag/2hu")
- assert [%{"id" => id}] = json_response(conn, 200)
+ assert [%{"id" => id}] = json_response(nconn, 200)
+
+ assert id == to_string(activity.id)
+
+ # works for different capitalization too
+ nconn =
+ conn
+ |> get("/api/v1/timelines/tag/2HU")
+
+ assert [%{"id" => id}] = json_response(nconn, 200)
assert id == to_string(activity.id)
end)
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index b9c019206..31554a07d 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -7,6 +7,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
+ test "a note with null content" do
+ note = insert(:note_activity)
+
+ data =
+ note.data
+ |> put_in(["object", "content"], nil)
+
+ note =
+ note
+ |> Map.put(:data, data)
+
+ user = User.get_cached_by_ap_id(note.data["actor"])
+
+ status = StatusView.render("status.json", %{activity: note})
+
+ assert status.content == ""
+ end
+
test "a note activity" do
note = insert(:note_activity)
user = User.get_cached_by_ap_id(note.data["actor"])
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index d48f40e47..a6376453c 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -14,4 +14,36 @@ defmodule Pleroma.Web.NodeInfoTest do
assert user.ap_id in result["metadata"]["staffAccounts"]
end
+
+ test "returns 404 when federation is disabled" do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:federating, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn
+ |> get("/.well-known/nodeinfo")
+ |> json_response(404)
+
+ conn
+ |> get("/nodeinfo/2.0.json")
+ |> json_response(404)
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:federating, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
+ test "returns 200 when federation is enabled" do
+ conn
+ |> get("/.well-known/nodeinfo")
+ |> json_response(200)
+
+ conn
+ |> get("/nodeinfo/2.0.json")
+ |> json_response(200)
+ end
end
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index f095e41dd..f95da8b0a 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -456,4 +456,28 @@ defmodule Pleroma.Web.OStatusTest do
"https://www.w3.org/ns/activitystreams#Public"
]
end
+
+ describe "is_representable?" do
+ test "Note objects are representable" do
+ note_activity = insert(:note_activity)
+
+ assert OStatus.is_representable?(note_activity)
+ end
+
+ test "Article objects are not representable" do
+ note_activity = insert(:note_activity)
+
+ note_object = Object.normalize(note_activity.data["object"])
+
+ note_data =
+ note_object.data
+ |> Map.put("type", "Article")
+
+ cs = Object.change(note_object, %{data: note_data})
+ {:ok, article_object} = Repo.update(cs)
+
+ # the underlying object is now an Article instead of a note, so this should fail
+ refute OStatus.is_representable?(note_activity)
+ end
+ end
end
diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs
new file mode 100644
index 000000000..1455a1c46
--- /dev/null
+++ b/test/web/plugs/federating_plug_test.exs
@@ -0,0 +1,33 @@
+defmodule Pleroma.Web.FederatingPlugTest do
+ use Pleroma.Web.ConnCase
+
+ test "returns and halt the conn when federating is disabled" do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:federating, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn =
+ build_conn()
+ |> Pleroma.Web.FederatingPlug.call(%{})
+
+ assert conn.status == 404
+ assert conn.halted
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:federating, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
+ test "does nothing when federating is enabled" do
+ conn =
+ build_conn()
+ |> Pleroma.Web.FederatingPlug.call(%{})
+
+ refute conn.status
+ refute conn.halted
+ end
+end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 87bcdaf71..788e3a6eb 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -100,6 +100,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert length(response) == 10
end
+
+ test "returns 403 to unauthenticated request when the instance is not public" do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn
+ |> get("/api/statuses/public_timeline.json")
+ |> json_response(403)
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
+ test "returns 200 to unauthenticated request when the instance is public" do
+ conn
+ |> get("/api/statuses/public_timeline.json")
+ |> json_response(200)
+ end
+ end
+
+ describe "GET /statuses/public_and_external_timeline.json" do
+ test "returns 403 to unauthenticated request when the instance is not public" do
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, false)
+
+ Application.put_env(:pleroma, :instance, instance)
+
+ conn
+ |> get("/api/statuses/public_and_external_timeline.json")
+ |> json_response(403)
+
+ instance =
+ Application.get_env(:pleroma, :instance)
+ |> Keyword.put(:public, true)
+
+ Application.put_env(:pleroma, :instance, instance)
+ end
+
+ test "returns 200 to unauthenticated request when the instance is public" do
+ conn
+ |> get("/api/statuses/public_and_external_timeline.json")
+ |> json_response(200)
+ end
end
describe "GET /statuses/show/:id.json" do
@@ -221,6 +271,36 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "GET /statuses/dm_timeline.json" do
+ test "it show direct messages", %{conn: conn} do
+ user_one = insert(:user)
+ user_two = insert(:user)
+
+ {:ok, user_two} = User.follow(user_two, user_one)
+
+ {:ok, direct} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, _follower_only} =
+ CommonAPI.post(user_one, %{
+ "status" => "Hi @#{user_two.nickname}!",
+ "visibility" => "private"
+ })
+
+ # Only direct should be visible here
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("/api/statuses/dm_timeline.json")
+
+ [status] = json_response(res_conn, 200)
+ assert status["id"] == direct.id
+ end
+ end
+
describe "GET /statuses/mentions.json" do
setup [:valid_user]
@@ -281,6 +361,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "POST /api/qvitter/statuses/notifications/read" do
+ setup [:valid_user]
+
+ test "without valid credentials", %{conn: conn} do
+ conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567})
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials, without any params", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/qvitter/statuses/notifications/read")
+
+ assert json_response(conn, 400) == %{
+ "error" => "You need to specify latest_id",
+ "request" => "/api/qvitter/statuses/notifications/read"
+ }
+ end
+
+ test "with credentials, with params", %{conn: conn, user: current_user} do
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
+
+ response_conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/qvitter/statuses/notifications.json")
+
+ [notification] = response = json_response(response_conn, 200)
+
+ assert length(response) == 1
+
+ assert notification["is_seen"] == 0
+
+ response_conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
+
+ [notification] = response = json_response(response_conn, 200)
+
+ assert length(response) == 1
+
+ assert notification["is_seen"] == 1
+ end
+ end
+
describe "GET /statuses/user_timeline.json" do
setup [:valid_user]
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 6486540f8..8b9920bd9 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
"https://www.w3.org/ns/activitystreams#Public"
)
- assert Enum.member?(get_in(activity.data, ["cc"]), "shp")
+ assert Enum.member?(get_in(activity.data, ["to"]), "shp")
assert activity.local == true
assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 2deb22fb1..2c583c0d3 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -13,6 +13,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
[user: user]
end
+ test "A user with only a nickname", %{user: user} do
+ user = %{user | name: nil, nickname: "scarlett@catgirl.science"}
+ represented = UserView.render("show.json", %{user: user})
+ assert represented["name"] == user.nickname
+ assert represented["name_html"] == user.nickname
+ end
+
test "A user with an avatar object", %{user: user} do
image = "image"
user = %{user | avatar: %{"url" => [%{"href" => image}]}}