Merge remote-tracking branch 'remotes/origin/develop' into feature/object-hashtags-rework

This commit is contained in:
Ivan Tashkinov 2021-03-02 08:26:30 +03:00
commit 882dd46843
146 changed files with 1354 additions and 272 deletions

View file

@ -92,4 +92,34 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
assert object.data["url"] ==
"https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
end
test "it works for peertube videos with only their mpegURL map" do
data =
File.read!("test/fixtures/peertube/video-object-mpegURL-only.json")
|> Jason.decode!()
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
assert object = Object.normalize(activity, fetch: false)
assert object.data["attachment"] == [
%{
"type" => "Link",
"mediaType" => "video/mp4",
"name" => nil,
"blurhash" => nil,
"url" => [
%{
"href" =>
"https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
"mediaType" => "video/mp4",
"type" => "Link"
}
]
}
]
assert object.data["url"] ==
"https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6"
end
end

View file

@ -202,7 +202,20 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it strips internal fields" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "#2hu :firefox:"})
{:ok, activity} =
CommonAPI.post(user, %{
status: "#2hu :firefox:",
generator: %{type: "Application", name: "TestClient", url: "https://pleroma.social"}
})
# Ensure injected application data made it into the activity
# as we don't have a Token to derive it from, otherwise it will
# be nil and the test will pass
assert %{
type: "Application",
name: "TestClient",
url: "https://pleroma.social"
} == activity.object.data["generator"]
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
@ -213,6 +226,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert is_nil(modified["object"]["announcements"])
assert is_nil(modified["object"]["announcement_count"])
assert is_nil(modified["object"]["context_id"])
assert is_nil(modified["object"]["generator"])
end
test "it strips internal fields of article" do

View file

@ -357,6 +357,50 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert activity.data["to"] == [user2.ap_id]
assert activity.data["cc"] == []
end
test "discloses application metadata when enabled" do
user = insert(:user, disclose_client: true)
%{user: _user, token: token, conn: conn} = oauth_access(["write:statuses"], user: user)
%Pleroma.Web.OAuth.Token{
app: %Pleroma.Web.OAuth.App{
client_name: app_name,
website: app_website
}
} = token
result =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{
"status" => "cofe is my copilot"
})
assert %{
"content" => "cofe is my copilot",
"application" => %{
"name" => ^app_name,
"website" => ^app_website
}
} = json_response_and_validate_schema(result, 200)
end
test "hides application metadata when disabled" do
user = insert(:user, disclose_client: false)
%{user: _user, token: _token, conn: conn} = oauth_access(["write:statuses"], user: user)
result =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{
"status" => "club mate is my wingman"
})
assert %{
"content" => "club mate is my wingman",
"application" => nil
} = json_response_and_validate_schema(result, 200)
end
end
describe "posting scheduled statuses" do
@ -383,6 +427,31 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
assert [] == Repo.all(Activity)
end
test "with expiration" do
%{conn: conn} = oauth_access(["write:statuses", "read:statuses"])
scheduled_at =
NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(6), :millisecond)
|> NaiveDateTime.to_iso8601()
|> Kernel.<>("Z")
assert %{"id" => status_id, "params" => %{"expires_in" => 300}} =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/v1/statuses", %{
"status" => "scheduled",
"scheduled_at" => scheduled_at,
"expires_in" => 300
})
|> json_response_and_validate_schema(200)
assert %{"id" => ^status_id, "params" => %{"expires_in" => 300}} =
conn
|> put_req_header("content-type", "application/json")
|> get("/api/v1/scheduled_statuses/#{status_id}")
|> json_response_and_validate_schema(200)
end
test "ignores nil values", %{conn: conn} do
conn =
conn

View file

@ -58,7 +58,8 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
sensitive: true,
spoiler_text: "spoiler",
text: "hi",
visibility: "unlisted"
visibility: "unlisted",
expires_in: nil
},
scheduled_at: Utils.to_masto_date(scheduled_activity.scheduled_at)
}

View file

@ -266,10 +266,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
url: "http://localhost:4001/tag/#{hd(object_data["tag"])}"
}
],
application: %{
name: "Web",
website: nil
},
application: nil,
language: nil,
emojis: [
%{

View file

@ -0,0 +1,80 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ReportControllerTest do
use Pleroma.Web.ConnCase, async: true
import Pleroma.Factory
alias Pleroma.Web.CommonAPI
describe "GET /api/v0/pleroma/reports" do
test "returns list of own reports" do
%{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
%{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
activity = insert(:note_activity, user: reported)
{:ok, %{id: report_id}} =
CommonAPI.report(reporter, %{
account_id: reported.id,
comment: "You stole my sandwich!",
status_ids: [activity.id]
})
assert reported_response =
reported_conn
|> get("/api/v0/pleroma/reports")
|> json_response_and_validate_schema(:ok)
assert reported_response == %{"reports" => [], "total" => 0}
assert reporter_response =
reporter_conn
|> get("/api/v0/pleroma/reports")
|> json_response_and_validate_schema(:ok)
assert %{"reports" => [report], "total" => 1} = reporter_response
assert report["id"] == report_id
refute report["notes"]
end
end
describe "GET /api/v0/pleroma/reports/:id" do
test "returns report by its id" do
%{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
%{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
activity = insert(:note_activity, user: reported)
{:ok, %{id: report_id}} =
CommonAPI.report(reporter, %{
account_id: reported.id,
comment: "You stole my sandwich!",
status_ids: [activity.id]
})
assert reported_conn
|> get("/api/v0/pleroma/reports/#{report_id}")
|> json_response_and_validate_schema(:not_found)
assert response =
reporter_conn
|> get("/api/v0/pleroma/reports/#{report_id}")
|> json_response_and_validate_schema(:ok)
assert response["id"] == report_id
refute response["notes"]
end
test "returns 404 when report id is invalid" do
%{conn: conn, user: _user} = oauth_access(["read:reports"])
assert response =
conn
|> get("/api/v0/pleroma/reports/0")
|> json_response_and_validate_schema(:not_found)
assert response == %{"error" => "Record not found"}
end
end
end

View file

@ -74,4 +74,35 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
assert %Plug.Conn{status: :success} = get(conn, url)
end
end
test "api routes are detected correctly" do
# If this test fails we have probably added something
# new that should be in /api/ instead
expected_routes = [
"api",
"main",
"ostatus_subscribe",
"oauth",
"objects",
"activities",
"notice",
"users",
"tags",
"mailer",
"inbox",
"relay",
"internal",
".well-known",
"nodeinfo",
"web",
"auth",
"embed",
"proxy",
"test",
"user_exists",
"check_password"
]
assert expected_routes == Pleroma.Web.get_api_routes()
end
end