From 22fc271e23a5dd1570ea7429b563f6edc42613c4 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 6 Dec 2019 09:32:29 +0300 Subject: init tag feed --- test/emails/admin_email_test.exs | 4 +- test/user_test.exs | 4 +- test/web/feed/feed_controller_test.exs | 251 --------------------------------- test/web/feed/tag_controller_test.exs | 31 ++++ test/web/feed/user_controller_test.exs | 251 +++++++++++++++++++++++++++++++++ 5 files changed, 286 insertions(+), 255 deletions(-) delete mode 100644 test/web/feed/feed_controller_test.exs create mode 100644 test/web/feed/tag_controller_test.exs create mode 100644 test/web/feed/user_controller_test.exs (limited to 'test') diff --git a/test/emails/admin_email_test.exs b/test/emails/admin_email_test.exs index ad89f9213..383cc3459 100644 --- a/test/emails/admin_email_test.exs +++ b/test/emails/admin_email_test.exs @@ -19,8 +19,8 @@ defmodule Pleroma.Emails.AdminEmailTest do AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment") status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12") - reporter_url = Helpers.feed_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id) - account_url = Helpers.feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id) + reporter_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.id) + account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id) assert res.to == [{to_user.name, to_user.email}] assert res.from == {config[:name], config[:notify_email]} diff --git a/test/user_test.exs b/test/user_test.exs index bfa8faafa..7b0842e24 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -548,7 +548,7 @@ defmodule Pleroma.UserTest do user = insert(:user) assert User.ap_id(user) == - Pleroma.Web.Router.Helpers.feed_url( + Pleroma.Web.Router.Helpers.user_feed_url( Pleroma.Web.Endpoint, :feed_redirect, user.nickname @@ -559,7 +559,7 @@ defmodule Pleroma.UserTest do user = insert(:user) assert User.ap_followers(user) == - Pleroma.Web.Router.Helpers.feed_url( + Pleroma.Web.Router.Helpers.user_feed_url( Pleroma.Web.Endpoint, :feed_redirect, user.nickname diff --git a/test/web/feed/feed_controller_test.exs b/test/web/feed/feed_controller_test.exs deleted file mode 100644 index 6f61acf43..000000000 --- a/test/web/feed/feed_controller_test.exs +++ /dev/null @@ -1,251 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.Feed.FeedControllerTest do - use Pleroma.Web.ConnCase - - import Pleroma.Factory - import SweetXml - - alias Pleroma.Object - alias Pleroma.User - - clear_config([:feed]) - - test "gets a feed", %{conn: conn} do - Pleroma.Config.put( - [:feed, :post_title], - %{max_length: 10, omission: "..."} - ) - - activity = insert(:note_activity) - - note = - insert(:note, - data: %{ - "content" => "This is :moominmamma: note ", - "attachment" => [ - %{ - "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}] - } - ], - "inReplyTo" => activity.data["id"] - } - ) - - note_activity = insert(:note_activity, note: note) - user = User.get_cached_by_ap_id(note_activity.data["actor"]) - - note2 = - insert(:note, - user: user, - data: %{"content" => "42 This is :moominmamma: note ", "inReplyTo" => activity.data["id"]} - ) - - _note_activity2 = insert(:note_activity, note: note2) - object = Object.normalize(note_activity) - - resp = - conn - |> put_req_header("content-type", "application/atom+xml") - |> get("/users/#{user.nickname}/feed.atom") - |> response(200) - - activity_titles = - resp - |> SweetXml.parse() - |> SweetXml.xpath(~x"//entry/title/text()"l) - - assert activity_titles == ['42 This...', 'This is...'] - assert resp =~ object.data["content"] - end - - test "returns 404 for a missing feed", %{conn: conn} do - conn = - conn - |> put_req_header("content-type", "application/atom+xml") - |> get("/users/nonexisting/feed.atom") - - assert response(conn, 404) - end - - describe "feed_redirect" do - test "undefined format. it redirects to feed", %{conn: conn} do - note_activity = insert(:note_activity) - user = User.get_cached_by_ap_id(note_activity.data["actor"]) - - response = - conn - |> put_req_header("accept", "application/xml") - |> get("/users/#{user.nickname}") - |> response(302) - - assert response == - "You are being redirected." - end - - test "undefined format. it returns error when user not found", %{conn: conn} do - response = - conn - |> put_req_header("accept", "application/xml") - |> get("/users/jimm") - |> response(404) - - assert response == ~S({"error":"Not found"}) - end - - test "activity+json format. it redirects on actual feed of user", %{conn: conn} do - note_activity = insert(:note_activity) - user = User.get_cached_by_ap_id(note_activity.data["actor"]) - - response = - conn - |> put_req_header("accept", "application/activity+json") - |> get("/users/#{user.nickname}") - |> json_response(200) - - assert response["endpoints"] == %{ - "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize", - "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps", - "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token", - "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox", - "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media" - } - - assert response["@context"] == [ - "https://www.w3.org/ns/activitystreams", - "http://localhost:4001/schemas/litepub-0.1.jsonld", - %{"@language" => "und"} - ] - - assert Map.take(response, [ - "followers", - "following", - "id", - "inbox", - "manuallyApprovesFollowers", - "name", - "outbox", - "preferredUsername", - "summary", - "tag", - "type", - "url" - ]) == %{ - "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers", - "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following", - "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}", - "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox", - "manuallyApprovesFollowers" => false, - "name" => user.name, - "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox", - "preferredUsername" => user.nickname, - "summary" => user.bio, - "tag" => [], - "type" => "Person", - "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}" - } - end - - test "activity+json format. it returns error whe use not found", %{conn: conn} do - response = - conn - |> put_req_header("accept", "application/activity+json") - |> get("/users/jimm") - |> json_response(404) - - assert response == "Not found" - end - - test "json format. it redirects on actual feed of user", %{conn: conn} do - note_activity = insert(:note_activity) - user = User.get_cached_by_ap_id(note_activity.data["actor"]) - - response = - conn - |> put_req_header("accept", "application/json") - |> get("/users/#{user.nickname}") - |> json_response(200) - - assert response["endpoints"] == %{ - "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize", - "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps", - "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token", - "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox", - "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media" - } - - assert response["@context"] == [ - "https://www.w3.org/ns/activitystreams", - "http://localhost:4001/schemas/litepub-0.1.jsonld", - %{"@language" => "und"} - ] - - assert Map.take(response, [ - "followers", - "following", - "id", - "inbox", - "manuallyApprovesFollowers", - "name", - "outbox", - "preferredUsername", - "summary", - "tag", - "type", - "url" - ]) == %{ - "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers", - "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following", - "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}", - "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox", - "manuallyApprovesFollowers" => false, - "name" => user.name, - "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox", - "preferredUsername" => user.nickname, - "summary" => user.bio, - "tag" => [], - "type" => "Person", - "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}" - } - end - - test "json format. it returns error whe use not found", %{conn: conn} do - response = - conn - |> put_req_header("accept", "application/json") - |> get("/users/jimm") - |> json_response(404) - - assert response == "Not found" - end - - test "html format. it redirects on actual feed of user", %{conn: conn} do - note_activity = insert(:note_activity) - user = User.get_cached_by_ap_id(note_activity.data["actor"]) - - response = - conn - |> get("/users/#{user.nickname}") - |> response(200) - - assert response == - Fallback.RedirectController.redirector_with_meta( - conn, - %{user: user} - ).resp_body - end - - test "html format. it returns error when user not found", %{conn: conn} do - response = - conn - |> get("/users/jimm") - |> json_response(404) - - assert response == %{"error" => "Not found"} - end - end -end diff --git a/test/web/feed/tag_controller_test.exs b/test/web/feed/tag_controller_test.exs new file mode 100644 index 000000000..82115f811 --- /dev/null +++ b/test/web/feed/tag_controller_test.exs @@ -0,0 +1,31 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Feed.TagControllerTest do + use Pleroma.Web.ConnCase + + import Pleroma.Factory + + clear_config([:feed]) + + test "gets a feed", %{conn: conn} do + Pleroma.Config.put( + [:feed, :post_title], + %{max_length: 10, omission: "..."} + ) + + user = insert(:user) + {:ok, _activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"}) + + {:ok, _activity2} = + Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"}) + + {:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"}) + + assert conn + |> put_req_header("content-type", "application/atom+xml") + |> get("/tags/pleromaart.rss") + |> response(200) + end +end diff --git a/test/web/feed/user_controller_test.exs b/test/web/feed/user_controller_test.exs new file mode 100644 index 000000000..e4386ff2c --- /dev/null +++ b/test/web/feed/user_controller_test.exs @@ -0,0 +1,251 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Feed.UserControllerTest do + use Pleroma.Web.ConnCase + + import Pleroma.Factory + import SweetXml + + alias Pleroma.Object + alias Pleroma.User + + clear_config([:feed]) + + test "gets a feed", %{conn: conn} do + Pleroma.Config.put( + [:feed, :post_title], + %{max_length: 10, omission: "..."} + ) + + activity = insert(:note_activity) + + note = + insert(:note, + data: %{ + "content" => "This is :moominmamma: note ", + "attachment" => [ + %{ + "url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}] + } + ], + "inReplyTo" => activity.data["id"] + } + ) + + note_activity = insert(:note_activity, note: note) + user = User.get_cached_by_ap_id(note_activity.data["actor"]) + + note2 = + insert(:note, + user: user, + data: %{"content" => "42 This is :moominmamma: note ", "inReplyTo" => activity.data["id"]} + ) + + _note_activity2 = insert(:note_activity, note: note2) + object = Object.normalize(note_activity) + + resp = + conn + |> put_req_header("content-type", "application/atom+xml") + |> get("/users/#{user.nickname}/feed.atom") + |> response(200) + + activity_titles = + resp + |> SweetXml.parse() + |> SweetXml.xpath(~x"//entry/title/text()"l) + + assert activity_titles == ['42 This...', 'This is...'] + assert resp =~ object.data["content"] + end + + test "returns 404 for a missing feed", %{conn: conn} do + conn = + conn + |> put_req_header("content-type", "application/atom+xml") + |> get("/users/nonexisting/feed.atom") + + assert response(conn, 404) + end + + describe "feed_redirect" do + test "undefined format. it redirects to feed", %{conn: conn} do + note_activity = insert(:note_activity) + user = User.get_cached_by_ap_id(note_activity.data["actor"]) + + response = + conn + |> put_req_header("accept", "application/xml") + |> get("/users/#{user.nickname}") + |> response(302) + + assert response == + "You are being redirected." + end + + test "undefined format. it returns error when user not found", %{conn: conn} do + response = + conn + |> put_req_header("accept", "application/xml") + |> get("/users/jimm") + |> response(404) + + assert response == ~S({"error":"Not found"}) + end + + test "activity+json format. it redirects on actual feed of user", %{conn: conn} do + note_activity = insert(:note_activity) + user = User.get_cached_by_ap_id(note_activity.data["actor"]) + + response = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/users/#{user.nickname}") + |> json_response(200) + + assert response["endpoints"] == %{ + "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize", + "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps", + "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token", + "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox", + "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media" + } + + assert response["@context"] == [ + "https://www.w3.org/ns/activitystreams", + "http://localhost:4001/schemas/litepub-0.1.jsonld", + %{"@language" => "und"} + ] + + assert Map.take(response, [ + "followers", + "following", + "id", + "inbox", + "manuallyApprovesFollowers", + "name", + "outbox", + "preferredUsername", + "summary", + "tag", + "type", + "url" + ]) == %{ + "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers", + "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following", + "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}", + "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox", + "manuallyApprovesFollowers" => false, + "name" => user.name, + "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox", + "preferredUsername" => user.nickname, + "summary" => user.bio, + "tag" => [], + "type" => "Person", + "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}" + } + end + + test "activity+json format. it returns error whe use not found", %{conn: conn} do + response = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/users/jimm") + |> json_response(404) + + assert response == "Not found" + end + + test "json format. it redirects on actual feed of user", %{conn: conn} do + note_activity = insert(:note_activity) + user = User.get_cached_by_ap_id(note_activity.data["actor"]) + + response = + conn + |> put_req_header("accept", "application/json") + |> get("/users/#{user.nickname}") + |> json_response(200) + + assert response["endpoints"] == %{ + "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize", + "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps", + "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token", + "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox", + "uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media" + } + + assert response["@context"] == [ + "https://www.w3.org/ns/activitystreams", + "http://localhost:4001/schemas/litepub-0.1.jsonld", + %{"@language" => "und"} + ] + + assert Map.take(response, [ + "followers", + "following", + "id", + "inbox", + "manuallyApprovesFollowers", + "name", + "outbox", + "preferredUsername", + "summary", + "tag", + "type", + "url" + ]) == %{ + "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers", + "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following", + "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}", + "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox", + "manuallyApprovesFollowers" => false, + "name" => user.name, + "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox", + "preferredUsername" => user.nickname, + "summary" => user.bio, + "tag" => [], + "type" => "Person", + "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}" + } + end + + test "json format. it returns error whe use not found", %{conn: conn} do + response = + conn + |> put_req_header("accept", "application/json") + |> get("/users/jimm") + |> json_response(404) + + assert response == "Not found" + end + + test "html format. it redirects on actual feed of user", %{conn: conn} do + note_activity = insert(:note_activity) + user = User.get_cached_by_ap_id(note_activity.data["actor"]) + + response = + conn + |> get("/users/#{user.nickname}") + |> response(200) + + assert response == + Fallback.RedirectController.redirector_with_meta( + conn, + %{user: user} + ).resp_body + end + + test "html format. it returns error when user not found", %{conn: conn} do + response = + conn + |> get("/users/jimm") + |> json_response(404) + + assert response == %{"error" => "Not found"} + end + end +end -- cgit v1.2.3 From eb11c6028973b945361095d3f4791ac6f61379a9 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Fri, 13 Dec 2019 19:00:26 +0300 Subject: Disable rate limiter for socket/localhost (unless RemoteIp is enabled) --- test/plugs/rate_limiter_test.exs | 35 ++++++++++++++++++++++ .../controllers/account_controller_test.exs | 1 + 2 files changed, 36 insertions(+) (limited to 'test') diff --git a/test/plugs/rate_limiter_test.exs b/test/plugs/rate_limiter_test.exs index 49f63c424..f3343abca 100644 --- a/test/plugs/rate_limiter_test.exs +++ b/test/plugs/rate_limiter_test.exs @@ -16,6 +16,7 @@ defmodule Pleroma.Plugs.RateLimiterTest do test "config is required for plug to work" do limiter_name = :test_init Pleroma.Config.put([:rate_limit, limiter_name], {1, 1}) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8}) assert %{limits: {1, 1}, name: :test_init, opts: [name: :test_init]} == RateLimiter.init(name: limiter_name) @@ -23,11 +24,39 @@ defmodule Pleroma.Plugs.RateLimiterTest do assert nil == RateLimiter.init(name: :foo) end + test "it is disabled for localhost" do + limiter_name = :test_init + Pleroma.Config.put([:rate_limit, limiter_name], {1, 1}) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {127, 0, 0, 1}) + Pleroma.Config.put([Pleroma.Plugs.RemoteIp, :enabled], false) + + assert RateLimiter.disabled?() == true + end + + test "it is disabled for socket" do + limiter_name = :test_init + Pleroma.Config.put([:rate_limit, limiter_name], {1, 1}) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {:local, "/path/to/pleroma.sock"}) + Pleroma.Config.put([Pleroma.Plugs.RemoteIp, :enabled], false) + + assert RateLimiter.disabled?() == true + end + + test "it is enabled for socket when remote ip is enabled" do + limiter_name = :test_init + Pleroma.Config.put([:rate_limit, limiter_name], {1, 1}) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {:local, "/path/to/pleroma.sock"}) + Pleroma.Config.put([Pleroma.Plugs.RemoteIp, :enabled], true) + + assert RateLimiter.disabled?() == false + end + test "it restricts based on config values" do limiter_name = :test_opts scale = 80 limit = 5 + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8}) Pleroma.Config.put([:rate_limit, limiter_name], {scale, limit}) opts = RateLimiter.init(name: limiter_name) @@ -61,6 +90,7 @@ defmodule Pleroma.Plugs.RateLimiterTest do limiter_name = :test_bucket_name Pleroma.Config.put([:rate_limit, limiter_name], {1000, 5}) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8}) base_bucket_name = "#{limiter_name}:group1" opts = RateLimiter.init(name: limiter_name, bucket_name: base_bucket_name) @@ -75,6 +105,7 @@ defmodule Pleroma.Plugs.RateLimiterTest do test "`params` option allows different queries to be tracked independently" do limiter_name = :test_params Pleroma.Config.put([:rate_limit, limiter_name], {1000, 5}) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8}) opts = RateLimiter.init(name: limiter_name, params: ["id"]) @@ -90,6 +121,7 @@ defmodule Pleroma.Plugs.RateLimiterTest do test "it supports combination of options modifying bucket name" do limiter_name = :test_options_combo Pleroma.Config.put([:rate_limit, limiter_name], {1000, 5}) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8}) base_bucket_name = "#{limiter_name}:group1" opts = RateLimiter.init(name: limiter_name, bucket_name: base_bucket_name, params: ["id"]) @@ -109,6 +141,7 @@ defmodule Pleroma.Plugs.RateLimiterTest do test "are restricted based on remote IP" do limiter_name = :test_unauthenticated Pleroma.Config.put([:rate_limit, limiter_name], [{1000, 5}, {1, 10}]) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8}) opts = RateLimiter.init(name: limiter_name) @@ -147,6 +180,7 @@ defmodule Pleroma.Plugs.RateLimiterTest do scale = 1000 limit = 5 + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8}) Pleroma.Config.put([:rate_limit, limiter_name], [{1, 10}, {scale, limit}]) opts = RateLimiter.init(name: limiter_name) @@ -179,6 +213,7 @@ defmodule Pleroma.Plugs.RateLimiterTest do test "diffrerent users are counted independently" do limiter_name = :test_authenticated Pleroma.Config.put([:rate_limit, limiter_name], [{1, 10}, {1000, 5}]) + Pleroma.Config.put([Pleroma.Web.Endpoint, :http, :ip], {8, 8, 8, 8}) opts = RateLimiter.init(name: limiter_name) diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index fa08ae4df..14d97e248 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -766,6 +766,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do end test "rate limit", %{conn: conn} do + Pleroma.Config.put([Pleroma.Plugs.RemoteIp, :enabled], true) app_token = insert(:oauth_token, user: nil) conn = -- cgit v1.2.3 From b53573a837e606ef3536ec338510cadacab55d7c Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Tue, 17 Dec 2019 22:13:45 +0300 Subject: add tag feeds --- test/web/feed/tag_controller_test.exs | 72 +++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/web/feed/tag_controller_test.exs b/test/web/feed/tag_controller_test.exs index 82115f811..e9b58c8cd 100644 --- a/test/web/feed/tag_controller_test.exs +++ b/test/web/feed/tag_controller_test.exs @@ -6,26 +6,84 @@ defmodule Pleroma.Web.Feed.TagControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory + import SweetXml + + alias Pleroma.Web.Feed.FeedView clear_config([:feed]) test "gets a feed", %{conn: conn} do Pleroma.Config.put( [:feed, :post_title], - %{max_length: 10, omission: "..."} + %{max_length: 25, omission: "..."} ) user = insert(:user) - {:ok, _activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"}) + {:ok, activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"}) + + object = Pleroma.Object.normalize(activity1) + + object_data = + Map.put(object.data, "attachment", [ + %{ + "url" => [ + %{ + "href" => + "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", + "mediaType" => "video/mp4", + "type" => "Link" + } + ] + } + ]) + + object + |> Ecto.Changeset.change(data: object_data) + |> Pleroma.Repo.update() - {:ok, _activity2} = + {:ok, activity2} = Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"}) {:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"}) - assert conn - |> put_req_header("content-type", "application/atom+xml") - |> get("/tags/pleromaart.rss") - |> response(200) + response = + conn + |> put_req_header("content-type", "application/atom+xml") + |> get("/tags/pleromaart.rss") + |> response(200) + + xml = parse(response) + assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart' + + assert xpath(xml, ~x"//channel/description/text()"s) == + "These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse." + + assert xpath(xml, ~x"//channel/link/text()") == + '#{Pleroma.Web.base_url()}/tags/pleromaart.rss' + + assert xpath(xml, ~x"//channel/webfeeds:logo/text()") == + '#{Pleroma.Web.base_url()}/static/logo.png' + + assert xpath(xml, ~x"//channel/item/title/text()"l) == [ + '42 This is :moominmamm...', + 'yeah #PleromaArt' + ] + + assert xpath(xml, ~x"//channel/item/pubDate/text()"sl) == [ + FeedView.pub_date(activity1.data["published"]), + FeedView.pub_date(activity2.data["published"]) + ] + + assert xpath(xml, ~x"//channel/item/enclosure/@url"sl) == [ + "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4" + ] + + obj1 = Pleroma.Object.normalize(activity1) + obj2 = Pleroma.Object.normalize(activity2) + + assert xpath(xml, ~x"//channel/item/description/text()"sl) == [ + HtmlEntities.decode(FeedView.activity_content(obj2)), + HtmlEntities.decode(FeedView.activity_content(obj1)) + ] end end -- cgit v1.2.3 From 969769730e0b7578ddc6a5cd02f9b24eff5902a0 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Mon, 23 Dec 2019 17:12:55 +0300 Subject: update tests --- test/web/feed/tag_controller_test.exs | 2 +- test/web/feed/user_controller_test.exs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/feed/tag_controller_test.exs b/test/web/feed/tag_controller_test.exs index e9b58c8cd..efc588070 100644 --- a/test/web/feed/tag_controller_test.exs +++ b/test/web/feed/tag_controller_test.exs @@ -49,7 +49,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do response = conn |> put_req_header("content-type", "application/atom+xml") - |> get("/tags/pleromaart.rss") + |> get(tag_feed_path(conn, :feed, "pleromaart.rss")) |> response(200) xml = parse(response) diff --git a/test/web/feed/user_controller_test.exs b/test/web/feed/user_controller_test.exs index e4386ff2c..41cc9e07e 100644 --- a/test/web/feed/user_controller_test.exs +++ b/test/web/feed/user_controller_test.exs @@ -49,7 +49,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do resp = conn |> put_req_header("content-type", "application/atom+xml") - |> get("/users/#{user.nickname}/feed.atom") + |> get(user_feed_path(conn, :feed, user.nickname)) |> response(200) activity_titles = @@ -65,7 +65,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do conn = conn |> put_req_header("content-type", "application/atom+xml") - |> get("/users/nonexisting/feed.atom") + |> get(user_feed_path(conn, :feed, "nonexisting")) assert response(conn, 404) end @@ -91,7 +91,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do response = conn |> put_req_header("accept", "application/xml") - |> get("/users/jimm") + |> get(user_feed_path(conn, :feed, "jimm")) |> response(404) assert response == ~S({"error":"Not found"}) -- cgit v1.2.3 From 108a39c8766402dcbd0235d8746e2100a18e5813 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 17 Jan 2020 14:55:36 +0300 Subject: updated error messages for authentication process --- test/user_test.exs | 36 ++++++++++++++-------- test/web/oauth/oauth_controller_test.exs | 51 +++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 9da1e02a9..158f98e66 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -1286,23 +1286,35 @@ defmodule Pleroma.UserTest do end end - test "auth_active?/1 works correctly" do - Pleroma.Config.put([:instance, :account_activation_required], true) + describe "account_status/1" do + clear_config([:instance, :account_activation_required]) - local_user = insert(:user, local: true, confirmation_pending: true) - confirmed_user = insert(:user, local: true, confirmation_pending: false) - remote_user = insert(:user, local: false) + test "return confirmation_pending for unconfirm user" do + Pleroma.Config.put([:instance, :account_activation_required], true) + user = insert(:user, confirmation_pending: true) + assert User.account_status(user) == :confirmation_pending + end - refute User.auth_active?(local_user) - assert User.auth_active?(confirmed_user) - assert User.auth_active?(remote_user) + test "return active for confirmed user" do + Pleroma.Config.put([:instance, :account_activation_required], true) + user = insert(:user, confirmation_pending: false) + assert User.account_status(user) == :active + end - # also shows unactive for deactivated users + test "return active for remote user" do + user = insert(:user, local: false) + assert User.account_status(user) == :active + end - deactivated_but_confirmed = - insert(:user, local: true, confirmation_pending: false, deactivated: true) + test "returns :password_reset_pending for user with reset password" do + user = insert(:user, password_reset_pending: true) + assert User.account_status(user) == :password_reset_pending + end - refute User.auth_active?(deactivated_but_confirmed) + test "returns :deactivated for deactivated user" do + user = insert(:user, local: true, confirmation_pending: false, deactivated: true) + assert User.account_status(user) == :deactivated + end end describe "superuser?/1" do diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index 59f4674eb..adeff8e25 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -819,7 +819,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do |> User.confirmation_changeset(need_confirmation: true) |> User.update_and_set_cache() - refute Pleroma.User.auth_active?(user) + refute Pleroma.User.account_status(user) == :active app = insert(:oauth_app) @@ -849,7 +849,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do app = insert(:oauth_app) - conn = + resp = build_conn() |> post("/oauth/token", %{ "grant_type" => "password", @@ -858,10 +858,12 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do "client_id" => app.client_id, "client_secret" => app.client_secret }) + |> json_response(403) - assert resp = json_response(conn, 403) - assert %{"error" => _} = resp - refute Map.has_key?(resp, "access_token") + assert resp == %{ + "error" => "Your account is currently disabled", + "identifier" => "account_is_disabled" + } end test "rejects token exchange for user with password_reset_pending set to true" do @@ -875,7 +877,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do app = insert(:oauth_app, scopes: ["read", "write"]) - conn = + resp = build_conn() |> post("/oauth/token", %{ "grant_type" => "password", @@ -884,12 +886,41 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do "client_id" => app.client_id, "client_secret" => app.client_secret }) + |> json_response(403) - assert resp = json_response(conn, 403) + assert resp == %{ + "error" => "Password reset is required", + "identifier" => "password_reset_required" + } + end - assert resp["error"] == "Password reset is required" - assert resp["identifier"] == "password_reset_required" - refute Map.has_key?(resp, "access_token") + test "rejects token exchange for user with confirmation_pending set to true" do + Pleroma.Config.put([:instance, :account_activation_required], true) + password = "testpassword" + + user = + insert(:user, + password_hash: Comeonin.Pbkdf2.hashpwsalt(password), + confirmation_pending: true + ) + + app = insert(:oauth_app, scopes: ["read", "write"]) + + resp = + build_conn() + |> post("/oauth/token", %{ + "grant_type" => "password", + "username" => user.nickname, + "password" => password, + "client_id" => app.client_id, + "client_secret" => app.client_secret + }) + |> json_response(403) + + assert resp == %{ + "error" => "Your login is missing a confirmed e-mail address", + "identifier" => "missing_confirmed_email" + } end test "rejects an invalid authorization code" do -- cgit v1.2.3 From 615b72238eb41f631c43e85d40c423017e848044 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 22 Jan 2020 20:06:12 +0100 Subject: Notifications: Add emoji reaction notifications --- test/notification_test.exs | 12 ++++++++++ .../mastodon_api/views/notification_view_test.exs | 27 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index 9a1c2f2b5..04bf5b41a 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -15,6 +15,18 @@ defmodule Pleroma.NotificationTest do alias Pleroma.Web.Streamer describe "create_notifications" do + test "creates a notification for an emoji reaction" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "yeah"}) + {:ok, activity, _object} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") + + {:ok, [notification]} = Notification.create_notifications(activity) + + assert notification.user_id == user.id + end + test "notifies someone when they are directly addressed" do user = insert(:user) other_user = insert(:user) diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index ba1721e06..1fe83cb2c 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -134,4 +134,31 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do assert [expected] == NotificationView.render("index.json", %{notifications: [notification], for: follower}) end + + test "EmojiReaction notification" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"}) + {:ok, _activity, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") + + activity = Repo.get(Activity, activity.id) + + [notification] = Notification.for_user(user) + + assert notification + + expected = %{ + id: to_string(notification.id), + pleroma: %{is_seen: false}, + type: "pleroma:emoji_reaction", + emoji: "☕", + account: AccountView.render("show.json", %{user: other_user, for: user}), + status: StatusView.render("show.json", %{activity: activity, for: user}), + created_at: Utils.to_masto_date(notification.inserted_at) + } + + assert expected == + NotificationView.render("show.json", %{notification: notification, for: user}) + end end -- cgit v1.2.3 From 34fc0ca05362d2dfd69352e8f4004b26d39315ac Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 23 Jan 2020 12:34:34 +0100 Subject: Emoji reactions: Add sanity checks for the cache --- test/web/activity_pub/utils_test.exs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs index 586eb1d2f..211fa6c95 100644 --- a/test/web/activity_pub/utils_test.exs +++ b/test/web/activity_pub/utils_test.exs @@ -636,4 +636,17 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do assert updated_object.data["announcement_count"] == 1 end end + + describe "get_cached_emoji_reactions/1" do + test "returns the data or an emtpy list" do + object = insert(:note) + assert Utils.get_cached_emoji_reactions(object) == [] + + object = insert(:note, data: %{"reactions" => [["x", ["lain"]]]}) + assert Utils.get_cached_emoji_reactions(object) == [["x", ["lain"]]] + + object = insert(:note, data: %{"reactions" => %{}}) + assert Utils.get_cached_emoji_reactions(object) == [] + end + end end -- cgit v1.2.3 From 2bad25cf148bdd7853021a18303484d0ada93a40 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 23 Jan 2020 15:13:27 +0300 Subject: fix for migrate to db test --- test/tasks/config_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index 2e56e6cfe..e7bb6e714 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -25,11 +25,11 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do end test "error if file with custom settings doesn't exist" do - Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) + Mix.Tasks.Pleroma.Config.migrate_to_db("config/not_existance_config_file.exs") assert_receive {:mix_shell, :info, [ - "To migrate settings, you must define custom settings in config/test.secret.exs." + "To migrate settings, you must define custom settings in config/not_existance_config_file.exs." ]}, 15 end -- cgit v1.2.3 From 4344c5d5b99cedcd08e168650af2f641ef8c6f0b Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 23 Jan 2020 17:23:02 +0300 Subject: truncate config table on migrate to db task --- test/tasks/config_test.exs | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index 2e56e6cfe..f2c294140 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -34,21 +34,41 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do 15 end - test "settings are migrated to db" do - initial = Application.get_env(:quack, :level) - on_exit(fn -> Application.put_env(:quack, :level, initial) end) - assert Repo.all(ConfigDB) == [] + describe "migrate_to_db/1" do + setup do + initial = Application.get_env(:quack, :level) + on_exit(fn -> Application.put_env(:quack, :level, initial) end) + end + + test "settings are migrated to db" do + assert Repo.all(ConfigDB) == [] + + Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs") + + config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"}) + config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"}) + config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"}) + refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"}) + + assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]] + assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]] + assert ConfigDB.from_binary(config3.value) == :info + end - Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs") + test "config table is truncated before migration" do + ConfigDB.create(%{ + group: ":pleroma", + key: ":first_setting", + value: [key: "value", key2: ["Activity"]] + }) + + assert Repo.aggregate(ConfigDB, :count, :id) == 1 - config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"}) - config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"}) - config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"}) - refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"}) + Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs") - assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]] - assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]] - assert ConfigDB.from_binary(config3.value) == :info + config = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"}) + assert ConfigDB.from_binary(config.value) == [key: "value", key2: [Repo]] + end end describe "with deletion temp file" do -- cgit v1.2.3 From 6cd2e851d9d61ce82edf83ced79c9d4c613c0373 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 23 Jan 2020 18:21:29 +0300 Subject: parsing Swoosh modules --- test/config/config_db_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/config/config_db_test.exs b/test/config/config_db_test.exs index 61a0b1d5d..812709fd8 100644 --- a/test/config/config_db_test.exs +++ b/test/config/config_db_test.exs @@ -307,6 +307,15 @@ defmodule Pleroma.ConfigDBTest do assert ConfigDB.from_binary(binary) == Quack.Logger end + test "Swoosh.Adapters modules" do + binary = ConfigDB.transform("Swoosh.Adapters.SMTP") + assert binary == :erlang.term_to_binary(Swoosh.Adapters.SMTP) + assert ConfigDB.from_binary(binary) == Swoosh.Adapters.SMTP + binary = ConfigDB.transform("Swoosh.Adapters.AmazonSES") + assert binary == :erlang.term_to_binary(Swoosh.Adapters.AmazonSES) + assert ConfigDB.from_binary(binary) == Swoosh.Adapters.AmazonSES + end + test "sigil" do binary = ConfigDB.transform("~r[comp[lL][aA][iI][nN]er]") assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/) -- cgit v1.2.3 From 6a0f0ac4a2a4387fd08c723a917216238f5fe8b3 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Fri, 24 Jan 2020 12:22:26 +0300 Subject: fix for non existing atom --- test/config/transfer_task_test.exs | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'test') diff --git a/test/config/transfer_task_test.exs b/test/config/transfer_task_test.exs index b9072e0fc..53e8703fd 100644 --- a/test/config/transfer_task_test.exs +++ b/test/config/transfer_task_test.exs @@ -105,17 +105,4 @@ defmodule Pleroma.Config.TransferTaskTest do Application.put_env(:pleroma, :assets, assets) end) end - - test "non existing atom" do - ConfigDB.create(%{ - group: ":pleroma", - key: ":undefined_atom_key", - value: [live: 2, com: 3] - }) - - assert ExUnit.CaptureLog.capture_log(fn -> - TransferTask.start_link([]) - end) =~ - "updating env causes error, group: \":pleroma\" key: \":undefined_atom_key\" value: [live: 2, com: 3] error: %ArgumentError{message: \"argument error\"}" - end end -- cgit v1.2.3 From 347f3ed2c625c49588b62b2d743c8d06221eb14b Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 24 Jan 2020 10:52:24 +0100 Subject: Emoji reactions: Change api format once more --- test/web/mastodon_api/views/status_view_test.exs | 5 ++++- test/web/pleroma_api/controllers/pleroma_api_controller_test.exs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index 069bb8eac..25777b011 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -36,7 +36,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do activity = Repo.get(Activity, activity.id) status = StatusView.render("show.json", activity: activity) - assert status[:pleroma][:emoji_reactions] == [["☕", 2], ["🍵", 1]] + assert status[:pleroma][:emoji_reactions] == [ + %{emoji: "☕", count: 2}, + %{emoji: "🍵", count: 1} + ] end test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs index a79ecd05b..3978c2ec5 100644 --- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs +++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs @@ -71,7 +71,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by") |> json_response(200) - [["🎅", [represented_user]]] = result + [%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user]}] = result assert represented_user["id"] == other_user.id end -- cgit v1.2.3 From 99c0a11c584ac13c368a3d8372f9e914cef14a06 Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 24 Jan 2020 22:08:10 +0300 Subject: added atom feed --- test/web/feed/tag_controller_test.exs | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/feed/tag_controller_test.exs b/test/web/feed/tag_controller_test.exs index a56a18738..214698192 100644 --- a/test/web/feed/tag_controller_test.exs +++ b/test/web/feed/tag_controller_test.exs @@ -12,7 +12,60 @@ defmodule Pleroma.Web.Feed.TagControllerTest do clear_config([:feed]) - test "gets a feed", %{conn: conn} do + test "gets a feed (ATOM)", %{conn: conn} do + Pleroma.Config.put( + [:feed, :post_title], + %{max_length: 25, omission: "..."} + ) + + user = insert(:user) + {:ok, activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"}) + + object = Pleroma.Object.normalize(activity1) + + object_data = + Map.put(object.data, "attachment", [ + %{ + "url" => [ + %{ + "href" => + "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", + "mediaType" => "video/mp4", + "type" => "Link" + } + ] + } + ]) + + object + |> Ecto.Changeset.change(data: object_data) + |> Pleroma.Repo.update() + + {:ok, _activity2} = + Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"}) + + {:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"}) + + response = + conn + |> put_req_header("content-type", "application/atom+xml") + |> get(tag_feed_path(conn, :feed, "pleromaart.atom")) + |> response(200) + + xml = parse(response) + + assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart' + + assert xpath(xml, ~x"//feed/entry/title/text()"l) == [ + '42 This is :moominmamm...', + 'yeah #PleromaArt' + ] + + assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname] + assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id] + end + + test "gets a feed (RSS)", %{conn: conn} do Pleroma.Config.put( [:feed, :post_title], %{max_length: 25, omission: "..."} -- cgit v1.2.3 From dabd535e436789e64f6630460bfadd2f49dcf069 Mon Sep 17 00:00:00 2001 From: Hakaba Hitoyo Date: Mon, 27 Jan 2020 13:21:50 +0000 Subject: Remove user recommendation by third party engine --- .../controllers/suggestion_controller_test.exs | 45 +--------------------- 1 file changed, 1 insertion(+), 44 deletions(-) (limited to 'test') diff --git a/test/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/web/mastodon_api/controllers/suggestion_controller_test.exs index c4118a576..c288c2fff 100644 --- a/test/web/mastodon_api/controllers/suggestion_controller_test.exs +++ b/test/web/mastodon_api/controllers/suggestion_controller_test.exs @@ -36,11 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do [other_user: other_user] end - clear_config(:suggestions) - - test "returns empty result when suggestions disabled", %{conn: conn} do - Config.put([:suggestions, :enabled], false) - + test "returns empty result", %{conn: conn} do res = conn |> get("/api/v1/suggestions") @@ -48,43 +44,4 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do assert res == [] end - - test "returns error", %{conn: conn} do - Config.put([:suggestions, :enabled], true) - Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}") - - assert capture_log(fn -> - res = - conn - |> get("/api/v1/suggestions") - |> json_response(500) - - assert res == "Something went wrong" - end) =~ "Could not retrieve suggestions" - end - - test "returns suggestions", %{conn: conn, other_user: other_user} do - Config.put([:suggestions, :enabled], true) - Config.put([:suggestions, :third_party_engine], "http://test200?{{host}}&{{user}}") - - res = - conn - |> get("/api/v1/suggestions") - |> json_response(200) - - assert res == [ - %{ - "acct" => "yj455", - "avatar" => "https://social.heldscal.la/avatar/201.jpeg", - "avatar_static" => "https://social.heldscal.la/avatar/s/201.jpeg", - "id" => 0 - }, - %{ - "acct" => other_user.ap_id, - "avatar" => "https://social.heldscal.la/avatar/202.jpeg", - "avatar_static" => "https://social.heldscal.la/avatar/s/202.jpeg", - "id" => other_user.id - } - ] - end end -- cgit v1.2.3 From be926863a8c4aa322dde0969e33c6addba85593a Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Mon, 27 Jan 2020 21:20:33 +0300 Subject: fix test --- test/web/feed/tag_controller_test.exs | 2 +- test/web/mastodon_api/controllers/suggestion_controller_test.exs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/feed/tag_controller_test.exs b/test/web/feed/tag_controller_test.exs index 214698192..2aa1b9587 100644 --- a/test/web/feed/tag_controller_test.exs +++ b/test/web/feed/tag_controller_test.exs @@ -101,7 +101,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do response = conn - |> put_req_header("content-type", "application/atom+xml") + |> put_req_header("content-type", "application/rss+xml") |> get(tag_feed_path(conn, :feed, "pleromaart.rss")) |> response(200) diff --git a/test/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/web/mastodon_api/controllers/suggestion_controller_test.exs index c288c2fff..0319d3475 100644 --- a/test/web/mastodon_api/controllers/suggestion_controller_test.exs +++ b/test/web/mastodon_api/controllers/suggestion_controller_test.exs @@ -7,7 +7,6 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do alias Pleroma.Config - import ExUnit.CaptureLog import Pleroma.Factory import Tesla.Mock -- cgit v1.2.3 From 51283bf9964edbf130b2920153319135807a2655 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 28 Jan 2020 13:38:21 +0100 Subject: Formatter: Add a test for domain / username clashes --- test/formatter_test.exs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 087bdbcc2..37f8bb800 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -119,7 +119,20 @@ defmodule Pleroma.FormatterTest do end end - describe "add_user_links" do + describe "Formatter.linkify" do + test "correctly finds mentions that contain the domain name" do + _user = insert(:user, %{nickname: "lain"}) + _remote_user = insert(:user, %{nickname: "lain@lain.com", local: false}) + + text = "hey @lain@lain.com what's up" + + {_text, mentions, []} = Formatter.linkify(text) + [{username, user}] = mentions + + assert username == "@lain@lain.com" + assert user.nickname == "lain@lain.com" + end + test "gives a replacement for user links, using local nicknames in user links text" do text = "@gsimg According to @archa_eme_, that is @daggsy. Also hello @archaeme@archae.me" gsimg = insert(:user, %{nickname: "gsimg"}) -- cgit v1.2.3 From d18a2e4e360bd6e630101a7dd2f4ae0902ac43a1 Mon Sep 17 00:00:00 2001 From: Roman Chvanikov Date: Tue, 28 Jan 2020 17:22:24 +0300 Subject: Add test for custom base_url when deleting an attachment --- test/object_test.exs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test') diff --git a/test/object_test.exs b/test/object_test.exs index 9b4e6f0bf..c6b2bc399 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -177,6 +177,39 @@ defmodule Pleroma.ObjectTest do assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") end + + test "With custom base_url" do + Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + Pleroma.Config.put([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/") + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image.jpg"), + filename: "an_image.jpg" + } + + user = insert(:user) + + {:ok, %Object{} = attachment} = + Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id) + + %{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} = + note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}}) + + uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads]) + + path = href |> Path.dirname() |> Path.basename() + + assert {:ok, ["an_image.jpg"]} == File.ls("#{uploads_dir}/#{path}") + + Object.delete(note) + + ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker)) + + assert Object.get_by_id(attachment.id) == nil + + assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") + end end describe "normalizer" do -- cgit v1.2.3 From 2ddd1bb0887425effd1c59f358e1dc2c5b98f65c Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Tue, 28 Jan 2020 18:23:59 +0400 Subject: Fix compatibility with Elixir v1.10 --- test/runtime_test.exs | 2 +- test/support/http_request_mock.ex | 2 +- test/web/mastodon_api/controllers/suggestion_controller_test.exs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/runtime_test.exs b/test/runtime_test.exs index f7b6f23d4..6bde608ae 100644 --- a/test/runtime_test.exs +++ b/test/runtime_test.exs @@ -6,6 +6,6 @@ defmodule Pleroma.RuntimeTest do use ExUnit.Case, async: true test "it loads custom runtime modules" do - assert Code.ensure_compiled?(RuntimeModule) + assert {:module, RuntimeModule} == Code.ensure_compiled(RuntimeModule) end end diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex index f43de700d..ba3341327 100644 --- a/test/support/http_request_mock.ex +++ b/test/support/http_request_mock.ex @@ -19,7 +19,7 @@ defmodule HttpRequestMock do else error -> with {:error, message} <- error do - Logger.warn(message) + Logger.warn(to_string(message)) end {_, _r} = error diff --git a/test/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/web/mastodon_api/controllers/suggestion_controller_test.exs index c288c2fff..0319d3475 100644 --- a/test/web/mastodon_api/controllers/suggestion_controller_test.exs +++ b/test/web/mastodon_api/controllers/suggestion_controller_test.exs @@ -7,7 +7,6 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do alias Pleroma.Config - import ExUnit.CaptureLog import Pleroma.Factory import Tesla.Mock -- cgit v1.2.3 From 77f24525ca6636f5fb0b3864c346be683566efd3 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 28 Jan 2020 16:40:44 +0100 Subject: Streamer: Correctly handle reblog mutes --- test/web/streamer/streamer_test.exs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index 7166d6f0b..848158a44 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -455,6 +455,34 @@ defmodule Pleroma.Web.StreamerTest do Task.await(task) end + test "it does send non-reblog notification for mtued" do + user1 = insert(:user) + user2 = insert(:user) + user3 = insert(:user) + CommonAPI.hide_reblogs(user1, user2) + + task = + Task.async(fn -> + assert_receive {:text, _}, 1_000 + end) + + fake_socket = %StreamerSocket{ + transport_pid: task.pid, + user: user1 + } + + {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"}) + {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, user2) + + topics = %{ + "public" => [fake_socket] + } + + Worker.push_to_socket(topics, "public", favorite_activity) + + Task.await(task) + end + test "it doesn't send posts from muted threads" do user = insert(:user) user2 = insert(:user) -- cgit v1.2.3 From e816edbb2f8966282d9e7c787272ed66d33ee088 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 28 Jan 2020 15:42:05 +0000 Subject: Update streamer_test.exs --- test/web/streamer/streamer_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index 848158a44..f33b95142 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -455,7 +455,7 @@ defmodule Pleroma.Web.StreamerTest do Task.await(task) end - test "it does send non-reblog notification for mtued" do + test "it does send non-reblog notification for reblog-muted actors" do user1 = insert(:user) user2 = insert(:user) user3 = insert(:user) -- cgit v1.2.3 From 4eb935be78eeaf1decb7fc109cec09ca18d82854 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 20 Jan 2020 13:23:21 +0100 Subject: Create pleroma.email mix task Closes: https://git.pleroma.social/pleroma/pleroma/issues/1061 --- test/tasks/email_test.exs | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/tasks/email_test.exs (limited to 'test') diff --git a/test/tasks/email_test.exs b/test/tasks/email_test.exs new file mode 100644 index 000000000..944c07064 --- /dev/null +++ b/test/tasks/email_test.exs @@ -0,0 +1,52 @@ +defmodule Mix.Tasks.Pleroma.EmailTest do + use Pleroma.DataCase + + import Swoosh.TestAssertions + + alias Pleroma.Config + alias Pleroma.Tests.ObanHelpers + + setup_all do + Mix.shell(Mix.Shell.Process) + + on_exit(fn -> + Mix.shell(Mix.Shell.IO) + end) + + :ok + end + + describe "pleroma.email test" do + test "Sends test email with no given address" do + mail_to = Config.get([:instance, :email]) + + :ok = Mix.Tasks.Pleroma.Email.run(["test"]) + + ObanHelpers.perform_all() + + assert_receive {:mix_shell, :info, [message]} + assert message =~ "Test email has been sent" + + assert_email_sent( + to: mail_to, + html_body: ~r/a test email was requested./i + ) + end + + test "Sends test email with given address" do + mail_to = "hewwo@example.com" + + :ok = Mix.Tasks.Pleroma.Email.run(["test", "--to", mail_to]) + + ObanHelpers.perform_all() + + assert_receive {:mix_shell, :info, [message]} + assert message =~ "Test email has been sent" + + assert_email_sent( + to: mail_to, + html_body: ~r/a test email was requested./i + ) + end + end +end -- cgit v1.2.3 From 7bd4c1458103920479ea39a5334b54d729faae6e Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Tue, 28 Jan 2020 19:29:27 +0300 Subject: meta tag parser respect first title header --- .../fixtures/margaret-corbin-grave-west-point.html | 2895 ++++++++++++++++++++ test/web/rich_media/parsers/twitter_card_test.exs | 19 + 2 files changed, 2914 insertions(+) create mode 100644 test/fixtures/margaret-corbin-grave-west-point.html (limited to 'test') diff --git a/test/fixtures/margaret-corbin-grave-west-point.html b/test/fixtures/margaret-corbin-grave-west-point.html new file mode 100644 index 000000000..f6d387cc8 --- /dev/null +++ b/test/fixtures/margaret-corbin-grave-west-point.html @@ -0,0 +1,2895 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The Missing Grave of Margaret Corbin, Revolutionary War Veteran - Atlas Obscura + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+
+
+

The Missing Grave of Margaret Corbin, Revolutionary War Veteran

+

+ She’s the only woman veteran honored with a monument at West Point. But where was she buried? +

+
+ + +
+
+
+
+ +
+
+
+ In 1926, the Daughters of the American Revolution joined forces with the U.S. Military Academy to exhume the supposed burial site of Margaret Corbin. +
+ In 1926, the Daughters of the American Revolution joined forces with the U.S. Military Academy to exhume + the supposed burial site of Margaret Corbin. Daughters of the American + Revolution +
+
+
+
+ +
+
+

In 2016, five days after + Thanksgiving, Margaret Corbin’s grave was dug up for the second time since her death in + 1800. It began by accident. Contractors were working on a retaining wall near the West Point Cemetery, + at the U.S. Military Academy, when a hydraulic excavator got too close and chewed through the grave.

+

As soon as they noticed bones spilling from the soil, they alerted the + military police. The plot was quickly cordoned off, her monument was wrapped in tarp, and rumors started + to spread about Corbin’s resting place—that is, if it even was her resting place. + When forensic archaeologists arrived at the scene, they were perplexed: The bones seemed oddly large. +

+

The monument to Margaret Corbin is West Point’s only monument to a + woman veteran, and it greets visitors near the main gate, just feet from a neoclassical chapel. It faces + Washington Road, where the Academy’s top brass live, and depicts Corbin in a long dress, operating + a cannon as her long hair and cape fly in the wind. She wears a powder horn and holds a rammer to load + cannonballs; the rest of the rather cramped cemetery sprawls out behind her. The monument portrays the + moments before Corbin became a prisoner of war.

+
On the West Point monument, Corbin wears a long dress and a powder horn, and she operates a cannon while her long hair flies in the wind. +
On the West Point monument, Corbin wears a long + dress and a powder horn, and she operates a cannon while her long hair flies in the wind. Science History Images / Alamy Stock Photo
+
+

The story goes that Corbin joined her husband, John, to fight in the + American Revolution. At the time, many women followed their husbands to war, where they were commonly + known as “camp followers.” Typically, they foraged for food, cooked, and did laundry. Before + Martha Washington was the United States’ first first lady, she was also a camp follower. In fact, + she and Margaret were with the same company—though the two experienced different lives, since + George was a general, and John manned a cannon.

+

At the Battle of Fort Washington, on November 16, 1776, in what is now + Washington Heights, the British and Hessians advanced far enough to make the Continental Army’s + position untenable. George Washington retreated with his forces to White Plains; John Corbin was shot + dead at his cannon. But Margaret was there to jump into John’s position and help fire the cannon. + During the battle, her jaw and shoulder were seriously injured, and grapeshot tore off part of her + breast. Despite the Continental Army’s efforts, the fort was soon surrendered, and Corbin was + captured along with approximately 2,837 soldiers.

+
A watercolor by Thomas Davies depicting the attack on Fort Washington by the British and Hessian Brigades. Margaret Corbin was taken prisoner after fighting in the battle. +
A watercolor by Thomas Davies depicting the attack + on Fort Washington by the British and Hessian Brigades. Margaret Corbin was taken prisoner after + fighting in the battle. Alamy Stock Photo
+
+

The British may have been unsure what to do with an injured woman, because + she was released fairly soon after the battle. The ordeal was one of many traumas in her life: According + to records collected by the historian Stella Bailey, + Margaret was only five years old when her father was killed in a conflict with Native Americans in + Pennsylvania, where they lived. Her mother was kidnapped, and Margaret and her brother moved in with an + uncle. They never saw her again.

+

After Corbin’s return, she joined the Corps of Invalids, a group of + wounded soldiers that were still able to contribute to the war effort. They were stationed at West + Point, New York, where Corbin became known as a cantankerous woman who had a tough time making a home + for herself in the neighboring village of Highland Falls. She moved between various local families who + tried to care for her. Having witnessed her husband’s death and sustaining wounds, she was + probably in constant mental and physical pain.

+
+

When Margaret Corbin + died in 1800, she was buried in a pauper’s cemetery in Highland Falls, just three miles + from West Point. But in 1926, the national society of women known as the Daughters of the American + Revolution saw to it that Corbin would earn her vaunted cemetery plot. The society, which is made up of + women who can trace their lineage to participants in the American Revolution, was celebrating the + sesquicentennial of American independence, and saw Corbin as the consummate symbol of both their + organization and the Revolution. A year-long effort convinced the U.S. Military Academy to help them + exhume and transport the remains to the prestigious cemetery, to be reburied with a military funeral. +

+
This sign directs visitors to the United States Military Academy to the purported site of Margaret Corbin's grave. +
This sign directs visitors to the United States + Military Academy to the purported site of Margaret Corbin’s grave. Ahodges7 / + CC BY-SA 3.0
+
+

Exhumation was not a simple task: By the time the DAR began their campaign + to move Corbin, the location of her exact burial was known only by word-of-mouth, passed down through + generations. In collaboration with West Point, the Daughters found the great-grandson of the man who + supposedly dug Corbin’s original grave, a steamboat captain by the name of Farout. Her burial site + was apparently marked by the stump of a cedar tree; during the exhumation process, the gravedigger + accidentally drove the shovel through the skull. Still, the Army Surgeon reported injuries to the + skeleton that were consistent with grapeshot. The remains were given a new, flag-draped casket and + delivered to West Point by horse-drawn hearse.

+

Every year since then, the Daughters have gathered at Corbin’s + monument for Margaret Corbin Day. On the first Tuesday of May, the Daughters fill the chapel, share + Corbin’s story, sing hymns, and stand at the grave while soldiers perform a 21-gun salute.

+
A horse-drawn hearse carried a flag-draped casket that was said to contain Corbin’s remains. +
A horse-drawn hearse carried a flag-draped casket + that was said to contain Corbin’s remains. Daughters of the + American Revolution
+
+

After the U.S. Military Academy unintentionally reopened the grave beneath + Corbin’s monument in 2016, they decided to conduct an emergency forensic archaeological + excavation. They enlisted the help of Elizabeth A. DiGangi, an anthropology professor at Binghamton + University, and Michael K. Trimble, an archaeologist for the Army Corps of Engineers. Almost + immediately, the pair noticed that the size of the bones didn’t match Corbin’s description. + Corbin was reportedly a stout woman. “One of the first bones I saw when I was on site was the + humerus, or upper arm bone,” DiGangi says. “It was very large, which is not what you would + expect with an arm bone from a woman.”

+

DiGangi took the remains to her laboratory at Binghamton University to do a + full analysis. Some worried that other remains were mixed up with Corbin’s. (In the past, West + Point has discovered unknown remains when they’ve broken new ground for construction.) Ultimately, + DiGangi’s analysis revealed something even more shocking: The remains in Corbin’s grave + actually came from an adult male. DiGangi determined that it was a large man, who could’ve been + anywhere from five-foot-seven to six and a half feet tall. The remains of Margaret Corbin were not in + Margaret Corbin’s grave.

+
In 1926, the remains from Highland Park were reinterred at West Point, and sat at the foot of the Margaret Corbin monument until 2016. +
In 1926, the remains from Highland Park were + reinterred at West Point, and sat at the foot of the Margaret Corbin monument until 2016. Daughters of the American Revolution
+
+

Once the archaeological excavation teams completed + their reports, the Army National Cemeteries contacted the Daughters of the American Revolution. They + wanted a meeting at DAR headquarters in Washington, DC.

+

Jennifer Minus, the head of the New York chapter of the DAR, was among + those present at the meeting. Minus, a graduate of West Point and a former member of the Corbin Forum, a + club for cadet women, knew her Corbin history better than most. She asked how it could’ve been a + man in the grave, if in 1926 the Army surgeon said that grapeshot injuries were present. In her report, + DiGangi explains that what the surgeon considered a grapeshot injury was, in fact, post-mortem damage to + the remains.

+

So where is Margaret Corbin? Since the attempted reburial of Corbin’s + remains, in 1926, her original gravesite in Highland Falls has been lost to time. Sometime in the 1970s, + the town dropped a sewage plant where many believe it was once located. Yet Minus remains optimistic + that Corbin’s remains will one day be found.

+
At left, another monument that pays homage to Margaret Corbin, near the site where she took over her husband's cannon; at right, a view of her monument at West Point. +
At left, another monument that pays homage to + Margaret Corbin, near the site where she took over her husband’s cannon; at right, a view of her + monument at West Point. Beyond + My Ken / CC BY-SA 4.0; Ahodges7 / CC BY-SA 3.0
+
+

As upsetting as it was to learn that her remains were missing, the + Daughters also tried to see the discovery as an opportunity to spread Margaret’s story. It’s + as though they picked up right where the 1926 DAR members left off. Minus formed an unofficial Margaret + Corbin Task Force, drawing on the strengths of DAR members: One was a genealogist, and another was a + Navy veteran who had worked on locating the remains of American soldiers overseas.

+
+

On April 30, 2019, + Minus combed the woods of Highland Falls, looking for the original gravesite. They tried to + match up the old photographs with newer ones, but this proved difficult, because most of the trees in + the photographs were saplings at the time. They looked for flat areas that would have been suitable for + burials: It was common at the time to bury people in elevated areas, to avoid rising water tables that + could push the caskets back up to the surface.

+

The next day, the Daughters gathered again around Corbin’s monument, + dressed in large hats and sashes. The ground looked as though it had never been disturbed. A casual + viewer would’ve never known that Corbin wasn’t under their feet.

+
In 2018, the Margaret Corbin monument was rededicated with a wreath laying.
+ +
In 2018, the Margaret Corbin monument was + rededicated with a wreath laying. + Daughters of the American Revolution
+
+

It was an important day for the Daughters, but especially for Minus, who + joined the DAR in part because of Corbin. Once, before she graduated from West Point, she told her + grandparents about a lunch honoring Margaret Corbin. Her grandmother told her that her heritage made her + eligible to join the Daughters of the American Revolution, and a few years later, when she returned from + a post in Germany, her grandma prepared the necessary papers.

+

Minus is hopeful that they’ll find Corbin near the river, not far + from the grave that the Daughters dug up in 1926. “When they started digging, they found bones. + So, they didn’t make, like, 10 different holes over a field. They got it on their first attempt + and found bones. What I’m hoping is that they just had to do a 180, and she would’ve been + five feet over.”

+

The man they found in Corbin’s grave has since come back to the West + Point cemetery, to be reinterred with the other unidentified remains found in the area. No one yet knows + who the man could be. Some theorize it’s Corbin’s second husband—but there’s no + proof that she remarried. Others believe it was a Native American. It’s possible that the unknown + man might be dug up a third time, should the proper clues demand his participation. Corbin’s + original gravesite did not turn up in 2018, but the search + continues.

+

On Corbin Day in 2019, after the 21-gun salute, the Daughters hold another + luncheon. This time, the Margaret Corbin Task Force has something special on display: a machine that + looks like a souped-up lawn mower. Many Daughters file into the room and ask what it is. “Just + wait,” Minus answers. Then Lieutenant Colonel Mindy Kimball, an environmental science professor at + West Point, holds a demonstration. It’s a ground-penetrating radar machine, which shoots + electromagnetic waves into the ground and sends information back up to the antennae, to identify + underground disturbances that could reveal human remains.

+
The monument to Margaret Corbin is West Point’s only monument to a woman veteran. +
The monument to Margaret Corbin is West + Point’s only monument to a woman veteran. Ahodges7 + / CC BY-SA 3.0
+
+

Whether or not Corbin is ever located, just sharing her story helps to + immortalize her. Minus is fascinated by the many identities that Corbin came to inhabit. + “She’s an army spouse, and then an army widow, and then she was a soldier, and then she was + a wounded soldier, and then she was a prisoner of war, and then she was a veteran,” she says. + Corbin was also the first woman to receive a military pension from the government, and is mentioned by + name in the Congressional Record. “I really think of her as that building block for women in the + military.”

+

Stella Bailey, the town historian of Highland Falls, has been researching + Margaret Corbin for decades. She’s pored over old maps, trying to pinpoint exactly where Corbin + might have been buried in 1800. She even gets emails from people who think they might be related to + Corbin.

+

Sitting in her office, overlooking Main Street in Highland + Falls, Bailey sighs. “We know she was real. West Point’s records acknowledge her + existence,” she says. But she can list discrepancies in Corbin’s story. Some say her husband + was shot in the head; some say he was shot in the heart. Others say Corbin dressed as a man to fight in + the war. Sometimes she wonders whether she will ever find answers. Perhaps these conflicting stories are + just a part of Corbin’s mystique. “The more I research, the less I know,” Bailey says. +

+

You can join the conversation about this and other stories in + the Atlas Obscura Community Forums.

+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + + + +
+ + + + + +
+ +
+ + + + + + + +
+
+ + + +
+
+ + + + + + + + + + + + \ No newline at end of file diff --git a/test/web/rich_media/parsers/twitter_card_test.exs b/test/web/rich_media/parsers/twitter_card_test.exs index f8e1c9b40..e2610f4c2 100644 --- a/test/web/rich_media/parsers/twitter_card_test.exs +++ b/test/web/rich_media/parsers/twitter_card_test.exs @@ -66,4 +66,23 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html" }} end + + test "respect only first title tag on the page" do + image_path = + "https://assets.atlasobscura.com/media/W1siZiIsInVwbG9hZHMvYXNzZXRzLzkwYzgyMzI4LThlMDUtNGRiNS05MDg3LTUzMGUxZTM5N2RmMmVkOTM5ZDM4MGM4OTIx" <> + "YTQ5MF9EQVIgZXhodW1hdGlvbiBvZiBNYXJnYXJldCBDb3JiaW4gZ3JhdmUgMTkyNi5qcGciXSxbInAiLCJjb252ZXJ0IiwiIl0sWyJwIiwiY29udmVydCIsIi1xdWFsaXR5IDgxIC1hdXRvLW9" <> + "yaWVudCJdLFsicCIsInRodW1iIiwiNjAweD4iXV0/DAR%20exhumation%20of%20Margaret%20Corbin%20grave%201926.jpg" + + html = File.read!("test/fixtures/margaret-corbin-grave-west-point.html") + + assert TwitterCard.parse(html, %{}) == + {:ok, + %{ + site: "@atlasobscura", + title: + "The Missing Grave of Margaret Corbin, Revolutionary War Veteran - Atlas Obscura", + card: "summary_large_image", + image: image_path + }} + end end -- cgit v1.2.3 From 1f4fbe9d98b7daef7eef2ffffbaca00e1d20c52b Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 29 Jan 2020 11:13:34 +0300 Subject: title parse improvement --- ...ypd-facial-recognition-children-teenagers4.html | 228 +++++++++++++++++++++ test/web/rich_media/parsers/twitter_card_test.exs | 15 ++ 2 files changed, 243 insertions(+) create mode 100644 test/fixtures/nypd-facial-recognition-children-teenagers4.html (limited to 'test') diff --git a/test/fixtures/nypd-facial-recognition-children-teenagers4.html b/test/fixtures/nypd-facial-recognition-children-teenagers4.html new file mode 100644 index 000000000..9f15cc42e --- /dev/null +++ b/test/fixtures/nypd-facial-recognition-children-teenagers4.html @@ -0,0 +1,228 @@ + + + + She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times + She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times + + + + + + + + + + + + + + + + + + + + + +

Advertisement

She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.

With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.

Image
CreditCreditSarah Blesener for The New York Times

[What you need to know to start the day: Get New York Today in your inbox.]

The New York Police Department has been loading thousands of arrest photos of children and teenagers into a facial recognition database despite evidence the technology has a higher risk of false matches in younger faces.

For about four years, internal records show, the department has used the technology to compare crime scene images with its collection of juvenile mug shots, the photos that are taken at an arrest. Most of the photos are of teenagers, largely 13 to 16 years old, but children as young as 11 have been included.

Elected officials and civil rights groups said the disclosure that the city was deploying a powerful surveillance tool on adolescents — whose privacy seems sacrosanct and whose status is protected in the criminal justice system — was a striking example of the Police Department’s ability to adopt advancing technology with little public scrutiny.

Several members of the City Council as well as a range of civil liberties groups said they were unaware of the policy until they were contacted by The New York Times.

Police Department officials defended the decision, saying it was just the latest evolution of a longstanding policing technique: using arrest photos to identify suspects.

“I don’t think this is any secret decision that’s made behind closed doors,” the city’s chief of detectives, Dermot F. Shea, said in an interview. “This is just process, and making sure we’re doing everything to fight crime.”

Other cities have begun to debate whether law enforcement should use facial recognition, which relies on an algorithm to quickly pore through images and suggest matches. In May, San Francisco blocked city agencies, including the police, from using the tool amid unease about potential government abuse. Detroit is facing public resistance to a technology that has been shown to have lower accuracy with people with darker skin.

In New York, the state Education Department recently told the Lockport, N.Y., school district to delay a plan to use facial recognition on students, citing privacy concerns.

“At the end of the day, it should be banned — no young people,” said Councilman Donovan Richards, a Queens Democrat who heads the Public Safety Committee, which oversees the Police Department.

The department said its legal bureau had approved using facial recognition on juveniles. The algorithm may suggest a lead, but detectives would not make an arrest based solely on that, Chief Shea said.

Image
CreditChang W. Lee/The New York Times

Still, facial recognition has not been widely tested on children. Most algorithms are taught to “think” based on adult faces, and there is growing evidence that they do not work as well on children.

The National Institute of Standards and Technology, which is part of the Commerce Department and evaluates facial recognition algorithms for accuracy, recently found the vast majority of more than 100 facial recognition algorithms had a higher rate of mistaken matches among children. The error rate was most pronounced in young children but was also seen in those aged 10 to 16.

Aging poses another problem: The appearance of children and adolescents can change drastically as bones stretch and shift, altering the underlying facial structure.

“I would use extreme caution in using those algorithms,” said Karl Ricanek Jr., a computer science professor and co-founder of the Face Aging Group at the University of North Carolina-Wilmington.

Technology that can match an image of a younger teenager to a recent arrest photo may be less effective at finding the same person even one or two years later, he said.

“The systems do not have the capacity to understand the dynamic changes that occur to a child’s face,” Dr. Ricanek said.

Idemia and DataWorks Plus, the two companies that provide facial recognition software to the Police Department, did not respond to requests for comment.

The New York Police Department can take arrest photos of minors as young as 11 who are charged with a felony, depending on the severity of the charge.

And in many cases, the department keeps the photos for years, making facial recognition comparisons to what may have effectively become outdated images. There are photos of 5,500 individuals in the juvenile database, 4,100 of whom are no longer 16 or under, the department said. Teenagers 17 and older are considered adults in the criminal justice system.

Police officials declined to provide statistics on how often their facial recognition systems provide false matches, or to explain how they evaluate the system’s effectiveness.

“We are comfortable with this technology because it has proved to be a valuable investigative method,” Chief Shea said. Facial recognition has helped lead to thousands of arrests of both adults and juveniles, the department has said.

Mayor Bill de Blasio had been aware the department was using the technology on minors, said Freddi Goldstein, a spokeswoman for the mayor.

She said the Police Department followed “strict guidelines” in applying the technology and City Hall monitored the agency’s compliance with the policies.

The Times learned details of the department’s use of facial recognition by reviewing documents posted online earlier this year by Clare Garvie, a senior associate at the Center on Privacy and Technology at Georgetown Law. Ms. Garvie received the documents as part of an open records lawsuit.

It could not be determined whether other large police departments used facial recognition with juveniles because very few have written policies governing the use of the technology, Ms. Garvie said.

New York detectives rely on a vast network of surveillance cameras throughout the city to provide images of people believed to have committed a crime. Since 2011, the department has had a dedicated unit of officers who use facial recognition to compare those images against millions of photos, usually mug shots. The software proposes matches, which have led to thousands of arrests, the department said.

By 2013, top police officials were meeting to discuss including juveniles in the program, the documents reviewed by The Times showed.

The documents showed that the juvenile database had been integrated into the system by 2015.

“We have these photos. It makes sense,” Chief Shea said in the interview.

State law requires that arrest photos be destroyed if the case is resolved in the juvenile’s favor, or if the child is found to have committed only a misdemeanor, rather than a felony. The photos also must be destroyed if a person reaches age 21 without a criminal record.

When children are charged with crimes, the court system usually takes some steps to prevent their acts from defining them in later years. Children who are 16 and under, for instance, are generally sent to Family Court, where records are not public.

Yet including their photos in a facial recognition database runs the risk that an imperfect algorithm identifies them as possible suspects in later crimes, civil rights advocates said. A mistaken match could lead investigators to focus on the wrong person from the outset, they said.

“It’s very disturbing to know that no matter what I’m doing at that moment, someone might be scanning my picture to try to find someone who committed a crime,” said Bailey, a 17-year-old Brooklyn girl who had admitted guilt in Family Court to a group attack that happened when she was 14. She said she was present at the attack but did not participate.

Bailey, who asked that she be identified only by her last name because she did not want her juvenile arrest to be public, has not been arrested again and is now a student at John Jay College of Criminal Justice.

Recent studies indicate that people of color, as well as children and women, have a greater risk of misidentification than their counterparts, said Joy Buolamwini, the founder of the Algorithmic Justice League and graduate researcher at the M.I.T. Media Lab, who has examined how human biases are built into artificial intelligence.

The racial disparities in the juvenile justice system are stark: In New York, black and Latino juveniles were charged with crimes at far higher rates than whites in 2017, the most recent year for which numbers were available. Black juveniles outnumbered white juveniles more than 15 to 1.

“If the facial recognition algorithm has a negative bias toward a black population, that will get magnified more toward children,” Dr. Ricanek said, adding that in terms of diminished accuracy, “you’re now putting yourself in unknown territory.”

Joseph Goldstein writes about policing and the criminal justice system. He has been a reporter at The Times since 2011, and is based in New York. He also worked for a year in the Kabul bureau, reporting on Afghanistan. @JoeKGoldstein

Ali Watkins is a reporter on the Metro Desk, covering courts and social services. Previously, she covered national security in Washington for The Times, BuzzFeed and McClatchy Newspapers. @AliWatkins

A version of this article appears in print on , Section A, Page 1 of the New York edition with the headline: In New York, Police Computers Scan Faces, Some as Young as 11. Order Reprints | Today’s Paper | Subscribe

Advertisement

+ + + + + + + + + + +
+ +
+ + + + diff --git a/test/web/rich_media/parsers/twitter_card_test.exs b/test/web/rich_media/parsers/twitter_card_test.exs index e2610f4c2..751ca614c 100644 --- a/test/web/rich_media/parsers/twitter_card_test.exs +++ b/test/web/rich_media/parsers/twitter_card_test.exs @@ -85,4 +85,19 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do image: image_path }} end + + test "takes first founded title in html head if there is html markup error" do + html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html") + + assert TwitterCard.parse(html, %{}) == + {:ok, + %{ + site: nil, + title: + "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times", + "app:id:googleplay": "com.nytimes.android", + "app:name:googleplay": "NYTimes", + "app:url:googleplay": "nytimes://reader/id/100000006583622" + }} + end end -- cgit v1.2.3 From a802e07241e441189f85568ee9ca58508ab6d0d3 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jan 2020 11:39:06 +0100 Subject: Emoji Reactions: Add `reacted` field to emoji reactions --- test/web/mastodon_api/views/status_view_test.exs | 11 +++++++++-- .../controllers/pleroma_api_controller_test.exs | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index 25777b011..fc110417c 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -37,8 +37,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do status = StatusView.render("show.json", activity: activity) assert status[:pleroma][:emoji_reactions] == [ - %{emoji: "☕", count: 2}, - %{emoji: "🍵", count: 1} + %{emoji: "☕", count: 2, reacted: false}, + %{emoji: "🍵", count: 1, reacted: false} + ] + + status = StatusView.render("show.json", activity: activity, for: user) + + assert status[:pleroma][:emoji_reactions] == [ + %{emoji: "☕", count: 2, reacted: true}, + %{emoji: "🍵", count: 1, reacted: false} ] end diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs index 3978c2ec5..bc676c99a 100644 --- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs +++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs @@ -25,9 +25,14 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do |> assign(:user, other_user) |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"])) |> post("/api/v1/pleroma/statuses/#{activity.id}/react_with_emoji", %{"emoji" => "☕"}) + |> json_response(200) - assert %{"id" => id} = json_response(result, 200) + assert %{"id" => id} = result assert to_string(activity.id) == id + + assert result["pleroma"]["emoji_reactions"] == [ + %{"emoji" => "☕", "count" => 1, "reacted" => true} + ] end test "POST /api/v1/pleroma/statuses/:id/unreact_with_emoji", %{conn: conn} do @@ -71,8 +76,20 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by") |> json_response(200) - [%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user]}] = result + [%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user], "reacted" => false}] = + result + assert represented_user["id"] == other_user.id + + result = + conn + |> assign(:user, other_user) + |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:statuses"])) + |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by") + |> json_response(200) + + assert [%{"emoji" => "🎅", "count" => 1, "accounts" => [_represented_user], "reacted" => true}] = + result end test "/api/v1/pleroma/conversations/:id" do -- cgit v1.2.3 From b3a877d6c9f7645c854527fc5bf05d9161c2480b Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jan 2020 11:43:36 +0100 Subject: Emoji Reactions: Correctly handle deleted users --- test/web/pleroma_api/controllers/pleroma_api_controller_test.exs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs index bc676c99a..be5007de5 100644 --- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs +++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs @@ -59,6 +59,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do test "GET /api/v1/pleroma/statuses/:id/emoji_reactions_by", %{conn: conn} do user = insert(:user) other_user = insert(:user) + doomed_user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"}) @@ -70,6 +71,9 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do assert result == [] {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅") + {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, doomed_user, "🎅") + + User.perform(:delete, doomed_user) result = conn -- cgit v1.2.3 From e2e9299b8e0eadb2b43c7f7e034539c0f721d699 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 29 Jan 2020 11:50:49 +0100 Subject: Streamer Tests: code readability improvements --- test/web/streamer/streamer_test.exs | 75 +++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'test') diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index 848158a44..16e3b8383 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -65,6 +65,9 @@ defmodule Pleroma.Web.StreamerTest do blocked = insert(:user) {:ok, _user_relationship} = User.block(user, blocked) + {:ok, activity} = CommonAPI.post(user, %{"status" => ":("}) + {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked) + task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end) Streamer.add_socket( @@ -72,9 +75,6 @@ defmodule Pleroma.Web.StreamerTest do %{transport_pid: task.pid, assigns: %{user: user}} ) - {:ok, activity} = CommonAPI.post(user, %{"status" => ":("}) - {:ok, notif, _} = CommonAPI.favorite(activity.id, blocked) - Streamer.stream("user:notification", notif) Task.await(task) end @@ -83,6 +83,11 @@ defmodule Pleroma.Web.StreamerTest do user: user } do user2 = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"}) + {:ok, activity} = CommonAPI.add_mute(user, activity) + {:ok, notif, _} = CommonAPI.favorite(activity.id, user2) + task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end) Streamer.add_socket( @@ -90,9 +95,6 @@ defmodule Pleroma.Web.StreamerTest do %{transport_pid: task.pid, assigns: %{user: user}} ) - {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"}) - {:ok, activity} = CommonAPI.add_mute(user, activity) - {:ok, notif, _} = CommonAPI.favorite(activity.id, user2) Streamer.stream("user:notification", notif) Task.await(task) end @@ -101,6 +103,11 @@ defmodule Pleroma.Web.StreamerTest do user: user } do user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"}) + + {:ok, user} = User.block_domain(user, "hecking-lewd-place.com") + {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"}) + {:ok, notif, _} = CommonAPI.favorite(activity.id, user2) + task = Task.async(fn -> refute_receive {:text, _}, @streamer_timeout end) Streamer.add_socket( @@ -108,10 +115,6 @@ defmodule Pleroma.Web.StreamerTest do %{transport_pid: task.pid, assigns: %{user: user}} ) - {:ok, user} = User.block_domain(user, "hecking-lewd-place.com") - {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"}) - {:ok, notif, _} = CommonAPI.favorite(activity.id, user2) - Streamer.stream("user:notification", notif) Task.await(task) end @@ -267,6 +270,8 @@ defmodule Pleroma.Web.StreamerTest do blocked_user = insert(:user) {:ok, _user_relationship} = User.block(user, blocked_user) + {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"}) + task = Task.async(fn -> refute_receive {:text, _}, 1_000 @@ -277,8 +282,6 @@ defmodule Pleroma.Web.StreamerTest do user: user } - {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"}) - topics = %{ "public" => [fake_socket] } @@ -335,6 +338,12 @@ defmodule Pleroma.Web.StreamerTest do {:ok, list} = List.create("Test", user_a) {:ok, list} = List.follow(list, user_b) + {:ok, activity} = + CommonAPI.post(user_b, %{ + "status" => "@#{user_c.nickname} Test", + "visibility" => "direct" + }) + task = Task.async(fn -> refute_receive {:text, _}, 1_000 @@ -345,12 +354,6 @@ defmodule Pleroma.Web.StreamerTest do user: user_a } - {:ok, activity} = - CommonAPI.post(user_b, %{ - "status" => "@#{user_c.nickname} Test", - "visibility" => "direct" - }) - topics = %{ "list:#{list.id}" => [fake_socket] } @@ -367,6 +370,12 @@ defmodule Pleroma.Web.StreamerTest do {:ok, list} = List.create("Test", user_a) {:ok, list} = List.follow(list, user_b) + {:ok, activity} = + CommonAPI.post(user_b, %{ + "status" => "Test", + "visibility" => "private" + }) + task = Task.async(fn -> refute_receive {:text, _}, 1_000 @@ -377,12 +386,6 @@ defmodule Pleroma.Web.StreamerTest do user: user_a } - {:ok, activity} = - CommonAPI.post(user_b, %{ - "status" => "Test", - "visibility" => "private" - }) - topics = %{ "list:#{list.id}" => [fake_socket] } @@ -401,6 +404,12 @@ defmodule Pleroma.Web.StreamerTest do {:ok, list} = List.create("Test", user_a) {:ok, list} = List.follow(list, user_b) + {:ok, activity} = + CommonAPI.post(user_b, %{ + "status" => "Test", + "visibility" => "private" + }) + task = Task.async(fn -> assert_receive {:text, _}, 1_000 @@ -411,12 +420,6 @@ defmodule Pleroma.Web.StreamerTest do user: user_a } - {:ok, activity} = - CommonAPI.post(user_b, %{ - "status" => "Test", - "visibility" => "private" - }) - Streamer.add_socket( "list:#{list.id}", fake_socket @@ -433,6 +436,9 @@ defmodule Pleroma.Web.StreamerTest do user3 = insert(:user) CommonAPI.hide_reblogs(user1, user2) + {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"}) + {:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2) + task = Task.async(fn -> refute_receive {:text, _}, 1_000 @@ -443,9 +449,6 @@ defmodule Pleroma.Web.StreamerTest do user: user1 } - {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"}) - {:ok, announce_activity, _} = CommonAPI.repeat(create_activity.id, user2) - topics = %{ "public" => [fake_socket] } @@ -461,6 +464,9 @@ defmodule Pleroma.Web.StreamerTest do user3 = insert(:user) CommonAPI.hide_reblogs(user1, user2) + {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"}) + {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, user2) + task = Task.async(fn -> assert_receive {:text, _}, 1_000 @@ -471,9 +477,6 @@ defmodule Pleroma.Web.StreamerTest do user: user1 } - {:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"}) - {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, user2) - topics = %{ "public" => [fake_socket] } -- cgit v1.2.3 From e7fee0d6fa7b2ba046e57ca9364be1b62bfc9661 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 29 Jan 2020 13:51:17 +0300 Subject: emoji api error on not writable dir --- test/web/pleroma_api/controllers/emoji_api_controller_test.exs | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/web/pleroma_api/controllers/emoji_api_controller_test.exs b/test/web/pleroma_api/controllers/emoji_api_controller_test.exs index 8e76f2f3d..6f1ea78ec 100644 --- a/test/web/pleroma_api/controllers/emoji_api_controller_test.exs +++ b/test/web/pleroma_api/controllers/emoji_api_controller_test.exs @@ -6,7 +6,6 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do use Pleroma.Web.ConnCase import Tesla.Mock - import Pleroma.Factory @emoji_dir_path Path.join( -- cgit v1.2.3 From a0d9d42eaab397a1913038fea5c2d3630b812849 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 30 Jan 2020 16:07:37 +0100 Subject: Emoji Reactions: Actually use the validation. --- test/web/activity_pub/transmogrifier_test.exs | 19 +++++++++++++++++++ test/web/common_api/common_api_test.exs | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 5da358c43..0829a6ec2 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -395,6 +395,25 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert data["content"] == "👌" end + test "it reject invalid emoji reactions" do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"}) + + data = + File.read!("test/fixtures/emoji-reaction-too-long.json") + |> Poison.decode!() + |> Map.put("object", activity.data["object"]) + + assert :error = Transmogrifier.handle_incoming(data) + + data = + File.read!("test/fixtures/emoji-reaction-no-emoji.json") + |> Poison.decode!() + |> Map.put("object", activity.data["object"]) + + assert :error = Transmogrifier.handle_incoming(data) + end + test "it works for incoming emoji reaction undos" do user = insert(:user) diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index f8963e42e..8fa0c6faa 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -238,7 +238,9 @@ defmodule Pleroma.Web.CommonAPITest do assert reaction.data["actor"] == user.ap_id assert reaction.data["content"] == "👍" - # TODO: test error case. + {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"}) + + {:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".") end test "unreacting to a status with an emoji" do -- cgit v1.2.3 From 01fb4dbeae2b08e5ffa3d5dd8eedf6c741c7b63f Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 30 Jan 2020 16:26:45 +0100 Subject: Emoji Reactions: Add fixtures --- test/fixtures/emoji-reaction-no-emoji.json | 30 ++++++++++++++++++++++++++++++ test/fixtures/emoji-reaction-too-long.json | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test/fixtures/emoji-reaction-no-emoji.json create mode 100644 test/fixtures/emoji-reaction-too-long.json (limited to 'test') diff --git a/test/fixtures/emoji-reaction-no-emoji.json b/test/fixtures/emoji-reaction-no-emoji.json new file mode 100644 index 000000000..fff77b29b --- /dev/null +++ b/test/fixtures/emoji-reaction-no-emoji.json @@ -0,0 +1,30 @@ +{ + "type": "EmojiReaction", + "signature": { + "type": "RsaSignature2017", + "signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-02-17T18:57:49Z" + }, + "object": "http://localtesting.pleroma.lol/objects/eb92579d-3417-42a8-8652-2492c2d4f454", + "content": "~", + "nickname": "lain", + "id": "http://mastodon.example.org/users/admin#reactions/2", + "actor": "http://mastodon.example.org/users/admin", + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "toot": "http://joinmastodon.org/ns#", + "sensitive": "as:sensitive", + "ostatus": "http://ostatus.org#", + "movedTo": "as:movedTo", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "atomUri": "ostatus:atomUri", + "Hashtag": "as:Hashtag", + "Emoji": "toot:Emoji" + } + ] +} diff --git a/test/fixtures/emoji-reaction-too-long.json b/test/fixtures/emoji-reaction-too-long.json new file mode 100644 index 000000000..31830d90c --- /dev/null +++ b/test/fixtures/emoji-reaction-too-long.json @@ -0,0 +1,30 @@ +{ + "type": "EmojiReaction", + "signature": { + "type": "RsaSignature2017", + "signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==", + "creator": "http://mastodon.example.org/users/admin#main-key", + "created": "2018-02-17T18:57:49Z" + }, + "object": "http://localtesting.pleroma.lol/objects/eb92579d-3417-42a8-8652-2492c2d4f454", + "content": "👌👌", + "nickname": "lain", + "id": "http://mastodon.example.org/users/admin#reactions/2", + "actor": "http://mastodon.example.org/users/admin", + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "toot": "http://joinmastodon.org/ns#", + "sensitive": "as:sensitive", + "ostatus": "http://ostatus.org#", + "movedTo": "as:movedTo", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "atomUri": "ostatus:atomUri", + "Hashtag": "as:Hashtag", + "Emoji": "toot:Emoji" + } + ] +} -- cgit v1.2.3 From 8057157ee3172c370200f328373f0a7e32092b91 Mon Sep 17 00:00:00 2001 From: Roman Chvanikov Date: Fri, 31 Jan 2020 01:20:37 +0300 Subject: Make attachments cleanup optional --- test/object_test.exs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test') diff --git a/test/object_test.exs b/test/object_test.exs index c6b2bc399..5690bedec 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -76,8 +76,43 @@ defmodule Pleroma.ObjectTest do describe "delete attachments" do clear_config([Pleroma.Upload]) + test "Disabled via config" do + Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + Pleroma.Config.put([:instance, :cleanup_attachments], false) + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image.jpg"), + filename: "an_image.jpg" + } + + user = insert(:user) + + {:ok, %Object{} = attachment} = + Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id) + + %{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} = + note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}}) + + uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads]) + + path = href |> Path.dirname() |> Path.basename() + + assert {:ok, ["an_image.jpg"]} == File.ls("#{uploads_dir}/#{path}") + + Object.delete(note) + + ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker)) + + assert Object.get_by_id(note.id).data["deleted"] + refute Object.get_by_id(attachment.id) == nil + + assert {:ok, ["an_image.jpg"]} == File.ls("#{uploads_dir}/#{path}") + end + test "in subdirectories" do Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + Pleroma.Config.put([:instance, :cleanup_attachments], true) file = %Plug.Upload{ content_type: "image/jpg", @@ -103,6 +138,7 @@ defmodule Pleroma.ObjectTest do ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker)) + assert Object.get_by_id(note.id).data["deleted"] assert Object.get_by_id(attachment.id) == nil assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") @@ -111,6 +147,7 @@ defmodule Pleroma.ObjectTest do test "with dedupe enabled" do Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) Pleroma.Config.put([Pleroma.Upload, :filters], [Pleroma.Upload.Filter.Dedupe]) + Pleroma.Config.put([:instance, :cleanup_attachments], true) uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads]) @@ -139,6 +176,7 @@ defmodule Pleroma.ObjectTest do ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker)) + assert Object.get_by_id(note.id).data["deleted"] assert Object.get_by_id(attachment.id) == nil assert {:ok, files} = File.ls(uploads_dir) refute filename in files @@ -146,6 +184,7 @@ defmodule Pleroma.ObjectTest do test "with objects that have legacy data.url attribute" do Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + Pleroma.Config.put([:instance, :cleanup_attachments], true) file = %Plug.Upload{ content_type: "image/jpg", @@ -173,6 +212,7 @@ defmodule Pleroma.ObjectTest do ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker)) + assert Object.get_by_id(note.id).data["deleted"] assert Object.get_by_id(attachment.id) == nil assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") @@ -181,6 +221,7 @@ defmodule Pleroma.ObjectTest do test "With custom base_url" do Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) Pleroma.Config.put([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/") + Pleroma.Config.put([:instance, :cleanup_attachments], true) file = %Plug.Upload{ content_type: "image/jpg", @@ -206,6 +247,7 @@ defmodule Pleroma.ObjectTest do ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker)) + assert Object.get_by_id(note.id).data["deleted"] assert Object.get_by_id(attachment.id) == nil assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") -- cgit v1.2.3