diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/httpoison_mock/puckipedia.com.json | 1 | ||||
-rw-r--r-- | test/fixtures/kroeg-post-activity.json | 50 | ||||
-rw-r--r-- | test/fixtures/test.txt | 1 | ||||
-rw-r--r-- | test/support/factory.ex | 20 | ||||
-rw-r--r-- | test/support/httpoison_mock.ex | 8 | ||||
-rw-r--r-- | test/upload_test.exs | 26 | ||||
-rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 26 | ||||
-rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 9 | ||||
-rw-r--r-- | test/web/mastodon_api/account_view_test.exs | 22 | ||||
-rw-r--r-- | test/web/twitter_api/twitter_api_test.exs | 66 | ||||
-rw-r--r-- | test/web/twitter_api/views/user_view_test.exs | 32 |
11 files changed, 258 insertions, 3 deletions
diff --git a/test/fixtures/httpoison_mock/puckipedia.com.json b/test/fixtures/httpoison_mock/puckipedia.com.json new file mode 100644 index 000000000..d18dfbae7 --- /dev/null +++ b/test/fixtures/httpoison_mock/puckipedia.com.json @@ -0,0 +1 @@ +{"@context":["https://www.w3.org/ns/activitystreams","https://puckipedia.com/-/context"],"endpoints":"https://puckipedia.com/#endpoints","followers":"https://puckipedia.com/followers","following":"https://puckipedia.com/following","icon":{"mediaType":"image/png","type":"Image","url":"https://puckipedia.com/images/avatar.png"},"id":"https://puckipedia.com/","inbox":"https://puckipedia.com/inbox","kroeg:blocks":{"id":"https://puckipedia.com/blocks"},"liked":"https://puckipedia.com/liked","manuallyApprovesFollowers":false,"name":"HACKER TEEN PUCKIPEDIA 👩💻","outbox":"https://puckipedia.com/outbox","preferredUsername":"puckipedia","publicKey":{"id":"https://puckipedia.com/#key","owner":"https://puckipedia.com/","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvN05xIcFE0Qgany7Rht4\n0ZI5wu++IT7K5iSqRimBYkpoeHbVcT9RFlW+aWH/QJJW/YgZ7+LMr8AMCrKrwSpS\nCndyrpx4O4lZ3FNRLu7tbklh01rGZfE6R1SFfYBpvMvImc9nYT6iezYDbv6NkHku\no3aVhjql216XlA0OhIrqQme9sAdrLbjbMrTUS8douCTkDOX+JFj1ghHCqdYEMZJI\nOY9kovtgnqyxFLm0RsPGsO1+g/OVojqG+VqHz6O2lceaTVQLlnZ4gOhLVG1tVsA2\nRfXQK+R/VgXncYE+BlQVd/tcdGAz7CDL7PP3rP65gmARnafhGR96cCOi/KzlAXSO\nMwIDAQAB\n-----END PUBLIC KEY-----","type":[]},"summary":"<p>federated hacker teen<br/>\n[<a href=\"https://pronoun.is/she\">she</a>/<a href=\"https://pronoun.is/they\">they</a>]</p>","type":"Person","updated":"2017-12-19T16:56:29.7576707+00:00"}
\ No newline at end of file diff --git a/test/fixtures/kroeg-post-activity.json b/test/fixtures/kroeg-post-activity.json new file mode 100644 index 000000000..32dabd947 --- /dev/null +++ b/test/fixtures/kroeg-post-activity.json @@ -0,0 +1,50 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://puckipedia.com/-/context" + ], + "actor": { + "endpoints": "https://puckipedia.com/#endpoints", + "followers": "https://puckipedia.com/followers", + "following": "https://puckipedia.com/following", + "icon": { + "mediaType": "image/png", + "type": "Image", + "url": "https://puckipedia.com/images/avatar.png" + }, + "id": "https://puckipedia.com/", + "inbox": "https://puckipedia.com/inbox", + "kroeg:blocks": { + "id": "https://puckipedia.com/blocks" + }, + "liked": "https://puckipedia.com/liked", + "manuallyApprovesFollowers": false, + "name": "HACKER TEEN PUCKIPEDIA \ud83d\udc69\u200d\ud83d\udcbb", + "outbox": "https://puckipedia.com/outbox", + "preferredUsername": "puckipedia", + "publicKey": { + "id": "https://puckipedia.com/#key", + "owner": "https://puckipedia.com/", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvN05xIcFE0Qgany7Rht4\n0ZI5wu++IT7K5iSqRimBYkpoeHbVcT9RFlW+aWH/QJJW/YgZ7+LMr8AMCrKrwSpS\nCndyrpx4O4lZ3FNRLu7tbklh01rGZfE6R1SFfYBpvMvImc9nYT6iezYDbv6NkHku\no3aVhjql216XlA0OhIrqQme9sAdrLbjbMrTUS8douCTkDOX+JFj1ghHCqdYEMZJI\nOY9kovtgnqyxFLm0RsPGsO1+g/OVojqG+VqHz6O2lceaTVQLlnZ4gOhLVG1tVsA2\nRfXQK+R/VgXncYE+BlQVd/tcdGAz7CDL7PP3rP65gmARnafhGR96cCOi/KzlAXSO\nMwIDAQAB\n-----END PUBLIC KEY-----", + "type": [] + }, + "summary": "<p>federated hacker teen<br/>\n[<a href=\"https://pronoun.is/she\">she</a>/<a href=\"https://pronoun.is/they\">they</a>]</p>", + "type": "Person", + "updated": "2017-12-19T16:56:29.7576707+00:00" + }, + "cc": "https://puckipedia.com/followers", + "id": "https://puckipedia.com/ae4ee4e8be/activity", + "object": { + "attributedTo": "https://puckipedia.com/", + "cc": "https://puckipedia.com/followers", + "content": "<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>", + "id": "https://puckipedia.com/ae4ee4e8be", + "likes": "https://puckipedia.com/ae4ee4e8be/likes", + "replies": "https://puckipedia.com/ae4ee4e8be/replies", + "shares": "https://puckipedia.com/ae4ee4e8be/shares", + "to": "https://www.w3.org/ns/activitystreams#Public", + "type": "Note" + }, + "to": "https://www.w3.org/ns/activitystreams#Public", + "type": "Create" +} diff --git a/test/fixtures/test.txt b/test/fixtures/test.txt new file mode 100644 index 000000000..e9ea42a12 --- /dev/null +++ b/test/fixtures/test.txt @@ -0,0 +1 @@ +this is a text file diff --git a/test/support/factory.ex b/test/support/factory.ex index 6c48d390f..4f5060abf 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -92,6 +92,26 @@ defmodule Pleroma.Factory do } end + def announce_activity_factory do + note_activity = insert(:note_activity) + user = insert(:user) + + data = %{ + "type" => "Announce", + "actor" => note_activity.actor, + "object" => note_activity.data["id"], + "to" => [user.follower_address, note_activity.data["actor"]], + "cc" => ["https://www.w3.org/ns/activitystreams#Public"], + "context" => note_activity.data["context"] + } + + %Pleroma.Activity{ + data: data, + actor: user.ap_id, + recipients: data["to"] + } + end + def like_activity_factory do note_activity = insert(:note_activity) user = insert(:user) diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index a52d44ed6..527c2e1f7 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -3,6 +3,14 @@ defmodule HTTPoisonMock do def get(url, body \\ [], headers \\ []) + def get("https://puckipedia.com/", [Accept: "application/activity+json"], _) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/puckipedia.com.json") + }} + end + def get( "https://gerzilla.de/.well-known/webfinger?resource=acct:kaniini@gerzilla.de", [Accept: "application/xrd+xml,application/jrd+json"], diff --git a/test/upload_test.exs b/test/upload_test.exs index 09aa5e068..d273ea5f6 100644 --- a/test/upload_test.exs +++ b/test/upload_test.exs @@ -56,5 +56,31 @@ defmodule Pleroma.UploadTest do data = Upload.store(file, false) assert data["name"] == "an [image.jpg" end + + test "fixes incorrect file extension" do + File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg") + + file = %Plug.Upload{ + content_type: "image/jpg", + path: Path.absname("test/fixtures/image_tmp.jpg"), + filename: "an [image.blah" + } + + data = Upload.store(file, false) + assert data["name"] == "an [image.jpg" + end + + test "don't modify filename of an unknown type" do + File.cp("test/fixtures/test.txt", "test/fixtures/test_tmp.txt") + + file = %Plug.Upload{ + content_type: "text/plain", + path: Path.absname("test/fixtures/test_tmp.txt"), + filename: "test.txt" + } + + data = Upload.store(file, false) + assert data["name"] == "test.txt" + end end end diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index bbf89136b..3ed7be402 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -62,6 +62,32 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do end end + describe "/users/:nickname/outbox" do + test "it returns a note activity in a collection", %{conn: conn} do + note_activity = insert(:note_activity) + user = User.get_cached_by_ap_id(note_activity.data["actor"]) + + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/users/#{user.nickname}/outbox") + + assert response(conn, 200) =~ note_activity.data["object"]["content"] + end + + test "it returns an announce activity in a collection", %{conn: conn} do + announce_activity = insert(:announce_activity) + user = User.get_cached_by_ap_id(announce_activity.data["actor"]) + + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/users/#{user.nickname}/outbox") + + assert response(conn, 200) =~ announce_activity.data["object"] + end + end + describe "/users/:nickname/followers" do test "it returns the followers in a collection", %{conn: conn} do user = insert(:user) diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 838ae169d..e455da39f 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -112,6 +112,15 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>" end + test "it works for incoming notices with to/cc not being an array (kroeg)" do + data = File.read!("test/fixtures/kroeg-post-activity.json") |> Poison.decode!() + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["object"]["content"] == + "<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>" + end + test "it works for incoming follow requests" do user = insert(:user) diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index b93418b3f..8bf194e6b 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -5,10 +5,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do alias Pleroma.User test "Represent a user account" do + source_data = %{ + "tag" => [ + %{ + "type" => "Emoji", + "icon" => %{"url" => "/file.png"}, + "name" => ":karjalanpiirakka:" + } + ] + } + user = insert(:user, %{ - info: %{"note_count" => 5, "follower_count" => 3}, + info: %{"note_count" => 5, "follower_count" => 3, "source_data" => source_data}, nickname: "shp@shitposter.club", + name: ":karjalanpiirakka: shp", inserted_at: ~N[2017-08-15 15:47:06.597036] }) @@ -28,7 +39,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do avatar_static: "http://localhost:4001/images/avi.png", header: "http://localhost:4001/images/banner.png", header_static: "http://localhost:4001/images/banner.png", - emojis: [], + emojis: [ + %{ + "static_url" => "/file.png", + "url" => "/file.png", + "shortcode" => "karjalanpiirakka", + "visible_in_picker" => false + } + ], fields: [], source: %{ note: "", diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 06c1ba6ec..6486540f8 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -2,7 +2,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do use Pleroma.DataCase alias Pleroma.Builders.UserBuilder alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} - alias Pleroma.{Activity, User, Object, Repo} + alias Pleroma.{Activity, User, Object, Repo, UserInviteToken} alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.ActivityView @@ -257,6 +257,70 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do UserView.render("show.json", %{user: fetched_user}) end + @moduletag skip: "needs 'registrations_open: false' in config" + test "it registers a new user via invite token and returns the user." do + {:ok, token} = UserInviteToken.create_token() + + data = %{ + "nickname" => "vinny", + "email" => "pasta@pizza.vs", + "fullname" => "Vinny Vinesauce", + "bio" => "streamer", + "password" => "hiptofbees", + "confirm" => "hiptofbees", + "token" => token.token + } + + {:ok, user} = TwitterAPI.register_user(data) + + fetched_user = Repo.get_by(User, nickname: "vinny") + token = Repo.get_by(UserInviteToken, token: token.token) + + assert token.used == true + + assert UserView.render("show.json", %{user: user}) == + UserView.render("show.json", %{user: fetched_user}) + end + + @moduletag skip: "needs 'registrations_open: false' in config" + test "it returns an error if invalid token submitted" do + data = %{ + "nickname" => "GrimReaper", + "email" => "death@reapers.afterlife", + "fullname" => "Reaper Grim", + "bio" => "Your time has come", + "password" => "scythe", + "confirm" => "scythe", + "token" => "DudeLetMeInImAFairy" + } + + {:error, msg} = TwitterAPI.register_user(data) + + assert msg == "Invalid token" + refute Repo.get_by(User, nickname: "GrimReaper") + end + + @moduletag skip: "needs 'registrations_open: false' in config" + test "it returns an error if expired token submitted" do + {:ok, token} = UserInviteToken.create_token() + UserInviteToken.mark_as_used(token.token) + + data = %{ + "nickname" => "GrimReaper", + "email" => "death@reapers.afterlife", + "fullname" => "Reaper Grim", + "bio" => "Your time has come", + "password" => "scythe", + "confirm" => "scythe", + "token" => token.token + } + + {:error, msg} = TwitterAPI.register_user(data) + + assert msg == "Expired token" + refute Repo.get_by(User, nickname: "GrimReaper") + end + test "it returns the error on registration problems" do data = %{ "nickname" => "lain", diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 49f73c2fe..fefb6bdcc 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -20,6 +20,30 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do assert represented["profile_image_url"] == image end + test "A user with emoji in username", %{user: user} do + expected = + "<img height='32px' width='32px' alt='karjalanpiirakka' title='karjalanpiirakka' src='/file.png' /> man" + + user = %{ + user + | info: %{ + "source_data" => %{ + "tag" => [ + %{ + "type" => "Emoji", + "icon" => %{"url" => "/file.png"}, + "name" => ":karjalanpiirakka:" + } + ] + } + } + } + + user = %{user | name: ":karjalanpiirakka: man"} + represented = UserView.render("show.json", %{user: user}) + assert represented["name_html"] == expected + end + test "A user" do note_activity = insert(:note_activity) user = User.get_cached_by_ap_id(note_activity.data["actor"]) @@ -40,7 +64,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "id" => user.id, "name" => user.name, "screen_name" => user.nickname, + "name_html" => user.name, "description" => HtmlSanitizeEx.strip_tags(user.bio), + "description_html" => HtmlSanitizeEx.strip_tags(user.bio), "created_at" => user.inserted_at |> Utils.format_naive_asctime(), "favourites_count" => 0, "statuses_count" => 1, @@ -77,7 +103,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "id" => user.id, "name" => user.name, "screen_name" => user.nickname, + "name_html" => user.name, "description" => HtmlSanitizeEx.strip_tags(user.bio), + "description_html" => HtmlSanitizeEx.strip_tags(user.bio), "created_at" => user.inserted_at |> Utils.format_naive_asctime(), "favourites_count" => 0, "statuses_count" => 0, @@ -115,7 +143,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "id" => follower.id, "name" => follower.name, "screen_name" => follower.nickname, + "name_html" => follower.name, "description" => HtmlSanitizeEx.strip_tags(follower.bio), + "description_html" => HtmlSanitizeEx.strip_tags(follower.bio), "created_at" => follower.inserted_at |> Utils.format_naive_asctime(), "favourites_count" => 0, "statuses_count" => 0, @@ -160,7 +190,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "id" => user.id, "name" => user.name, "screen_name" => user.nickname, + "name_html" => user.name, "description" => HtmlSanitizeEx.strip_tags(user.bio), + "description_html" => HtmlSanitizeEx.strip_tags(user.bio), "created_at" => user.inserted_at |> Utils.format_naive_asctime(), "favourites_count" => 0, "statuses_count" => 0, |