diff options
Diffstat (limited to 'test')
85 files changed, 789 insertions, 23 deletions
diff --git a/test/activity_test.exs b/test/activity_test.exs index 55849c522..36c718869 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -1,17 +1,22 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.ActivityTest do    use Pleroma.DataCase +  alias Pleroma.Activity    import Pleroma.Factory    test "returns an activity by it's AP id" do      activity = insert(:note_activity) -    found_activity = Pleroma.Activity.get_by_ap_id(activity.data["id"]) +    found_activity = Activity.get_by_ap_id(activity.data["id"])      assert activity == found_activity    end    test "returns activities by it's objects AP ids" do      activity = insert(:note_activity) -    [found_activity] = Pleroma.Activity.all_by_object_ap_id(activity.data["object"]["id"]) +    [found_activity] = Activity.all_by_object_ap_id(activity.data["object"]["id"])      assert activity == found_activity    end @@ -19,8 +24,7 @@ defmodule Pleroma.ActivityTest do    test "returns the activity that created an object" do      activity = insert(:note_activity) -    found_activity = -      Pleroma.Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"]) +    found_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"]["id"])      assert activity == found_activity    end diff --git a/test/captcha_test.exs b/test/captcha_test.exs index 93b8930da..7ca9a4607 100644 --- a/test/captcha_test.exs +++ b/test/captcha_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.CaptchaTest do    use ExUnit.Case diff --git a/test/config_test.exs b/test/config_test.exs index 837cbb30c..0a6f0395a 100644 --- a/test/config_test.exs +++ b/test/config_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.ConfigTest do    use ExUnit.Case diff --git a/test/filter_test.exs b/test/filter_test.exs index 2b31bcc08..b31c68efd 100644 --- a/test/filter_test.exs +++ b/test/filter_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.FilterTest do    alias Pleroma.Repo    use Pleroma.DataCase diff --git a/test/fixtures/activitypub-client-post-activity.json b/test/fixtures/activitypub-client-post-activity.json new file mode 100644 index 000000000..c985e072b --- /dev/null +++ b/test/fixtures/activitypub-client-post-activity.json @@ -0,0 +1,9 @@ +{ +  "@context": ["https://www.w3.org/ns/activitystreams", {"@language": "en-GB"}], +  "type": "Create", +  "object": { +    "type": "Note", +    "content": "It's a note" +  }, +  "to": ["https://www.w3.org/ns/activitystreams#Public"] +} diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 584700b6a..c76149e38 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.FormatterTest do    alias Pleroma.Formatter    alias Pleroma.User diff --git a/test/html_test.exs b/test/html_test.exs index f7150759b..29cab17f3 100644 --- a/test/html_test.exs +++ b/test/html_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.HTMLTest do    alias Pleroma.HTML    use Pleroma.DataCase diff --git a/test/http_test.exs b/test/http_test.exs index 62f3ccb30..5f9522cf0 100644 --- a/test/http_test.exs +++ b/test/http_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.HTTPTest do    use Pleroma.DataCase    import Tesla.Mock diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs index b5f3d3a47..03aabf12c 100644 --- a/test/integration/mastodon_websocket_test.exs +++ b/test/integration/mastodon_websocket_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Integration.MastodonWebsocketTest do    use Pleroma.DataCase diff --git a/test/list_test.exs b/test/list_test.exs index 2ab822815..1909c0cd9 100644 --- a/test/list_test.exs +++ b/test/list_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.ListTest do    alias Pleroma.Repo    use Pleroma.DataCase diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs index cb455ca79..05d927422 100644 --- a/test/media_proxy_test.exs +++ b/test/media_proxy_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.MediaProxyTest do    use ExUnit.Case    import Pleroma.Web.MediaProxy diff --git a/test/notification_test.exs b/test/notification_test.exs index 385210793..31c0d2c64 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.NotificationTest do    use Pleroma.DataCase    alias Pleroma.Web.TwitterAPI.TwitterAPI diff --git a/test/object_test.exs b/test/object_test.exs index 909605560..72194975d 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.ObjectTest do    use Pleroma.DataCase    import Pleroma.Factory @@ -32,6 +36,8 @@ defmodule Pleroma.ObjectTest do        found_object = Object.get_by_ap_id(object.data["id"])        refute object == found_object + +      assert found_object.data["type"] == "Tombstone"      end      test "ensures cache is cleared for the object" do @@ -47,6 +53,8 @@ defmodule Pleroma.ObjectTest do        cached_object = Object.get_cached_by_ap_id(object.data["id"])        refute object == cached_object + +      assert cached_object.data["type"] == "Tombstone"      end    end  end diff --git a/test/plugs/admin_secret_authentication_plug_test.exs b/test/plugs/admin_secret_authentication_plug_test.exs index c0fe2cf97..e1d4b391f 100644 --- a/test/plugs/admin_secret_authentication_plug_test.exs +++ b/test/plugs/admin_secret_authentication_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.AdminSecretAuthenticationPlugTest do    use Pleroma.Web.ConnCase, async: true    import Pleroma.Factory diff --git a/test/plugs/authentication_plug_test.exs b/test/plugs/authentication_plug_test.exs index 061fa0cac..6158086ea 100644 --- a/test/plugs/authentication_plug_test.exs +++ b/test/plugs/authentication_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.AuthenticationPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/basic_auth_decoder_plug_test.exs b/test/plugs/basic_auth_decoder_plug_test.exs index a4876fef7..4d7728e93 100644 --- a/test/plugs/basic_auth_decoder_plug_test.exs +++ b/test/plugs/basic_auth_decoder_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.BasicAuthDecoderPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/ensure_authenticated_plug_test.exs b/test/plugs/ensure_authenticated_plug_test.exs index b32817fef..37ab5213a 100644 --- a/test/plugs/ensure_authenticated_plug_test.exs +++ b/test/plugs/ensure_authenticated_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.EnsureAuthenticatedPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/ensure_user_key_plug_test.exs b/test/plugs/ensure_user_key_plug_test.exs index 9beda838e..6a9627f6a 100644 --- a/test/plugs/ensure_user_key_plug_test.exs +++ b/test/plugs/ensure_user_key_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.EnsureUserKeyPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs index 169c3b3a8..0cbb7e4b1 100644 --- a/test/plugs/http_security_plug_test.exs +++ b/test/plugs/http_security_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do    use Pleroma.Web.ConnCase    alias Pleroma.Config diff --git a/test/plugs/http_signature_plug_test.exs b/test/plugs/http_signature_plug_test.exs index a15c5b470..6a00dd4fd 100644 --- a/test/plugs/http_signature_plug_test.exs +++ b/test/plugs/http_signature_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.Plugs.HTTPSignaturePlugTest do    use Pleroma.Web.ConnCase    alias Pleroma.Web.HTTPSignatures diff --git a/test/plugs/instance_static_test.exs b/test/plugs/instance_static_test.exs index 526679aae..e2dcfa3d8 100644 --- a/test/plugs/instance_static_test.exs +++ b/test/plugs/instance_static_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.RuntimeStaticPlugTest do    use Pleroma.Web.ConnCase diff --git a/test/plugs/legacy_authentication_plug_test.exs b/test/plugs/legacy_authentication_plug_test.exs index 383a22ff8..302662797 100644 --- a/test/plugs/legacy_authentication_plug_test.exs +++ b/test/plugs/legacy_authentication_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/oauth_plug_test.exs b/test/plugs/oauth_plug_test.exs index 4dd12f207..17fdba916 100644 --- a/test/plugs/oauth_plug_test.exs +++ b/test/plugs/oauth_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.OAuthPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/session_authentication_plug_test.exs b/test/plugs/session_authentication_plug_test.exs index bb51bc0db..0000f4258 100644 --- a/test/plugs/session_authentication_plug_test.exs +++ b/test/plugs/session_authentication_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.SessionAuthenticationPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/set_user_session_id_plug_test.exs b/test/plugs/set_user_session_id_plug_test.exs index 7cf8e42cc..f8bfde039 100644 --- a/test/plugs/set_user_session_id_plug_test.exs +++ b/test/plugs/set_user_session_id_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.SetUserSessionIdPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/user_enabled_plug_test.exs b/test/plugs/user_enabled_plug_test.exs index eeb167933..c0fafcab1 100644 --- a/test/plugs/user_enabled_plug_test.exs +++ b/test/plugs/user_enabled_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.UserEnabledPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/user_fetcher_plug_test.exs b/test/plugs/user_fetcher_plug_test.exs index 5195a0c4a..262eb8d93 100644 --- a/test/plugs/user_fetcher_plug_test.exs +++ b/test/plugs/user_fetcher_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.UserFetcherPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/plugs/user_is_admin_plug_test.exs b/test/plugs/user_is_admin_plug_test.exs index cdab6b8ed..9e05fff18 100644 --- a/test/plugs/user_is_admin_plug_test.exs +++ b/test/plugs/user_is_admin_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Plugs.UserIsAdminPlugTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex index 410318dc4..9061f2b45 100644 --- a/test/support/captcha_mock.ex +++ b/test/support/captcha_mock.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Captcha.Mock do    alias Pleroma.Captcha.Service    @behaviour Service diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex index 68995a01d..466d8986f 100644 --- a/test/support/channel_case.ex +++ b/test/support/channel_case.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.ChannelCase do    @moduledoc """    This module defines the test case to be used by diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index d25c28f49..c201d9a9b 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.ConnCase do    @moduledoc """    This module defines the test case to be used by diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 53e7234d2..56d5896ad 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.DataCase do    @moduledoc """    This module defines the setup for tests requiring diff --git a/test/support/factory.ex b/test/support/factory.ex index 2889d8977..e5c0c5bcc 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Factory do    use ExMachina.Ecto, repo: Pleroma.Repo diff --git a/test/support/helpers.ex b/test/support/helpers.ex index 64b6b1900..6e389ce52 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Tests.Helpers do    @moduledoc """    Helpers for use in tests. diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index 6f98fc5d0..e4279e14d 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule HttpRequestMock do    require Logger diff --git a/test/support/ostatus_mock.ex b/test/support/ostatus_mock.ex index 36865ae02..9c0f2f323 100644 --- a/test/support/ostatus_mock.ex +++ b/test/support/ostatus_mock.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OStatusMock do    import Pleroma.Factory diff --git a/test/support/websocket_client.ex b/test/support/websocket_client.ex index 57e9bb17f..121231452 100644 --- a/test/support/websocket_client.ex +++ b/test/support/websocket_client.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Integration.WebsocketClient do    # https://github.com/phoenixframework/phoenix/blob/master/test/support/websocket_client.exs diff --git a/test/support/websub_mock.ex b/test/support/websub_mock.ex index 0cba0b740..e3d5a5b16 100644 --- a/test/support/websub_mock.ex +++ b/test/support/websub_mock.ex @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.WebsubMock do    def verify(sub) do      {:ok, sub} diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs index 737293865..96fac4811 100644 --- a/test/tasks/relay_test.exs +++ b/test/tasks/relay_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Mix.Tasks.Pleroma.RelayTest do    alias Pleroma.Activity    alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils} diff --git a/test/tasks/uploads_test.exs b/test/tasks/uploads_test.exs index 93035abb6..b0b8eda11 100644 --- a/test/tasks/uploads_test.exs +++ b/test/tasks/uploads_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Mix.Tasks.Pleroma.UploadsTest do    alias Pleroma.Upload    use Pleroma.DataCase diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs index 7479bf749..44271898c 100644 --- a/test/tasks/user_test.exs +++ b/test/tasks/user_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Mix.Tasks.Pleroma.UserTest do    alias Pleroma.User    use Pleroma.DataCase diff --git a/test/test_helper.exs b/test/test_helper.exs index 94ba68ff8..f604ba63d 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  ExUnit.start()  Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual) diff --git a/test/upload_test.exs b/test/upload_test.exs index f2cad4cf0..d4ea3a573 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.UploadTest do    alias Pleroma.Upload    use Pleroma.DataCase diff --git a/test/user_test.exs b/test/user_test.exs index b4d8174c6..869e9196d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.UserTest do    alias Pleroma.Builders.UserBuilder    alias Pleroma.{User, Repo, Activity} @@ -149,6 +153,20 @@ defmodule Pleroma.UserTest do        end)      end +    test "it restricts certain nicknames" do +      [restricted_name | _] = Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) + +      assert is_bitstring(restricted_name) + +      params = +        @full_user_data +        |> Map.put(:nickname, restricted_name) + +      changeset = User.register_changeset(%User{}, params) + +      refute changeset.valid? +    end +      test "it sets the password_hash, ap_id and following fields" do        changeset = User.register_changeset(%User{}, @full_user_data) @@ -260,6 +278,24 @@ defmodule Pleroma.UserTest do        assert user == fetched_user      end +    test "gets an existing user by fully qualified nickname" do +      user = insert(:user) + +      fetched_user = +        User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host()) + +      assert user == fetched_user +    end + +    test "gets an existing user by fully qualified nickname, case insensitive" do +      user = insert(:user, nickname: "nick") +      casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host()) + +      fetched_user = User.get_or_fetch_by_nickname(casing_altered_fqn) + +      assert user == fetched_user +    end +      test "fetches an external user via ostatus if no user exists" do        fetched_user = User.get_or_fetch_by_nickname("shp@social.heldscal.la")        assert fetched_user.nickname == "shp@social.heldscal.la" @@ -467,6 +503,21 @@ defmodule Pleroma.UserTest do      end    end +  describe "follow_import" do +    test "it imports user followings from list" do +      [user1, user2, user3] = insert_list(3, :user) + +      identifiers = [ +        user2.ap_id, +        user3.nickname +      ] + +      result = User.follow_import(user1, identifiers) +      assert is_list(result) +      assert result == [user2, user3] +    end +  end +    describe "blocks" do      test "it blocks people" do        user = insert(:user) @@ -566,6 +617,21 @@ defmodule Pleroma.UserTest do      end    end +  describe "blocks_import" do +    test "it imports user blocks from list" do +      [user1, user2, user3] = insert_list(3, :user) + +      identifiers = [ +        user2.ap_id, +        user3.nickname +      ] + +      result = User.blocks_import(user1, identifiers) +      assert is_list(result) +      assert result == [user2, user3] +    end +  end +    test "get recipients from activity" do      actor = insert(:user)      user = insert(:user, local: true) @@ -640,10 +706,10 @@ defmodule Pleroma.UserTest do    end    describe "per-user rich-text filtering" do -    test "html_filter_policy returns nil when rich-text is enabled" do +    test "html_filter_policy returns default policies, when rich-text is enabled" do        user = insert(:user) -      assert nil == User.html_filter_policy(user) +      assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)      end      test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index faeace016..cb95e0e09 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do    use Pleroma.Web.ConnCase    import Pleroma.Factory @@ -108,6 +112,32 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        :timer.sleep(500)        assert Activity.get_by_ap_id(data["id"])      end + +    test "it rejects reads from other users", %{conn: conn} do +      user = insert(:user) +      otheruser = insert(:user) + +      conn = +        conn +        |> assign(:user, otheruser) +        |> put_req_header("accept", "application/activity+json") +        |> get("/users/#{user.nickname}/inbox") + +      assert json_response(conn, 403) +    end + +    test "it returns a note activity in a collection", %{conn: conn} do +      note_activity = insert(:direct_note_activity) +      user = User.get_cached_by_ap_id(hd(note_activity.data["to"])) + +      conn = +        conn +        |> assign(:user, user) +        |> put_req_header("accept", "application/activity+json") +        |> get("/users/#{user.nickname}/inbox") + +      assert response(conn, 200) =~ note_activity.data["object"]["content"] +    end    end    describe "/users/:nickname/outbox" do @@ -134,6 +164,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        assert response(conn, 200) =~ announce_activity.data["object"]      end + +    test "it rejects posts from other users", %{conn: conn} do +      data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!() +      user = insert(:user) +      otheruser = insert(:user) + +      conn = +        conn +        |> assign(:user, otheruser) +        |> put_req_header("content-type", "application/activity+json") +        |> post("/users/#{user.nickname}/outbox", data) + +      assert json_response(conn, 403) +    end + +    test "it inserts an incoming activity into the database", %{conn: conn} do +      data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!() +      user = insert(:user) + +      conn = +        conn +        |> assign(:user, user) +        |> put_req_header("content-type", "application/activity+json") +        |> post("/users/#{user.nickname}/outbox", data) + +      result = json_response(conn, 201) +      assert Activity.get_by_ap_id(result["id"]) +    end    end    describe "/users/:nickname/followers" do diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 470ed08b2..2453998ad 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    use Pleroma.DataCase    alias Pleroma.Web.ActivityPub.ActivityPub @@ -27,6 +31,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    end    describe "insertion" do +    test "drops activities beyond a certain limit" do +      limit = Pleroma.Config.get([:instance, :remote_limit]) + +      random_text = +        :crypto.strong_rand_bytes(limit + 1) +        |> Base.encode64() +        |> binary_part(0, limit + 1) + +      data = %{ +        "ok" => true, +        "object" => %{ +          "content" => random_text +        } +      } + +      assert {:error, {:remote_limit_error, _}} = ActivityPub.insert(data) +    end +      test "returns the activity if one with the same id is already in" do        activity = insert(:note_activity)        {:ok, new_activity} = ActivityPub.insert(activity.data) @@ -176,6 +198,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      assert Enum.member?(activities, activity_one)    end +  test "excludes reblogs on request" do +    user = insert(:user) +    {:ok, expected_activity} = ActivityBuilder.insert(%{"type" => "Create"}, %{:user => user}) +    {:ok, _} = ActivityBuilder.insert(%{"type" => "Announce"}, %{:user => user}) + +    [activity] = ActivityPub.fetch_user_activities(user, nil, %{"exclude_reblogs" => "true"}) + +    assert activity == expected_activity +  end +    describe "public fetch activities" do      test "doesn't retrieve unlisted activities" do        user = insert(:user) @@ -478,7 +510,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert Repo.get(Activity, delete.id) != nil -      assert Repo.get(Object, object.id) == nil +      assert Repo.get(Object, object.id).data["type"] == "Tombstone"      end    end diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs index 41d13e055..21a63c493 100644 --- a/test/web/activity_pub/relay_test.exs +++ b/test/web/activity_pub/relay_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.ActivityPub.RelayTest do    use Pleroma.DataCase diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 0428e052d..a5fd87ed4 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do    use Pleroma.DataCase    alias Pleroma.Web.ActivityPub.Transmogrifier @@ -684,6 +688,36 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        :error = Transmogrifier.handle_incoming(data)      end + +    test "it remaps video URLs as attachments if necessary" do +      {:ok, object} = +        ActivityPub.fetch_object_from_id( +          "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" +        ) + +      attachment = %{ +        "type" => "Link", +        "mediaType" => "video/mp4", +        "href" => +          "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", +        "mimeType" => "video/mp4", +        "size" => 5_015_880, +        "url" => [ +          %{ +            "href" => +              "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", +            "mediaType" => "video/mp4", +            "type" => "Link" +          } +        ], +        "width" => 480 +      } + +      assert object.data["url"] == +               "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" + +      assert object.data["attachment"] == [attachment] +    end    end    describe "prepare outgoing" do diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index e183da3a1..42450a7b6 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    use Pleroma.Web.ConnCase diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 0b5a235f8..c3674711a 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.CommonAPI.Test do    use Pleroma.DataCase    alias Pleroma.Web.CommonAPI diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index b01ce04f8..fc89e3116 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.CommonAPI.UtilsTest do    alias Pleroma.Web.CommonAPI.Utils    alias Pleroma.Web.Endpoint diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 87bf73dbd..a49265c0c 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.FederatorTest do    alias Pleroma.Web.Federator    alias Pleroma.Web.CommonAPI diff --git a/test/web/http_sigs/http_sig_test.exs b/test/web/http_sigs/http_sig_test.exs index 74d86a9e1..c4d2eaf78 100644 --- a/test/web/http_sigs/http_sig_test.exs +++ b/test/web/http_sigs/http_sig_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  # http signatures  # Test data from https://tools.ietf.org/html/draft-cavage-http-signatures-08#appendix-C  defmodule Pleroma.Web.HTTPSignaturesTest do diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index fec97c700..d53e11963 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.MastodonAPI.AccountViewTest do    use Pleroma.DataCase    import Pleroma.Factory diff --git a/test/web/mastodon_api/list_view_test.exs b/test/web/mastodon_api/list_view_test.exs index a12acc2b2..73143467f 100644 --- a/test/web/mastodon_api/list_view_test.exs +++ b/test/web/mastodon_api/list_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.MastodonAPI.ListViewTest do    use Pleroma.DataCase    import Pleroma.Factory diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index aec0f851c..0136acf8c 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do    use Pleroma.Web.ConnCase @@ -292,7 +296,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        assert %{} = json_response(conn, 200) -      assert Repo.get(Activity, activity.id) == nil +      refute Repo.get(Activity, activity.id)      end      test "when you didn't create it", %{conn: conn} do @@ -836,6 +840,26 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        assert [%{"id" => id}] = json_response(conn, 200)        assert id == to_string(image_post.id)      end + +    test "gets a user's statuses without reblogs", %{conn: conn} do +      user = insert(:user) +      {:ok, post} = CommonAPI.post(user, %{"status" => "HI!!!"}) +      {:ok, _, _} = CommonAPI.repeat(post.id, user) + +      conn = +        conn +        |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "true"}) + +      assert [%{"id" => id}] = json_response(conn, 200) +      assert id == to_string(post.id) + +      conn = +        conn +        |> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_reblogs" => "1"}) + +      assert [%{"id" => id}] = json_response(conn, 200) +      assert id == to_string(post.id) +    end    end    describe "user relationships" do diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index b7ac92760..b953ccd76 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.MastodonAPI.StatusViewTest do    use Pleroma.DataCase @@ -5,6 +9,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do    alias Pleroma.User    alias Pleroma.Web.OStatus    alias Pleroma.Web.CommonAPI +  alias Pleroma.Web.ActivityPub.ActivityPub +  alias Pleroma.Activity    import Pleroma.Factory    import Tesla.Mock @@ -157,6 +163,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      assert represented[:emojis] == []    end +  test "a peertube video" do +    user = insert(:user) + +    {:ok, object} = +      ActivityPub.fetch_object_from_id( +        "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" +      ) + +    %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"]) + +    represented = StatusView.render("status.json", %{for: user, activity: activity}) + +    assert represented[:id] == to_string(activity.id) +    assert length(represented[:media_attachments]) == 1 +  end +    describe "build_tags/1" do      test "it returns a a dictionary tags" do        object_tags = [ diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs index a5b0b7869..5981c70a7 100644 --- a/test/web/node_info_test.exs +++ b/test/web/node_info_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.NodeInfoTest do    use Pleroma.Web.ConnCase @@ -15,6 +19,17 @@ defmodule Pleroma.Web.NodeInfoTest do      assert user.ap_id in result["metadata"]["staffAccounts"]    end +  test "nodeinfo shows restricted nicknames", %{conn: conn} do +    conn = +      conn +      |> get("/nodeinfo/2.0.json") + +    assert result = json_response(conn, 200) + +    assert Pleroma.Config.get([Pleroma.User, :restricted_nicknames]) == +             result["metadata"]["restrictedNicknames"] +  end +    test "returns 404 when federation is disabled", %{conn: conn} do      instance =        Application.get_env(:pleroma, :instance) diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs index 2b7fb2fad..3b1ddada8 100644 --- a/test/web/oauth/authorization_test.exs +++ b/test/web/oauth/authorization_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OAuth.AuthorizationTest do    use Pleroma.DataCase    alias Pleroma.Web.OAuth.{Authorization, App} diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index 52441407d..ccd552258 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OAuth.OAuthControllerTest do    use Pleroma.Web.ConnCase    import Pleroma.Factory diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs index e36ca5abc..9a241d61a 100644 --- a/test/web/oauth/token_test.exs +++ b/test/web/oauth/token_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OAuth.TokenTest do    use Pleroma.DataCase    alias Pleroma.Web.OAuth.{App, Token, Authorization} diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index a351510d8..0869f2fd5 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do    use Pleroma.DataCase diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs index bf3feb14e..55717dec7 100644 --- a/test/web/ostatus/feed_representer_test.exs +++ b/test/web/ostatus/feed_representer_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OStatus.FeedRepresenterTest do    use Pleroma.DataCase    import Pleroma.Factory diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs index 1e041e5b0..c8fbff6cc 100644 --- a/test/web/ostatus/incoming_documents/delete_handling_test.exs +++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs @@ -25,7 +25,7 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do        refute Repo.get(Activity, note.id)        refute Repo.get(Activity, like.id) -      refute Object.get_by_ap_id(note.data["object"]["id"]) +      assert Object.get_by_ap_id(note.data["object"]["id"]).data["type"] == "Tombstone"        assert Repo.get(Activity, second_note.id)        assert Object.get_by_ap_id(second_note.data["object"]["id"]) diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 560305c15..995cc00d6 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -1,7 +1,11 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OStatus.OStatusControllerTest do    use Pleroma.Web.ConnCase    import Pleroma.Factory -  alias Pleroma.{User, Repo} +  alias Pleroma.{User, Repo, Object}    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.OStatus.ActivityRepresenter @@ -110,6 +114,22 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do      |> response(404)    end +  test "404s on deleted objects", %{conn: conn} do +    note_activity = insert(:note_activity) +    [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"])) +    object = Object.get_by_ap_id(note_activity.data["object"]["id"]) + +    conn +    |> get("/objects/#{uuid}") +    |> response(200) + +    Object.delete(object) + +    conn +    |> get("/objects/#{uuid}") +    |> response(404) +  end +    test "gets an activity", %{conn: conn} do      note_activity = insert(:note_activity)      [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index e577a6bee..403cc7095 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OStatusTest do    use Pleroma.DataCase    alias Pleroma.Web.OStatus diff --git a/test/web/ostatus/user_representer_test.exs b/test/web/ostatus/user_representer_test.exs index 82fb8e793..e3863d2e9 100644 --- a/test/web/ostatus/user_representer_test.exs +++ b/test/web/ostatus/user_representer_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.OStatus.UserRepresenterTest do    use Pleroma.DataCase    alias Pleroma.Web.OStatus.UserRepresenter diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs index 1455a1c46..612db7e32 100644 --- a/test/web/plugs/federating_plug_test.exs +++ b/test/web/plugs/federating_plug_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.FederatingPlugTest do    use Pleroma.Web.ConnCase diff --git a/test/web/retry_queue_test.exs b/test/web/retry_queue_test.exs index b5a6ab030..ecb3ce5d0 100644 --- a/test/web/retry_queue_test.exs +++ b/test/web/retry_queue_test.exs @@ -1,5 +1,10 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule MockActivityPub do -  def publish_one(ret) do +  def publish_one({ret, waiter}) do +    send(waiter, :complete)      {ret, "success"}    end  end @@ -11,21 +16,33 @@ defmodule Pleroma.Web.Federator.RetryQueueTest do    @small_retry_count 0    @hopeless_retry_count 10 +  setup do +    RetryQueue.reset_stats() +  end + +  test "RetryQueue responds to stats request" do +    assert %{delivered: 0, dropped: 0} == RetryQueue.get_stats() +  end +    test "failed posts are retried" do      {:retry, _timeout} = RetryQueue.get_retry_params(@small_retry_count) -    assert {:noreply, %{delivered: 1}} == -             RetryQueue.handle_info({:send, :ok, MockActivityPub, @small_retry_count}, %{ -               delivered: 0 -             }) +    wait_task = +      Task.async(fn -> +        receive do +          :complete -> :ok +        end +      end) + +    RetryQueue.enqueue({:ok, wait_task.pid}, MockActivityPub, @small_retry_count) +    Task.await(wait_task) +    assert %{delivered: 1, dropped: 0} == RetryQueue.get_stats()    end    test "posts that have been tried too many times are dropped" do      {:drop, _timeout} = RetryQueue.get_retry_params(@hopeless_retry_count) -    assert {:noreply, %{dropped: 1}} == -             RetryQueue.handle_cast({:maybe_enqueue, %{}, nil, @hopeless_retry_count}, %{ -               dropped: 0 -             }) +    RetryQueue.enqueue({:ok, nil}, MockActivityPub, @hopeless_retry_count) +    assert %{delivered: 0, dropped: 1} == RetryQueue.get_stats()    end  end diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs index 7e922ad83..c539a28b2 100644 --- a/test/web/salmon/salmon_test.exs +++ b/test/web/salmon/salmon_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.Salmon.SalmonTest do    use Pleroma.DataCase    alias Pleroma.Web.Salmon diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs index df58441f0..905e29d06 100644 --- a/test/web/streamer_test.exs +++ b/test/web/streamer_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.StreamerTest do    use Pleroma.DataCase diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index f6c60a744..2ac32aeb2 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do    use Pleroma.DataCase    alias Pleroma.{User, Activity, Object} diff --git a/test/web/twitter_api/representers/object_representer_test.exs b/test/web/twitter_api/representers/object_representer_test.exs index 228b2ac42..c3cf330f1 100644 --- a/test/web/twitter_api/representers/object_representer_test.exs +++ b/test/web/twitter_api/representers/object_representer_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do    use Pleroma.DataCase diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 1324bcc71..c41f615ac 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.TwitterAPI.ControllerTest do    use Pleroma.Web.ConnCase    alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter @@ -108,6 +112,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do    end    describe "GET /statuses/public_timeline.json" do +    setup [:valid_user] +      test "returns statuses", %{conn: conn} do        user = insert(:user)        activities = ActivityBuilder.insert_list(30, %{}, %{user: user}) @@ -141,14 +147,44 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        Application.put_env(:pleroma, :instance, instance)      end +    test "returns 200 to authenticated request when the instance is not public", +         %{conn: conn, user: user} do +      instance = +        Application.get_env(:pleroma, :instance) +        |> Keyword.put(:public, false) + +      Application.put_env(:pleroma, :instance, instance) + +      conn +      |> with_credentials(user.nickname, "test") +      |> get("/api/statuses/public_timeline.json") +      |> json_response(200) + +      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", %{conn: conn} do        conn        |> get("/api/statuses/public_timeline.json")        |> json_response(200)      end + +    test "returns 200 to authenticated request when the instance is public", +         %{conn: conn, user: user} do +      conn +      |> with_credentials(user.nickname, "test") +      |> get("/api/statuses/public_timeline.json") +      |> json_response(200) +    end    end    describe "GET /statuses/public_and_external_timeline.json" do +    setup [:valid_user] +      test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do        instance =          Application.get_env(:pleroma, :instance) @@ -167,11 +203,39 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        Application.put_env(:pleroma, :instance, instance)      end +    test "returns 200 to authenticated request when the instance is not public", +         %{conn: conn, user: user} do +      instance = +        Application.get_env(:pleroma, :instance) +        |> Keyword.put(:public, false) + +      Application.put_env(:pleroma, :instance, instance) + +      conn +      |> with_credentials(user.nickname, "test") +      |> get("/api/statuses/public_and_external_timeline.json") +      |> json_response(200) + +      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", %{conn: conn} do        conn        |> get("/api/statuses/public_and_external_timeline.json")        |> json_response(200)      end + +    test "returns 200 to authenticated request when the instance is public", +         %{conn: conn, user: user} do +      conn +      |> with_credentials(user.nickname, "test") +      |> get("/api/statuses/public_and_external_timeline.json") +      |> json_response(200) +    end    end    describe "GET /statuses/show/:id.json" do @@ -515,6 +579,34 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        assert length(response) == 1        assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user})      end + +    test "with credentials with user_id, excluding RTs", %{conn: conn, user: current_user} do +      user = insert(:user) +      {:ok, activity} = ActivityBuilder.insert(%{"id" => 1, "type" => "Create"}, %{user: user}) +      {:ok, _} = ActivityBuilder.insert(%{"id" => 2, "type" => "Announce"}, %{user: user}) + +      conn = +        conn +        |> with_credentials(current_user.nickname, "test") +        |> get("/api/statuses/user_timeline.json", %{ +          "user_id" => user.id, +          "include_rts" => "false" +        }) + +      response = json_response(conn, 200) + +      assert length(response) == 1 +      assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user}) + +      conn = +        conn +        |> get("/api/statuses/user_timeline.json", %{"user_id" => user.id, "include_rts" => "0"}) + +      response = json_response(conn, 200) + +      assert length(response) == 1 +      assert Enum.at(response, 0) == ActivityRepresenter.to_map(activity, %{user: user}) +    end    end    describe "POST /friendships/create.json" do @@ -1053,6 +1145,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do      end    end +  describe "GET /api/statuses/blocks" do +    test "it returns the list of users blocked by requester", %{conn: conn} do +      user = insert(:user) +      other_user = insert(:user) + +      {:ok, user} = User.block(user, other_user) + +      conn = +        conn +        |> assign(:user, user) +        |> get("/api/statuses/blocks") + +      expected = UserView.render("index.json", %{users: [other_user], for: user}) +      result = json_response(conn, 200) +      assert Enum.sort(expected) == Enum.sort(result) +    end +  end +    describe "GET /api/statuses/friends" do      test "it returns the logged in user's friends", %{conn: conn} do        user = insert(:user) diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index b7c89b605..b9feb23d4 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    use Pleroma.DataCase    alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs new file mode 100644 index 000000000..73aa70bd5 --- /dev/null +++ b/test/web/twitter_api/util_controller_test.exs @@ -0,0 +1,35 @@ +defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do +  use Pleroma.Web.ConnCase + +  import Pleroma.Factory + +  describe "POST /api/pleroma/follow_import" do +    test "it returns HTTP 200", %{conn: conn} do +      user1 = insert(:user) +      user2 = insert(:user) + +      response = +        conn +        |> assign(:user, user1) +        |> post("/api/pleroma/follow_import", %{"list" => "#{user2.ap_id}"}) +        |> json_response(:ok) + +      assert response == "job started" +    end +  end + +  describe "POST /api/pleroma/blocks_import" do +    test "it returns HTTP 200", %{conn: conn} do +      user1 = insert(:user) +      user2 = insert(:user) + +      response = +        conn +        |> assign(:user, user1) +        |> post("/api/pleroma/blocks_import", %{"list" => "#{user2.ap_id}"}) +        |> json_response(:ok) + +      assert response == "job started" +    end +  end +end diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 8aa9e3130..013245033 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do    use Pleroma.DataCase @@ -12,6 +16,13 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do    alias Pleroma.Web.ActivityPub.ActivityPub    import Pleroma.Factory +  import Tesla.Mock + +  setup do +    mock(fn env -> apply(HttpRequestMock, :request, [env]) end) +    :ok +  end +    import Mock    test "a create activity with a html status" do @@ -258,4 +269,18 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do      assert result == expected    end + +  test "a peertube video" do +    {:ok, object} = +      ActivityPub.fetch_object_from_id( +        "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" +      ) + +    %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"]) + +    result = ActivityView.render("activity.json", activity: activity) + +    assert length(result["attachments"]) == 1 +    assert result["summary"] == "Friday Night" +  end  end diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs index fcf2b3d90..8367fc6c7 100644 --- a/test/web/twitter_api/views/notification_view_test.exs +++ b/test/web/twitter_api/views/notification_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do    use Pleroma.DataCase diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 0adc69ff9..5f7481eb6 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.TwitterAPI.UserViewTest do    use Pleroma.DataCase @@ -86,7 +90,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "follows_you" => false,        "statusnet_blocking" => false,        "rights" => %{ -        "delete_others_notice" => false +        "delete_others_notice" => false, +        "admin" => false        },        "statusnet_profile_url" => user.ap_id,        "cover_photo" => banner, @@ -131,7 +136,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "follows_you" => false,        "statusnet_blocking" => false,        "rights" => %{ -        "delete_others_notice" => false +        "delete_others_notice" => false, +        "admin" => false        },        "statusnet_profile_url" => user.ap_id,        "cover_photo" => banner, @@ -177,7 +183,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "follows_you" => true,        "statusnet_blocking" => false,        "rights" => %{ -        "delete_others_notice" => false +        "delete_others_notice" => false, +        "admin" => false        },        "statusnet_profile_url" => follower.ap_id,        "cover_photo" => banner, @@ -203,6 +210,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do      assert represented["rights"]["delete_others_notice"]    end +  test "a user that is a admin" do +    user = insert(:user, %{info: %{is_admin: true}}) +    represented = UserView.render("show.json", %{user: user, for: user}) + +    assert represented["rights"]["admin"] +  end +    test "A blocked user for the blocker" do      user = insert(:user)      blocker = insert(:user) @@ -230,7 +244,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "follows_you" => false,        "statusnet_blocking" => true,        "rights" => %{ -        "delete_others_notice" => false +        "delete_others_notice" => false, +        "admin" => false        },        "statusnet_profile_url" => user.ap_id,        "cover_photo" => banner, diff --git a/test/web/views/error_view_test.exs b/test/web/views/error_view_test.exs index 1d443b187..16a0c8cef 100644 --- a/test/web/views/error_view_test.exs +++ b/test/web/views/error_view_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.ErrorViewTest do    use Pleroma.Web.ConnCase, async: true diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs index 844ff51d2..43fccfc7a 100644 --- a/test/web/web_finger/web_finger_controller_test.exs +++ b/test/web/web_finger/web_finger_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do    use Pleroma.Web.ConnCase diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs index 32eff9b7c..6b20d8d56 100644 --- a/test/web/web_finger/web_finger_test.exs +++ b/test/web/web_finger/web_finger_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.WebFingerTest do    use Pleroma.DataCase    alias Pleroma.Web.WebFinger diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index d861c241f..9cbcda063 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.Websub.WebsubControllerTest do    use Pleroma.Web.ConnCase    import Pleroma.Factory diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index fd559743f..9751d161d 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.Web.WebsubTest do    use Pleroma.DataCase    alias Pleroma.Web.Websub diff --git a/test/xml_builder_test.exs b/test/xml_builder_test.exs index 4be7bbd01..a7742f339 100644 --- a/test/xml_builder_test.exs +++ b/test/xml_builder_test.exs @@ -1,3 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only +  defmodule Pleroma.XmlBuilderTest do    use Pleroma.DataCase    alias Pleroma.XmlBuilder  | 
