summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2021-02-28 16:17:34 +0000
committerlain <lain@soykaf.club>2021-02-28 16:17:34 +0000
commite6a14e1cd10a52450eaf3d1ba258eac4042d82a9 (patch)
tree79c9920f4b01dc45a7292efcdaf9e97c7391a373 /test
parentd0823d7f1e95c91a53545fae9299e5bcc6eaf758 (diff)
parent0faf8dbef8f0d77fdd42b36ade4d55c42f0ccc8c (diff)
Merge branch 'feat/client_app_details' into 'develop'
Support application field See merge request pleroma/pleroma!3311
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/web/activity_pub/transmogrifier_test.exs16
-rw-r--r--test/pleroma/web/mastodon_api/controllers/status_controller_test.exs44
-rw-r--r--test/pleroma/web/mastodon_api/views/status_view_test.exs5
3 files changed, 60 insertions, 5 deletions
diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs
index 7c97fa8f8..f6a8cbb6f 100644
--- a/test/pleroma/web/activity_pub/transmogrifier_test.exs
+++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs
@@ -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:",
+ application: %{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["application"]
{: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"]["application"])
end
test "it strips internal fields of article" do
diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
index c59b156bf..dd2f306b7 100644
--- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs
@@ -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
diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs
index ed59cf285..2de3afc4f 100644
--- a/test/pleroma/web/mastodon_api/views/status_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs
@@ -266,10 +266,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
url: "http://localhost:4001/tag/#{object_data["tag"]}"
}
],
- application: %{
- name: "Web",
- website: nil
- },
+ application: nil,
language: nil,
emojis: [
%{