From 2c820e10b828ca2a00f94d09127d1234bf001d6b Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 26 Sep 2018 07:48:34 +0200 Subject: transmogrifier_test: incoming notices with tag not being an array (kroeg) --- test/fixtures/https___puckipedia.com_1jjx-ob5r.json | 1 + test/web/activity_pub/transmogrifier_test.exs | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 test/fixtures/https___puckipedia.com_1jjx-ob5r.json (limited to 'test') diff --git a/test/fixtures/https___puckipedia.com_1jjx-ob5r.json b/test/fixtures/https___puckipedia.com_1jjx-ob5r.json new file mode 100644 index 000000000..3d7025f55 --- /dev/null +++ b/test/fixtures/https___puckipedia.com_1jjx-ob5r.json @@ -0,0 +1 @@ +{"@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 πŸ‘©β€πŸ’»","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":"

federated hacker teen
\n[she/they]

","type":"Person","updated":"2017-12-19T16:56:29.7576707+00:00"},"cc":"https://puckipedia.com/followers","id":"https://puckipedia.com/1jjx-ob5r","object":{"attributedTo":"https://puckipedia.com/","cc":"https://puckipedia.com/followers","content":"

spinning up an extra process that just handles the delivery queue to see what happens. The concept of this working is kind of amusing :icon_e_smile:

I should probably add back some code to synchronize state between multiple processes; and add back the pubsub mechanism so live streams of collections can return! Also I should add database transactions back.

","conversation":"https://puckipedia.com/f/conversation/4eae6d6c-d046-4737-9c17-c7a791c7ad77","id":"https://puckipedia.com/1jjx-ob5r/note","likes":"https://puckipedia.com/1jjx-ob5r/note/likes","name":"Kroeg dev thread","published":"2018-09-25T22:35:59.770Z","replies":"https://puckipedia.com/1jjx-ob5r/note/replies","shares":"https://puckipedia.com/1jjx-ob5r/note/shares","tag":{"icon":{"mediaType":"image/png","type":"Image","url":"https://puckipedia.com/forum/images/smilies/icon_e_smile.png"},"id":"https://puckipedia.com/forum/images/smilies/icon_e_smile","name":":icon_e_smile:","type":"Emoji","updated":"2018-09-16T11:11:11.111Z"},"to":"https://www.w3.org/ns/activitystreams#Public","type":"Note"},"published":"2018-09-25T22:35:59.770Z","to":"https://www.w3.org/ns/activitystreams#Public","type":"Create"} \ No newline at end of file diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index afa25bb60..42ce701ca 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -121,6 +121,16 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do "

henlo from my Psion netBook

message sent from my Psion netBook

" end + test "it works for incoming notices with tag not being an array (kroeg)" do + data = File.read!("test/fixtures/https___puckipedia.com_1jjx-ob5r.json") |> Poison.decode!() + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["object"]["emoji"] == %{ + "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png" + } + end + test "it works for incoming follow requests" do user = insert(:user) -- cgit v1.2.3 From eebe33e86a064f8dff43663af634f101d25f88b3 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 26 Sep 2018 11:27:00 +0200 Subject: transmogrifier: Add support for array-less hashtags, add broken announce, harden get_actor --- test/fixtures/https___puckipedia.com_1jjx-ob5r.json | 1 - test/fixtures/kroeg-announce-with-inline-actor.json | 1 + test/fixtures/kroeg-array-less-emoji.json | 1 + test/fixtures/kroeg-array-less-hashtag.json | 1 + test/web/activity_pub/transmogrifier_test.exs | 18 +++++++++++++++++- 5 files changed, 20 insertions(+), 2 deletions(-) delete mode 100644 test/fixtures/https___puckipedia.com_1jjx-ob5r.json create mode 100644 test/fixtures/kroeg-announce-with-inline-actor.json create mode 100644 test/fixtures/kroeg-array-less-emoji.json create mode 100644 test/fixtures/kroeg-array-less-hashtag.json (limited to 'test') diff --git a/test/fixtures/https___puckipedia.com_1jjx-ob5r.json b/test/fixtures/https___puckipedia.com_1jjx-ob5r.json deleted file mode 100644 index 3d7025f55..000000000 --- a/test/fixtures/https___puckipedia.com_1jjx-ob5r.json +++ /dev/null @@ -1 +0,0 @@ -{"@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 πŸ‘©β€πŸ’»","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":"

federated hacker teen
\n[she/they]

","type":"Person","updated":"2017-12-19T16:56:29.7576707+00:00"},"cc":"https://puckipedia.com/followers","id":"https://puckipedia.com/1jjx-ob5r","object":{"attributedTo":"https://puckipedia.com/","cc":"https://puckipedia.com/followers","content":"

spinning up an extra process that just handles the delivery queue to see what happens. The concept of this working is kind of amusing :icon_e_smile:

I should probably add back some code to synchronize state between multiple processes; and add back the pubsub mechanism so live streams of collections can return! Also I should add database transactions back.

","conversation":"https://puckipedia.com/f/conversation/4eae6d6c-d046-4737-9c17-c7a791c7ad77","id":"https://puckipedia.com/1jjx-ob5r/note","likes":"https://puckipedia.com/1jjx-ob5r/note/likes","name":"Kroeg dev thread","published":"2018-09-25T22:35:59.770Z","replies":"https://puckipedia.com/1jjx-ob5r/note/replies","shares":"https://puckipedia.com/1jjx-ob5r/note/shares","tag":{"icon":{"mediaType":"image/png","type":"Image","url":"https://puckipedia.com/forum/images/smilies/icon_e_smile.png"},"id":"https://puckipedia.com/forum/images/smilies/icon_e_smile","name":":icon_e_smile:","type":"Emoji","updated":"2018-09-16T11:11:11.111Z"},"to":"https://www.w3.org/ns/activitystreams#Public","type":"Note"},"published":"2018-09-25T22:35:59.770Z","to":"https://www.w3.org/ns/activitystreams#Public","type":"Create"} \ No newline at end of file diff --git a/test/fixtures/kroeg-announce-with-inline-actor.json b/test/fixtures/kroeg-announce-with-inline-actor.json new file mode 100644 index 000000000..a2a7e2396 --- /dev/null +++ b/test/fixtures/kroeg-announce-with-inline-actor.json @@ -0,0 +1 @@ +{"@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 πŸ‘©β€πŸ’»","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":"

federated hacker teen
\n[she/they]

","type":"Person","updated":"2017-12-19T16:56:29.7576707+00:00"},"cc":"https://mastodon.social/users/revenant","id":"https://puckipedia.com/cc56a9658e","object":{"as:sensitive":false,"attributedTo":{"endpoints":{"sharedInbox":"https://mastodon.social/inbox","type":[]},"followers":"https://mastodon.social/users/revenant/followers","following":"https://mastodon.social/users/revenant/following","icon":{"mediaType":"image/png","type":"Image","url":"https://files.mastodon.social/accounts/avatars/000/015/163/original/70ca6c52b01ca913.png"},"id":"https://mastodon.social/users/revenant","inbox":"https://mastodon.social/users/revenant/inbox","manuallyApprovesFollowers":{"@value":"False","type":"xsd:boolean"},"name":"","outbox":"https://mastodon.social/users/revenant/outbox","preferredUsername":"revenant","publicKey":{"id":"https://mastodon.social/users/revenant#main-key","owner":"https://mastodon.social/users/revenant","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0gEN3wPW7gkE2gQqnmfB\n1ychjmFIf2LIwY0oCJLiGE/xpZrUKoq+eWH30AP7mATw4LD0gOYABL/ijqPUrPqR\nDXLL+0CqMP8HsZKvRlj9KArMK3YtNiSGGj2U7iReiRrD7nJzjJlsjjJXflLZhZ7/\nenSv1CcaeK8tB0PoAgShy/MyfhPF7WI5/Zm9DmmDQFvUEnDYKXAf/vG/IWw1EyMC\nkbaEYJeIowQU3GsbPxzRGI22bQtfotm431Ch2MbNo+kyzmYVFLAVoSGNMzvJwOPg\nTxLIIBeQXG7MinRyK887yPKhxhcALea4yCcALaa+3jPE7yqwIKYwTHtSlblsHDAo\nmQIDAQAB\n-----END PUBLIC KEY-----\n","type":[]},"summary":"

neatly partitioned meats and cheeses appeal to me on an aesthetic level | any pronouns | revenant1.net

","type":"Person","url":"https://mastodon.social/@revenant"},"cc":"https://mastodon.social/users/revenant/followers","content":"

the name's jond (jeans bond)

","contentMap":{"en":"

the name's jond (jeans bond)

"},"conversation":"tag:mastodon.social,2018-09-25:objectId=55659382:objectType=Conversation","id":"https://mastodon.social/users/revenant/statuses/100787282858396771","ostatus:atomUri":"https://mastodon.social/users/revenant/statuses/100787282858396771","published":"2018-09-25T16:11:29Z","to":"https://www.w3.org/ns/activitystreams#Public","type":"Note","url":"https://mastodon.social/@revenant/100787282858396771"},"to":["https://www.w3.org/ns/activitystreams#Public","https://puckipedia.com/followers"],"type":"Announce"} \ No newline at end of file diff --git a/test/fixtures/kroeg-array-less-emoji.json b/test/fixtures/kroeg-array-less-emoji.json new file mode 100644 index 000000000..3d7025f55 --- /dev/null +++ b/test/fixtures/kroeg-array-less-emoji.json @@ -0,0 +1 @@ +{"@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 πŸ‘©β€πŸ’»","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":"

federated hacker teen
\n[she/they]

","type":"Person","updated":"2017-12-19T16:56:29.7576707+00:00"},"cc":"https://puckipedia.com/followers","id":"https://puckipedia.com/1jjx-ob5r","object":{"attributedTo":"https://puckipedia.com/","cc":"https://puckipedia.com/followers","content":"

spinning up an extra process that just handles the delivery queue to see what happens. The concept of this working is kind of amusing :icon_e_smile:

I should probably add back some code to synchronize state between multiple processes; and add back the pubsub mechanism so live streams of collections can return! Also I should add database transactions back.

","conversation":"https://puckipedia.com/f/conversation/4eae6d6c-d046-4737-9c17-c7a791c7ad77","id":"https://puckipedia.com/1jjx-ob5r/note","likes":"https://puckipedia.com/1jjx-ob5r/note/likes","name":"Kroeg dev thread","published":"2018-09-25T22:35:59.770Z","replies":"https://puckipedia.com/1jjx-ob5r/note/replies","shares":"https://puckipedia.com/1jjx-ob5r/note/shares","tag":{"icon":{"mediaType":"image/png","type":"Image","url":"https://puckipedia.com/forum/images/smilies/icon_e_smile.png"},"id":"https://puckipedia.com/forum/images/smilies/icon_e_smile","name":":icon_e_smile:","type":"Emoji","updated":"2018-09-16T11:11:11.111Z"},"to":"https://www.w3.org/ns/activitystreams#Public","type":"Note"},"published":"2018-09-25T22:35:59.770Z","to":"https://www.w3.org/ns/activitystreams#Public","type":"Create"} \ No newline at end of file diff --git a/test/fixtures/kroeg-array-less-hashtag.json b/test/fixtures/kroeg-array-less-hashtag.json new file mode 100644 index 000000000..28a01904c --- /dev/null +++ b/test/fixtures/kroeg-array-less-hashtag.json @@ -0,0 +1 @@ +{"@context":["https://www.w3.org/ns/activitystreams","https://puckipedia.com/-/context"],"actor":"https://puckipedia.com/","id":"https://puckipedia.com/ur33-818k","object":{"attributedTo":{"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":"

federated hacker teen
\n[she/they]

","type":"Person","updated":"2017-12-19T16:56:29.7576707+00:00"},"content":"test","id":"https://puckipedia.com/ur33-818k/note","likes":"https://puckipedia.com/ur33-818k/note/likes","replies":"https://puckipedia.com/ur33-818k/note/replies","shares":"https://puckipedia.com/ur33-818k/note/shares","tag":{"href":"https://puckipedia.com/ur33-818k/note/hashtag","id":"https://puckipedia.com/ur33-818k/note/hashtag","name":"#test","type":"Hashtag"},"to":"https://www.w3.org/ns/activitystreams#Public","type":"Note"},"to":"https://www.w3.org/ns/activitystreams#Public","type":"Create"} \ No newline at end of file diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 42ce701ca..7b3c05caa 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -121,14 +121,30 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do "

henlo from my Psion netBook

message sent from my Psion netBook

" end + # Broken ;/ + # + # test "it works for incoming announces with actor being inlined (kroeg)" do + # data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Poison.decode!() + # + # {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + # + # assert data["object"]["actor"] == "https://puckipedia.com/" + # end + test "it works for incoming notices with tag not being an array (kroeg)" do - data = File.read!("test/fixtures/https___puckipedia.com_1jjx-ob5r.json") |> Poison.decode!() + data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) assert data["object"]["emoji"] == %{ "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png" } + + data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Poison.decode!() + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert "test" in data["object"]["tag"] end test "it works for incoming follow requests" do -- cgit v1.2.3 From d830a243a34b1c41ac81f368bce565285bd89ab7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 27 Sep 2018 07:14:15 +0000 Subject: transmogrifier: more robustly handle dereferencing pointer URIs --- ...stodon.example.org_users_admin_status_1234.json | 55 ++++++++++++++++++++++ .../fixtures/kroeg-announce-with-inline-actor.json | 2 +- test/support/httpoison_mock.ex | 11 +++++ test/web/activity_pub/transmogrifier_test.exs | 16 +++---- 4 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json (limited to 'test') diff --git a/test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json b/test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json new file mode 100644 index 000000000..5c7c9c6d3 --- /dev/null +++ b/test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json @@ -0,0 +1,55 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "sensitive": "as:sensitive", + "movedTo": { + "@id": "as:movedTo", + "@type": "@id" + }, + "Hashtag": "as:Hashtag", + "ostatus": "http://ostatus.org#", + "atomUri": "ostatus:atomUri", + "inReplyToAtomUri": "ostatus:inReplyToAtomUri", + "conversation": "ostatus:conversation", + "toot": "http://joinmastodon.org/ns#", + "Emoji": "toot:Emoji", + "focalPoint": { + "@container": "@list", + "@id": "toot:focalPoint" + }, + "featured": { + "@id": "toot:featured", + "@type": "@id" + }, + "schema": "http://schema.org#", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value" + } + ], + "id": "http://mastodon.example.org/users/admin/statuses/100787282858396771", + "type": "Note", + "summary": null, + "inReplyTo": null, + "published": "2018-09-25T16:11:29Z", + "url": "https://mastodon.example.org/@admin/100787282858396771", + "attributedTo": "http://mastodon.example.org/users/admin", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "http://mastodon.example.org/users/admin/followers" + ], + "sensitive": false, + "atomUri": "http://mastodon.example.org/users/admin/statuses/100787282858396771", + "inReplyToAtomUri": null, + "conversation": "tag:mastodon.social,2018-09-25:objectId=55659382:objectType=Conversation", + "content": "

the name's jond (jeans bond)

", + "contentMap": { + "en": "

the name's jond (jeans bond)

" + }, + "attachment": [], + "tag": [] +} diff --git a/test/fixtures/kroeg-announce-with-inline-actor.json b/test/fixtures/kroeg-announce-with-inline-actor.json index a2a7e2396..7bd6e8199 100644 --- a/test/fixtures/kroeg-announce-with-inline-actor.json +++ b/test/fixtures/kroeg-announce-with-inline-actor.json @@ -1 +1 @@ -{"@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 πŸ‘©β€πŸ’»","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":"

federated hacker teen
\n[she/they]

","type":"Person","updated":"2017-12-19T16:56:29.7576707+00:00"},"cc":"https://mastodon.social/users/revenant","id":"https://puckipedia.com/cc56a9658e","object":{"as:sensitive":false,"attributedTo":{"endpoints":{"sharedInbox":"https://mastodon.social/inbox","type":[]},"followers":"https://mastodon.social/users/revenant/followers","following":"https://mastodon.social/users/revenant/following","icon":{"mediaType":"image/png","type":"Image","url":"https://files.mastodon.social/accounts/avatars/000/015/163/original/70ca6c52b01ca913.png"},"id":"https://mastodon.social/users/revenant","inbox":"https://mastodon.social/users/revenant/inbox","manuallyApprovesFollowers":{"@value":"False","type":"xsd:boolean"},"name":"","outbox":"https://mastodon.social/users/revenant/outbox","preferredUsername":"revenant","publicKey":{"id":"https://mastodon.social/users/revenant#main-key","owner":"https://mastodon.social/users/revenant","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0gEN3wPW7gkE2gQqnmfB\n1ychjmFIf2LIwY0oCJLiGE/xpZrUKoq+eWH30AP7mATw4LD0gOYABL/ijqPUrPqR\nDXLL+0CqMP8HsZKvRlj9KArMK3YtNiSGGj2U7iReiRrD7nJzjJlsjjJXflLZhZ7/\nenSv1CcaeK8tB0PoAgShy/MyfhPF7WI5/Zm9DmmDQFvUEnDYKXAf/vG/IWw1EyMC\nkbaEYJeIowQU3GsbPxzRGI22bQtfotm431Ch2MbNo+kyzmYVFLAVoSGNMzvJwOPg\nTxLIIBeQXG7MinRyK887yPKhxhcALea4yCcALaa+3jPE7yqwIKYwTHtSlblsHDAo\nmQIDAQAB\n-----END PUBLIC KEY-----\n","type":[]},"summary":"

neatly partitioned meats and cheeses appeal to me on an aesthetic level | any pronouns | revenant1.net

","type":"Person","url":"https://mastodon.social/@revenant"},"cc":"https://mastodon.social/users/revenant/followers","content":"

the name's jond (jeans bond)

","contentMap":{"en":"

the name's jond (jeans bond)

"},"conversation":"tag:mastodon.social,2018-09-25:objectId=55659382:objectType=Conversation","id":"https://mastodon.social/users/revenant/statuses/100787282858396771","ostatus:atomUri":"https://mastodon.social/users/revenant/statuses/100787282858396771","published":"2018-09-25T16:11:29Z","to":"https://www.w3.org/ns/activitystreams#Public","type":"Note","url":"https://mastodon.social/@revenant/100787282858396771"},"to":["https://www.w3.org/ns/activitystreams#Public","https://puckipedia.com/followers"],"type":"Announce"} \ No newline at end of file +{"@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 πŸ‘©β€πŸ’»","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":"

federated hacker teen
\n[she/they]

","type":"Person","updated":"2017-12-19T16:56:29.7576707+00:00"},"cc":"http://mastodon.example.org/users/admin","id":"https://puckipedia.com/cc56a9658e","object":{"as:sensitive":false,"attributedTo":{"endpoints":{"sharedInbox":"https://mastodon.social/inbox","type":[]},"followers":"http://mastodon.example.org/users/admin/followers","following":"http://mastodon.example.org/users/admin/following","icon":{"mediaType":"image/png","type":"Image","url":"https://files.mastodon.social/accounts/avatars/000/015/163/original/70ca6c52b01ca913.png"},"id":"http://mastodon.example.org/users/admin","inbox":"http://mastodon.example.org/users/admin/inbox","manuallyApprovesFollowers":{"@value":"False","type":"xsd:boolean"},"name":"","outbox":"http://mastodon.example.org/users/admin/outbox","preferredUsername":"revenant","publicKey":{"id":"http://mastodon.example.org/users/admin#main-key","owner":"http://mastodon.example.org/users/admin","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0gEN3wPW7gkE2gQqnmfB\n1ychjmFIf2LIwY0oCJLiGE/xpZrUKoq+eWH30AP7mATw4LD0gOYABL/ijqPUrPqR\nDXLL+0CqMP8HsZKvRlj9KArMK3YtNiSGGj2U7iReiRrD7nJzjJlsjjJXflLZhZ7/\nenSv1CcaeK8tB0PoAgShy/MyfhPF7WI5/Zm9DmmDQFvUEnDYKXAf/vG/IWw1EyMC\nkbaEYJeIowQU3GsbPxzRGI22bQtfotm431Ch2MbNo+kyzmYVFLAVoSGNMzvJwOPg\nTxLIIBeQXG7MinRyK887yPKhxhcALea4yCcALaa+3jPE7yqwIKYwTHtSlblsHDAo\nmQIDAQAB\n-----END PUBLIC KEY-----\n","type":[]},"summary":"

neatly partitioned meats and cheeses appeal to me on an aesthetic level | any pronouns | revenant1.net

","type":"Person","url":"https://mastodon.social/@revenant"},"cc":"http://mastodon.example.org/users/admin/followers","content":"

the name's jond (jeans bond)

","contentMap":{"en":"

the name's jond (jeans bond)

"},"conversation":"tag:mastodon.social,2018-09-25:objectId=55659382:objectType=Conversation","id":"http://mastodon.example.org/users/admin/statuses/100787282858396771","ostatus:atomUri":"http://mastodon.example.org/users/admin/statuses/100787282858396771","published":"2018-09-25T16:11:29Z","to":"https://www.w3.org/ns/activitystreams#Public","type":"Note","url":"https://mastodon.social/@revenant/100787282858396771"},"to":["https://www.w3.org/ns/activitystreams#Public","https://puckipedia.com/followers"],"type":"Announce"} diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 7057f30fb..d8b79abef 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -404,6 +404,17 @@ defmodule HTTPoisonMock do }} end + def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _) do + {:ok, + %Response{ + status_code: 200, + body: + File.read!( + "test/fixtures/httpoison_mock/http___mastodon.example.org_users_admin_status_1234.json" + ) + }} + end + def get( "https://pawoo.net/.well-known/webfinger", [Accept: "application/xrd+xml,application/jrd+json"], diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 7b3c05caa..6a6f2a44c 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -121,15 +121,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do "

henlo from my Psion netBook

message sent from my Psion netBook

" end - # Broken ;/ - # - # test "it works for incoming announces with actor being inlined (kroeg)" do - # data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Poison.decode!() - # - # {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - # - # assert data["object"]["actor"] == "https://puckipedia.com/" - # end + test "it works for incoming announces with actor being inlined (kroeg)" do + data = File.read!("test/fixtures/kroeg-announce-with-inline-actor.json") |> Poison.decode!() + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["actor"] == "https://puckipedia.com/" + end test "it works for incoming notices with tag not being an array (kroeg)" do data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!() -- cgit v1.2.3 From 82b57ebad1b5de0fc4614441e8838cbdb4fe32b3 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 27 Sep 2018 20:17:44 +0200 Subject: [Pleroma.Web.TwitterAPI.UserView]: Add mastodon-fields in "fields" --- test/web/twitter_api/views/user_view_test.exs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 50687f450..383d7d34c 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -88,7 +88,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "is_local" => true, "locked" => false, "default_scope" => "public", - "no_rich_text" => false + "no_rich_text" => false, + "fields" => [] } assert represented == UserView.render("show.json", %{user: user}) @@ -128,7 +129,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "is_local" => true, "locked" => false, "default_scope" => "public", - "no_rich_text" => false + "no_rich_text" => false, + "fields" => [] } assert represented == UserView.render("show.json", %{user: user, for: follower}) @@ -169,7 +171,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "is_local" => true, "locked" => false, "default_scope" => "public", - "no_rich_text" => false + "no_rich_text" => false, + "fields" => [] } assert represented == UserView.render("show.json", %{user: follower, for: user}) @@ -217,7 +220,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do "is_local" => true, "locked" => false, "default_scope" => "public", - "no_rich_text" => false + "no_rich_text" => false, + "fields" => [] } blocker = Repo.get(User, blocker.id) -- cgit v1.2.3 From a74daabfae5ed149942b5afc64982d3e2ca95b11 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 28 Sep 2018 11:17:33 +0200 Subject: [Pleroma.Web.TwitterAPI.UserViewTest]: Add test for mastodon-fields --- test/web/twitter_api/views/user_view_test.exs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 383d7d34c..2deb22fb1 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -227,4 +227,30 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do blocker = Repo.get(User, blocker.id) assert represented == UserView.render("show.json", %{user: user, for: blocker}) end + + test "a user with mastodon fields" do + fields = [ + %{ + "name" => "Pronouns", + "value" => "she/her" + }, + %{ + "name" => "Website", + "value" => "https://example.org/" + } + ] + + user = + insert(:user, %{ + info: %{ + "source_data" => %{ + "attachment" => + Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end) + } + } + }) + + userview = UserView.render("show.json", %{user: user}) + assert userview["fields"] == fields + end end -- cgit v1.2.3 From a3cffd3566495edfe823b75142524717d0b64b24 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Fri, 28 Sep 2018 17:20:28 +0200 Subject: formatter: Stop using phoenix HTML and format it ourselves MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Pheonix has an extra scheme whitelist conflicting with ours * Pheonix doesn’t seems to do URL encoding, just HTML encoding Closes: https://git.pleroma.social/pleroma/pleroma/issues/307 --- test/formatter_test.exs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 273eefb8a..e37b17879 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -23,7 +23,7 @@ defmodule Pleroma.FormatterTest do text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ." expected = - "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ." + "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla ." assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected @@ -54,7 +54,7 @@ defmodule Pleroma.FormatterTest do text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087" expected = - "https://forum.zdoom.org/viewtopic.php?f=44&t=57087" + "https://forum.zdoom.org/viewtopic.php?f=44&t=57087" assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected @@ -75,7 +75,7 @@ defmodule Pleroma.FormatterTest do text = "https://en.wikipedia.org/wiki/Duff's_device" expected = - "https://en.wikipedia.org/wiki/Duff's_device" + "https://en.wikipedia.org/wiki/Duff's_device" assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected @@ -91,6 +91,13 @@ defmodule Pleroma.FormatterTest do expected = "xmpp:contact@hacktivis.me" assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected + + text = + "magnet:?xt=urn:btih:7ec9d298e91d6e4394d1379caf073c77ff3e3136&tr=udp%3A%2F%2Fopentor.org%3A2710&tr=udp%3A%2F%2Ftracker.blackunicorn.xyz%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com" + + expected = "#{text}" + + assert Formatter.add_links({[], text}) |> Formatter.finalize() == expected end end -- cgit v1.2.3 From b1be9415effadf81e557eddee3f60bdf0fa359af Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 2 Sep 2018 00:14:25 +0000 Subject: Revert "Merge branch 'revert-a26d5e6b' into 'develop'" This reverts commit d31bbb1cfe04ca6073a322bcf77239e7d4b79839, reversing changes made to 340ab3cb9068d444b77213e07beb8c2c3ca128b9. --- test/web/common_api/common_api_test.exs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 2a2c40833..cd5aca961 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -21,4 +21,36 @@ defmodule Pleroma.Web.CommonAPI.Test do assert karjalanpiirakka["name"] == ":karjalanpiirakka:" end + + describe "posting" do + test "it filters out obviously bad tags when accepting a post as HTML" do + user = insert(:user) + + post = "

2hu

" + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => post, + "content_type" => "text/html" + }) + + content = activity.data["object"]["content"] + assert content == "

2hu

alert('xss')" + end + + test "it filters out obviously bad tags when accepting a post as Markdown" do + user = insert(:user) + + post = "

2hu

" + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => post, + "content_type" => "text/markdown" + }) + + content = activity.data["object"]["content"] + assert content == "

2hu

alert('xss')" + end + end end -- cgit v1.2.3 From 497814cbbb4baea91b2882fbddd5cd8d5ad6e170 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 5 Oct 2018 21:11:22 +0000 Subject: test: update test for new html scrub policy --- test/web/common_api/common_api_test.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index cd5aca961..cd36e409c 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -26,7 +26,7 @@ defmodule Pleroma.Web.CommonAPI.Test do test "it filters out obviously bad tags when accepting a post as HTML" do user = insert(:user) - post = "

2hu

" + post = "

2hu

" {:ok, activity} = CommonAPI.post(user, %{ @@ -35,13 +35,13 @@ defmodule Pleroma.Web.CommonAPI.Test do }) content = activity.data["object"]["content"] - assert content == "

2hu

alert('xss')" + assert content == "

2hu

alert('xss')" end test "it filters out obviously bad tags when accepting a post as Markdown" do user = insert(:user) - post = "

2hu

" + post = "

2hu

" {:ok, activity} = CommonAPI.post(user, %{ @@ -50,7 +50,7 @@ defmodule Pleroma.Web.CommonAPI.Test do }) content = activity.data["object"]["content"] - assert content == "

2hu

alert('xss')" + assert content == "

2hu

alert('xss')" end end end -- cgit v1.2.3 From ebc32045f0e2d0baa47fb45f9bd4e6c8e3507b5d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 11 Oct 2018 10:35:32 +0000 Subject: test: add regression test for #316 --- test/user_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 4b0f0739e..248c26a3d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -55,6 +55,15 @@ defmodule Pleroma.UserTest do {:error, _} = User.follow(blockee, blocker) end + test "local users do not automatically follow local locked accounts" do + follower = insert(:user, info: %{"locked" => true}) + followed = insert(:user, info: %{"locked" => true}) + + {:ok, follower} = User.maybe_direct_follow(follower, followed) + + refute User.following?(follower, followed) + end + # This is a somewhat useless test. # test "following a remote user will ensure a websub subscription is present" do # user = insert(:user) -- cgit v1.2.3 From eacab0fb056ffc018b7e0abea27db7af435dc553 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 14 Oct 2018 01:45:11 +0200 Subject: Delete Tokens and Authorizations on password change Closes: https://git.pleroma.social/pleroma/pleroma/issues/320 --- test/web/oauth/authorization_test.exs | 22 ++++++++++++++++++++++ test/web/oauth/token_test.exs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'test') diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs index 4a9e2a3ac..98c7c4133 100644 --- a/test/web/oauth/authorization_test.exs +++ b/test/web/oauth/authorization_test.exs @@ -55,4 +55,26 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do assert {:error, "token expired"} == Authorization.use_token(expired_auth) end + + test "delete authorizations" do + {:ok, app} = + Repo.insert( + App.register_changeset(%App{}, %{ + client_name: "client", + scopes: "scope", + redirect_uris: "url" + }) + ) + + user = insert(:user) + + {:ok, auth} = Authorization.create_authorization(app, user) + {:ok, auth} = Authorization.use_token(auth) + + {auths, _} = Authorization.delete_user_authorizations(user) + + {_, invalid} = Authorization.use_token(auth) + + assert auth != invalid + end end diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs index 58448949c..f926ff50b 100644 --- a/test/web/oauth/token_test.exs +++ b/test/web/oauth/token_test.exs @@ -29,4 +29,36 @@ defmodule Pleroma.Web.OAuth.TokenTest do auth = Repo.get(Authorization, auth.id) {:error, "already used"} = Token.exchange_token(app, auth) end + + test "deletes all tokens of a user" do + {:ok, app1} = + Repo.insert( + App.register_changeset(%App{}, %{ + client_name: "client1", + scopes: "scope", + redirect_uris: "url" + }) + ) + + {:ok, app2} = + Repo.insert( + App.register_changeset(%App{}, %{ + client_name: "client2", + scopes: "scope", + redirect_uris: "url" + }) + ) + + user = insert(:user) + + {:ok, auth1} = Authorization.create_authorization(app1, user) + {:ok, auth2} = Authorization.create_authorization(app2, user) + + {:ok, token1} = Token.exchange_token(app1, auth1) + {:ok, token2} = Token.exchange_token(app2, auth2) + + {tokens, _} = Token.delete_user_tokens(user) + + assert tokens == 2 + end end -- cgit v1.2.3 From 958c5e02e8ba37a5412c46f944e0e8458b125ee8 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 17 Oct 2018 19:27:05 +0000 Subject: tests: add a testcase for matching osada users in the formatter --- .../https___osada.macgirvin.com_channel_mike.json | 54 ++++++++++++++++++++++ .../httpoison_mock/mike@osada.macgirvin.com.json | 53 +++++++++++++++++++++ test/formatter_test.exs | 19 ++++++++ test/support/httpoison_mock.ex | 21 +++++++++ 4 files changed, 147 insertions(+) create mode 100644 test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json create mode 100644 test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json (limited to 'test') diff --git a/test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json b/test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json new file mode 100644 index 000000000..c42f3a53c --- /dev/null +++ b/test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json @@ -0,0 +1,54 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + "type": "Person", + "id": "https://osada.macgirvin.com/channel/mike", + "preferredUsername": "mike", + "name": "Mike Macgirvin (Osada)", + "updated": "2018-08-29T03:09:11Z", + "icon": { + "type": "Image", + "mediaType": "image/jpeg", + "updated": "2018-08-29T03:10:13Z", + "url": "https://osada.macgirvin.com/photo/profile/l/2", + "height": 300, + "width": 300 + }, + "url": [ + { + "type": "Link", + "mediaType": "text/html", + "href": "https://osada.macgirvin.com/channel/mike" + }, + { + "type": "Link", + "mediaType": "text/x-zot+json", + "href": "https://osada.macgirvin.com/channel/mike" + } + ], + "inbox": "https://osada.macgirvin.com/inbox/mike", + "outbox": "https://osada.macgirvin.com/outbox/mike", + "followers": "https://osada.macgirvin.com/followers/mike", + "following": "https://osada.macgirvin.com/following/mike", + "endpoints": { + "sharedInbox": "https://osada.macgirvin.com/inbox" + }, + "publicKey": { + "id": "https://osada.macgirvin.com/channel/mike/public_key_pem", + "owner": "https://osada.macgirvin.com/channel/mike", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAskSyK2VwBNKbzZl9XNJk\nvxU5AAilmRArMmmKSzphdHaVBHakeafUfixvqNrQ/oX2srJvJKcghNmEMrJ6MJ7r\npeEndVOo7pcP4PwVjtnC06p3J711q5tBehqM25BfCLCrB2YqWF6c8zk3CPN3Na21\n8k5s4cO95N/rGN+Po0XFAX/HjKjlpgNpKRDrpxmXxTU8NZfAqeQGJ5oiMBZI9vVB\n+eU7t1L6F5/XWuUCeP4OMrG8oZX822AREba8rknS6DpkWGES0Rx2eNOyYTf6ue75\nI6Ek6rlO+da5wMWr+3BvYMq4JMIwTHzAO+ZqqJPFpzKSiVuAWb2DOX/MDFecVWJE\ntF/R60lONxe4e/00MPCoDdqkLKdwROsk1yGL7z4Zk6jOWFEhIcWy/d2Ya5CpPvS3\nu4wNN4jkYAjra+8TiloRELhV4gpcEk8nkyNwLXOhYm7zQ5sIc5rfXoIrFzALB86W\nG05Nnqg+77zZIaTZpD9qekYlaEt+0OVtt9TTIeTiudQ983l6mfKwZYymrzymH1dL\nVgxBRYo+Z53QOSLiSKELfTBZxEoP1pBw6RiOHXydmJ/39hGgc2YAY/5ADwW2F2yb\nJ7+gxG6bPJ3ikDLYcD4CB5iJQdnTcDsFt3jyHAT6wOCzFAYPbHUqtzHfUM30dZBn\nnJhQF8udPLcXLaj6GW75JacCAwEAAQ==\n-----END PUBLIC KEY-----\n" + }, + "signature": { + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + "type": "RsaSignature2017", + "nonce": "bd60167a764a936788d9538531284dfacc258daae0297bc34a83bce136dedb5d", + "creator": "https://osada.macgirvin.com/channel/mike/public_key_pem", + "created": "2018-10-17T07:16:28Z", + "signatureValue": "WbfFVIPImkd3yNu6brz0CvZaeV242rwAbH0vy8DM4vfnXCxLr5Uv/Wj9gwP+tbooTxGaahAKBeqlGkQp8RLEo37LATrKMRLA/0V6DeeV+C5ORWR9B4WxyWiD3s/9Wf+KesFMtktNLAcMZ5PfnOS/xNYerhnpkp/gWPxtkglmLIWJv+w18A5zZ01JCxsO4QljHbhYaEUPHUfQ97abrkLECeam+FThVwdO6BFCtbjoNXHfzjpSZL/oKyBpi5/fpnqMqOLOQPs5WgBBZJvjEYYkQcoPTyxYI5NGpNbzIjGHPQNuACnOelH16A7L+q4swLWDIaEFeXQ2/5bmqVKZDZZ6usNP4QyTVszwd8jqo27qcDTNibXDUTsTdKpNQvM/3UncBuzuzmUV3FczhtGshIU1/pRVZiQycpVqPlGLvXhP/yZCe+1siyqDd+3uMaS2vkHTObSl5r+VYof+c+TcjrZXHSWnQTg8/X3zkoBWosrQ93VZcwjzMxQoARYv6rphbOoTz7RPmGAXYUt3/PDWkqDlmQDwCpLNNkJo1EidyefZBdD9HXQpCBO0ZU0NHb0JmPvg/+zU0krxlv70bm3RHA/maBETVjroIWzt7EwQEg5pL2hVnvSBG+1wF3BtRVe77etkPOHxLnYYIcAMLlVKCcgDd89DPIziQyruvkx1busHI08=" + } +} diff --git a/test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json b/test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json new file mode 100644 index 000000000..fe6b83ca6 --- /dev/null +++ b/test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json @@ -0,0 +1,53 @@ +{ + "subject": "acct:mike@osada.macgirvin.com", + "aliases": [ + "https://osada.macgirvin.com/channel/mike", + "https://osada.macgirvin.com/~mike", + "https://osada.macgirvin.com/@mike" + ], + "properties": { + "http://webfinger.net/ns/name": "Mike Macgirvin (Osada)", + "http://xmlns.com/foaf/0.1/name": "Mike Macgirvin (Osada)", + "https://w3id.org/security/v1#publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAskSyK2VwBNKbzZl9XNJk\nvxU5AAilmRArMmmKSzphdHaVBHakeafUfixvqNrQ/oX2srJvJKcghNmEMrJ6MJ7r\npeEndVOo7pcP4PwVjtnC06p3J711q5tBehqM25BfCLCrB2YqWF6c8zk3CPN3Na21\n8k5s4cO95N/rGN+Po0XFAX/HjKjlpgNpKRDrpxmXxTU8NZfAqeQGJ5oiMBZI9vVB\n+eU7t1L6F5/XWuUCeP4OMrG8oZX822AREba8rknS6DpkWGES0Rx2eNOyYTf6ue75\nI6Ek6rlO+da5wMWr+3BvYMq4JMIwTHzAO+ZqqJPFpzKSiVuAWb2DOX/MDFecVWJE\ntF/R60lONxe4e/00MPCoDdqkLKdwROsk1yGL7z4Zk6jOWFEhIcWy/d2Ya5CpPvS3\nu4wNN4jkYAjra+8TiloRELhV4gpcEk8nkyNwLXOhYm7zQ5sIc5rfXoIrFzALB86W\nG05Nnqg+77zZIaTZpD9qekYlaEt+0OVtt9TTIeTiudQ983l6mfKwZYymrzymH1dL\nVgxBRYo+Z53QOSLiSKELfTBZxEoP1pBw6RiOHXydmJ/39hGgc2YAY/5ADwW2F2yb\nJ7+gxG6bPJ3ikDLYcD4CB5iJQdnTcDsFt3jyHAT6wOCzFAYPbHUqtzHfUM30dZBn\nnJhQF8udPLcXLaj6GW75JacCAwEAAQ==\n-----END PUBLIC KEY-----\n", + "http://purl.org/zot/federation": "zot6,activitypub" + }, + "links": [ + { + "rel": "http://webfinger.net/rel/avatar", + "type": "image/jpeg", + "href": "https://osada.macgirvin.com/photo/profile/l/2" + }, + { + "rel": "http://webfinger.net/rel/blog", + "href": "https://osada.macgirvin.com/channel/mike" + }, + { + "rel": "http://openid.net/specs/connect/1.0/issuer", + "href": "https://osada.macgirvin.com" + }, + { + "rel": "http://purl.org/zot/protocol/6.0", + "type": "application/x-zot+json", + "href": "https://osada.macgirvin.com/channel/mike" + }, + { + "rel": "http://purl.org/openwebauth/v1", + "type": "application/x-zot+json", + "href": "https://osada.macgirvin.com/owa" + }, + { + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": "https://osada.macgirvin.com/follow?url={uri}" + }, + { + "rel": "self", + "type": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", + "href": "https://osada.macgirvin.com/channel/mike" + }, + { + "rel": "self", + "type": "application/activity+json", + "href": "https://osada.macgirvin.com/channel/mike" + } + ] +} diff --git a/test/formatter_test.exs b/test/formatter_test.exs index e37b17879..13084baa7 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -1,5 +1,6 @@ defmodule Pleroma.FormatterTest do alias Pleroma.Formatter + alias Pleroma.User use Pleroma.DataCase import Pleroma.Factory @@ -131,6 +132,24 @@ defmodule Pleroma.FormatterTest do assert expected_text == Formatter.finalize({subs, text}) end + test "gives a replacement for user links when the user is using Osada" do + mike = User.get_or_fetch("mike@osada.macgirvin.com") + + text = "@mike@osada.macgirvin.com test" + + mentions = Formatter.parse_mentions(text) + + {subs, text} = Formatter.add_user_links({[], text}, mentions) + + assert length(subs) == 1 + Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) + + expected_text = + "@mike test" + + assert expected_text == Formatter.finalize({subs, text}) + end + test "gives a replacement for single-character local nicknames" do text = "@o hi" o = insert(:user, %{nickname: "o"}) diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index d8b79abef..75c78d70e 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -3,6 +3,27 @@ defmodule HTTPoisonMock do def get(url, body \\ [], headers \\ []) + def get("https://osada.macgirvin.com/channel/mike", _, _) do + {:ok, + %Response{ + status_code: 200, + body: + File.read!("test/fixtures/httpoison_mock/https___osada.macgirvin.com_channel_mike.json") + }} + end + + def get( + "https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com", + _, + _ + ) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/mike@osada.macgirvin.com.json") + }} + end + def get("https://info.pleroma.site/activity.json", _, _) do {:ok, %Response{ -- cgit v1.2.3 From a249cbf18724084d6bcb7fee0ba577241c1f6adb Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Fri, 19 Oct 2018 21:24:15 +0900 Subject: Add a test for List.get_lists_account_belongs --- test/list_test.exs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/list_test.exs b/test/list_test.exs index da3b88024..3c07e56b2 100644 --- a/test/list_test.exs +++ b/test/list_test.exs @@ -90,4 +90,24 @@ defmodule Pleroma.ListTest do assert list_two in lists refute list_three in lists end + + test "getting onwered lists the user belongs" do + owner = insert(:user) + not_owner = insert(:user) + member_1 = insert(:user) + member_2 = insert(:user) + {:ok, ownered_list} = Pleroma.List.create("ownered", owner) + {:ok, not_ownered_list} = Pleroma.List.create("not ownered", not_owner) + {:ok, ownered_list} = Pleroma.List.follow(ownered_list, member_1) + {:ok, ownered_list} = Pleroma.List.follow(ownered_list, member_2) + {:ok, not_ownered_list} = Pleroma.List.follow(not_ownered_list, member_1) + {:ok, not_ownered_list} = Pleroma.List.follow(not_ownered_list, member_2) + + lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1.id) + assert ownered_list in lists_1 + refute not_ownered_list in lists_1 + lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2.id) + assert ownered_list in lists_2 + refute not_ownered_list in lists_2 + end end -- cgit v1.2.3 From 5e9a0e2460a1f58aaa1213c5b4e9ccdf4d9b6a78 Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 20 Oct 2018 13:03:45 +0300 Subject: Fix some typos in the list test. --- test/list_test.exs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/list_test.exs b/test/list_test.exs index 3c07e56b2..19eef8f6b 100644 --- a/test/list_test.exs +++ b/test/list_test.exs @@ -91,23 +91,23 @@ defmodule Pleroma.ListTest do refute list_three in lists end - test "getting onwered lists the user belongs" do + test "getting own lists a given user belongs to" do owner = insert(:user) not_owner = insert(:user) member_1 = insert(:user) member_2 = insert(:user) - {:ok, ownered_list} = Pleroma.List.create("ownered", owner) - {:ok, not_ownered_list} = Pleroma.List.create("not ownered", not_owner) - {:ok, ownered_list} = Pleroma.List.follow(ownered_list, member_1) - {:ok, ownered_list} = Pleroma.List.follow(ownered_list, member_2) - {:ok, not_ownered_list} = Pleroma.List.follow(not_ownered_list, member_1) - {:ok, not_ownered_list} = Pleroma.List.follow(not_ownered_list, member_2) + {:ok, owned_list} = Pleroma.List.create("owned", owner) + {:ok, not_owned_list} = Pleroma.List.create("not owned", not_owner) + {:ok, owned_list} = Pleroma.List.follow(owned_list, member_1) + {:ok, owned_list} = Pleroma.List.follow(owned_list, member_2) + {:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_1) + {:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_2) lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1.id) - assert ownered_list in lists_1 - refute not_ownered_list in lists_1 + assert owned_list in lists_1 + refute not_owned_list in lists_1 lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2.id) - assert ownered_list in lists_2 - refute not_ownered_list in lists_2 + assert owned_list in lists_2 + refute not_owned_list in lists_2 end end -- cgit v1.2.3 From 9563f3766d45e6c95fe50e371bc0048d9f4a2452 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 03:03:44 +0000 Subject: tests: update for new in_reply_to_screen_name field --- test/web/twitter_api/representers/activity_representer_test.exs | 1 + test/web/twitter_api/views/activity_view_test.exs | 1 + 2 files changed, 2 insertions(+) (limited to 'test') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 894d20049..ae6f62ed0 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -139,6 +139,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "is_post_verb" => true, "created_at" => "Tue May 24 13:26:08 +0000 2016", "in_reply_to_status_id" => 213_123, + "in_reply_to_screen_name" => nil, "statusnet_conversation_id" => convo_object.id, "attachments" => [ ObjectRepresenter.to_map(object) diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index b9a8efdad..3ab87d6fa 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -36,6 +36,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "favorited" => false, "id" => activity.id, "in_reply_to_status_id" => nil, + "in_reply_to_screen_name" => nil, "is_local" => true, "is_post_verb" => true, "possibly_sensitive" => false, -- cgit v1.2.3 From 6cfba7db8de1cdb409243885724101500fa21e6d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 04:06:42 +0000 Subject: tests: twitterapi: add additional fields --- test/web/twitter_api/representers/activity_representer_test.exs | 3 +++ test/web/twitter_api/views/activity_view_test.exs | 3 +++ 2 files changed, 6 insertions(+) (limited to 'test') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index ae6f62ed0..291fd5237 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -140,6 +140,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "created_at" => "Tue May 24 13:26:08 +0000 2016", "in_reply_to_status_id" => 213_123, "in_reply_to_screen_name" => nil, + "in_reply_to_user_id" => nil, + "in_reply_to_profileurl" => nil, + "in_reply_to_ostatus_uri" => nil, "statusnet_conversation_id" => convo_object.id, "attachments" => [ ObjectRepresenter.to_map(object) diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 3ab87d6fa..5cef06f88 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -37,6 +37,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "id" => activity.id, "in_reply_to_status_id" => nil, "in_reply_to_screen_name" => nil, + "in_reply_to_user_id" => nil, + "in_reply_to_profileurl" => nil, + "in_reply_to_ostatus_uri" => nil, "is_local" => true, "is_post_verb" => true, "possibly_sensitive" => false, -- cgit v1.2.3 From b1d1f9bc271d80f05b2f636e304775e6803c02f6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 25 Oct 2018 05:24:17 +0000 Subject: tests: add test for user inbox --- test/fixtures/mastodon-post-activity.json | 1 - .../activity_pub/activity_pub_controller_test.exs | 23 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/fixtures/mastodon-post-activity.json b/test/fixtures/mastodon-post-activity.json index 693e0ce39..b91263431 100644 --- a/test/fixtures/mastodon-post-activity.json +++ b/test/fixtures/mastodon-post-activity.json @@ -21,7 +21,6 @@ "http://localtesting.pleroma.lol/users/lain" ], "id": "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity", - "nickname": "lain", "object": { "atomUri": "http://mastodon.example.org/users/admin/statuses/99512778738411822", "attachment": [], diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 3ed7be402..e63cd6583 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -46,7 +46,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do end end - describe "/users/:nickname/inbox" do + describe "/inbox" do test "it inserts an incoming activity into the database", %{conn: conn} do data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!() @@ -62,6 +62,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do end end + describe "/users/:nickname/inbox" do + test "it inserts an incoming activity into the database", %{conn: conn} do + user = insert(:user) + + data = + File.read!("test/fixtures/mastodon-post-activity.json") + |> Poison.decode!() + |> Map.put("bcc", [user.ap_id]) + + conn = + conn + |> assign(:valid_signature, true) + |> put_req_header("content-type", "application/activity+json") + |> post("/users/#{user.nickname}/inbox", data) + + assert "ok" == json_response(conn, 200) + :timer.sleep(500) + assert Activity.get_by_ap_id(data["id"]) + end + end + describe "/users/:nickname/outbox" do test "it returns a note activity in a collection", %{conn: conn} do note_activity = insert(:note_activity) -- cgit v1.2.3 From 0d0c1dcf440707535afa852503e9afa049cd8374 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 26 Oct 2018 06:35:06 +0000 Subject: tests: add testsuite for broken thread filter --- test/web/activity_pub/activity_pub_test.exs | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 1cf7d6bbc..14011a010 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -476,6 +476,42 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do end end + describe "timeline post-processing" do + test "it filters broken threads" do + user1 = insert(:user) + user2 = insert(:user) + user3 = insert(:user) + + {:ok, user1} = User.follow(user1, user3) + assert User.following?(user1, user3) + + {:ok, user2} = User.follow(user2, user3) + assert User.following?(user2, user3) + + {:ok, user3} = User.follow(user3, user2) + assert User.following?(user3, user2) + + {:ok, public_activity} = CommonAPI.post(user3, %{"status" => "hi 1"}) + + {:ok, private_activity_1} = CommonAPI.post(user3, %{"status" => "hi 2", "visibility" => "private"}) + {:ok, private_activity_2} = CommonAPI.post(user2, %{"status" => "hi 3", "visibility" => "private", "in_reply_to_status_id" => private_activity_1.id}) + {:ok, private_activity_3} = CommonAPI.post(user3, %{"status" => "hi 4", "visibility" => "private", "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 + assert length(activities) == 3 + + activities = ActivityPub.contain_timeline(activities, user1) + + assert [public_activity, private_activity_1] == activities + assert length(activities) == 2 + end + end + test "it can fetch plume articles" do {:ok, object} = ActivityPub.fetch_object_from_id( -- cgit v1.2.3 From 2ac13061afe4c360bb98ba8f05bc540b2cf27e74 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 26 Oct 2018 06:37:00 +0000 Subject: testsuite: formatting --- test/web/activity_pub/activity_pub_test.exs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 14011a010..35c381ac3 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -493,14 +493,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do {:ok, public_activity} = CommonAPI.post(user3, %{"status" => "hi 1"}) - {:ok, private_activity_1} = CommonAPI.post(user3, %{"status" => "hi 2", "visibility" => "private"}) - {:ok, private_activity_2} = CommonAPI.post(user2, %{"status" => "hi 3", "visibility" => "private", "in_reply_to_status_id" => private_activity_1.id}) - {:ok, private_activity_3} = CommonAPI.post(user3, %{"status" => "hi 4", "visibility" => "private", "in_reply_to_status_id" => private_activity_2.id}) + {:ok, private_activity_1} = + CommonAPI.post(user3, %{"status" => "hi 2", "visibility" => "private"}) + + {:ok, private_activity_2} = + CommonAPI.post(user2, %{ + "status" => "hi 3", + "visibility" => "private", + "in_reply_to_status_id" => private_activity_1.id + }) + + {:ok, private_activity_3} = + CommonAPI.post(user3, %{ + "status" => "hi 4", + "visibility" => "private", + "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]) + activities = ActivityPub.fetch_activities([user1.ap_id | user1.following]) assert [public_activity, private_activity_1, private_activity_3] == activities assert length(activities) == 3 -- cgit v1.2.3 From b92e38d2d4c05da19b00162d7ca35f1905b44a80 Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 29 Oct 2018 23:08:56 +0000 Subject: Add user reactivation task. --- test/user_test.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 248c26a3d..05da24f8d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -487,11 +487,13 @@ defmodule Pleroma.UserTest do assert addressed in recipients end - test ".deactivate deactivates a user" do + test ".deactivate can de-activate then re-activate a user" do user = insert(:user) assert false == !!user.info["deactivated"] {:ok, user} = User.deactivate(user) assert true == user.info["deactivated"] + {:ok, user} = User.deactivate(user, false) + assert false == !!user.info["deactivated"] end test ".delete deactivates a user, all follow relationships and all create activities" do -- cgit v1.2.3 From f55fc68f766c71e81ce754408007e3b763f32e0f Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 1 Nov 2018 07:37:07 +0000 Subject: tests: add tests for object deletion --- test/object_test.exs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/object_test.exs b/test/object_test.exs index 5eb9b7530..3e398776c 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -19,4 +19,34 @@ defmodule Pleroma.ObjectTest do {:error, _result} = Repo.insert(cs) end end + + describe "deletion function" do + test "deletes an object" do + object = insert(:note) + found_object = Object.get_by_ap_id(object.data["id"]) + + assert object == found_object + + Object.delete(found_object) + + found_object = Object.get_by_ap_id(object.data["id"]) + + refute object == found_object + end + + test "ensures cache is cleared for the object" do + object = insert(:note) + cached_object = Object.get_cached_by_ap_id(object.data["id"]) + + assert object == cached_object + + Object.delete(cached_object) + + {:ok, nil} = Cachex.get(:user_cache, "object:#{object.data["id"]}") + + cached_object = Object.get_cached_by_ap_id(object.data["id"]) + + refute object == cached_object + end + end end -- cgit v1.2.3 From 21dafa7cd029870c3dc60846ead23f1866bc4cd3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 1 Nov 2018 08:09:51 +0000 Subject: tests: add tests for User + cache interactions --- test/user_test.exs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 05da24f8d..9b3519ece 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -551,4 +551,31 @@ defmodule Pleroma.UserTest do assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user) end end + + describe "caching" do + test "invalidate_cache works" do + user = insert(:user) + user_info = User.get_cached_user_info(user) + + User.invalidate_cache(user) + + {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}") + {:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}") + {:ok, nil} = Cachex.get(:user_cache, "user_info:#{user.id}") + end + + test "User.delete() plugs any possible zombie objects" do + user = insert(:user) + + {:ok, _} = User.delete(user) + + {:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}") + + assert cached_user != user + + {:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}") + + assert cached_user != user + end + end end -- cgit v1.2.3 From 2c092ed355872cd08bf4caaf85625245764ccf77 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 1 Nov 2018 08:23:49 +0000 Subject: test: fixup test breakage caused by User.delete() harmonization --- test/user_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 9b3519ece..7dec3462f 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -511,7 +511,7 @@ defmodule Pleroma.UserTest do {:ok, _, _} = CommonAPI.favorite(activity.id, follower) {:ok, _, _} = CommonAPI.repeat(activity.id, follower) - :ok = User.delete(user) + {:ok, _} = User.delete(user) followed = Repo.get(User, followed.id) follower = Repo.get(User, follower.id) -- cgit v1.2.3 From 2b3a40d0383f2ea79c1704c7700ff4d3e5f3c17a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 1 Nov 2018 08:30:10 +0000 Subject: object: split object_cache from user_cache --- test/object_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/object_test.exs b/test/object_test.exs index 3e398776c..909605560 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -42,7 +42,7 @@ defmodule Pleroma.ObjectTest do Object.delete(cached_object) - {:ok, nil} = Cachex.get(:user_cache, "object:#{object.data["id"]}") + {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}") cached_object = Object.get_cached_by_ap_id(object.data["id"]) -- cgit v1.2.3 From 9b77030d3ca9530fbea05aeb2191915bb1c454cb Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 8 Sep 2018 14:01:00 +0200 Subject: Add basic configuration management module. --- test/config_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/config_test.exs (limited to 'test') diff --git a/test/config_test.exs b/test/config_test.exs new file mode 100644 index 000000000..6d0f0a2d4 --- /dev/null +++ b/test/config_test.exs @@ -0,0 +1,10 @@ +defmodule Pleroma.ConfigTest do + use Pleroma.DataCase + alias Pleroma.Config + + test "get returns the item at the path if there is one" do + Config.put([:instance, :name], "Plemora") + assert Config.get([:instance, :name]) == "Plemora" + assert Config.get([:unknown]) == nil + end +end -- cgit v1.2.3 From 1e9ced5af478ba38c9e9d46140891a8f4473e02d Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 8 Sep 2018 14:02:38 +0200 Subject: Test Relay, switch to runtime configuration. --- .../activity_pub/activity_pub_controller_test.exs | 23 +++++++++++ test/web/activity_pub/relay_test.exs | 11 ++++++ test/web/federator_test.exs | 45 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 test/web/activity_pub/relay_test.exs (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index e63cd6583..5b46bbe76 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -4,6 +4,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do alias Pleroma.Web.ActivityPub.{UserView, ObjectView} alias Pleroma.{Repo, User} alias Pleroma.Activity + alias Pleroma.Config + + describe "/relay" do + test "with the relay active, it returns the relay user", %{conn: conn} do + Config.put([:instance, :allow_relay], true) + + res = + conn + |> get(activity_pub_path(conn, :relay)) + |> json_response(200) + + assert res["id"] =~ "/relay" + end + + test "with the relay disabled, it returns 404", %{conn: conn} do + Config.put([:instance, :allow_relay], false) + + res = + conn + |> get(activity_pub_path(conn, :relay)) + |> json_response(404) + end + end describe "/users/:nickname" do test "it returns a json representation of the user", %{conn: conn} do diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs new file mode 100644 index 000000000..41d13e055 --- /dev/null +++ b/test/web/activity_pub/relay_test.exs @@ -0,0 +1,11 @@ +defmodule Pleroma.Web.ActivityPub.RelayTest do + use Pleroma.DataCase + + alias Pleroma.Web.ActivityPub.Relay + + test "gets an actor for the relay" do + user = Relay.get_actor() + + assert user.ap_id =~ "/relay" + end +end diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 09533362a..966702935 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -1,6 +1,10 @@ defmodule Pleroma.Web.FederatorTest do alias Pleroma.Web.Federator + alias Pleroma.Web.CommonAPI + alias Pleroma.Config use Pleroma.DataCase + import Pleroma.Factory + import Mock test "enqueues an element according to priority" do queue = [%{item: 1, priority: 2}] @@ -17,4 +21,45 @@ defmodule Pleroma.Web.FederatorTest do assert {2, [%{item: 1, priority: 2}]} = Federator.queue_pop(queue) end + + describe "Publish an activity" do + setup do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "HI"}) + + relay_mock = { + Pleroma.Web.ActivityPub.Relay, + [], + [publish: fn _activity -> send(self(), :relay_publish) end] + } + + %{activity: activity, relay_mock: relay_mock} + end + + test "with relays active, it publishes to the relay", %{ + activity: activity, + relay_mock: relay_mock + } do + Config.put([:instance, :allow_relay], true) + + with_mocks([relay_mock]) do + Federator.handle(:publish, activity) + end + + assert_received :relay_publish + end + + test "with relays deactivated, it does not publish to the relay", %{ + activity: activity, + relay_mock: relay_mock + } do + Config.put([:instance, :allow_relay], false) + + with_mocks([relay_mock]) do + Federator.handle(:publish, activity) + end + + refute_received :relay_publish + end + end end -- cgit v1.2.3 From 585b29337ce66eb2c574e71588db542044574609 Mon Sep 17 00:00:00 2001 From: Lee Starnes Date: Fri, 12 Oct 2018 00:19:43 -0500 Subject: Ensure filters have a filter_id --- test/filter_test.exs | 91 +++++++++++++++++++--- .../mastodon_api/mastodon_api_controller_test.exs | 2 + 2 files changed, 82 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/filter_test.exs b/test/filter_test.exs index d81c92f08..509c15317 100644 --- a/test/filter_test.exs +++ b/test/filter_test.exs @@ -5,19 +5,88 @@ defmodule Pleroma.FilterTest do import Pleroma.Factory import Ecto.Query - test "creating a filter" do - user = insert(:user) + describe "creating filters" do + test "creating one filter" do + user = insert(:user) - query = %Pleroma.Filter{ - user_id: user.id, - filter_id: 42, - phrase: "knights", - context: ["home"] - } + query = %Pleroma.Filter{ + user_id: user.id, + filter_id: 42, + phrase: "knights", + context: ["home"] + } + + {:ok, %Pleroma.Filter{} = filter} = Pleroma.Filter.create(query) + result = Pleroma.Filter.get(filter.filter_id, user) + assert query.phrase == result.phrase + end + + test "creating one filter without a pre-defined filter_id" do + user = insert(:user) + + query = %Pleroma.Filter{ + user_id: user.id, + phrase: "knights", + context: ["home"] + } + + {:ok, %Pleroma.Filter{} = filter} = Pleroma.Filter.create(query) + # Should start at 1 + assert filter.filter_id == 1 + end + + test "creating additional filters uses previous highest filter_id + 1" do + user = insert(:user) + + query_one = %Pleroma.Filter{ + user_id: user.id, + filter_id: 42, + phrase: "knights", + context: ["home"] + } + + {:ok, %Pleroma.Filter{} = filter_one} = Pleroma.Filter.create(query_one) + + query_two = %Pleroma.Filter{ + user_id: user.id, + # No filter_id + phrase: "who", + context: ["home"] + } + + {:ok, %Pleroma.Filter{} = filter_two} = Pleroma.Filter.create(query_two) + assert filter_two.filter_id == filter_one.filter_id + 1 + end + + test "filter_id is unique per user" do + user_one = insert(:user) + user_two = insert(:user) + + query_one = %Pleroma.Filter{ + user_id: user_one.id, + phrase: "knights", + context: ["home"] + } + + {:ok, %Pleroma.Filter{} = filter_one} = Pleroma.Filter.create(query_one) + + query_two = %Pleroma.Filter{ + user_id: user_two.id, + phrase: "who", + context: ["home"] + } + + {:ok, %Pleroma.Filter{} = filter_two} = Pleroma.Filter.create(query_two) + + assert filter_one.filter_id == 1 + assert filter_two.filter_id == 1 + + result_one = Pleroma.Filter.get(filter_one.filter_id, user_one) + assert result_one.phrase == filter_one.phrase - {:ok, %Pleroma.Filter{} = filter} = Pleroma.Filter.create(query) - result = Pleroma.Filter.get(filter.filter_id, user) - assert query.phrase == result.phrase + result_two = Pleroma.Filter.get(filter_two.filter_id, user_two) + assert result_two.phrase == filter_two.phrase + end end test "deleting a filter" do diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index e9deae64d..42a43f129 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -280,6 +280,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert response = json_response(conn, 200) assert response["phrase"] == filter.phrase assert response["context"] == filter.context + assert response["id"] != nil + assert response["id"] != "" end test "fetching a list of filters", %{conn: conn} do -- cgit v1.2.3 From c5f26f3ce2ef84a424a59498cc2d5e4ca9e1b525 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 1 Nov 2018 11:27:22 +0100 Subject: Test that prismo url-map transforms into a string --- test/fixtures/prismo-url-map.json | 52 +++++++++++++++++++++++++++ test/web/activity_pub/transmogrifier_test.exs | 8 +++++ 2 files changed, 60 insertions(+) create mode 100644 test/fixtures/prismo-url-map.json (limited to 'test') diff --git a/test/fixtures/prismo-url-map.json b/test/fixtures/prismo-url-map.json new file mode 100644 index 000000000..9088d01af --- /dev/null +++ b/test/fixtures/prismo-url-map.json @@ -0,0 +1,52 @@ +{ + "id": "https://prismo.news/posts/83", + "type": "Article", + "name": "Introducing: Federated follows!", + "published": "2018-11-01T07:10:05Z", + "content": "We are more than thrilled to announce that Prismo now supports federated follows! It means you ca...", + "url": { + "type": "Link", + "mimeType": "text/html", + "href": "https://prismo.news/posts/83" + }, + "votes": 12, + "attributedTo": [ + { + "type": "Person", + "id": "https://prismo.news/@mxb" + } + ], + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "tags": [ + { + "type": "Hashtag", + "href": "https://prismo.news/tags/prismo", + "name": "#prismo" + }, + { + "type": "Hashtag", + "href": "https://prismo.news/tags/prismodev", + "name": "#prismodev" + }, + { + "type": "Hashtag", + "href": "https://prismo.news/tags/meta", + "name": "#meta" + } + ], + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "Hashtag": "as:Hashtag" + }, + { + "votes": { + "@id": "as:votes", + "@type": "@id" + } + } + ] +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 6a6f2a44c..14b02eb71 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -145,6 +145,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert "test" in data["object"]["tag"] end + test "it works for incoming notices with url not being a string (prismo)" do + data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!() + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + + assert data["object"]["url"] == "https://prismo.news/posts/83" + end + test "it works for incoming follow requests" do user = insert(:user) -- cgit v1.2.3 From 45ebc8dd9a27ae862aad1c8251a71b95a2c3be17 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 2 Nov 2018 17:33:51 +0100 Subject: Check for empty string in_reply_to ids. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 42a43f129..938d556c7 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -198,6 +198,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert activity.data["object"]["inReplyToStatusId"] == replied_to.id end + test "posting a status with an invalid in_reply_to_id", %{conn: conn} do + user = insert(:user) + + conn = + conn + |> assign(:user, user) + |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""}) + + assert %{"content" => "xD", "id" => id} = json_response(conn, 200) + + activity = Repo.get(Activity, id) + + assert activity + end + test "verify_credentials", %{conn: conn} do user = insert(:user) -- cgit v1.2.3 From 7dfe611620fbcc45411345ee3e5c5cf7fb169f76 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 3 Nov 2018 11:41:40 +0100 Subject: Test for case-insensitive mastodon hashtag timelines. --- test/web/mastodon_api/mastodon_api_controller_test.exs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 938d556c7..3f9324fcc 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -944,11 +944,20 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do {:ok, [_activity]} = OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873") - conn = + nconn = conn |> get("/api/v1/timelines/tag/2hu") - assert [%{"id" => id}] = json_response(conn, 200) + assert [%{"id" => id}] = json_response(nconn, 200) + + assert id == to_string(activity.id) + + # works for different capitalization too + nconn = + conn + |> get("/api/v1/timelines/tag/2HU") + + assert [%{"id" => id}] = json_response(nconn, 200) assert id == to_string(activity.id) end) -- cgit v1.2.3 From 81af7fd02d2ca0430e0470b78ad2384e5598fbe1 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 3 Nov 2018 16:28:29 +0100 Subject: Test for null-content activities. --- test/web/mastodon_api/status_view_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index b9c019206..b29f13e20 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -7,6 +7,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do alias Pleroma.Web.CommonAPI import Pleroma.Factory + test "a note with null content" do + note = insert(:note_activity) + data = note.data + |> put_in(["object", "content"], nil) + note = note + |> Map.put(:data, data) + + user = User.get_cached_by_ap_id(note.data["actor"]) + + status = StatusView.render("status.json", %{activity: note}) + + assert status.content == "" + end + test "a note activity" do note = insert(:note_activity) user = User.get_cached_by_ap_id(note.data["actor"]) -- cgit v1.2.3 From 2fedd93931ad3430daa9a311cb0905dac71ee01d Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 3 Nov 2018 16:40:57 +0100 Subject: Fix formatting. --- test/web/mastodon_api/status_view_test.exs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index b29f13e20..31554a07d 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -9,10 +9,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do test "a note with null content" do note = insert(:note_activity) - data = note.data - |> put_in(["object", "content"], nil) - note = note - |> Map.put(:data, data) + + data = + note.data + |> put_in(["object", "content"], nil) + + note = + note + |> Map.put(:data, data) user = User.get_cached_by_ap_id(note.data["actor"]) -- cgit v1.2.3 From 013f7ba8c1c4e6519cf30d192e3a41c6c96f8a63 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 6 Nov 2018 14:44:00 +0100 Subject: Add federating plug & public tests --- test/web/node_info_test.exs | 32 ++++++++++++++ test/web/plugs/federating_plug_test.exs | 33 ++++++++++++++ .../twitter_api/twitter_api_controller_test.exs | 50 ++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 test/web/plugs/federating_plug_test.exs (limited to 'test') diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs index d48f40e47..a6376453c 100644 --- a/test/web/node_info_test.exs +++ b/test/web/node_info_test.exs @@ -14,4 +14,36 @@ defmodule Pleroma.Web.NodeInfoTest do assert user.ap_id in result["metadata"]["staffAccounts"] end + + test "returns 404 when federation is disabled" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/.well-known/nodeinfo") + |> json_response(404) + + conn + |> get("/nodeinfo/2.0.json") + |> json_response(404) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 when federation is enabled" do + conn + |> get("/.well-known/nodeinfo") + |> json_response(200) + + conn + |> get("/nodeinfo/2.0.json") + |> json_response(200) + end end diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs new file mode 100644 index 000000000..1455a1c46 --- /dev/null +++ b/test/web/plugs/federating_plug_test.exs @@ -0,0 +1,33 @@ +defmodule Pleroma.Web.FederatingPlugTest do + use Pleroma.Web.ConnCase + + test "returns and halt the conn when federating is disabled" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, false) + + Application.put_env(:pleroma, :instance, instance) + + conn = + build_conn() + |> Pleroma.Web.FederatingPlug.call(%{}) + + assert conn.status == 404 + assert conn.halted + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:federating, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "does nothing when federating is enabled" do + conn = + build_conn() + |> Pleroma.Web.FederatingPlug.call(%{}) + + refute conn.status + refute conn.halted + end +end diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 87bcdaf71..b64f416e3 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -100,6 +100,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert length(response) == 10 end + + test "returns 403 to unauthenticated request when the instance is not public" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/api/statuses/public_timeline.json") + |> json_response(403) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 to unauthenticated request when the instance is public" do + conn + |> get("/api/statuses/public_timeline.json") + |> json_response(200) + end + end + + describe "GET /statuses/public_and_external_timeline.json" do + test "returns 403 to unauthenticated request when the instance is not public" do + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, false) + + Application.put_env(:pleroma, :instance, instance) + + conn + |> get("/api/statuses/public_and_external_timeline.json") + |> json_response(403) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:public, true) + + Application.put_env(:pleroma, :instance, instance) + end + + test "returns 200 to unauthenticated request when the instance is public" do + conn + |> get("/api/statuses/public_and_external_timeline.json") + |> json_response(200) + end end describe "GET /statuses/show/:id.json" do -- cgit v1.2.3 From 2bc924ba451b1a324663133632093914192cec2d Mon Sep 17 00:00:00 2001 From: href Date: Tue, 6 Nov 2018 11:34:34 +0100 Subject: Get rid of Pleroma.Config in favor of Application Discussed in https://git.pleroma.social/pleroma/pleroma/merge_requests/426#note_7232 --- test/config_test.exs | 10 ---------- test/web/activity_pub/activity_pub_controller_test.exs | 16 ++++++++++++---- test/web/federator_test.exs | 15 +++++++++++---- 3 files changed, 23 insertions(+), 18 deletions(-) delete mode 100644 test/config_test.exs (limited to 'test') diff --git a/test/config_test.exs b/test/config_test.exs deleted file mode 100644 index 6d0f0a2d4..000000000 --- a/test/config_test.exs +++ /dev/null @@ -1,10 +0,0 @@ -defmodule Pleroma.ConfigTest do - use Pleroma.DataCase - alias Pleroma.Config - - test "get returns the item at the path if there is one" do - Config.put([:instance, :name], "Plemora") - assert Config.get([:instance, :name]) == "Plemora" - assert Config.get([:unknown]) == nil - 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 5b46bbe76..524ed9eaa 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -4,12 +4,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do alias Pleroma.Web.ActivityPub.{UserView, ObjectView} alias Pleroma.{Repo, User} alias Pleroma.Activity - alias Pleroma.Config describe "/relay" do test "with the relay active, it returns the relay user", %{conn: conn} do - Config.put([:instance, :allow_relay], true) - res = conn |> get(activity_pub_path(conn, :relay)) @@ -19,12 +16,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do end test "with the relay disabled, it returns 404", %{conn: conn} do - Config.put([:instance, :allow_relay], false) + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:allow_relay, false) + + Application.put_env(:pleroma, :instance, instance) res = conn |> get(activity_pub_path(conn, :relay)) |> json_response(404) + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:allow_relay, true) + + Application.put_env(:pleroma, :instance, instance) + end end diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 966702935..88aef0d0f 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -1,7 +1,6 @@ defmodule Pleroma.Web.FederatorTest do alias Pleroma.Web.Federator alias Pleroma.Web.CommonAPI - alias Pleroma.Config use Pleroma.DataCase import Pleroma.Factory import Mock @@ -40,8 +39,6 @@ defmodule Pleroma.Web.FederatorTest do activity: activity, relay_mock: relay_mock } do - Config.put([:instance, :allow_relay], true) - with_mocks([relay_mock]) do Federator.handle(:publish, activity) end @@ -53,13 +50,23 @@ defmodule Pleroma.Web.FederatorTest do activity: activity, relay_mock: relay_mock } do - Config.put([:instance, :allow_relay], false) + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:allow_relay, false) + + Application.put_env(:pleroma, :instance, instance) with_mocks([relay_mock]) do Federator.handle(:publish, activity) end refute_received :relay_publish + + instance = + Application.get_env(:pleroma, :instance) + |> Keyword.put(:allow_relay, true) + + Application.put_env(:pleroma, :instance, instance) end end end -- cgit v1.2.3 From 36ca3c1b3ec814609d14815a672239a31b1e0ec5 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 6 Nov 2018 15:17:13 +0100 Subject: format --- test/web/activity_pub/activity_pub_controller_test.exs | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 524ed9eaa..f22975f86 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -32,7 +32,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do |> Keyword.put(:allow_relay, true) Application.put_env(:pleroma, :instance, instance) - end end -- cgit v1.2.3 From 7d328c658da69ec236d10fa89d23f2a6886b3205 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 6 Nov 2018 16:00:48 +0100 Subject: Small wrapper module around Application.get_env/put_env Same API as the old Pleroma.Config --- test/config_test.exs | 39 ++++++++++++++++++++++ .../activity_pub/activity_pub_controller_test.exs | 12 ++----- test/web/federator_test.exs | 12 ++----- 3 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 test/config_test.exs (limited to 'test') diff --git a/test/config_test.exs b/test/config_test.exs new file mode 100644 index 000000000..32d5cc90c --- /dev/null +++ b/test/config_test.exs @@ -0,0 +1,39 @@ +defmodule Pleroma.ConfigTest do + use ExUnit.Case + + test "get/1 with an atom" do + assert Pleroma.Config.get(:instance) == Application.get_env(:pleroma, :instance) + assert Pleroma.Config.get(:azertyuiop) == nil + end + + test "get/1 with a list of keys" do + assert Pleroma.Config.get([:instance, :public]) == + Keyword.get(Application.get_env(:pleroma, :instance), :public) + + assert Pleroma.Config.get([Pleroma.Web.Endpoint, :render_errors, :view]) == + get_in( + Application.get_env( + :pleroma, + Pleroma.Web.Endpoint + ), + [:render_errors, :view] + ) + + assert Pleroma.Config.get([:azerty, :uiop]) == nil + end + + test "put/2 with a key" do + Pleroma.Config.put(:config_test, true) + + assert Pleroma.Config.get(:config_test) == true + end + + test "put/2 with a list of keys" do + Pleroma.Config.put([:instance, :config_test], true) + Pleroma.Config.put([:instance, :config_nested_test], []) + Pleroma.Config.put([:instance, :config_nested_test, :x], true) + + assert Pleroma.Config.get([:instance, :config_test]) == true + assert Pleroma.Config.get([:instance, :config_nested_test, :x]) == true + 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 f22975f86..1c24b348c 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -16,22 +16,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do end test "with the relay disabled, it returns 404", %{conn: conn} do - instance = - Application.get_env(:pleroma, :instance) - |> Keyword.put(:allow_relay, false) - - Application.put_env(:pleroma, :instance, instance) + Pleroma.Config.put([:instance, :allow_relay], false) res = conn |> get(activity_pub_path(conn, :relay)) |> json_response(404) - instance = - Application.get_env(:pleroma, :instance) - |> Keyword.put(:allow_relay, true) - - Application.put_env(:pleroma, :instance, instance) + Pleroma.Config.put([:instance, :allow_relay], true) end end diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 88aef0d0f..c709d1181 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -50,11 +50,7 @@ defmodule Pleroma.Web.FederatorTest do activity: activity, relay_mock: relay_mock } do - instance = - Application.get_env(:pleroma, :instance) - |> Keyword.put(:allow_relay, false) - - Application.put_env(:pleroma, :instance, instance) + Pleroma.Config.put([:instance, :allow_relay], false) with_mocks([relay_mock]) do Federator.handle(:publish, activity) @@ -62,11 +58,7 @@ defmodule Pleroma.Web.FederatorTest do refute_received :relay_publish - instance = - Application.get_env(:pleroma, :instance) - |> Keyword.put(:allow_relay, true) - - Application.put_env(:pleroma, :instance, instance) + Pleroma.Config.put([:instance, :allow_relay], true) end end end -- cgit v1.2.3 From 5bb88fd1749931e755157760ec833c5d50ebb8c8 Mon Sep 17 00:00:00 2001 From: href Date: Tue, 6 Nov 2018 19:34:57 +0100 Subject: Runtime configuration Related to #85 Everything should now be configured at runtime, with the exception of the `Pleroma.HTML` scrubbers (the scrubbers used can be changed at runtime, but their configuration is compile-time) because it's building a module with a macro. --- test/config_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/config_test.exs b/test/config_test.exs index 32d5cc90c..0124544c8 100644 --- a/test/config_test.exs +++ b/test/config_test.exs @@ -4,6 +4,7 @@ defmodule Pleroma.ConfigTest do test "get/1 with an atom" do assert Pleroma.Config.get(:instance) == Application.get_env(:pleroma, :instance) assert Pleroma.Config.get(:azertyuiop) == nil + assert Pleroma.Config.get(:azertyuiop, true) == true end test "get/1 with a list of keys" do @@ -20,6 +21,22 @@ defmodule Pleroma.ConfigTest do ) assert Pleroma.Config.get([:azerty, :uiop]) == nil + assert Pleroma.Config.get([:azerty, :uiop], true) == true + end + + test "get!/1" do + assert Pleroma.Config.get!(:instance) == Application.get_env(:pleroma, :instance) + + assert Pleroma.Config.get!([:instance, :public]) == + Keyword.get(Application.get_env(:pleroma, :instance), :public) + + assert_raise(Pleroma.Config.Error, fn -> + Pleroma.Config.get!(:azertyuiop) + end) + + assert_raise(Pleroma.Config.Error, fn -> + Pleroma.Config.get!([:azerty, :uiop]) + end) end test "put/2 with a key" do -- cgit v1.2.3 From 50bf17465138cbd81117404231b22b3891cb67c3 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 6 Nov 2018 23:02:55 +0000 Subject: tests: add tests for Notification.set_read_up_to() --- test/notification_test.exs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index d86b5c1ab..79290ac78 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -121,6 +121,41 @@ defmodule Pleroma.NotificationTest do end end + describe "set_read_up_to()" do + test "it sets all notifications as read up to a specified notification ID" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = + TwitterAPI.create_status(user, %{ + "status" => "hey @#{other_user.nickname}!" + }) + + {:ok, activity} = + TwitterAPI.create_status(user, %{ + "status" => "hey again @#{other_user.nickname}!" + }) + + [n2, n1] = notifs = Notification.for_user(other_user) + assert length(notifs) == 2 + + assert n2.id > n1.id + + {:ok, activity} = + TwitterAPI.create_status(user, %{ + "status" => "hey yet again @#{other_user.nickname}!" + }) + + Notification.set_read_up_to(other_user, n2.id) + + [n3, n2, n1] = notifs = Notification.for_user(other_user) + + assert n1.seen == true + assert n2.seen == true + assert n3.seen == false + end + end + describe "notification lifecycle" do test "liking an activity results in 1 notification, then 0 if the activity is deleted" do user = insert(:user) -- cgit v1.2.3 From d675b8a16f84728134b09340a78db9e77f87839c Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 6 Nov 2018 23:25:16 +0000 Subject: tests: add tests for twitterapi endpoint --- .../twitter_api/twitter_api_controller_test.exs | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index b64f416e3..13480c21b 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -331,6 +331,56 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "POST /api/qvitter/statuses/notifications/read" do + setup [:valid_user] + + test "without valid credentials", %{conn: conn} do + conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567}) + assert json_response(conn, 403) == %{"error" => "Invalid credentials."} + end + + test "with credentials, without any params", %{conn: conn, user: current_user} do + conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/qvitter/statuses/notifications/read") + + assert json_response(conn, 400) == %{ + "error" => "You need to specify latest_id", + "request" => "/api/qvitter/statuses/notifications/read" + } + end + + test "with credentials, with params", %{conn: conn, user: current_user} do + other_user = insert(:user) + + {:ok, _activity} = + ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user}) + + response_conn = + conn + |> with_credentials(current_user.nickname, "test") + |> get("/api/qvitter/statuses/notifications.json") + + [notification] = response = json_response(response_conn, 200) + + assert length(response) == 1 + + assert notification["is_seen"] == 0 + + response_conn = + conn + |> with_credentials(current_user.nickname, "test") + |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]}) + + [notification] = response = json_response(response_conn, 200) + + assert length(response) == 1 + + assert notification["is_seen"] == 1 + end + end + describe "GET /statuses/user_timeline.json" do setup [:valid_user] -- cgit v1.2.3 From 3b02fd9fb7a834771c0582bf5a113f04ec2d46e0 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 8 Nov 2018 16:05:28 +0100 Subject: Small refactor. --- test/web/activity_pub/views/object_view_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs index 6a1311be7..7e08dff5d 100644 --- a/test/web/activity_pub/views/object_view_test.exs +++ b/test/web/activity_pub/views/object_view_test.exs @@ -13,5 +13,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do assert result["to"] == note.data["to"] assert result["content"] == note.data["content"] assert result["type"] == "Note" + assert result["@context"] end end -- cgit v1.2.3 From 34bd411781c598386f35397eb0affe124390c066 Mon Sep 17 00:00:00 2001 From: lain Date: Thu, 8 Nov 2018 16:39:38 +0100 Subject: Unify json ld header handling. --- test/web/activity_pub/transmogrifier_test.exs | 4 +++- 1 file changed, 3 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 6a6f2a44c..07ff1deeb 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -695,7 +695,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"}) {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) - assert modified["@context"] == "https://www.w3.org/ns/activitystreams" + assert modified["@context"] == + Pleroma.Web.ActivityPub.Utils.make_json_ld_header()["@context"] + assert modified["object"]["conversation"] == modified["context"] end -- cgit v1.2.3 From 719a8a1f826972a43b80f100d3cbe65e75891366 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 8 Nov 2018 19:17:15 +0000 Subject: tests: flip testing to/cc for mentions --- test/web/twitter_api/twitter_api_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 6486540f8..8b9920bd9 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -48,7 +48,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do "https://www.w3.org/ns/activitystreams#Public" ) - assert Enum.member?(get_in(activity.data, ["cc"]), "shp") + assert Enum.member?(get_in(activity.data, ["to"]), "shp") assert activity.local == true assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} = -- cgit v1.2.3 From dfc26d0fdd0bff8b2571a722fcddb37a757513d9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 9 Nov 2018 09:33:12 +0000 Subject: tests: add testing for new notification behavior --- test/notification_test.exs | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index 79290ac78..a36ed5bb8 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -3,6 +3,7 @@ defmodule Pleroma.NotificationTest do alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.CommonAPI alias Pleroma.{User, Notification} + alias Pleroma.Web.ActivityPub.Transmogrifier import Pleroma.Factory describe "create_notifications" do @@ -156,6 +157,100 @@ defmodule Pleroma.NotificationTest do end end + describe "notification target determination" do + test "it sends notifications to addressed users in new messages" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => "hey @#{other_user.nickname}!" + }) + + assert other_user in Notification.get_notified_from_activity(activity) + end + + test "it sends notifications to mentioned users in new messages" do + user = insert(:user) + other_user = insert(:user) + + create_activity = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Create", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "actor" => user.ap_id, + "object" => %{ + "type" => "Note", + "content" => "message with a Mention tag, but no explicit tagging", + "tag" => [ + %{ + "type" => "Mention", + "href" => other_user.ap_id, + "name" => other_user.nickname + } + ], + "attributedTo" => user.ap_id + } + } + + {:ok, activity} = Transmogrifier.handle_incoming(create_activity) + + assert other_user in Notification.get_notified_from_activity(activity) + end + + test "it does not send notifications to users who are only cc in new messages" do + user = insert(:user) + other_user = insert(:user) + + create_activity = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "type" => "Create", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "cc" => [other_user.ap_id], + "actor" => user.ap_id, + "object" => %{ + "type" => "Note", + "content" => "hi everyone", + "attributedTo" => user.ap_id + } + } + + {:ok, activity} = Transmogrifier.handle_incoming(create_activity) + + assert other_user not in Notification.get_notified_from_activity(activity) + end + + test "it does not send notification to mentioned users in likes" do + user = insert(:user) + other_user = insert(:user) + third_user = insert(:user) + + {:ok, activity_one} = + CommonAPI.post(user, %{ + "status" => "hey @#{other_user.nickname}!" + }) + + {:ok, activity_two, _} = CommonAPI.favorite(activity_one.id, third_user) + + assert other_user not in Notification.get_notified_from_activity(activity_two) + end + + test "it does not send notification to mentioned users in announces" do + user = insert(:user) + other_user = insert(:user) + third_user = insert(:user) + + {:ok, activity_one} = + CommonAPI.post(user, %{ + "status" => "hey @#{other_user.nickname}!" + }) + + {:ok, activity_two, _} = CommonAPI.repeat(activity_one.id, third_user) + + assert other_user not in Notification.get_notified_from_activity(activity_two) + end + end + describe "notification lifecycle" do test "liking an activity results in 1 notification, then 0 if the activity is deleted" do user = insert(:user) -- cgit v1.2.3 From c9df0112155c066a6120675a8b5d974564e9ccb4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 10 Nov 2018 10:39:42 +0000 Subject: tests: add tests for new OStatus.is_representable? function --- test/web/ostatus/ostatus_test.exs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index f095e41dd..f95da8b0a 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -456,4 +456,28 @@ defmodule Pleroma.Web.OStatusTest do "https://www.w3.org/ns/activitystreams#Public" ] end + + describe "is_representable?" do + test "Note objects are representable" do + note_activity = insert(:note_activity) + + assert OStatus.is_representable?(note_activity) + end + + test "Article objects are not representable" do + note_activity = insert(:note_activity) + + note_object = Object.normalize(note_activity.data["object"]) + + note_data = + note_object.data + |> Map.put("type", "Article") + + cs = Object.change(note_object, %{data: note_data}) + {:ok, article_object} = Repo.update(cs) + + # the underlying object is now an Article instead of a note, so this should fail + refute OStatus.is_representable?(note_activity) + end + end end -- cgit v1.2.3 From 1d9fcbf2ba77030dd82b32b2666ddae59649661b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 10 Nov 2018 11:06:29 +0000 Subject: add missing prismo testcase data --- .../httpoison_mock/https___prismo.news__mxb.json | 1 + test/fixtures/prismo-url-map.json | 111 ++++++++++++--------- test/support/httpoison_mock.ex | 8 ++ 3 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 test/fixtures/httpoison_mock/https___prismo.news__mxb.json (limited to 'test') diff --git a/test/fixtures/httpoison_mock/https___prismo.news__mxb.json b/test/fixtures/httpoison_mock/https___prismo.news__mxb.json new file mode 100644 index 000000000..a2fe53117 --- /dev/null +++ b/test/fixtures/httpoison_mock/https___prismo.news__mxb.json @@ -0,0 +1 @@ +{"id":"https://prismo.news/@mxb","type":"Person","name":"mxb","preferredUsername":"mxb","summary":"Creator of β–³ Prismo\r\n\r\nFollow me at @mb@mstdn.io","inbox":"https://prismo.news/ap/accounts/mxb/inbox","outbox":"https://prismo.news/ap/accounts/mxb/outbox","url":"https://prismo.news/@mxb","publicKey":{"id":"https://prismo.news/@mxb#main-key","owner":"https://prismo.news/@mxb","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA41gqLkBYuPLurC2TarF8\nbdyvqP54XzKyScJ6iPNkk4D4plYdWUVj0aOIHQ8LVfBeziH83jDMpRegm1sRLpNG\n1Ti+SzlWyTwugJ8wfQvwJL7iEzqhuPFddjPLpv0djMptvm5vtG6u6O3g4RpX12bv\n4pYRoMStPSv9KRKD/8Naw5Nv85PIWRc9rOly/EoVZBnbesroo69caiGthgChE2pa\niisQ5CEgj/615WUlUATkz3VdExKQkQOdeVABheIvcS5OsMurXnpWyLQ4n9WalNvF\nlJc08aOTIo4plsLAvdcGRDsBzio4qPok3jgzPpFkDqe+02WG/QMPT9VrzKO49N5R\nqQIDAQAB\n-----END PUBLIC KEY-----\n"},"icon":{"type":"Image","url":"https://prismo.s3.wasabisys.com/account/1/avatar/size_400-b6e570850878684362ba3b4bd9ceb007.jpg","media_type":null},"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"Hashtag":"as:Hashtag"},{"votes":{"@id":"as:votes","@type":"@id"}}]} \ No newline at end of file diff --git a/test/fixtures/prismo-url-map.json b/test/fixtures/prismo-url-map.json index 9088d01af..4e2e2fd4a 100644 --- a/test/fixtures/prismo-url-map.json +++ b/test/fixtures/prismo-url-map.json @@ -1,52 +1,65 @@ { - "id": "https://prismo.news/posts/83", - "type": "Article", - "name": "Introducing: Federated follows!", - "published": "2018-11-01T07:10:05Z", - "content": "We are more than thrilled to announce that Prismo now supports federated follows! It means you ca...", - "url": { - "type": "Link", - "mimeType": "text/html", - "href": "https://prismo.news/posts/83" - }, - "votes": 12, - "attributedTo": [ - { - "type": "Person", - "id": "https://prismo.news/@mxb" + "id": "https://prismo.news/posts/83#Create", + "type": "Create", + "actor": [ + { + "type": "Person", + "id": "https://prismo.news/@mxb" + } + ], + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "object": { + "id": "https://prismo.news/posts/83", + "type": "Article", + "name": "Introducing: Federated follows!", + "published": "2018-11-01T07:10:05Z", + "content": "We are more than thrilled to announce that Prismo now supports federated follows! It means you ca...", + "url": { + "type": "Link", + "mimeType": "text/html", + "href": "https://prismo.news/posts/83" + }, + "votes": 12, + "attributedTo": [ + { + "type": "Person", + "id": "https://prismo.news/@mxb" + } + ], + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "tags": [ + { + "type": "Hashtag", + "href": "https://prismo.news/tags/prismo", + "name": "#prismo" + }, + { + "type": "Hashtag", + "href": "https://prismo.news/tags/prismodev", + "name": "#prismodev" + }, + { + "type": "Hashtag", + "href": "https://prismo.news/tags/meta", + "name": "#meta" + } + ], + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "Hashtag": "as:Hashtag" + }, + { + "votes": { + "@id": "as:votes", + "@type": "@id" + } + } + ] } - ], - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "tags": [ - { - "type": "Hashtag", - "href": "https://prismo.news/tags/prismo", - "name": "#prismo" - }, - { - "type": "Hashtag", - "href": "https://prismo.news/tags/prismodev", - "name": "#prismodev" - }, - { - "type": "Hashtag", - "href": "https://prismo.news/tags/meta", - "name": "#meta" - } - ], - "@context": [ - "https://www.w3.org/ns/activitystreams", - "https://w3id.org/security/v1", - { - "Hashtag": "as:Hashtag" - }, - { - "votes": { - "@id": "as:votes", - "@type": "@id" - } - } - ] } diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 75c78d70e..ab964334d 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://prismo.news/@mxb", _, _) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https___prismo.news__mxb.json") + }} + end + def get("https://osada.macgirvin.com/channel/mike", _, _) do {:ok, %Response{ -- cgit v1.2.3 From 69b8c0e299c9d4ec16bd056adf2fede326de7f69 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 10 Nov 2018 12:16:10 +0000 Subject: tests: add test for internal data stripping --- test/web/activity_pub/transmogrifier_test.exs | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 6e4820dbc..0278ef5d1 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -743,6 +743,39 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29" end + + test "it strips internal hashtag data" do + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu"}) + + expected_tag = %{ + "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu", + "type" => "Hashtag", + "name" => "#2hu" + } + + {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) + + assert modified["object"]["tag"] == [expected_tag] + end + + test "it strips internal fields" do + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :moominmamma:"}) + + {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) + + assert length(modified["object"]["tag"]) == 2 + + assert is_nil(modified["object"]["emoji"]) + assert is_nil(modified["object"]["likes"]) + assert is_nil(modified["object"]["like_count"]) + assert is_nil(modified["object"]["announcements"]) + assert is_nil(modified["object"]["announcement_count"]) + assert is_nil(modified["object"]["context_id"]) + end end describe "user upgrade" do -- cgit v1.2.3 From 54fdce9107af85321d3ce73ec59a48567dc1bdba Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 11 Nov 2018 07:26:31 +0000 Subject: tests: add tests for CSPPlug --- test/plugs/csp_plug_test.exs | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/plugs/csp_plug_test.exs (limited to 'test') diff --git a/test/plugs/csp_plug_test.exs b/test/plugs/csp_plug_test.exs new file mode 100644 index 000000000..e27b24db9 --- /dev/null +++ b/test/plugs/csp_plug_test.exs @@ -0,0 +1,61 @@ +defmodule Pleroma.Web.Plugs.CSPPlugTest do + use Pleroma.Web.ConnCase + alias Pleroma.Config + alias Plug.Conn + + test "it sends CSP headers when enabled", %{conn: conn} do + Config.put([:csp, :enabled], true) + + conn = + conn + |> get("/api/v1/instance") + + refute Conn.get_resp_header(conn, "x-xss-protection") == [] + refute Conn.get_resp_header(conn, "x-permitted-cross-domain-policies") == [] + refute Conn.get_resp_header(conn, "x-frame-options") == [] + refute Conn.get_resp_header(conn, "x-content-type-options") == [] + refute Conn.get_resp_header(conn, "x-download-options") == [] + refute Conn.get_resp_header(conn, "referrer-policy") == [] + refute Conn.get_resp_header(conn, "content-security-policy") == [] + end + + test "it does not send CSP headers when disabled", %{conn: conn} do + Config.put([:csp, :enabled], false) + + conn = + conn + |> get("/api/v1/instance") + + assert Conn.get_resp_header(conn, "x-xss-protection") == [] + assert Conn.get_resp_header(conn, "x-permitted-cross-domain-policies") == [] + assert Conn.get_resp_header(conn, "x-frame-options") == [] + assert Conn.get_resp_header(conn, "x-content-type-options") == [] + assert Conn.get_resp_header(conn, "x-download-options") == [] + assert Conn.get_resp_header(conn, "referrer-policy") == [] + assert Conn.get_resp_header(conn, "content-security-policy") == [] + end + + test "it sends STS headers when enabled", %{conn: conn} do + Config.put([:csp, :enabled], true) + Config.put([:csp, :sts], true) + + conn = + conn + |> get("/api/v1/instance") + + refute Conn.get_resp_header(conn, "strict-transport-security") == [] + refute Conn.get_resp_header(conn, "expect-ct") == [] + end + + test "it does not send STS headers when disabled", %{conn: conn} do + Config.put([:csp, :enabled], true) + Config.put([:csp, :sts], false) + + conn = + conn + |> get("/api/v1/instance") + + assert Conn.get_resp_header(conn, "strict-transport-security") == [] + assert Conn.get_resp_header(conn, "expect-ct") == [] + end +end -- cgit v1.2.3 From fe67665e19cc98faff4a8ee53a3f4ca4190ca2ef Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 12 Nov 2018 15:08:02 +0000 Subject: rename CSPPlug to HTTPSecurityPlug. --- test/plugs/csp_plug_test.exs | 61 ---------------------------------- test/plugs/http_security_plug_test.exs | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 test/plugs/csp_plug_test.exs create mode 100644 test/plugs/http_security_plug_test.exs (limited to 'test') diff --git a/test/plugs/csp_plug_test.exs b/test/plugs/csp_plug_test.exs deleted file mode 100644 index e27b24db9..000000000 --- a/test/plugs/csp_plug_test.exs +++ /dev/null @@ -1,61 +0,0 @@ -defmodule Pleroma.Web.Plugs.CSPPlugTest do - use Pleroma.Web.ConnCase - alias Pleroma.Config - alias Plug.Conn - - test "it sends CSP headers when enabled", %{conn: conn} do - Config.put([:csp, :enabled], true) - - conn = - conn - |> get("/api/v1/instance") - - refute Conn.get_resp_header(conn, "x-xss-protection") == [] - refute Conn.get_resp_header(conn, "x-permitted-cross-domain-policies") == [] - refute Conn.get_resp_header(conn, "x-frame-options") == [] - refute Conn.get_resp_header(conn, "x-content-type-options") == [] - refute Conn.get_resp_header(conn, "x-download-options") == [] - refute Conn.get_resp_header(conn, "referrer-policy") == [] - refute Conn.get_resp_header(conn, "content-security-policy") == [] - end - - test "it does not send CSP headers when disabled", %{conn: conn} do - Config.put([:csp, :enabled], false) - - conn = - conn - |> get("/api/v1/instance") - - assert Conn.get_resp_header(conn, "x-xss-protection") == [] - assert Conn.get_resp_header(conn, "x-permitted-cross-domain-policies") == [] - assert Conn.get_resp_header(conn, "x-frame-options") == [] - assert Conn.get_resp_header(conn, "x-content-type-options") == [] - assert Conn.get_resp_header(conn, "x-download-options") == [] - assert Conn.get_resp_header(conn, "referrer-policy") == [] - assert Conn.get_resp_header(conn, "content-security-policy") == [] - end - - test "it sends STS headers when enabled", %{conn: conn} do - Config.put([:csp, :enabled], true) - Config.put([:csp, :sts], true) - - conn = - conn - |> get("/api/v1/instance") - - refute Conn.get_resp_header(conn, "strict-transport-security") == [] - refute Conn.get_resp_header(conn, "expect-ct") == [] - end - - test "it does not send STS headers when disabled", %{conn: conn} do - Config.put([:csp, :enabled], true) - Config.put([:csp, :sts], false) - - conn = - conn - |> get("/api/v1/instance") - - assert Conn.get_resp_header(conn, "strict-transport-security") == [] - assert Conn.get_resp_header(conn, "expect-ct") == [] - end -end diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs new file mode 100644 index 000000000..5268a1972 --- /dev/null +++ b/test/plugs/http_security_plug_test.exs @@ -0,0 +1,61 @@ +defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do + use Pleroma.Web.ConnCase + alias Pleroma.Config + alias Plug.Conn + + test "it sends CSP headers when enabled", %{conn: conn} do + Config.put([:http_security, :enabled], true) + + conn = + conn + |> get("/api/v1/instance") + + refute Conn.get_resp_header(conn, "x-xss-protection") == [] + refute Conn.get_resp_header(conn, "x-permitted-cross-domain-policies") == [] + refute Conn.get_resp_header(conn, "x-frame-options") == [] + refute Conn.get_resp_header(conn, "x-content-type-options") == [] + refute Conn.get_resp_header(conn, "x-download-options") == [] + refute Conn.get_resp_header(conn, "referrer-policy") == [] + refute Conn.get_resp_header(conn, "content-security-policy") == [] + end + + test "it does not send CSP headers when disabled", %{conn: conn} do + Config.put([:http_security, :enabled], false) + + conn = + conn + |> get("/api/v1/instance") + + assert Conn.get_resp_header(conn, "x-xss-protection") == [] + assert Conn.get_resp_header(conn, "x-permitted-cross-domain-policies") == [] + assert Conn.get_resp_header(conn, "x-frame-options") == [] + assert Conn.get_resp_header(conn, "x-content-type-options") == [] + assert Conn.get_resp_header(conn, "x-download-options") == [] + assert Conn.get_resp_header(conn, "referrer-policy") == [] + assert Conn.get_resp_header(conn, "content-security-policy") == [] + end + + test "it sends STS headers when enabled", %{conn: conn} do + Config.put([:http_security, :enabled], true) + Config.put([:http_security, :sts], true) + + conn = + conn + |> get("/api/v1/instance") + + refute Conn.get_resp_header(conn, "strict-transport-security") == [] + refute Conn.get_resp_header(conn, "expect-ct") == [] + end + + test "it does not send STS headers when disabled", %{conn: conn} do + Config.put([:http_security, :enabled], true) + Config.put([:http_security, :sts], false) + + conn = + conn + |> get("/api/v1/instance") + + assert Conn.get_resp_header(conn, "strict-transport-security") == [] + assert Conn.get_resp_header(conn, "expect-ct") == [] + end +end -- cgit v1.2.3 From ee5932a504d69e591aad7bdd52bd97d1f92d4e32 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 12 Nov 2018 15:14:46 +0000 Subject: http security: allow referrer-policy to be configured --- test/plugs/http_security_plug_test.exs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs index 5268a1972..55040a108 100644 --- a/test/plugs/http_security_plug_test.exs +++ b/test/plugs/http_security_plug_test.exs @@ -58,4 +58,20 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do assert Conn.get_resp_header(conn, "strict-transport-security") == [] assert Conn.get_resp_header(conn, "expect-ct") == [] end + + test "referrer-policy header reflects configured value", %{conn: conn} do + conn = + conn + |> get("/api/v1/instance") + + assert Conn.get_resp_header(conn, "referrer-policy") == ["same-origin"] + + Config.put([:http_security, :referrer_policy], "no-referrer") + + conn = + build_conn() + |> get("/api/v1/instance") + + assert Conn.get_resp_header(conn, "referrer-policy") == ["no-referrer"] + end end -- cgit v1.2.3 From db78c72868358eed6c07ee43a5f1427d545c45ed Mon Sep 17 00:00:00 2001 From: scarlett Date: Mon, 12 Nov 2018 16:40:34 +0000 Subject: Twitter API: Add tests for nil names. --- test/web/twitter_api/views/user_view_test.exs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index 2deb22fb1..2c583c0d3 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -13,6 +13,13 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do [user: user] end + test "A user with only a nickname", %{user: user} do + user = %{user | name: nil, nickname: "scarlett@catgirl.science"} + represented = UserView.render("show.json", %{user: user}) + assert represented["name"] == user.nickname + assert represented["name_html"] == user.nickname + end + test "A user with an avatar object", %{user: user} do image = "image" user = %{user | avatar: %{"url" => [%{"href" => image}]}} -- cgit v1.2.3 From 2cf40237ff44cdb04b20546ca51efb671270dbc2 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 13 Nov 2018 19:46:34 +0100 Subject: MastodonAPI: Add pagination to private messages. --- .../mastodon_api/mastodon_api_controller_test.exs | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 3f9324fcc..ad67cae6b 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -178,6 +178,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> get("api/v1/timelines/home") [_s1, _s2] = json_response(res_conn, 200) + + # Test pagination + Enum.each(1..20, fn _ -> + {:ok, _} = + CommonAPI.post(user_one, %{ + "status" => "Hi @#{user_two.nickname}!", + "visibility" => "direct" + }) + end) + + res_conn = + conn + |> assign(:user, user_two) + |> get("api/v1/timelines/direct") + + statuses = json_response(res_conn, 200) + assert length(statuses) == 20 + + res_conn = + conn + |> assign(:user, user_two) + |> get("api/v1/timelines/direct", %{max_id: List.last(statuses)["id"]}) + + [status] = json_response(res_conn, 200) + + assert status["url"] != direct.data["id"] end test "replying to a status", %{conn: conn} do -- cgit v1.2.3 From ea9a776d7beb32b157269652759b85cdc17fec32 Mon Sep 17 00:00:00 2001 From: lain Date: Tue, 13 Nov 2018 20:08:50 +0100 Subject: TwitterApi: Add direct message endpoint --- .../twitter_api/twitter_api_controller_test.exs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 13480c21b..788e3a6eb 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -271,6 +271,36 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "GET /statuses/dm_timeline.json" do + test "it show direct messages", %{conn: conn} do + user_one = insert(:user) + user_two = insert(:user) + + {:ok, user_two} = User.follow(user_two, user_one) + + {:ok, direct} = + CommonAPI.post(user_one, %{ + "status" => "Hi @#{user_two.nickname}!", + "visibility" => "direct" + }) + + {:ok, _follower_only} = + CommonAPI.post(user_one, %{ + "status" => "Hi @#{user_two.nickname}!", + "visibility" => "private" + }) + + # Only direct should be visible here + res_conn = + conn + |> assign(:user, user_two) + |> get("/api/statuses/dm_timeline.json") + + [status] = json_response(res_conn, 200) + assert status["id"] == direct.id + end + end + describe "GET /statuses/mentions.json" do setup [:valid_user] -- cgit v1.2.3 From 7b170cd6161166e153ad54856d5f1cf189f4e3ae Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 14 Nov 2018 20:33:23 +0100 Subject: Add Pleroma user search api for PleromaFE. --- test/web/twitter_api/twitter_api_controller_test.exs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 788e3a6eb..07f9c7814 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1211,4 +1211,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do assert relationship["follows_you"] == false end end + + describe "GET /api/pleroma/search_user" do + test "it returns users, ordered by similarity", %{conn: conn} do + user = insert(:user, %{name: "eal"}) + user_two = insert(:user, %{name: "ean"}) + user_three = insert(:user, %{name: "ebn"}) + + resp = conn + |> get(twitter_api_search__path(conn, :search_user), query: "eal") + |> json_response(200) + + assert length(resp) == 3 + assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn (%{"id" => id}) -> id end) + end + end end -- cgit v1.2.3 From 27aa136aacb43084089234df59649bc81e53d63c Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 14 Nov 2018 20:41:12 +0100 Subject: Format. --- test/web/twitter_api/twitter_api_controller_test.exs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 07f9c7814..1d45d9437 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1218,12 +1218,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do user_two = insert(:user, %{name: "ean"}) user_three = insert(:user, %{name: "ebn"}) - resp = conn - |> get(twitter_api_search__path(conn, :search_user), query: "eal") - |> json_response(200) + resp = + conn + |> get(twitter_api_search__path(conn, :search_user), query: "eal") + |> json_response(200) assert length(resp) == 3 - assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn (%{"id" => id}) -> id end) + assert [user.id, user_two.id, user_three.id] == Enum.map(resp, fn %{"id" => id} -> id end) end end end -- cgit v1.2.3 From 62944b47fb15d66aed5d3a6250eb3334c2835ea7 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Sat, 17 Nov 2018 00:45:21 +0900 Subject: Reset http security settings to fix plug test --- test/plugs/http_security_plug_test.exs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs index 55040a108..169c3b3a8 100644 --- a/test/plugs/http_security_plug_test.exs +++ b/test/plugs/http_security_plug_test.exs @@ -60,6 +60,8 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do end test "referrer-policy header reflects configured value", %{conn: conn} do + Config.put([:http_security, :enabled], true) + conn = conn |> get("/api/v1/instance") -- cgit v1.2.3 From e8d8c84f795152a0522e6848e75b47dcbce5aa89 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 16 Nov 2018 18:31:32 +0100 Subject: Add better test for user search functionlity. --- test/user_test.exs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 7dec3462f..231f1d94d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -578,4 +578,16 @@ defmodule Pleroma.UserTest do assert cached_user != user end end + + describe "User.search" do + test "finds a user, ranking by similarity" do + user = insert(:user, %{name: "lain"}) + user_two = insert(:user, %{name: "ean"}) + user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"}) + user_four = insert(:user, %{nickname: "lain@pleroma.soykaf.com"}) + + assert user_four == + User.search("lain@ple") |> List.first() |> Map.put(:search_distance, nil) + end + end end -- cgit v1.2.3 From f87b315618cf55f5c0794ab0dfc5523bdce348ef Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 16 Nov 2018 19:47:36 +0100 Subject: TwitterAPI: Fix dm_timeline displaying only half of the conversation. --- test/web/twitter_api/twitter_api_controller_test.exs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 1d45d9437..6bdcb4fd8 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -284,6 +284,12 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do "visibility" => "direct" }) + {:ok, direct_two} = + CommonAPI.post(user_two, %{ + "status" => "Hi @#{user_one.nickname}!", + "visibility" => "direct" + }) + {:ok, _follower_only} = CommonAPI.post(user_one, %{ "status" => "Hi @#{user_two.nickname}!", @@ -296,8 +302,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do |> assign(:user, user_two) |> get("/api/statuses/dm_timeline.json") - [status] = json_response(res_conn, 200) - assert status["id"] == direct.id + [status, status_two] = json_response(res_conn, 200) + assert status["id"] == direct_two.id + assert status_two["id"] == direct.id end end -- cgit v1.2.3 From 010fcb73d7e308c15b3f2c10fa27bd49d25d56cf Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 17:42:47 +0000 Subject: test: httpoison mock: add second spoofing activity test --- .../httpoison_mock/https___info.pleroma.site_actor.json | 17 +++++++++++++++++ .../https__info.pleroma.site_activity2.json | 14 ++++++++++++++ test/support/httpoison_mock.ex | 16 ++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json create mode 100644 test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json (limited to 'test') diff --git a/test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json b/test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json new file mode 100644 index 000000000..9dabf0e52 --- /dev/null +++ b/test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json @@ -0,0 +1,17 @@ +{ + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://info.pleroma.site/actor.json", + "type": "Person", + "following": "https://info.pleroma.site/following.json", + "followers": "https://info.pleroma.site/followers.json", + "inbox": "https://info.pleroma.site/inbox.json", + "outbox": "https://info.pleroma.site/outbox.json", + "preferredUsername": "admin", + "name": null, + "summary": "

", + "publicKey": { + "id": "https://info.pleroma.site/actor.json#main-key", + "owner": "https://info.pleroma.site/actor.json", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtc4Tir+3ADhSNF6VKrtW\nOU32T01w7V0yshmQei38YyiVwVvFu8XOP6ACchkdxbJ+C9mZud8qWaRJKVbFTMUG\nNX4+6Q+FobyuKrwN7CEwhDALZtaN2IPbaPd6uG1B7QhWorrY+yFa8f2TBM3BxnUy\nI4T+bMIZIEYG7KtljCBoQXuTQmGtuffO0UwJksidg2ffCF5Q+K//JfQagJ3UzrR+\nZXbKMJdAw4bCVJYs4Z5EhHYBwQWiXCyMGTd7BGlmMkY6Av7ZqHKC/owp3/0EWDNz\nNqF09Wcpr3y3e8nA10X40MJqp/wR+1xtxp+YGbq/Cj5hZGBG7etFOmIpVBrDOhry\nBwIDAQAB\n-----END PUBLIC KEY-----\n" + } +} diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json new file mode 100644 index 000000000..8ce35958d --- /dev/null +++ b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json @@ -0,0 +1,14 @@ +{ + "@context": "https://www.w3.org/ns/activitystreams", + "attributedTo": "https://info.pleroma.site/actor.json", + "attachment": [], + "actor": "https://mastodon.example.org/users/admin", + "content": "

this post was not actually written by Haelwenn

", + "id": "https://info.pleroma.site/activity2.json", + "published": "2018-09-01T22:15:00Z", + "tag": [], + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "type": "Note" +} diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index ab964334d..2ea10910e 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -40,6 +40,22 @@ defmodule HTTPoisonMock do }} end + def get("https://info.pleroma.site/activity2.json", _, _) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json") + }} + end + + def get("https://info.pleroma.site/actor.json", _, _) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https___info.pleroma.site_actor.json") + }} + end + def get("https://puckipedia.com/", [Accept: "application/activity+json"], _) do {:ok, %Response{ -- cgit v1.2.3 From 2ab8e287289d3b4d6458f6d9cc29c5d29dfcd102 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 18:11:31 +0000 Subject: transmogrifier tests: fix defective spoofing test --- test/web/activity_pub/transmogrifier_test.exs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 0278ef5d1..9250598f4 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -872,12 +872,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do end test "it rejects activities which reference objects with bogus origins" do - user = insert(:user, %{local: false}) - data = %{ "@context" => "https://www.w3.org/ns/activitystreams", - "id" => user.ap_id <> "/activities/1234", - "actor" => user.ap_id, + "id" => "https://mastodon.example.org/users/admin/activities/1234", + "actor" => "https://mastodon.example.org/users/admin", "to" => ["https://www.w3.org/ns/activitystreams#Public"], "object" => "https://info.pleroma.site/activity.json", "type" => "Announce" -- cgit v1.2.3 From d9cb081f0723881343b6dd71e1bb1b52b5492f2b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 18:12:11 +0000 Subject: tests: add additional spoofing tests --- test/web/activity_pub/transmogrifier_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 9250598f4..0ba969263 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -883,5 +883,22 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do :error = Transmogrifier.handle_incoming(data) end + + test "it rejects objects when the ID does not match the fetched URI" do + {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity2.json") + end + + test "it rejects activities which reference objects by mismatched URI" do + data = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "http://mastodon.example.org/users/admin/activities/1234", + "actor" => "http://mastodon.example.org/users/admin", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "object" => "https://info.pleroma.site/activity2.json", + "type" => "Announce" + } + + :error = Transmogrifier.handle_incoming(data) + end end end -- cgit v1.2.3 From 9c8adfb6efb0adf0638f91533ff1bc9f9df36668 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 18:16:55 +0000 Subject: test: fix more test defects --- test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json | 4 ++-- test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json | 2 +- test/web/activity_pub/transmogrifier_test.exs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json index eab0341fe..a0dc4c830 100644 --- a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json +++ b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity.json @@ -1,8 +1,8 @@ { "@context": "https://www.w3.org/ns/activitystreams", - "actor": "https://mastodon.example.org/users/admin", + "actor": "http://mastodon.example.org/users/admin", "attachment": [], - "attributedTo": "https://mastodon.example.org/users/admin", + "attributedTo": "http://mastodon.example.org/users/admin", "content": "

this post was not actually written by Haelwenn

", "id": "https://info.pleroma.site/activity.json", "published": "2018-09-01T22:15:00Z", diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json index 8ce35958d..b16a9279b 100644 --- a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json +++ b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity2.json @@ -2,7 +2,7 @@ "@context": "https://www.w3.org/ns/activitystreams", "attributedTo": "https://info.pleroma.site/actor.json", "attachment": [], - "actor": "https://mastodon.example.org/users/admin", + "actor": "http://mastodon.example.org/users/admin", "content": "

this post was not actually written by Haelwenn

", "id": "https://info.pleroma.site/activity2.json", "published": "2018-09-01T22:15:00Z", diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 0ba969263..e5308d125 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -874,8 +874,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do test "it rejects activities which reference objects with bogus origins" do data = %{ "@context" => "https://www.w3.org/ns/activitystreams", - "id" => "https://mastodon.example.org/users/admin/activities/1234", - "actor" => "https://mastodon.example.org/users/admin", + "id" => "http://mastodon.example.org/users/admin/activities/1234", + "actor" => "http://mastodon.example.org/users/admin", "to" => ["https://www.w3.org/ns/activitystreams#Public"], "object" => "https://info.pleroma.site/activity.json", "type" => "Announce" -- cgit v1.2.3 From b483ae0a724a2b76e8c61f63a96d7867339dacb1 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 18:24:58 +0000 Subject: tests: add a second spoofing variant --- .../https__info.pleroma.site_activity3.json | 13 +++++++++++++ test/support/httpoison_mock.ex | 8 ++++++++ test/web/activity_pub/transmogrifier_test.exs | 21 +++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json (limited to 'test') diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json new file mode 100644 index 000000000..1df73f2c5 --- /dev/null +++ b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json @@ -0,0 +1,13 @@ +{ + "@context": "https://www.w3.org/ns/activitystreams", + "attributedTo": "http://mastodon.example.org/users/admin", + "attachment": [], + "content": "

this post was not actually written by Haelwenn

", + "id": "https://info.pleroma.site/activity2.json", + "published": "2018-09-01T22:15:00Z", + "tag": [], + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "type": "Note" +} diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 2ea10910e..ebd1e9c4d 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -48,6 +48,14 @@ defmodule HTTPoisonMock do }} end + def get("https://info.pleroma.site/activity3.json", _, _) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https__info.pleroma.site_activity3.json") + }} + end + def get("https://info.pleroma.site/actor.json", _, _) do {:ok, %Response{ diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index e5308d125..6320b5b6e 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -884,11 +884,11 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do :error = Transmogrifier.handle_incoming(data) end - test "it rejects objects when the ID does not match the fetched URI" do + test "it rejects objects when attributedTo is wrong (variant 1)" do {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity2.json") end - test "it rejects activities which reference objects by mismatched URI" do + test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do data = %{ "@context" => "https://www.w3.org/ns/activitystreams", "id" => "http://mastodon.example.org/users/admin/activities/1234", @@ -900,5 +900,22 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do :error = Transmogrifier.handle_incoming(data) end + + test "it rejects objects when attributedTo is wrong (variant 2)" do + {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity3.json") + end + + test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do + data = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "id" => "http://mastodon.example.org/users/admin/activities/1234", + "actor" => "http://mastodon.example.org/users/admin", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "object" => "https://info.pleroma.site/activity3.json", + "type" => "Announce" + } + + :error = Transmogrifier.handle_incoming(data) + end end end -- cgit v1.2.3 From 1a940cb46e1fb06b391043ae2efa3ac0d3c49fe0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 20:07:49 +0000 Subject: tests: add tests for contain_origin_from_id() --- test/web/activity_pub/transmogrifier_test.exs | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 6320b5b6e..b8adf3b8a 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -918,4 +918,42 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do :error = Transmogrifier.handle_incoming(data) end end + + describe "general origin containment" do + test "contain_origin_from_id() catches obvious spoofing attempts" do + data = %{ + "id" => "http://example.com/~alyssa/activities/1234.json" + } + + :error = + Transmogrifier.contain_origin_from_id( + "http://example.org/~alyssa/activities/1234.json", + data + ) + end + + test "contain_origin_from_id() allows alternate IDs within the same origin domain" do + data = %{ + "id" => "http://example.com/~alyssa/activities/1234.json" + } + + :ok = + Transmogrifier.contain_origin_from_id( + "http://example.com/~alyssa/activities/1234", + data + ) + end + + test "contain_origin_from_id() allows matching IDs" do + data = %{ + "id" => "http://example.com/~alyssa/activities/1234.json" + } + + :ok = + Transmogrifier.contain_origin_from_id( + "http://example.com/~alyssa/activities/1234.json", + data + ) + end + end end -- cgit v1.2.3 From dc1d8e13b483d6e5df4ea6432aa3e37971bb3fb1 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 20:20:45 +0000 Subject: tests: add a testcase for user collision --- test/support/httpoison_mock.ex | 8 ++++++++ test/web/activity_pub/transmogrifier_test.exs | 12 ++++++++++++ 2 files changed, 20 insertions(+) (limited to 'test') diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index ebd1e9c4d..e3310bb5d 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -756,6 +756,14 @@ defmodule HTTPoisonMock do }} end + def get("https://n1u.moe/users/rye", [Accept: "application/activity+json"], _) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/rye.json") + }} + end + def get( "https://mst3k.interlinked.me/users/luciferMysticus", [Accept: "application/activity+json"], diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index b8adf3b8a..f8a82dd5b 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -955,5 +955,17 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do data ) end + + test "users cannot be collided through fake direction spoofing attempts" do + user = + insert(:user, %{ + nickname: "rye@niu.moe", + local: false, + ap_id: "https://niu.moe/users/rye", + follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"}) + }) + + {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye") + end end end -- cgit v1.2.3 From 55640c4804d1fe1c39b155f8acd5f820425fb7f6 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 20:31:20 +0000 Subject: tests: add a test to verify the general fake direction protection works in all cases --- .../httpoison_mock/https__info.pleroma.site_activity4.json | 13 +++++++++++++ test/support/httpoison_mock.ex | 8 ++++++++ test/web/activity_pub/transmogrifier_test.exs | 7 +++++++ 3 files changed, 28 insertions(+) create mode 100644 test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json (limited to 'test') diff --git a/test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json new file mode 100644 index 000000000..57a73b12a --- /dev/null +++ b/test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json @@ -0,0 +1,13 @@ +{ + "@context": "https://www.w3.org/ns/activitystreams", + "attributedTo": "http://mastodon.example.org/users/admin", + "attachment": [], + "content": "

this post was not actually written by Haelwenn

", + "id": "http://mastodon.example.org/users/admin/activities/1234", + "published": "2018-09-01T22:15:00Z", + "tag": [], + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "type": "Note" +} diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index e3310bb5d..0be09b6ce 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -56,6 +56,14 @@ defmodule HTTPoisonMock do }} end + def get("https://info.pleroma.site/activity4.json", _, _) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/https__info.pleroma.site_activity4.json") + }} + end + def get("https://info.pleroma.site/actor.json", _, _) do {:ok, %Response{ diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index f8a82dd5b..9174d9b76 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -967,5 +967,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye") end + + test "all objects with fake directions are rejected by the object fetcher" do + {:error, _} = + ActivityPub.fetch_and_contain_remote_object_from_id( + "https://info.pleroma.site/activity4.json" + ) + end end end -- cgit v1.2.3 From b1a6e8d80d47efdea5110e9d86e080a16b5aeaa8 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 21:01:19 +0000 Subject: test: add sanity tests for federator handling of AP docs --- test/web/federator_test.exs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test') diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index c709d1181..1d48931b5 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -61,4 +61,42 @@ defmodule Pleroma.Web.FederatorTest do Pleroma.Config.put([:instance, :allow_relay], true) end end + + describe "Receive an activity" do + test "successfully processes incoming AP docs with correct origin" do + params = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "actor" => "http://mastodon.example.org/users/admin", + "type" => "Create", + "id" => "http://mastodon.example.org/users/admin/activities/1", + "object" => %{ + "type" => "Note", + "content" => "hi world!", + "id" => "http://mastodon.example.org/users/admin/objects/1", + "attributedTo" => "http://mastodon.example.org/users/admin", + }, + "to" => ["https://www.w3.org/ns/activitystreams#Public"] + } + + {:ok, _activity} = Federator.handle(:incoming_ap_doc, params) + end + + test "rejects incoming AP docs with incorrect origin" do + params = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "actor" => "https://niu.moe/users/rye", + "type" => "Create", + "id" => "http://mastodon.example.org/users/admin/activities/1", + "object" => %{ + "type" => "Note", + "content" => "hi world!", + "id" => "http://mastodon.example.org/users/admin/objects/1", + "attributedTo" => "http://mastodon.example.org/users/admin", + }, + "to" => ["https://www.w3.org/ns/activitystreams#Public"] + } + + :error = Federator.handle(:incoming_ap_doc, params) + end + end end -- cgit v1.2.3 From 76bd80d462be88db6edf730d81269704480f87fe Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 17 Nov 2018 20:04:54 +0100 Subject: test/plugs/user_is_admin_plug_test: New test --- test/plugs/user_is_admin_plug_test.exs | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/plugs/user_is_admin_plug_test.exs (limited to 'test') diff --git a/test/plugs/user_is_admin_plug_test.exs b/test/plugs/user_is_admin_plug_test.exs new file mode 100644 index 000000000..ddf9eb139 --- /dev/null +++ b/test/plugs/user_is_admin_plug_test.exs @@ -0,0 +1,39 @@ +defmodule Pleroma.Plugs.UserIsAdminPlugTest do + use Pleroma.Web.ConnCase, async: true + + alias Pleroma.Plugs.UserIsAdminPlug + import Pleroma.Factory + + test "accepts a user that is admin", %{conn: conn} do + user = insert(:user, info: %{"is_admin" => true}) + + conn = + build_conn() + |> assign(:user, user) + + ret_conn = + conn + |> UserIsAdminPlug.call(%{}) + + assert conn == ret_conn + end + + test "denies a user that isn't admin", %{conn: conn} do + user = insert(:user) + + conn = + build_conn() + |> assign(:user, user) + |> UserIsAdminPlug.call(%{}) + + assert conn.status == 403 + end + + test "denies when a user isn't set", %{conn: conn} do + conn = + build_conn() + |> UserIsAdminPlug.call(%{}) + + assert conn.status == 403 + end +end -- cgit v1.2.3 From 52681f7fd01c17876b03176cd82b299e6a342d56 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 17 Nov 2018 22:11:18 +0100 Subject: Web.AdminAPI.AdminAPIControllerTest: New Test --- test/web/admin_api/admin_api_controller_test.exs | 112 +++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 test/web/admin_api/admin_api_controller_test.exs (limited to 'test') diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs new file mode 100644 index 000000000..fa0cb71bf --- /dev/null +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -0,0 +1,112 @@ +defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do + use Pleroma.Web.ConnCase + + alias Pleroma.{Repo, User} + + import Pleroma.Factory + import ExUnit.CaptureLog + + describe "/api/pleroma/admin/user" do + test "Delete" do + admin = insert(:user, info: %{"is_admin" => true}) + user = insert(:user) + + conn = + build_conn() + |> assign(:user, admin) + |> put_req_header("accept", "application/json") + |> delete("/api/pleroma/admin/user?nickname=#{user.nickname}") + + assert json_response(conn, 200) == user.nickname + end + + test "Create" do + admin = insert(:user, info: %{"is_admin" => true}) + + conn = + build_conn() + |> assign(:user, admin) + |> put_req_header("accept", "application/json") + |> post("/api/pleroma/admin/user", %{ + "nickname" => "lain", + "email" => "lain@example.org", + "password" => "test" + }) + + assert json_response(conn, 200) == "lain" + end + end + + describe "/api/pleroma/admin/permission_group" do + test "GET is giving user_info" do + admin = insert(:user, info: %{"is_admin" => true}) + + conn = + build_conn() + |> assign(:user, admin) + |> put_req_header("accept", "application/json") + |> get("/api/pleroma/admin/permission_group/#{admin.nickname}") + + assert json_response(conn, 200) == admin.info + end + + test "/:right POST, can add to a permission group" do + admin = insert(:user, info: %{"is_admin" => true}) + user = insert(:user) + + user_info = + user.info + |> Map.put("is_admin", true) + + conn = + build_conn() + |> assign(:user, admin) + |> put_req_header("accept", "application/json") + |> post("/api/pleroma/admin/permission_group/#{user.nickname}/admin") + + assert json_response(conn, 200) == user_info + end + + test "/:right DELETE, can remove from a permission group" do + admin = insert(:user, info: %{"is_admin" => true}) + user = insert(:user, info: %{"is_admin" => true}) + + user_info = + user.info + |> Map.put("is_admin", false) + + conn = + build_conn() + |> assign(:user, admin) + |> put_req_header("accept", "application/json") + |> delete("/api/pleroma/admin/permission_group/#{user.nickname}/admin") + + assert json_response(conn, 200) == user_info + end + end + + test "/api/pleroma/admin/invite_token" do + admin = insert(:user, info: %{"is_admin" => true}) + + conn = + build_conn() + |> assign(:user, admin) + |> put_req_header("accept", "application/json") + |> get("/api/pleroma/admin/invite_token") + + assert conn.status == 200 + end + + test "/api/pleroma/admin/password_reset" do + admin = insert(:user, info: %{"is_admin" => true}) + user = insert(:user, info: %{"is_admin" => true}) + + conn = + build_conn() + |> assign(:user, admin) + |> put_req_header("accept", "application/json") + |> get("/api/pleroma/admin/password_reset?nickname=#{user.nickname}") + + assert conn.status == 200 + end +end -- cgit v1.2.3 From dfcfb184b10428af8d37492e64f271c0275fc2c9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 21:22:30 +0000 Subject: activitypub: transmogrifier: make deletes secure --- test/web/activity_pub/transmogrifier_test.exs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 9174d9b76..829da0a65 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -361,6 +361,26 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do refute Repo.get(Activity, activity.id) end + test "it fails for incoming deletes with spoofed origin" do + activity = insert(:note_activity) + + data = + File.read!("test/fixtures/mastodon-delete.json") + |> Poison.decode!() + + object = + data["object"] + |> Map.put("id", activity.data["object"]["id"]) + + data = + data + |> Map.put("object", object) + + :error = Transmogrifier.handle_incoming(data) + + assert Repo.get(Activity, activity.id) + end + test "it works for incoming unannounces with an existing notice" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"}) -- cgit v1.2.3 From e10f839e9b413a58dfa2c55f136862ec0f56e314 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 21:41:08 +0000 Subject: tests: federator: fix formatting --- test/web/federator_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 1d48931b5..02e1ca76e 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -73,7 +73,7 @@ defmodule Pleroma.Web.FederatorTest do "type" => "Note", "content" => "hi world!", "id" => "http://mastodon.example.org/users/admin/objects/1", - "attributedTo" => "http://mastodon.example.org/users/admin", + "attributedTo" => "http://mastodon.example.org/users/admin" }, "to" => ["https://www.w3.org/ns/activitystreams#Public"] } @@ -91,7 +91,7 @@ defmodule Pleroma.Web.FederatorTest do "type" => "Note", "content" => "hi world!", "id" => "http://mastodon.example.org/users/admin/objects/1", - "attributedTo" => "http://mastodon.example.org/users/admin", + "attributedTo" => "http://mastodon.example.org/users/admin" }, "to" => ["https://www.w3.org/ns/activitystreams#Public"] } -- cgit v1.2.3 From 98795172a76db8d3331015461a021092c75cae5d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 22:10:15 +0000 Subject: ostatus controller: respond with AS2 objects instead of activities to notice URIs --- test/web/ostatus/ostatus_controller_test.exs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test') diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index c23b175e8..371c835c0 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -2,6 +2,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory alias Pleroma.{User, Repo} + alias Pleroma.Web.CommonAPI alias Pleroma.Web.OStatus.ActivityRepresenter test "decodes a salmon", %{conn: conn} do @@ -167,6 +168,32 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do assert json_response(conn, 200) end + test "only gets a notice in AS2 format for Create messages", %{conn: conn} do + note_activity = insert(:note_activity) + url = "/notice/#{note_activity.id}" + + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get(url) + + assert json_response(conn, 200) + + user = insert(:user) + + {:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user) + url = "/notice/#{like_activity.id}" + + assert like_activity.data["type"] == "Like" + + conn = + build_conn() + |> put_req_header("accept", "application/activity+json") + |> get(url) + + assert response(conn, 404) + end + test "gets an activity in AS2 format", %{conn: conn} do note_activity = insert(:note_activity) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"])) -- cgit v1.2.3 From f6be980f4faaef9408333fe59f0bb915dd087fd0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 17 Nov 2018 22:29:08 +0000 Subject: activitypub: object view: avoid leaking private details --- test/web/activity_pub/views/object_view_test.exs | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs index 7e08dff5d..d144a77fc 100644 --- a/test/web/activity_pub/views/object_view_test.exs +++ b/test/web/activity_pub/views/object_view_test.exs @@ -2,6 +2,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do use Pleroma.DataCase import Pleroma.Factory + alias Pleroma.Web.CommonAPI alias Pleroma.Web.ActivityPub.ObjectView test "renders a note object" do @@ -15,4 +16,43 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do assert result["type"] == "Note" assert result["@context"] end + + test "renders a note activity" do + note = insert(:note_activity) + + result = ObjectView.render("object.json", %{object: note}) + + assert result["id"] == note.data["id"] + assert result["to"] == note.data["to"] + assert result["object"]["type"] == "Note" + assert result["object"]["content"] == note.data["object"]["content"] + assert result["type"] == "Create" + assert result["@context"] + end + + test "renders a like activity" do + note = insert(:note_activity) + user = insert(:user) + + {:ok, like_activity, _} = CommonAPI.favorite(note.id, user) + + result = ObjectView.render("object.json", %{object: like_activity}) + + assert result["id"] == like_activity.data["id"] + assert result["object"] == note.data["object"]["id"] + assert result["type"] == "Like" + end + + test "renders an announce activity" do + note = insert(:note_activity) + user = insert(:user) + + {:ok, announce_activity, _} = CommonAPI.repeat(note.id, user) + + result = ObjectView.render("object.json", %{object: announce_activity}) + + assert result["id"] == announce_activity.data["id"] + assert result["object"] == note.data["object"]["id"] + assert result["type"] == "Announce" + end end -- cgit v1.2.3 From 689b46efc87dd128fd7c26f0eaf8c514b8295b30 Mon Sep 17 00:00:00 2001 From: eal Date: Mon, 19 Nov 2018 18:08:41 +0200 Subject: RetryQueue: tiny refractor, add tests --- test/web/retry_queue_test.exs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/web/retry_queue_test.exs (limited to 'test') diff --git a/test/web/retry_queue_test.exs b/test/web/retry_queue_test.exs new file mode 100644 index 000000000..ce2964993 --- /dev/null +++ b/test/web/retry_queue_test.exs @@ -0,0 +1,31 @@ +defmodule MockActivityPub do + def publish_one(ret) do + {ret, "success"} + end +end + +defmodule Pleroma.ActivityTest do + use Pleroma.DataCase + alias Pleroma.Web.Federator.RetryQueue + + @small_retry_count 0 + @hopeless_retry_count 10 + + test "failed posts are retried" do + {:retry, _timeout} = RetryQueue.get_retry_params(@small_retry_count) + + assert {:noreply, %{delivered: 1}} == + RetryQueue.handle_info({:send, :ok, MockActivityPub, @small_retry_count}, %{ + delivered: 0 + }) + end + + test "posts that have been tried too many times are dropped" do + {:drop, _timeout} = RetryQueue.get_retry_params(@hopeless_retry_count) + + assert {:noreply, %{dropped: 1}} == + RetryQueue.handle_cast({:maybe_enqueue, %{}, nil, @hopeless_retry_count}, %{ + dropped: 0 + }) + end +end -- cgit v1.2.3 From 7f4c3a1e993a3827b58f9cb8049a8ee5f54a1bdf Mon Sep 17 00:00:00 2001 From: href Date: Tue, 20 Nov 2018 17:46:54 +0100 Subject: mediaproxy: fix empty url & add some tests --- test/media_proxy_test.exs | 113 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 test/media_proxy_test.exs (limited to 'test') diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs new file mode 100644 index 000000000..c69ed7ea4 --- /dev/null +++ b/test/media_proxy_test.exs @@ -0,0 +1,113 @@ +defmodule Pleroma.MediaProxyTest do + use ExUnit.Case + import Pleroma.Web.MediaProxy + + describe "when enabled" do + setup do + enabled = Pleroma.Config.get([:media_proxy, :enabled]) + + unless enabled do + Pleroma.Config.put([:media_proxy, :enabled], true) + on_exit(fn -> Pleroma.Config.put([:media_proxy, :enabled], enabled) end) + end + + :ok + end + + test "ignores invalid url" do + assert url(nil) == nil + assert url("") == nil + end + + test "ignores relative url" do + assert url("/local") == "/local" + assert url("/") == "/" + end + + test "ignores local url" do + local_url = Pleroma.Web.Endpoint.url() <> "/hello" + local_root = Pleroma.Web.Endpoint.url() + assert url(local_url) == local_url + assert url(local_root) == local_root + end + + test "encodes and decodes URL" do + url = "https://pleroma.soykaf.com/static/logo.png" + encoded = url(url) + + assert String.starts_with?( + encoded, + Pleroma.Config.get([:media_proxy, :base_url], Pleroma.Web.base_url()) + ) + + assert String.ends_with?(encoded, "/logo.png") + + assert decode_result(encoded) == url + end + + test "encodes and decodes URL without a path" do + url = "https://pleroma.soykaf.com" + encoded = url(url) + assert decode_result(encoded) == url + end + + test "encodes and decodes URL without an extension" do + url = "https://pleroma.soykaf.com/path/" + encoded = url(url) + assert String.ends_with?(encoded, "/path") + assert decode_result(encoded) == url + end + + test "encodes and decodes URL and ignores query params for the path" do + url = "https://pleroma.soykaf.com/static/logo.png?93939393939&bunny=true" + encoded = url(url) + assert String.ends_with?(encoded, "/logo.png") + assert decode_result(encoded) == url + end + + test "validates signature" do + secret_key_base = Pleroma.Config.get([Pleroma.Web.Endpoint, :secret_key_base]) + + on_exit(fn -> + Pleroma.Config.put([Pleroma.Web.Endpoint, :secret_key_base], secret_key_base) + end) + + encoded = url("https://pleroma.social") + + Pleroma.Config.put( + [Pleroma.Web.Endpoint, :secret_key_base], + "00000000000000000000000000000000000000000000000" + ) + + [_, "proxy", sig, base64 | _] = URI.parse(encoded).path |> String.split("/") + assert decode_url(sig, base64) == {:error, :invalid_signature} + end + end + + describe "when disabled" do + setup do + enabled = Pleroma.Config.get([:media_proxy, :enabled]) + + if enabled do + Pleroma.Config.put([:media_proxy, :enabled], false) + + on_exit(fn -> + Pleroma.Config.put([:media_proxy, :enabled], enabled) + :ok + end) + end + + :ok + end + + test "does not encode remote urls" do + assert url("https://google.fr") == "https://google.fr" + end + end + + defp decode_result(encoded) do + [_, "proxy", sig, base64 | _] = URI.parse(encoded).path |> String.split("/") + {:ok, decoded} = decode_url(sig, base64) + decoded + end +end -- cgit v1.2.3 From cc8952b45fc9c8d77f1d7c83674d4194b032c5fd Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 24 Nov 2018 08:47:35 +0100 Subject: Web.MastodonApi.MastodonSocketTest: Add test for unauthenticated websocket --- test/web/mastodon_api/mastodon_socket_test.exs | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/web/mastodon_api/mastodon_socket_test.exs (limited to 'test') diff --git a/test/web/mastodon_api/mastodon_socket_test.exs b/test/web/mastodon_api/mastodon_socket_test.exs new file mode 100644 index 000000000..c7d71defc --- /dev/null +++ b/test/web/mastodon_api/mastodon_socket_test.exs @@ -0,0 +1,33 @@ +defmodule Pleroma.Web.MastodonApi.MastodonSocketTest do + use Pleroma.DataCase + + alias Pleroma.Web.MastodonApi.MastodonSocket + alias Pleroma.Web.{Streamer, CommonAPI} + alias Pleroma.User + + import Pleroma.Factory + + test "public is working when non-authenticated" do + user = insert(:user) + + task = + Task.async(fn -> + assert_receive {:text, _}, 4_000 + end) + + fake_socket = %{ + transport_pid: task.pid, + assigns: %{} + } + + topics = %{ + "public" => [fake_socket] + } + + {:ok, activity} = CommonAPI.post(user, %{"status" => "Test"}) + + Streamer.push_to_socket(topics, "public", activity) + + Task.await(task) + end +end -- cgit v1.2.3 From 87098d1676b4521f83804c19a94d34f0cd8a8109 Mon Sep 17 00:00:00 2001 From: KokaKiwi Date: Tue, 27 Nov 2018 01:14:43 +0100 Subject: Streamer: Don't send unwanted DMs to list streams --- test/web/streamer_test.exs | 109 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs index 47d491d1b..df58441f0 100644 --- a/test/web/streamer_test.exs +++ b/test/web/streamer_test.exs @@ -2,7 +2,7 @@ defmodule Pleroma.Web.StreamerTest do use Pleroma.DataCase alias Pleroma.Web.Streamer - alias Pleroma.User + alias Pleroma.{List, User} alias Pleroma.Web.CommonAPI import Pleroma.Factory @@ -60,4 +60,111 @@ defmodule Pleroma.Web.StreamerTest do Task.await(task) end + + test "it doesn't send unwanted DMs to list" do + user_a = insert(:user) + user_b = insert(:user) + user_c = insert(:user) + + {:ok, user_a} = User.follow(user_a, user_b) + + {:ok, list} = List.create("Test", user_a) + {:ok, list} = List.follow(list, user_b) + + task = + Task.async(fn -> + refute_receive {:text, _}, 1_000 + end) + + fake_socket = %{ + transport_pid: task.pid, + assigns: %{ + user: user_a + } + } + + {:ok, activity} = + CommonAPI.post(user_b, %{ + "status" => "@#{user_c.nickname} Test", + "visibility" => "direct" + }) + + topics = %{ + "list:#{list.id}" => [fake_socket] + } + + Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics) + + Task.await(task) + end + + test "it doesn't send unwanted private posts to list" do + user_a = insert(:user) + user_b = insert(:user) + + {:ok, list} = List.create("Test", user_a) + {:ok, list} = List.follow(list, user_b) + + task = + Task.async(fn -> + refute_receive {:text, _}, 1_000 + end) + + fake_socket = %{ + transport_pid: task.pid, + assigns: %{ + user: user_a + } + } + + {:ok, activity} = + CommonAPI.post(user_b, %{ + "status" => "Test", + "visibility" => "private" + }) + + topics = %{ + "list:#{list.id}" => [fake_socket] + } + + Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics) + + Task.await(task) + end + + test "it send wanted private posts to list" do + user_a = insert(:user) + user_b = insert(:user) + + {:ok, user_a} = User.follow(user_a, user_b) + + {:ok, list} = List.create("Test", user_a) + {:ok, list} = List.follow(list, user_b) + + task = + Task.async(fn -> + assert_receive {:text, _}, 1_000 + end) + + fake_socket = %{ + transport_pid: task.pid, + assigns: %{ + user: user_a + } + } + + {:ok, activity} = + CommonAPI.post(user_b, %{ + "status" => "Test", + "visibility" => "private" + }) + + topics = %{ + "list:#{list.id}" => [fake_socket] + } + + Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics) + + Task.await(task) + end end -- cgit v1.2.3