summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/flake_id_test.exs1
-rw-r--r--test/support/http_request_mock.ex8
-rw-r--r--test/user_test.exs6
-rw-r--r--test/web/activity_pub/activity_pub_test.exs41
-rw-r--r--test/web/mastodon_api/account_view_test.exs8
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs69
-rw-r--r--test/web/mastodon_api/status_view_test.exs1
-rw-r--r--test/web/oauth/oauth_controller_test.exs25
-rw-r--r--test/web/rich_media/controllers/rich_media_controller_test.exs54
-rw-r--r--test/web/rich_media/parser_test.exs41
-rw-r--r--test/web/twitter_api/representers/activity_representer_test.exs1
-rw-r--r--test/web/twitter_api/util_controller_test.exs67
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs3
13 files changed, 245 insertions, 80 deletions
diff --git a/test/flake_id_test.exs b/test/flake_id_test.exs
index 8e969fd1c..ca2338041 100644
--- a/test/flake_id_test.exs
+++ b/test/flake_id_test.exs
@@ -11,6 +11,7 @@ defmodule Pleroma.FlakeIdTest do
test "from_string/1" do
fake_flake = <<0::integer-size(64), 42::integer-size(64)>>
assert from_string("42") == fake_flake
+ assert from_string(42) == fake_flake
end
test "zero or -1 is a null flake" do
diff --git a/test/support/http_request_mock.ex b/test/support/http_request_mock.ex
index e4279e14d..3043d2be6 100644
--- a/test/support/http_request_mock.ex
+++ b/test/support/http_request_mock.ex
@@ -653,6 +653,14 @@ defmodule HttpRequestMock do
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
end
+ def get("http://example.com/ogp", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}}
+ end
+
+ def get("http://example.com/empty", _, _, _) do
+ {:ok, %Tesla.Env{status: 200, body: "hello"}}
+ end
+
def get(url, query, body, headers) do
{:error,
"Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
diff --git a/test/user_test.exs b/test/user_test.exs
index a0657c7b6..cd202e360 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -50,13 +50,19 @@ defmodule Pleroma.UserTest do
test "follow_all follows mutliple users" do
user = insert(:user)
+ followed_zero = insert(:user)
followed_one = insert(:user)
followed_two = insert(:user)
+ not_followed = insert(:user)
+
+ {:ok, user} = User.follow(user, followed_zero)
{:ok, user} = User.follow_all(user, [followed_one, followed_two])
assert User.following?(user, followed_one)
assert User.following?(user, followed_two)
+ assert User.following?(user, followed_zero)
+ refute User.following?(user, not_followed)
end
test "follow takes a user and another user" do
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index d2e54d804..b826f5a1b 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -64,6 +64,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert user.info.ap_enabled
assert user.follower_address == "http://mastodon.example.org/users/admin/followers"
end
+
+ test "it fetches the appropriate tag-restricted posts" do
+ user = insert(:user)
+
+ {:ok, status_one} = CommonAPI.post(user, %{"status" => ". #test"})
+ {:ok, status_two} = CommonAPI.post(user, %{"status" => ". #essais"})
+ {:ok, status_three} = CommonAPI.post(user, %{"status" => ". #test #reject"})
+
+ fetch_one = ActivityPub.fetch_activities([], %{"tag" => "test"})
+ fetch_two = ActivityPub.fetch_activities([], %{"tag" => ["test", "essais"]})
+
+ fetch_three =
+ ActivityPub.fetch_activities([], %{
+ "tag" => ["test", "essais"],
+ "tag_reject" => ["reject"]
+ })
+
+ fetch_four =
+ ActivityPub.fetch_activities([], %{
+ "tag" => ["test"],
+ "tag_all" => ["test", "reject"]
+ })
+
+ assert fetch_one == [status_one, status_three]
+ assert fetch_two == [status_one, status_two, status_three]
+ assert fetch_three == [status_one, status_two]
+ assert fetch_four == [status_three]
+ end
end
describe "insertion" do
@@ -85,6 +113,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert {:error, {:remote_limit_error, _}} = ActivityPub.insert(data)
end
+ test "doesn't drop activities with content being null" do
+ data = %{
+ "ok" => true,
+ "object" => %{
+ "content" => nil
+ }
+ }
+
+ assert {:ok, _} = ActivityPub.insert(data)
+ end
+
test "returns the activity if one with the same id is already in" do
activity = insert(:note_activity)
{:ok, new_activity} = ActivityPub.insert(activity.data)
@@ -584,8 +623,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
"in_reply_to_status_id" => private_activity_2.id
})
- assert user1.following == [user3.ap_id <> "/followers", user1.ap_id]
-
activities = ActivityPub.fetch_activities([user1.ap_id | user1.following])
assert [public_activity, private_activity_1, private_activity_3] == activities
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index d53e11963..f8cd68173 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -61,7 +61,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
},
pleroma: %{
confirmation_pending: false,
- tags: []
+ tags: [],
+ is_admin: false,
+ is_moderator: false
}
}
@@ -102,7 +104,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
},
pleroma: %{
confirmation_pending: false,
- tags: []
+ tags: [],
+ is_admin: false,
+ is_moderator: false
}
}
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 6004285d6..1a5eb090c 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -136,6 +136,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert Repo.get(Activity, id)
end
+ test "posting a status with OGP link preview", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses", %{
+ "status" => "http://example.com/ogp"
+ })
+
+ assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
+ assert Repo.get(Activity, id)
+ end
+
test "posting a direct status", %{conn: conn} do
user1 = insert(:user)
user2 = insert(:user)
@@ -1044,6 +1058,34 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end)
end
+ test "multi-hashtag timeline", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
+ {:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"})
+ {:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
+
+ any_test =
+ conn
+ |> get("/api/v1/timelines/tag/test", %{"any" => ["test1"]})
+
+ [status_none, status_test1, status_test] = json_response(any_test, 200)
+
+ assert to_string(activity_test.id) == status_test["id"]
+ assert to_string(activity_test1.id) == status_test1["id"]
+ assert to_string(activity_none.id) == status_none["id"]
+
+ restricted_test =
+ conn
+ |> get("/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
+
+ assert [status_test1] == json_response(restricted_test, 200)
+
+ all_test = conn |> get("/api/v1/timelines/tag/test", %{"all" => ["none"]})
+
+ assert [status_none] == json_response(all_test, 200)
+ end
+
test "getting followers", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -1623,5 +1665,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> post("/api/v1/statuses/#{activity_two.id}/pin")
|> json_response(400)
end
+
+ test "Status rich-media Card", %{conn: conn, user: user} do
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "http://example.com/ogp"})
+
+ response =
+ conn
+ |> get("/api/v1/statuses/#{activity.id}/card")
+ |> json_response(200)
+
+ assert response == %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "provider_name" => "www.imdb.com",
+ "provider_url" => "http://www.imdb.com",
+ "title" => "The Rock",
+ "type" => "link",
+ "url" => "http://www.imdb.com/title/tt0117500/",
+ "description" => nil,
+ "pleroma" => %{
+ "opengraph" => %{
+ "image" => "http://ia.media-imdb.com/images/rock.jpg",
+ "title" => "The Rock",
+ "type" => "video.movie",
+ "url" => "http://www.imdb.com/title/tt0117500/"
+ }
+ }
+ }
+ end
end
end
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index ebf6273e8..f957fedac 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -84,6 +84,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
account: AccountView.render("account.json", %{user: user}),
in_reply_to_id: nil,
in_reply_to_account_id: nil,
+ card: nil,
reblog: nil,
content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
created_at: created_at,
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index ccd552258..e0d3cb55f 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -34,6 +34,31 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert Repo.get_by(Authorization, token: code)
end
+ test "correctly handles wrong credentials", %{conn: conn} do
+ user = insert(:user)
+ app = insert(:oauth_app)
+
+ result =
+ conn
+ |> post("/oauth/authorize", %{
+ "authorization" => %{
+ "name" => user.nickname,
+ "password" => "wrong",
+ "client_id" => app.client_id,
+ "redirect_uri" => app.redirect_uris,
+ "state" => "statepassed"
+ }
+ })
+ |> html_response(:unauthorized)
+
+ # Keep the details
+ assert result =~ app.client_id
+ assert result =~ app.redirect_uris
+
+ # Error message
+ assert result =~ "Invalid"
+ end
+
test "issues a token for an all-body request" do
user = insert(:user)
app = insert(:oauth_app)
diff --git a/test/web/rich_media/controllers/rich_media_controller_test.exs b/test/web/rich_media/controllers/rich_media_controller_test.exs
deleted file mode 100644
index 37c82631f..000000000
--- a/test/web/rich_media/controllers/rich_media_controller_test.exs
+++ /dev/null
@@ -1,54 +0,0 @@
-defmodule Pleroma.Web.RichMedia.RichMediaControllerTest do
- use Pleroma.Web.ConnCase
- import Pleroma.Factory
-
- setup do
- Tesla.Mock.mock(fn
- %{
- method: :get,
- url: "http://example.com/ogp"
- } ->
- %Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
-
- %{method: :get, url: "http://example.com/empty"} ->
- %Tesla.Env{status: 200, body: "hello"}
- end)
-
- :ok
- end
-
- describe "GET /api/rich_media/parse" do
- setup do
- user = insert(:user)
-
- [user: user]
- end
-
- test "returns 404 if not metadata found", %{user: user} do
- build_conn()
- |> with_credentials(user.nickname, "test")
- |> get("/api/rich_media/parse", %{"url" => "http://example.com/empty"})
- |> json_response(404)
- end
-
- test "returns OGP metadata", %{user: user} do
- response =
- build_conn()
- |> with_credentials(user.nickname, "test")
- |> get("/api/rich_media/parse", %{"url" => "http://example.com/ogp"})
- |> json_response(200)
-
- assert response == %{
- "image" => "http://ia.media-imdb.com/images/rock.jpg",
- "title" => "The Rock",
- "type" => "video.movie",
- "url" => "http://www.imdb.com/title/tt0117500/"
- }
- end
- end
-
- defp with_credentials(conn, username, password) do
- header_content = "Basic " <> Base.encode64("#{username}:#{password}")
- put_req_header(conn, "authorization", header_content)
- end
-end
diff --git a/test/web/rich_media/parser_test.exs b/test/web/rich_media/parser_test.exs
index e14b5061a..93a58c528 100644
--- a/test/web/rich_media/parser_test.exs
+++ b/test/web/rich_media/parser_test.exs
@@ -65,28 +65,27 @@ defmodule Pleroma.Web.RichMedia.ParserTest do
assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/oembed") ==
{:ok,
%{
- "author_name" => "‮‭‬bees‬",
- "author_url" => "https://www.flickr.com/photos/bees/",
- "cache_age" => 3600,
- "flickr_type" => "photo",
- "height" => "768",
- "html" =>
+ author_name: "‮‭‬bees‬",
+ author_url: "https://www.flickr.com/photos/bees/",
+ cache_age: 3600,
+ flickr_type: "photo",
+ height: "768",
+ html:
"<a data-flickr-embed=\"true\" href=\"https://www.flickr.com/photos/bees/2362225867/\" title=\"Bacon Lollys by ‮‭‬bees‬, on Flickr\"><img src=\"https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg\" width=\"1024\" height=\"768\" alt=\"Bacon Lollys\"></a><script async src=\"https://embedr.flickr.com/assets/client-code.js\" charset=\"utf-8\"></script>",
- "license" => "All Rights Reserved",
- "license_id" => 0,
- "provider_name" => "Flickr",
- "provider_url" => "https://www.flickr.com/",
- "thumbnail_height" => 150,
- "thumbnail_url" =>
- "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
- "thumbnail_width" => 150,
- "title" => "Bacon Lollys",
- "type" => "photo",
- "url" => "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
- "version" => "1.0",
- "web_page" => "https://www.flickr.com/photos/bees/2362225867/",
- "web_page_short_url" => "https://flic.kr/p/4AK2sc",
- "width" => "1024"
+ license: "All Rights Reserved",
+ license_id: 0,
+ provider_name: "Flickr",
+ provider_url: "https://www.flickr.com/",
+ thumbnail_height: 150,
+ thumbnail_url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_q.jpg",
+ thumbnail_width: 150,
+ title: "Bacon Lollys",
+ type: "photo",
+ url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg",
+ version: "1.0",
+ web_page: "https://www.flickr.com/photos/bees/2362225867/",
+ web_page_short_url: "https://flic.kr/p/4AK2sc",
+ width: "1024"
}}
end
end
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index ef0294140..ea5813733 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -164,6 +164,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"possibly_sensitive" => true,
"uri" => activity.data["object"]["id"],
"visibility" => "direct",
+ "card" => nil,
"summary" => "2hu :2hu:",
"summary_html" =>
"2hu <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" />"
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 73aa70bd5..dc9bad369 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -32,4 +32,71 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert response == "job started"
end
end
+
+ describe "GET /api/statusnet/config.json" do
+ test "it returns the managed config", %{conn: conn} do
+ Pleroma.Config.put([:instance, :managed_config], false)
+
+ response =
+ conn
+ |> get("/api/statusnet/config.json")
+ |> json_response(:ok)
+
+ refute response["site"]["pleromafe"]
+
+ Pleroma.Config.put([:instance, :managed_config], true)
+
+ response =
+ conn
+ |> get("/api/statusnet/config.json")
+ |> json_response(:ok)
+
+ assert response["site"]["pleromafe"]
+ end
+
+ test "if :pleroma, :fe is false, it returns the new style config settings", %{conn: conn} do
+ Pleroma.Config.put([:instance, :managed_config], true)
+ Pleroma.Config.put([:fe, :theme], "rei-ayanami-towel")
+ Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
+
+ response =
+ conn
+ |> get("/api/statusnet/config.json")
+ |> json_response(:ok)
+
+ assert response["site"]["pleromafe"]["theme"] == "rei-ayanami-towel"
+
+ Pleroma.Config.put([:fe], false)
+
+ response =
+ conn
+ |> get("/api/statusnet/config.json")
+ |> json_response(:ok)
+
+ assert response["site"]["pleromafe"]["theme"] == "asuka-hospital"
+ end
+ end
+
+ describe "GET /api/pleroma/frontend_configurations" do
+ test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
+ config = [
+ frontend_a: %{
+ x: 1,
+ y: 2
+ },
+ frontend_b: %{
+ z: 3
+ }
+ ]
+
+ Pleroma.Config.put(:frontend_configurations, config)
+
+ response =
+ conn
+ |> get("/api/pleroma/frontend_configurations")
+ |> json_response(:ok)
+
+ assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
+ end
+ end
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index ba053d20d..4f854ecaa 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -148,7 +148,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
- "visibility" => "direct"
+ "visibility" => "direct",
+ "card" => nil
}
assert result == expected