aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json1
-rw-r--r--test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json1
-rw-r--r--test/fixtures/mastodon-post-activity-contentmap.json67
-rw-r--r--test/fixtures/mastodon-reject-activity.json34
-rw-r--r--test/fixtures/test.txt1
-rw-r--r--test/formatter_test.exs4
-rw-r--r--test/list_test.exs16
-rw-r--r--test/support/factory.ex38
-rw-r--r--test/support/httpoison_mock.ex22
-rw-r--r--test/upload_test.exs74
-rw-r--r--test/user_test.exs76
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs12
-rw-r--r--test/web/activity_pub/activity_pub_test.exs13
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs227
-rw-r--r--test/web/activity_pub/views/user_view_test.exs2
-rw-r--r--test/web/mastodon_api/account_view_test.exs24
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs182
-rw-r--r--test/web/mastodon_api/status_view_test.exs7
-rw-r--r--test/web/oauth/oauth_controller_test.exs113
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs101
-rw-r--r--test/web/twitter_api/representers/activity_representer_test.exs5
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs180
-rw-r--r--test/web/twitter_api/twitter_api_test.exs79
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs3
-rw-r--r--test/web/twitter_api/views/user_view_test.exs48
25 files changed, 1285 insertions, 45 deletions
diff --git a/test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json b/test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json
new file mode 100644
index 000000000..3f3f0f4fb
--- /dev/null
+++ b/test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"Emoji":"toot:Emoji","Hashtag":"as:Hashtag","atomUri":"ostatus:atomUri","conversation":"ostatus:conversation","featured":"toot:featured","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"inReplyToAtomUri":"ostatus:inReplyToAtomUri","manuallyApprovesFollowers":"as:manuallyApprovesFollowers","movedTo":"as:movedTo","ostatus":"http://ostatus.org#","sensitive":"as:sensitive","toot":"http://joinmastodon.org/ns#"}],"attributedTo":["https://baptiste.gelez.xyz/@/BaptisteGelez"],"cc":[],"content":"<p>It has been one month since the last \"This Month in Plume\" article, so it is time for another edition of our monthly changelog!</p>\n<h2>Bug Fixes and Security</h2>\n<p>Let's start with the hidden, but still (very) important changes: bug fixes and security patches.</p>\n<p>First of all, <a href=\"/@/Trinity%20/\" title=\"Trinity \" rel=\"noopener noreferrer\">@Trinity </a> protected us against two major security flaws, called <em>XSS</em> and <em>CSRF</em>. The first one allows the attacker to run malicious code if you visit a Plume page where some of their personal data is present. The second one lets them post data with your Plume account by visiting one of their own website. It is two very common attack, and it is great we are now protected against them!</p>\n<p>The other big change in this area, is that we are now validating the data you are sending before doing anything with it. It means that, for instance, you will no longer be able to register with an empty username and to break everything.</p>\n<p>On the federation side, many issues were reported by <a href=\"/@/kaniini%20/\" title=\"kaniini \" rel=\"noopener noreferrer\">@kaniini </a> and <em>redmatrix</em> (respectively contributing to Pleroma and Hubzilla). By fixing some of them, we made it possible to <a href=\"https://baptiste.gelez.xyz/%7E/KaniiniTestBlog/current-status-of-plume-and-pleroma-federation/\" rel=\"noopener noreferrer\">federate Plume articles to Pleroma</a>!</p>\n<p><a href=\"/@/Trinity%20/\" title=\"Trinity \" rel=\"noopener noreferrer\">@Trinity </a> hopefully noticed that there was a bug in our password check code: we were not checking that your password was correct, but only that the verification process went without errors. Concretely, it means that you could login to any account with any password. I wrote this part of the code when I was still the only contributor to the project, so nobody could review my work. We will now be trying to check every change, especially when it deals with critical parts of Plume, to avoid similar issues in the future, and we I'm really sorry this happened (even if I think nobody exploited it).</p>\n<p><em>Zanfib</em> and <em>stephenburgess8</em> also commited some small bugfixes, improving the general experience.</p>\n<h2>New Features</h2>\n<p>Let's now talk about the features that we introduced during this month.</p>\n<p>One of the most easy to spot is the redesign of Plume, made by <a href=\"/@/Madeorsk.%20/\" title=\"Madeorsk. \" rel=\"noopener noreferrer\">@Madeorsk. </a> I personaly love what he did, it really improved the readability and gave Plume a bit more of identity than the previous design. And he is <a href=\"https://github.com/Plume-org/Plume/pull/104\" rel=\"noopener noreferrer\">still improving it</a>.</p>\n<p>We also enabled Mardown in comment, to let you write more structured and nicely formatted responses.</p>\n<p>As you may have noticed, I have used mentions in this post. Indeed, it is now possible to mention someone in your articles or in comments. It works exactly the same way as in other apps, and you should receive a notification if someone mentionned you.</p>\n<p>A dashboard to manage your blogs has also been introduced. In the future it may be used to manage your drafts, and eventually to show some statistics. The goal is to have a more specific homepage for authors.</p>\n<p>The federation with other ActivityPub softwares, like Mastodon or Pleroma is starting to work quite well, but the federation between Plume instances is far from being complete. However, we started to work on it, and it is now possible to view a distant user profile or blog from your instance, even if only basic informations are fetched yet (the articles are not loaded for instance).</p>\n<p>Another new feature that may not be visible for everyone, is the new NodeInfo endpoint. NodeInfo is a protocol allowing to get informations about a specific federated instance (whatever software it runs). It means that Plume instances can now be listed on sites like <a href=\"https://fediverse.network/plume\" rel=\"noopener noreferrer\">fediverse.network</a>.</p>\n<p>Maybe you wanted to host a Plume instance, but you don't like long install process during which you are just copy/pasting commands that you don't really understand from the documentation. That's why we introduced a setup script: the first you'll launch Plume, it will ask you a few questions and automatically setup your instance in a few minutes. We hope that this feature will help to host small instances, run by non-professional adminsys. You can see a demo of this tool on <a href=\"https://asciinema.org/a/tHktBK5iOd0zTulxmBX7LYQDc?t=32\" rel=\"noopener noreferrer\">asciinema</a>.</p>\n<p>Last but not least, Plume is now translatable! It is already available in English, French, Polish (thanks to <a href=\"/@/m4sk1n)/\" title=\"m4sk1n)\" rel=\"noopener noreferrer\">@m4sk1n)</a>) and German (thanks to <em>bitkeks</em>). If your browser is configured to display pages in these languages, you should normally see the interface in your language. And if your language is not present yet, feel free to <a href=\"https://github.com/Plume-org/Plume/blob/master/INTERNATIONALIZATION.md\" rel=\"noopener noreferrer\">add your translation</a>.</p>\n<h2>Other Changes</h2>\n<p>We also improved the code a lot. We tried to separate each part as much as possible, making it easier to re-use for other projects. For instance, our database code is now isolated from the rest of the app, which means it will be easier to make import tools from other blogging engines. Some parts of the code are even shared with another project, <a href=\"https://github.com/Aardwolf-Social/aardwolf\" rel=\"noopener noreferrer\">Aardwolf</a> a federated Facebook alternative. For instance, both of our projects use the same internationalization code, and once Aardwolf will implement federation, this part of the code will probably be shared too. Since the WebFinger module (used to find new users and blogs) and the CSRF protection code (see the \"Bug fixes and Security\" section) have been isolated in their own modules, they may be shared by both projects too.</p>\n<p>We also worked a lot on documentation. We now have articles explaining how to setup your Plume instance on various operating systems, but also documenting the translation process. I want to thank <em>BanjoFox</em> (who imported some documentation from their project, Aardwolf, as the setup is quite similar), <em>Kushal</em> and <a href=\"/@/gled@plume.mastodon.host%20/\" title=\"gled@plume.mastodon.host \" rel=\"noopener noreferrer\">@gled@plume.mastodon.host </a> for working on this.</p>\n<p>As you can see, there were many changes this month, but there still a lot to do. Your help will of course be welcome. If you want to contribute to the code, translate Plume in your language, write some documentation, or anything else (or even if you're just curious about the project), feel free to join our Matrix room: <a href=\"https://riot.im/app/#/room/#plume:disroot.org\" rel=\"noopener noreferrer\">#plume:disroot.org</a>. Otherwise, as <em>BanjoFox</em> <a href=\"https://glitch.social/@aardwolf/100329435838406278\" rel=\"noopener noreferrer\">said on the <em>Aardwolf Team</em> Mastodon account</a>, talking about the project around you is one of the easiest way to help.</p>\n","id":"https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/","likes":null,"name":"This Month in Plume: June 2018","published":"2018-07-10T20:16:24.087622Z","shares":null,"source":null,"tag":[{"href":"https://baptiste.gelez.xyz/@/Trinity","name":"@Trinity","type":"Mention"},{"href":"https://baptiste.gelez.xyz/@/kaniini/","name":"@kaniini","type":"Mention"},{"href":"https://baptiste.gelez.xyz/@/Trinity","name":"@Trinity","type":"Mention"}],"to":["https://unixcorn.xyz/users/Bat","https://mastodon.host/users/federationbot","https://social.tcit.fr/users/tcit","https://framapiaf.org/users/qwerty","https://mastodon.social/users/lthms","https://eldritch.cafe/users/Nausicaa","https://imaginair.es/users/Elanndelh","https://framapiaf.org/users/Drulac","https://mastodon.partipirate.org/users/NicolasConstant","https://aleph.land/users/Madeorsk","https://maly.io/users/Troll","https://hostux.social/users/superjey","https://mamot.fr/users/Phigger","https://mastodon.social/users/wakest","https://social.coop/users/wakest","https://unixcorn.xyz/users/Ce_lo","https://social.art-software.fr/users/Electron","https://framapiaf.org/users/Quenti","https://toot.plus.yt/users/Djyp","https://mastodon.social/users/brainblasted","https://social.mochi.academy/users/Ambraven","https://social.hacktivis.me/users/lanodan","https://mastodon.eliotberriot.com/users/eliotberriot","https://edolas.world/users/0x1C3B00DA","https://toot.cafe/users/zack","https://manowar.social/users/zatnosk","https://eldritch.cafe/users/fluffy","https://mastodon.social/users/david_ross","https://kosmos.social/users/xiroux","https://mastodon.art/users/EmergencyBattle","https://mastodon.social/users/trwnh","https://octodon.social/users/pybyte","https://anticapitalist.party/users/Trinity","https://mstdn.mx/users/xavavu","https://baptiste.gelez.xyz/@/m4sk1n","https://eldritch.cafe/users/milia","https://mastodon.zaclys.com/users/arx","https://toot.cafe/users/sivy","https://mastodon.social/users/ortegacmanuel","https://mastodon.observer/users/stephen","https://octodon.social/users/chloe","https://unixcorn.xyz/users/AmauryPi","https://cybre.space/users/rick_777","https://mastodon.social/users/wezm","https://baptiste.gelez.xyz/@/idlesong","https://mamot.fr/users/dr4Ke","https://imaginair.es/users/Phigger","https://mamot.fr/users/dlink","https://anticapitalist.party/users/a000d4f7a91939d0e71df1646d7a48","https://framapiaf.org/users/PhieLaidMignon","https://mastodon.social/users/y6nH","https://crazynoisybizarre.town/users/FederationBot","https://social.weho.st/users/dvn","https://mastodon.art/users/Wolthera","https://diaspodon.fr/users/dada","https://pachyder.me/users/Lanza","https://mastodon.xyz/users/ag","https://aleph.land/users/yahananxie","https://mstdn.io/users/chablis_social","https://mastodon.gougere.fr/users/fabien","https://functional.cafe/users/otini","https://social.coop/users/bhaugen","https://octodon.social/users/donblanco","https://chaos.social/users/astro","https://pachyder.me/users/sibear","https://mamot.fr/users/yohann","https://social.wxcafe.net/users/Bat","https://mastodon.social/users/dansup","https://chaos.social/users/juh","https://scifi.fyi/users/paeneultima","https://hostux.social/users/Deuchnord","https://mstdn.fr/users/taziden","https://mamot.fr/users/PifyZ","https://mastodon.social/users/plantabaja","https://mastodon.social/users/gitzgrog","https://mastodon.social/users/Syluban","https://masto.pt/users/eloisa","https://pleroma.soykaf.com/users/notclacke","https://mastodon.social/users/SiegfriedEhret","https://writing.exchange/users/write_as","https://mstdn.io/users/shellkr","https://mastodon.uy/users/jorge","https://mastodon.technology/users/bobstechsite","https://mastodon.social/users/hinterwaeldler","https://mastodon.xyz/users/mgdelacroix","https://mastodon.cloud/users/jjatria","https://baptiste.gelez.xyz/@/Jade/","https://edolas.world/users/pfm","https://mstdn.io/users/jort","https://mastodon.social/users/andreipetcu","https://mastodon.technology/users/0xf00fc7c8","https://mastodon.social/users/khanate","https://mastodon.technology/users/francois","https://mastodon.social/users/glherrmann","https://mastodon.host/users/gled","https://social.holdmybeer.solutions/users/kemonine","https://scholar.social/users/bgcarlisle","https://mastodon.social/users/oldgun","https://baptiste.gelez.xyz/@/snoe/","https://mastodon.at/users/switchingsocial","https://scifi.fyi/users/BrokenBiscuit","https://dev.glitch.social/users/hoodie","https://todon.nl/users/paulfree14","https://mastodon.social/users/aadilayub","https://social.fsck.club/users/anarchosaurus","https://mastodonten.de/users/GiantG","https://mastodon.technology/users/cj","https://cybre.space/users/sam","https://layer8.space/users/silkevicious","https://mastodon.xyz/users/Jimmyrwx","https://fosstodon.org/users/danyspin97","https://mstdn.io/users/cristhyano","https://mastodon.social/users/vanyok","https://hulvr.com/users/rook","https://niu.moe/users/Lucifer","https://mamot.fr/users/Thibaut","https://mastodont.cat/users/bgta","https://mstdn.io/users/hontoni","https://niu.moe/users/lionirdeadman","https://functional.cafe/users/phoe","https://mastodon.social/users/toontoet","https://mastodon.social/users/danipozo","https://scholar.social/users/robertson","https://mastodon.social/users/aldatsa","https://elekk.xyz/users/maloki","https://kitty.town/users/nursemchurt","https://neigh.horse/users/commagray","https://mastodon.social/users/hirojin","https://mastodon.xyz/users/mareklach","https://chaos.social/users/benthor","https://mastodon.social/users/djperreault","https://mastodon.art/users/eylul","https://mastodon.opportunis.me/users/bob","https://tootplanet.space/users/Shutsumon","https://toot.cat/users/woozle","https://mastodon.social/users/StephenLB","https://sleeping.town/users/oct2pus","https://mastodon.indie.host/users/stragu","https://social.coop/users/gilscottfitzgerald","https://icosahedron.website/users/joeld","https://mastodon.social/users/hellion","https://cybre.space/users/cooler_ranch","https://mastodon.social/users/kelsonv","https://mastodon.lat/users/scalpol","https://writing.exchange/users/hnb","https://hex.bz/users/Horst","https://mastodon.social/users/weddle","https://maly.io/users/sonya","https://social.coop/users/medusa","https://mastodon.social/users/DystopianK","https://mstdn.io/users/d_io","https://fosstodon.org/users/brandon","https://fosstodon.org/users/Cando","https://mastodon.host/users/panina","https://floss.social/users/tuxether","https://social.tchncs.de/users/suitbertmonz","https://mastodon.social/users/jrt","https://mastodon.social/users/sirikon","https://mstdn.io/users/yabirgb","https://mastodon.cloud/users/FerdiZ","https://mastodon.social/users/carlchenet","https://social.polonkai.eu/users/calendar_social","https://social.polonkai.eu/users/gergely","https://mastodon.social/users/Jelv","https://mastodon.social/users/srinicame","https://cybre.space/users/mastoabed","https://mastodon.social/users/tagomago","https://lgbt.io/users/bootblackCub","https://niu.moe/users/Nopplyy","https://mastodon.social/users/bpugh","https://www.w3.org/ns/activitystreams#Public"],"type":"Article","uploadMedia":null,"url":"https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"} \ No newline at end of file
diff --git a/test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json b/test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json
new file mode 100644
index 000000000..b226204ba
--- /dev/null
+++ b/test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"Emoji":"toot:Emoji","Hashtag":"as:Hashtag","atomUri":"ostatus:atomUri","conversation":"ostatus:conversation","featured":"toot:featured","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"inReplyToAtomUri":"ostatus:inReplyToAtomUri","manuallyApprovesFollowers":"as:manuallyApprovesFollowers","movedTo":"as:movedTo","ostatus":"http://ostatus.org#","sensitive":"as:sensitive","toot":"http://joinmastodon.org/ns#"}],"endpoints":{"oauthAuthorizationEndpoint":null,"oauthTokenEndpoint":null,"provideClientKey":null,"proxyUrl":null,"sharedInbox":"https://baptiste.gelez.xyz/inbox/","signClientKey":null},"followers":null,"following":null,"id":"https://baptiste.gelez.xyz/@/BaptisteGelez","inbox":"https://baptiste.gelez.xyz/@/BaptisteGelez/inbox","liked":null,"likes":null,"name":"Baptiste Gelez","outbox":"https://baptiste.gelez.xyz/@/BaptisteGelez/outbox","preferredUsername":"BaptisteGelez","publicKey":{"id":"https://baptiste.gelez.xyz/@/BaptisteGelez#main-key","owner":"https://baptiste.gelez.xyz/@/BaptisteGelez","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA56vPlCAyxZDDy8hNiT1p\n0cdFKnUK/51LiP4nTAxGf5Eb8NmsB2ftDgiDWZfg3LiHkjNcfTDpmN0aZyRxnTg9\nZ4JiQagfynVEbMkcOQhO64OFZpB47GpLtxrb49IcUes/p4ngp/Wkp+arYZSpoSs6\n3I995mZp3ZJ78pNQf1/lV0VIdDe6SqvRj1GmBDXXcecxF0O7rN/WYNO7Jag4i/XA\nU1ToDAMeUFeijRioSNoD3CHkMIu7AN+gqAWzZ21H/ZUvmfxh3WqQi/MDNcUhhA+0\nXv7/dv4S20EGnHadtE7OrBC1IwiHEuRM41zZq0ze9cKpoXg3VK2fiSNrCHlYrA18\n2wIDAQAB\n-----END PUBLIC KEY-----\n"},"shares":null,"source":null,"streams":null,"summary":"Main Plume developer","type":"Person","uploadMedia":null,"url":"https://baptiste.gelez.xyz/@/BaptisteGelez"} \ No newline at end of file
diff --git a/test/fixtures/mastodon-post-activity-contentmap.json b/test/fixtures/mastodon-post-activity-contentmap.json
new file mode 100644
index 000000000..2e94380b6
--- /dev/null
+++ b/test/fixtures/mastodon-post-activity-contentmap.json
@@ -0,0 +1,67 @@
+{
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "Emoji": "toot:Emoji",
+ "Hashtag": "as:Hashtag",
+ "atomUri": "ostatus:atomUri",
+ "conversation": "ostatus:conversation",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "movedTo": "as:movedTo",
+ "ostatus": "http://ostatus.org#",
+ "sensitive": "as:sensitive",
+ "toot": "http://joinmastodon.org/ns#"
+ }
+ ],
+ "actor": "http://mastodon.example.org/users/admin",
+ "cc": [
+ "http://mastodon.example.org/users/admin/followers",
+ "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": [],
+ "attributedTo": "http://mastodon.example.org/users/admin",
+ "cc": [
+ "http://mastodon.example.org/users/admin/followers",
+ "http://localtesting.pleroma.lol/users/lain"
+ ],
+ "contentMap": {
+ "en": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
+ },
+ "conversation": "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation",
+ "id": "http://mastodon.example.org/users/admin/statuses/99512778738411822",
+ "inReplyTo": null,
+ "inReplyToAtomUri": null,
+ "published": "2018-02-12T14:08:20Z",
+ "sensitive": true,
+ "summary": "cw",
+ "tag": [
+ {
+ "href": "http://localtesting.pleroma.lol/users/lain",
+ "name": "@lain@localtesting.pleroma.lol",
+ "type": "Mention"
+ }
+ ],
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Note",
+ "url": "http://mastodon.example.org/@admin/99512778738411822"
+ },
+ "published": "2018-02-12T14:08:20Z",
+ "signature": {
+ "created": "2018-02-12T14:08:20Z",
+ "creator": "http://mastodon.example.org/users/admin#main-key",
+ "signatureValue": "rnNfcopkc6+Ju73P806popcfwrK9wGYHaJVG1/ZvrlEbWVDzaHjkXqj9Q3/xju5l8CSn9tvSgCCtPFqZsFQwn/pFIFUcw7ZWB2xi4bDm3NZ3S4XQ8JRaaX7og5hFxAhWkGhJhAkfxVnOg2hG+w2d/7d7vRVSC1vo5ip4erUaA/PkWusZvPIpxnRWoXaxJsFmVx0gJgjpJkYDyjaXUlp+jmaoseeZ4EPQUWqHLKJ59PRG0mg8j2xAjYH9nQaN14qMRmTGPxY8gfv/CUFcatA+8VJU9KEsJkDAwLVvglydNTLGrxpAJU78a2eaht0foV43XUIZGe3DKiJPgE+UOKGCJw==",
+ "type": "RsaSignature2017"
+ },
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "type": "Create"
+}
diff --git a/test/fixtures/mastodon-reject-activity.json b/test/fixtures/mastodon-reject-activity.json
new file mode 100644
index 000000000..9559d6c73
--- /dev/null
+++ b/test/fixtures/mastodon-reject-activity.json
@@ -0,0 +1,34 @@
+{
+ "type": "Reject",
+ "signature": {
+ "type": "RsaSignature2017",
+ "signatureValue": "rBzK4Kqhd4g7HDS8WE5oRbWQb2R+HF/6awbUuMWhgru/xCODT0SJWSri0qWqEO4fPcpoUyz2d25cw6o+iy9wiozQb3hQNnu69AR+H5Mytc06+g10KCHexbGhbAEAw/7IzmeXELHUbaqeduaDIbdt1zw4RkwLXdqgQcGXTJ6ND1wM3WMHXQCK1m0flasIXFoBxpliPAGiElV8s0+Ltuh562GvflG3kB3WO+j+NaR0ZfG5G9N88xMj9UQlCKit5gpAE5p6syUsCU2WGBHywTumv73i3OVTIFfq+P9AdMsRuzw1r7zoKEsthW4aOzLQDi01ZjvdBz8zH6JnjDU7SMN/Ig==",
+ "creator": "http://mastodon.example.org/users/admin#main-key",
+ "created": "2018-02-17T14:36:41Z"
+ },
+ "object": {
+ "type": "Follow",
+ "object": "http://mastodon.example.org/users/admin",
+ "id": "http://localtesting.pleroma.lol/users/lain#follows/4",
+ "actor": "http://localtesting.pleroma.lol/users/lain"
+ },
+ "nickname": "lain",
+ "id": "http://mastodon.example.org/users/admin#rejects/follows/4",
+ "actor": "http://mastodon.example.org/users/admin",
+ "@context": [
+ "https://www.w3.org/ns/activitystreams",
+ "https://w3id.org/security/v1",
+ {
+ "toot": "http://joinmastodon.org/ns#",
+ "sensitive": "as:sensitive",
+ "ostatus": "http://ostatus.org#",
+ "movedTo": "as:movedTo",
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "atomUri": "ostatus:atomUri",
+ "Hashtag": "as:Hashtag",
+ "Emoji": "toot:Emoji"
+ }
+ ]
+}
diff --git a/test/fixtures/test.txt b/test/fixtures/test.txt
new file mode 100644
index 000000000..e9ea42a12
--- /dev/null
+++ b/test/fixtures/test.txt
@@ -0,0 +1 @@
+this is a text file
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index e89b36663..c2b3d4ac0 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -109,9 +109,9 @@ defmodule Pleroma.FormatterTest do
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text =
- "<span><a href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a href='#{
+ "<span><a class='mention' href='#{gsimg.ap_id}'>@<span>gsimg</span></a></span> According to <span><a class='mention' href='#{
"https://archeme/@archaeme"
- }'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a href='#{
+ }'>@<span>archaeme</span></a></span>, that is @daggsy. Also hello <span><a class='mention' href='#{
archaeme_remote.ap_id
}'>@<span>archaeme</span></a></span>"
diff --git a/test/list_test.exs b/test/list_test.exs
index ced012093..da3b88024 100644
--- a/test/list_test.exs
+++ b/test/list_test.exs
@@ -74,4 +74,20 @@ defmodule Pleroma.ListTest do
assert list_two in lists
refute list_three in lists
end
+
+ test "getting all lists the user is a member of" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, list_one} = Pleroma.List.create("title", user)
+ {:ok, list_two} = Pleroma.List.create("other title", user)
+ {:ok, list_three} = Pleroma.List.create("third title", other_user)
+ {:ok, list_one} = Pleroma.List.follow(list_one, other_user)
+ {:ok, list_two} = Pleroma.List.follow(list_two, other_user)
+ {:ok, list_three} = Pleroma.List.follow(list_three, user)
+
+ lists = Pleroma.List.get_lists_from_activity(%Pleroma.Activity{actor: other_user.ap_id})
+ assert list_one in lists
+ assert list_two in lists
+ refute list_three in lists
+ end
end
diff --git a/test/support/factory.ex b/test/support/factory.ex
index e9b4beb7d..4f5060abf 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -45,6 +45,33 @@ defmodule Pleroma.Factory do
}
end
+ def direct_note_factory do
+ user2 = insert(:user)
+
+ %Pleroma.Object{data: data} = note_factory()
+ %Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
+ end
+
+ def direct_note_activity_factory do
+ dm = insert(:direct_note)
+
+ data = %{
+ "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
+ "type" => "Create",
+ "actor" => dm.data["actor"],
+ "to" => dm.data["to"],
+ "object" => dm.data,
+ "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
+ "context" => dm.data["context"]
+ }
+
+ %Pleroma.Activity{
+ data: data,
+ actor: data["actor"],
+ recipients: data["to"]
+ }
+ end
+
def note_activity_factory do
note = insert(:note)
@@ -139,4 +166,15 @@ defmodule Pleroma.Factory do
subscribers: []
}
end
+
+ def oauth_app_factory do
+ %Pleroma.Web.OAuth.App{
+ client_name: "Some client",
+ redirect_uris: "https://example.com/callback",
+ scopes: "read",
+ website: "https://example.com",
+ client_id: "aaabbb==",
+ client_secret: "aaa;/&bbb"
+ }
+ end
end
diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex
index 6e8336a93..a52d44ed6 100644
--- a/test/support/httpoison_mock.ex
+++ b/test/support/httpoison_mock.ex
@@ -4,7 +4,7 @@ defmodule HTTPoisonMock do
def get(url, body \\ [], headers \\ [])
def get(
- "http://gerzilla.de/.well-known/webfinger?resource=acct:kaniini@gerzilla.de",
+ "https://gerzilla.de/.well-known/webfinger?resource=acct:kaniini@gerzilla.de",
[Accept: "application/xrd+xml,application/jrd+json"],
follow_redirect: true
) do
@@ -16,7 +16,7 @@ defmodule HTTPoisonMock do
end
def get(
- "http://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org",
+ "https://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org",
[Accept: "application/xrd+xml,application/jrd+json"],
follow_redirect: true
) do
@@ -28,7 +28,7 @@ defmodule HTTPoisonMock do
end
def get(
- "http://gnusocial.de/.well-known/webfinger?resource=acct:winterdienst@gnusocial.de",
+ "https://gnusocial.de/.well-known/webfinger?resource=acct:winterdienst@gnusocial.de",
[Accept: "application/xrd+xml,application/jrd+json"],
follow_redirect: true
) do
@@ -736,6 +736,22 @@ defmodule HTTPoisonMock do
}}
end
+ def get("https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/", _, _) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-article.json")
+ }}
+ end
+
+ def get("https://baptiste.gelez.xyz/@/BaptisteGelez", _, _) do
+ {:ok,
+ %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/baptiste.gelex.xyz-user.json")
+ }}
+ end
+
def get(url, body, headers) do
{:error,
"Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{
diff --git a/test/upload_test.exs b/test/upload_test.exs
index d68b3e7ba..d273ea5f6 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -3,40 +3,84 @@ defmodule Pleroma.UploadTest do
use Pleroma.DataCase
describe "Storing a file" do
- test "copies the file to the configured folder" do
+ test "copies the file to the configured folder with deduping" do
+ File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
+
file = %Plug.Upload{
content_type: "image/jpg",
- path: Path.absname("test/fixtures/image.jpg"),
+ path: Path.absname("test/fixtures/image_tmp.jpg"),
filename: "an [image.jpg"
}
- data = Upload.store(file)
- assert data["name"] == "an [image.jpg"
+ data = Upload.store(file, true)
- assert List.first(data["url"])["href"] ==
- "http://localhost:4001/media/#{data["uuid"]}/an%20%5Bimage.jpg"
+ assert data["name"] ==
+ "e7a6d0cf595bff76f14c9a98b6c199539559e8b844e02e51e5efcfd1f614a2df.jpeg"
end
- test "fixes an incorrect content type" do
+ test "copies the file to the configured folder without deduping" do
+ File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image_tmp.jpg"),
+ filename: "an [image.jpg"
+ }
+
+ data = Upload.store(file, false)
+ assert data["name"] == "an [image.jpg"
+ end
+
+ test "fixes incorrect content type" do
+ File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
+
file = %Plug.Upload{
content_type: "application/octet-stream",
- path: Path.absname("test/fixtures/image.jpg"),
+ path: Path.absname("test/fixtures/image_tmp.jpg"),
filename: "an [image.jpg"
}
- data = Upload.store(file)
+ data = Upload.store(file, true)
assert hd(data["url"])["mediaType"] == "image/jpeg"
end
- test "does not modify a valid content type" do
+ test "adds missing extension" do
+ File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
+
file = %Plug.Upload{
- content_type: "image/png",
- path: Path.absname("test/fixtures/image.jpg"),
- filename: "an [image.jpg"
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image_tmp.jpg"),
+ filename: "an [image"
+ }
+
+ data = Upload.store(file, false)
+ assert data["name"] == "an [image.jpg"
+ end
+
+ test "fixes incorrect file extension" do
+ File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image_tmp.jpg"),
+ filename: "an [image.blah"
+ }
+
+ data = Upload.store(file, false)
+ assert data["name"] == "an [image.jpg"
+ end
+
+ test "don't modify filename of an unknown type" do
+ File.cp("test/fixtures/test.txt", "test/fixtures/test_tmp.txt")
+
+ file = %Plug.Upload{
+ content_type: "text/plain",
+ path: Path.absname("test/fixtures/test_tmp.txt"),
+ filename: "test.txt"
}
- data = Upload.store(file)
- assert hd(data["url"])["mediaType"] == "image/png"
+ data = Upload.store(file, false)
+ assert data["name"] == "test.txt"
end
end
end
diff --git a/test/user_test.exs b/test/user_test.exs
index 8c8cfd673..352a16687 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -359,6 +359,82 @@ defmodule Pleroma.UserTest do
refute User.blocks?(user, blocked_user)
end
+
+ test "blocks tear down cyclical follow relationships" do
+ blocker = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, blocker} = User.follow(blocker, blocked)
+ {:ok, blocked} = User.follow(blocked, blocker)
+
+ assert User.following?(blocker, blocked)
+ assert User.following?(blocked, blocker)
+
+ {:ok, blocker} = User.block(blocker, blocked)
+ blocked = Repo.get(User, blocked.id)
+
+ assert User.blocks?(blocker, blocked)
+
+ refute User.following?(blocker, blocked)
+ refute User.following?(blocked, blocker)
+ end
+
+ test "blocks tear down blocker->blocked follow relationships" do
+ blocker = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, blocker} = User.follow(blocker, blocked)
+
+ assert User.following?(blocker, blocked)
+ refute User.following?(blocked, blocker)
+
+ {:ok, blocker} = User.block(blocker, blocked)
+ blocked = Repo.get(User, blocked.id)
+
+ assert User.blocks?(blocker, blocked)
+
+ refute User.following?(blocker, blocked)
+ refute User.following?(blocked, blocker)
+ end
+
+ test "blocks tear down blocked->blocker follow relationships" do
+ blocker = insert(:user)
+ blocked = insert(:user)
+
+ {:ok, blocked} = User.follow(blocked, blocker)
+
+ refute User.following?(blocker, blocked)
+ assert User.following?(blocked, blocker)
+
+ {:ok, blocker} = User.block(blocker, blocked)
+ blocked = Repo.get(User, blocked.id)
+
+ assert User.blocks?(blocker, blocked)
+
+ refute User.following?(blocker, blocked)
+ refute User.following?(blocked, blocker)
+ end
+ end
+
+ describe "domain blocking" do
+ test "blocks domains" do
+ user = insert(:user)
+ collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
+
+ {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
+
+ assert User.blocks?(user, collateral_user)
+ end
+
+ test "unblocks domains" do
+ user = insert(:user)
+ collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
+
+ {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
+ {:ok, user} = User.unblock_domain(user, "awful-and-rude-instance.com")
+
+ refute User.blocks?(user, collateral_user)
+ end
end
test "get recipients from activity" do
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 8a1c0d361..3ed7be402 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -32,6 +32,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert json_response(conn, 200) == ObjectView.render("object.json", %{object: note})
end
+
+ test "it returns 404 for non-public messages", %{conn: conn} do
+ note = insert(:direct_note)
+ uuid = String.split(note.data["id"], "/") |> List.last()
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}")
+
+ assert json_response(conn, 404)
+ end
end
describe "/users/:nickname/inbox" do
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 081c202b1..90c0bd768 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -318,11 +318,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, announce_activity, object} = ActivityPub.announce(user, object)
assert object.data["announcement_count"] == 1
- {:ok, unannounce_activity, activity, object} = ActivityPub.unannounce(user, object)
+ {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object)
assert object.data["announcement_count"] == 0
- assert activity == announce_activity
-
assert unannounce_activity.data["to"] == [
User.ap_followers(user),
announce_activity.data["actor"]
@@ -478,6 +476,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
+ test "it can fetch plume articles" do
+ {:ok, object} =
+ ActivityPub.fetch_object_from_id(
+ "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
+ )
+
+ assert object
+ end
+
describe "update" do
test "it creates an update activity with the new user data" do
user = insert(:user)
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index cf6b1d0b5..838ae169d 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -2,13 +2,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
use Pleroma.DataCase
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus
alias Pleroma.Activity
alias Pleroma.User
alias Pleroma.Repo
alias Pleroma.Web.Websub.WebsubClientSubscription
- alias Pleroma.Web.Websub.WebsubServerSubscription
- import Ecto.Query
import Pleroma.Factory
alias Pleroma.Web.CommonAPI
@@ -103,6 +102,16 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert Enum.at(data["object"]["tag"], 2) == "moo"
end
+ test "it works for incoming notices with contentMap" do
+ data =
+ File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["object"]["content"] ==
+ "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
+ end
+
test "it works for incoming follow requests" do
user = insert(:user)
@@ -267,6 +276,29 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.bio == "<p>Some bio</p>"
end
+ test "it works for incoming update activities which lock the account" do
+ data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
+
+ object =
+ update_data["object"]
+ |> Map.put("actor", data["actor"])
+ |> Map.put("id", data["actor"])
+ |> Map.put("manuallyApprovesFollowers", true)
+
+ update_data =
+ update_data
+ |> Map.put("actor", data["actor"])
+ |> Map.put("object", object)
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
+
+ user = User.get_cached_by_ap_id(data["actor"])
+ assert user.info["locked"] == true
+ end
+
test "it works for incoming deletes" do
activity = insert(:note_activity)
@@ -283,7 +315,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|> Map.put("object", object)
|> Map.put("actor", activity.data["actor"])
- {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
refute Repo.get(Activity, activity.id)
end
@@ -360,6 +392,37 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert User.blocks?(blocker, user)
end
+ test "incoming blocks successfully tear down any follow relationship" do
+ blocker = insert(:user)
+ blocked = insert(:user)
+
+ data =
+ File.read!("test/fixtures/mastodon-block-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", blocked.ap_id)
+ |> Map.put("actor", blocker.ap_id)
+
+ {:ok, blocker} = User.follow(blocker, blocked)
+ {:ok, blocked} = User.follow(blocked, blocker)
+
+ assert User.following?(blocker, blocked)
+ assert User.following?(blocked, blocker)
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["type"] == "Block"
+ assert data["object"] == blocked.ap_id
+ assert data["actor"] == blocker.ap_id
+
+ blocker = User.get_by_ap_id(data["actor"])
+ blocked = User.get_by_ap_id(data["object"])
+
+ assert User.blocks?(blocker, blocked)
+
+ refute User.following?(blocker, blocked)
+ refute User.following?(blocked, blocker)
+ end
+
test "it works for incoming unblocks with an existing block" do
user = insert(:user)
@@ -385,6 +448,164 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
refute User.blocks?(blocker, user)
end
+
+ test "it works for incoming accepts which were pre-accepted" do
+ follower = insert(:user)
+ followed = insert(:user)
+
+ {:ok, follower} = User.follow(follower, followed)
+ assert User.following?(follower, followed) == true
+
+ {:ok, follow_activity} = ActivityPub.follow(follower, followed)
+
+ accept_data =
+ File.read!("test/fixtures/mastodon-accept-activity.json")
+ |> Poison.decode!()
+ |> Map.put("actor", followed.ap_id)
+
+ object =
+ accept_data["object"]
+ |> Map.put("actor", follower.ap_id)
+ |> Map.put("id", follow_activity.data["id"])
+
+ accept_data = Map.put(accept_data, "object", object)
+
+ {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
+ refute activity.local
+
+ assert activity.data["object"] == follow_activity.data["id"]
+
+ follower = Repo.get(User, follower.id)
+
+ assert User.following?(follower, followed) == true
+ end
+
+ test "it works for incoming accepts which were orphaned" do
+ follower = insert(:user)
+ followed = insert(:user, %{info: %{"locked" => true}})
+
+ {:ok, follow_activity} = ActivityPub.follow(follower, followed)
+
+ accept_data =
+ File.read!("test/fixtures/mastodon-accept-activity.json")
+ |> Poison.decode!()
+ |> Map.put("actor", followed.ap_id)
+
+ accept_data =
+ Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
+
+ {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
+ assert activity.data["object"] == follow_activity.data["id"]
+
+ follower = Repo.get(User, follower.id)
+
+ assert User.following?(follower, followed) == true
+ end
+
+ test "it works for incoming accepts which are referenced by IRI only" do
+ follower = insert(:user)
+ followed = insert(:user, %{info: %{"locked" => true}})
+
+ {:ok, follow_activity} = ActivityPub.follow(follower, followed)
+
+ accept_data =
+ File.read!("test/fixtures/mastodon-accept-activity.json")
+ |> Poison.decode!()
+ |> Map.put("actor", followed.ap_id)
+ |> Map.put("object", follow_activity.data["id"])
+
+ {:ok, activity} = Transmogrifier.handle_incoming(accept_data)
+ assert activity.data["object"] == follow_activity.data["id"]
+
+ follower = Repo.get(User, follower.id)
+
+ assert User.following?(follower, followed) == true
+ end
+
+ test "it fails for incoming accepts which cannot be correlated" do
+ follower = insert(:user)
+ followed = insert(:user, %{info: %{"locked" => true}})
+
+ accept_data =
+ File.read!("test/fixtures/mastodon-accept-activity.json")
+ |> Poison.decode!()
+ |> Map.put("actor", followed.ap_id)
+
+ accept_data =
+ Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
+
+ :error = Transmogrifier.handle_incoming(accept_data)
+
+ follower = Repo.get(User, follower.id)
+
+ refute User.following?(follower, followed) == true
+ end
+
+ test "it fails for incoming rejects which cannot be correlated" do
+ follower = insert(:user)
+ followed = insert(:user, %{info: %{"locked" => true}})
+
+ accept_data =
+ File.read!("test/fixtures/mastodon-reject-activity.json")
+ |> Poison.decode!()
+ |> Map.put("actor", followed.ap_id)
+
+ accept_data =
+ Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
+
+ :error = Transmogrifier.handle_incoming(accept_data)
+
+ follower = Repo.get(User, follower.id)
+
+ refute User.following?(follower, followed) == true
+ end
+
+ test "it works for incoming rejects which are orphaned" do
+ follower = insert(:user)
+ followed = insert(:user, %{info: %{"locked" => true}})
+
+ {:ok, follower} = User.follow(follower, followed)
+ {:ok, _follow_activity} = ActivityPub.follow(follower, followed)
+
+ assert User.following?(follower, followed) == true
+
+ reject_data =
+ File.read!("test/fixtures/mastodon-reject-activity.json")
+ |> Poison.decode!()
+ |> Map.put("actor", followed.ap_id)
+
+ reject_data =
+ Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
+
+ {:ok, activity} = Transmogrifier.handle_incoming(reject_data)
+ refute activity.local
+
+ follower = Repo.get(User, follower.id)
+
+ assert User.following?(follower, followed) == false
+ end
+
+ test "it works for incoming rejects which are referenced by IRI only" do
+ follower = insert(:user)
+ followed = insert(:user, %{info: %{"locked" => true}})
+
+ {:ok, follower} = User.follow(follower, followed)
+ {:ok, follow_activity} = ActivityPub.follow(follower, followed)
+
+ assert User.following?(follower, followed) == true
+
+ reject_data =
+ File.read!("test/fixtures/mastodon-reject-activity.json")
+ |> Poison.decode!()
+ |> Map.put("actor", followed.ap_id)
+ |> Map.put("object", follow_activity.data["id"])
+
+ {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
+
+ follower = Repo.get(User, follower.id)
+
+ assert User.following?(follower, followed) == false
+ end
end
describe "prepare outgoing" do
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 0c64e62c3..7fc870e96 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -13,6 +13,6 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert result["id"] == user.ap_id
assert result["preferredUsername"] == user.nickname
- assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN RSA PUBLIC KEY")
+ assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end
end
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index 597690bf7..8bf194e6b 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -5,10 +5,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
alias Pleroma.User
test "Represent a user account" do
+ source_data = %{
+ "tag" => [
+ %{
+ "type" => "Emoji",
+ "icon" => %{"url" => "/file.png"},
+ "name" => ":karjalanpiirakka:"
+ }
+ ]
+ }
+
user =
insert(:user, %{
- info: %{"note_count" => 5, "follower_count" => 3},
+ info: %{"note_count" => 5, "follower_count" => 3, "source_data" => source_data},
nickname: "shp@shitposter.club",
+ name: ":karjalanpiirakka: shp",
inserted_at: ~N[2017-08-15 15:47:06.597036]
})
@@ -28,6 +39,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
avatar_static: "http://localhost:4001/images/avi.png",
header: "http://localhost:4001/images/banner.png",
header_static: "http://localhost:4001/images/banner.png",
+ emojis: [
+ %{
+ "static_url" => "/file.png",
+ "url" => "/file.png",
+ "shortcode" => "karjalanpiirakka",
+ "visible_in_picker" => false
+ }
+ ],
+ fields: [],
source: %{
note: "",
privacy: "public",
@@ -60,7 +80,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
expected = %{
id: to_string(other_user.id),
- following: true,
+ following: false,
followed_by: false,
blocking: true,
muting: false,
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 0f091b986..9e33c1d04 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -4,6 +4,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.{Repo, User, Activity, Notification}
alias Pleroma.Web.{OStatus, CommonAPI}
+ alias Pleroma.Web.ActivityPub.ActivityPub
import Pleroma.Factory
import ExUnit.CaptureLog
@@ -124,6 +125,61 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert Repo.get(Activity, id)
end
+ test "posting a direct status", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ content = "direct cofe @#{user2.nickname}"
+
+ conn =
+ conn
+ |> assign(:user, user1)
+ |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
+
+ assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
+ assert activity = Repo.get(Activity, id)
+ assert activity.recipients == [user2.ap_id]
+ assert activity.data["to"] == [user2.ap_id]
+ assert activity.data["cc"] == []
+ end
+
+ test "direct timeline", %{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/v1/timelines/direct")
+
+ [status] = json_response(res_conn, 200)
+
+ assert %{"visibility" => "direct"} = status
+ assert status["url"] != direct.data["id"]
+
+ # Both should be visible here
+ res_conn =
+ conn
+ |> assign(:user, user_two)
+ |> get("api/v1/timelines/home")
+
+ [_s1, _s2] = json_response(res_conn, 200)
+ end
+
test "replying to a status", %{conn: conn} do
user = insert(:user)
@@ -298,7 +354,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "list timeline", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."})
+ {:ok, _activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."})
{:ok, activity_two} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
{:ok, list} = Pleroma.List.create("name", user)
{:ok, list} = Pleroma.List.follow(list, other_user)
@@ -450,6 +506,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert to_string(activity.id) == id
end
+
+ test "returns 500 for a wrong id", %{conn: conn} do
+ user = insert(:user)
+
+ resp =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/statuses/1/favourite")
+ |> json_response(500)
+
+ assert resp == "Something went wrong"
+ end
end
describe "unfavoriting" do
@@ -577,6 +645,73 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
end
+ describe "locked accounts" do
+ test "/api/v1/follow_requests works" do
+ user = insert(:user, %{info: %{"locked" => true}})
+ other_user = insert(:user)
+
+ {:ok, activity} = ActivityPub.follow(other_user, user)
+
+ user = Repo.get(User, user.id)
+ other_user = Repo.get(User, other_user.id)
+
+ assert User.following?(other_user, user) == false
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/v1/follow_requests")
+
+ assert [relationship] = json_response(conn, 200)
+ assert to_string(other_user.id) == relationship["id"]
+ end
+
+ test "/api/v1/follow_requests/:id/authorize works" do
+ user = insert(:user, %{info: %{"locked" => true}})
+ other_user = insert(:user)
+
+ {:ok, activity} = ActivityPub.follow(other_user, user)
+
+ user = Repo.get(User, user.id)
+ other_user = Repo.get(User, other_user.id)
+
+ assert User.following?(other_user, user) == false
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/follow_requests/#{other_user.id}/authorize")
+
+ assert relationship = json_response(conn, 200)
+ assert to_string(other_user.id) == relationship["id"]
+
+ user = Repo.get(User, user.id)
+ other_user = Repo.get(User, other_user.id)
+
+ assert User.following?(other_user, user) == true
+ end
+
+ test "/api/v1/follow_requests/:id/reject works" do
+ user = insert(:user, %{info: %{"locked" => true}})
+ other_user = insert(:user)
+
+ {:ok, activity} = ActivityPub.follow(other_user, user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/v1/follow_requests/#{other_user.id}/reject")
+
+ assert relationship = json_response(conn, 200)
+ assert to_string(other_user.id) == relationship["id"]
+
+ user = Repo.get(User, user.id)
+ other_user = Repo.get(User, other_user.id)
+
+ assert User.following?(other_user, user) == false
+ end
+ end
+
test "account fetching", %{conn: conn} do
user = insert(:user)
@@ -601,16 +736,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
filename: "an_image.jpg"
}
+ desc = "Description of the image"
+
user = insert(:user)
conn =
conn
|> assign(:user, user)
- |> post("/api/v1/media", %{"file" => file})
+ |> post("/api/v1/media", %{"file" => file, "description" => desc})
assert media = json_response(conn, 200)
assert media["type"] == "image"
+ assert media["description"] == desc
end
test "hashtag timeline", %{conn: conn} do
@@ -725,6 +863,46 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
end
+ test "blocking / unblocking a domain", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
+
+ assert %{} = json_response(conn, 200)
+ user = User.get_cached_by_ap_id(user.ap_id)
+ assert User.blocks?(user, other_user)
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
+
+ assert %{} = json_response(conn, 200)
+ user = User.get_cached_by_ap_id(user.ap_id)
+ refute User.blocks?(user, other_user)
+ end
+
+ test "getting a list of domain blocks" do
+ user = insert(:user)
+
+ {:ok, user} = User.block_domain(user, "bad.site")
+ {:ok, user} = User.block_domain(user, "even.worse.site")
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/domain_blocks")
+
+ domain_blocks = json_response(conn, 200)
+
+ assert "bad.site" in domain_blocks
+ assert "even.worse.site" in domain_blocks
+ end
+
test "unimplemented mute endpoints" do
user = insert(:user)
other_user = insert(:user)
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index d9a0a8a95..03c798bef 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -64,11 +64,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("status.json", %{activity: activity})
- assert status.in_reply_to_id == note.id
+ assert status.in_reply_to_id == to_string(note.id)
[status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
- assert status.in_reply_to_id == note.id
+ assert status.in_reply_to_id == to_string(note.id)
end
test "contains mentions" do
@@ -102,7 +102,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
url: "someurl",
remote_url: "someurl",
preview_url: "someurl",
- text_url: "someurl"
+ text_url: "someurl",
+ description: nil
}
assert expected == StatusView.render("attachment.json", %{attachment: object})
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
new file mode 100644
index 000000000..3a902f128
--- /dev/null
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -0,0 +1,113 @@
+defmodule Pleroma.Web.OAuth.OAuthControllerTest do
+ use Pleroma.Web.ConnCase
+ import Pleroma.Factory
+
+ alias Pleroma.Repo
+ alias Pleroma.Web.OAuth.{Authorization, Token}
+
+ test "redirects with oauth authorization" do
+ user = insert(:user)
+ app = insert(:oauth_app)
+
+ conn =
+ build_conn()
+ |> post("/oauth/authorize", %{
+ "authorization" => %{
+ "name" => user.nickname,
+ "password" => "test",
+ "client_id" => app.client_id,
+ "redirect_uri" => app.redirect_uris,
+ "state" => "statepassed"
+ }
+ })
+
+ target = redirected_to(conn)
+ assert target =~ app.redirect_uris
+
+ query = URI.parse(target).query |> URI.query_decoder() |> Map.new()
+
+ assert %{"state" => "statepassed", "code" => code} = query
+ assert Repo.get_by(Authorization, token: code)
+ end
+
+ test "issues a token for an all-body request" do
+ user = insert(:user)
+ app = insert(:oauth_app)
+
+ {:ok, auth} = Authorization.create_authorization(app, user)
+
+ conn =
+ build_conn()
+ |> post("/oauth/token", %{
+ "grant_type" => "authorization_code",
+ "code" => auth.token,
+ "redirect_uri" => app.redirect_uris,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret
+ })
+
+ assert %{"access_token" => token} = json_response(conn, 200)
+ assert Repo.get_by(Token, token: token)
+ end
+
+ test "issues a token for request with HTTP basic auth client credentials" do
+ user = insert(:user)
+ app = insert(:oauth_app)
+
+ {:ok, auth} = Authorization.create_authorization(app, user)
+
+ app_encoded =
+ (URI.encode_www_form(app.client_id) <> ":" <> URI.encode_www_form(app.client_secret))
+ |> Base.encode64()
+
+ conn =
+ build_conn()
+ |> put_req_header("authorization", "Basic " <> app_encoded)
+ |> post("/oauth/token", %{
+ "grant_type" => "authorization_code",
+ "code" => auth.token,
+ "redirect_uri" => app.redirect_uris
+ })
+
+ assert %{"access_token" => token} = json_response(conn, 200)
+ assert Repo.get_by(Token, token: token)
+ end
+
+ test "rejects token exchange with invalid client credentials" do
+ user = insert(:user)
+ app = insert(:oauth_app)
+
+ {:ok, auth} = Authorization.create_authorization(app, user)
+
+ conn =
+ build_conn()
+ |> put_req_header("authorization", "Basic JTIxOiVGMCU5RiVBNCVCNwo=")
+ |> post("/oauth/token", %{
+ "grant_type" => "authorization_code",
+ "code" => auth.token,
+ "redirect_uri" => app.redirect_uris
+ })
+
+ assert resp = json_response(conn, 400)
+ assert %{"error" => _} = resp
+ refute Map.has_key?(resp, "access_token")
+ end
+
+ test "rejects an invalid authorization code" do
+ app = insert(:oauth_app)
+
+ conn =
+ build_conn()
+ |> post("/oauth/token", %{
+ "grant_type" => "authorization_code",
+ "code" => "Imobviouslyinvalid",
+ "redirect_uri" => app.redirect_uris,
+ "client_id" => app.client_id,
+ "client_secret" => app.client_secret
+ })
+
+ assert resp = json_response(conn, 400)
+ assert %{"error" => _} = json_response(conn, 400)
+ refute Map.has_key?(resp, "access_token")
+ end
+end
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index ba8855093..c23b175e8 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -53,11 +53,21 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
conn =
conn
+ |> put_req_header("content-type", "application/atom+xml")
|> get("/users/#{user.nickname}/feed.atom")
assert response(conn, 200) =~ note_activity.data["object"]["content"]
end
+ test "returns 404 for a missing feed", %{conn: conn} do
+ conn =
+ conn
+ |> put_req_header("content-type", "application/atom+xml")
+ |> get("/users/nonexisting/feed.atom")
+
+ assert response(conn, 404)
+ end
+
test "gets an object", %{conn: conn} do
note_activity = insert(:note_activity)
user = User.get_by_ap_id(note_activity.data["actor"])
@@ -77,6 +87,29 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 200) == expected
end
+ test "404s on private objects", %{conn: conn} do
+ note_activity = insert(:direct_note_activity)
+ user = User.get_by_ap_id(note_activity.data["actor"])
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
+ url = "/objects/#{uuid}"
+
+ conn =
+ conn
+ |> get(url)
+
+ assert response(conn, 404)
+ end
+
+ test "404s on nonexisting objects", %{conn: conn} do
+ url = "/objects/123"
+
+ conn =
+ conn
+ |> get(url)
+
+ assert response(conn, 404)
+ end
+
test "gets an activity", %{conn: conn} do
note_activity = insert(:note_activity)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
@@ -89,6 +122,28 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 200)
end
+ test "404s on private activities", %{conn: conn} do
+ note_activity = insert(:direct_note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
+ url = "/activities/#{uuid}"
+
+ conn =
+ conn
+ |> get(url)
+
+ assert response(conn, 404)
+ end
+
+ test "404s on nonexistent activities", %{conn: conn} do
+ url = "/activities/123"
+
+ conn =
+ conn
+ |> get(url)
+
+ assert response(conn, 404)
+ end
+
test "gets a notice", %{conn: conn} do
note_activity = insert(:note_activity)
url = "/notice/#{note_activity.id}"
@@ -99,4 +154,50 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 200)
end
+
+ test "gets a notice in AS2 format", %{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)
+ 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"]))
+ url = "/activities/#{uuid}"
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get(url)
+
+ assert json_response(conn, 200)
+ end
+
+ test "404s a private notice", %{conn: conn} do
+ note_activity = insert(:direct_note_activity)
+ url = "/notice/#{note_activity.id}"
+
+ conn =
+ conn
+ |> get(url)
+
+ assert response(conn, 404)
+ end
+
+ test "404s a nonexisting notice", %{conn: conn} do
+ url = "/notice/123"
+
+ conn =
+ conn
+ |> get(url)
+
+ assert response(conn, 404)
+ end
end
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 16c6e7b0d..3f85e028b 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -126,7 +126,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
}
expected_html =
- "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
+ "<p>2hu</p>alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
mentioned_user.ap_id
}\">@shp</a>"
@@ -155,7 +155,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
"activity_type" => "post",
"possibly_sensitive" => true,
"uri" => activity.data["object"]["id"],
- "visibility" => "direct"
+ "visibility" => "direct",
+ "summary" => "2hu"
}
assert ActivityRepresenter.to_map(activity, %{
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index c2ea41aa3..3a035e298 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -260,7 +260,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "with credentials", %{conn: conn, user: current_user} do
other_user = insert(:user)
- {:ok, activity} =
+ {:ok, _activity} =
ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
conn =
@@ -491,6 +491,26 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "GET /api/qvitter/mutes.json" do
+ setup [:valid_user]
+
+ test "unimplemented mutes without valid credentials", %{conn: conn} do
+ conn = get(conn, "/api/qvitter/mutes.json")
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "unimplemented mutes with credentials", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> get("/api/qvitter/mutes.json")
+
+ current_user = Repo.get(User, current_user.id)
+
+ assert [] = json_response(conn, 200)
+ end
+ end
+
describe "POST /api/favorites/create/:id" do
setup [:valid_user]
@@ -510,6 +530,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200)
end
+
+ test "with credentials, invalid param", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/favorites/create/wrong.json")
+
+ assert json_response(conn, 400)
+ end
+
+ test "with credentials, invalid activity", %{conn: conn, user: current_user} do
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/favorites/create/1.json")
+
+ assert json_response(conn, 500)
+ end
end
describe "POST /api/favorites/destroy/:id" do
@@ -562,6 +600,40 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
end
end
+ describe "POST /api/statuses/unretweet/:id" do
+ setup [:valid_user]
+
+ test "without valid credentials", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ conn = post(conn, "/api/statuses/unretweet/#{note_activity.id}.json")
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials", %{conn: conn, user: current_user} do
+ note_activity = insert(:note_activity)
+
+ request_path = "/api/statuses/retweet/#{note_activity.id}.json"
+
+ _response =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post(request_path)
+
+ request_path = String.replace(request_path, "retweet", "unretweet")
+
+ response =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post(request_path)
+
+ activity = Repo.get(Activity, note_activity.id)
+ activity_user = Repo.get_by(User, ap_id: note_activity.data["actor"])
+
+ assert json_response(response, 200) ==
+ ActivityRepresenter.to_map(activity, %{user: activity_user, for: current_user})
+ end
+ end
+
describe "POST /api/account/register" do
test "it creates a new user", %{conn: conn} do
data = %{
@@ -668,6 +740,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
conn =
conn
+ |> assign(:user, user)
|> get("/api/statuses/friends", %{"user_id" => user.id})
assert MapSet.equal?(
@@ -689,6 +762,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
conn =
conn
+ |> assign(:user, user)
|> get("/api/statuses/friends", %{"screen_name" => user.nickname})
assert MapSet.equal?(
@@ -742,6 +816,38 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
end
+
+ test "it locks an account", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "locked" => "true"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info["locked"] == true
+
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
+ end
+
+ test "it unlocks an account", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> post("/api/account/update_profile.json", %{
+ "locked" => "false"
+ })
+
+ user = Repo.get!(User, user.id)
+ assert user.info["locked"] == false
+
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})
+ end
end
defp valid_user(_context) do
@@ -791,7 +897,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "Convert newlines to <br> in bio", %{conn: conn} do
user = insert(:user)
- conn =
+ _conn =
conn
|> assign(:user, user)
|> post("/api/account/update_profile.json", %{
@@ -902,6 +1008,76 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> post("/api/pleroma/delete_account", %{"password" => "test"})
assert json_response(conn, 200) == %{"status" => "success"}
+ # Wait a second for the started task to end
+ :timer.sleep(1000)
+ end
+ end
+
+ describe "GET /api/pleroma/friend_requests" do
+ test "it lists friend requests" do
+ user = insert(:user, %{info: %{"locked" => true}})
+ other_user = insert(:user)
+
+ {:ok, activity} = ActivityPub.follow(other_user, user)
+
+ user = Repo.get(User, user.id)
+ other_user = Repo.get(User, other_user.id)
+
+ assert User.following?(other_user, user) == false
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> get("/api/pleroma/friend_requests")
+
+ assert [relationship] = json_response(conn, 200)
+ assert other_user.id == relationship["id"]
+ end
+ end
+
+ describe "POST /api/pleroma/friendships/approve" do
+ test "it approves a friend request" do
+ user = insert(:user, %{info: %{"locked" => true}})
+ other_user = insert(:user)
+
+ {:ok, activity} = ActivityPub.follow(other_user, user)
+
+ user = Repo.get(User, user.id)
+ other_user = Repo.get(User, other_user.id)
+
+ assert User.following?(other_user, user) == false
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/pleroma/friendships/approve", %{"user_id" => to_string(other_user.id)})
+
+ assert relationship = json_response(conn, 200)
+ assert other_user.id == relationship["id"]
+ assert relationship["follows_you"] == true
+ end
+ end
+
+ describe "POST /api/pleroma/friendships/deny" do
+ test "it denies a friend request" do
+ user = insert(:user, %{info: %{"locked" => true}})
+ other_user = insert(:user)
+
+ {:ok, activity} = ActivityPub.follow(other_user, user)
+
+ user = Repo.get(User, user.id)
+ other_user = Repo.get(User, other_user.id)
+
+ assert User.following?(other_user, user) == false
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> post("/api/pleroma/friendships/deny", %{"user_id" => to_string(other_user.id)})
+
+ assert relationship = json_response(conn, 200)
+ assert other_user.id == relationship["id"]
+ assert relationship["follows_you"] == false
end
end
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 4716abb84..6486540f8 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -2,7 +2,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
- alias Pleroma.{Activity, User, Object, Repo}
+ alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.ActivityView
@@ -35,7 +35,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
expected_text =
- "Hello again, <span><a href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<br>This is on another :moominmamma: line. <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
+ "Hello again, <span><a class='mention' href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<br>This is on another :moominmamma: line. <a href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
assert get_in(activity.data, ["object", "content"]) == expected_text
assert get_in(activity.data, ["object", "type"]) == "Note"
@@ -228,6 +228,17 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert status == updated_activity
end
+ test "it unretweets an already retweeted status" do
+ user = insert(:user)
+ note_activity = insert(:note_activity)
+
+ {:ok, _status} = TwitterAPI.repeat(user, note_activity.id)
+ {:ok, status} = TwitterAPI.unrepeat(user, note_activity.id)
+ updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+
+ assert status == updated_activity
+ end
+
test "it registers a new user and returns the user." do
data = %{
"nickname" => "lain",
@@ -246,6 +257,70 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
UserView.render("show.json", %{user: fetched_user})
end
+ @moduletag skip: "needs 'registrations_open: false' in config"
+ test "it registers a new user via invite token and returns the user." do
+ {:ok, token} = UserInviteToken.create_token()
+
+ data = %{
+ "nickname" => "vinny",
+ "email" => "pasta@pizza.vs",
+ "fullname" => "Vinny Vinesauce",
+ "bio" => "streamer",
+ "password" => "hiptofbees",
+ "confirm" => "hiptofbees",
+ "token" => token.token
+ }
+
+ {:ok, user} = TwitterAPI.register_user(data)
+
+ fetched_user = Repo.get_by(User, nickname: "vinny")
+ token = Repo.get_by(UserInviteToken, token: token.token)
+
+ assert token.used == true
+
+ assert UserView.render("show.json", %{user: user}) ==
+ UserView.render("show.json", %{user: fetched_user})
+ end
+
+ @moduletag skip: "needs 'registrations_open: false' in config"
+ test "it returns an error if invalid token submitted" do
+ data = %{
+ "nickname" => "GrimReaper",
+ "email" => "death@reapers.afterlife",
+ "fullname" => "Reaper Grim",
+ "bio" => "Your time has come",
+ "password" => "scythe",
+ "confirm" => "scythe",
+ "token" => "DudeLetMeInImAFairy"
+ }
+
+ {:error, msg} = TwitterAPI.register_user(data)
+
+ assert msg == "Invalid token"
+ refute Repo.get_by(User, nickname: "GrimReaper")
+ end
+
+ @moduletag skip: "needs 'registrations_open: false' in config"
+ test "it returns an error if expired token submitted" do
+ {:ok, token} = UserInviteToken.create_token()
+ UserInviteToken.mark_as_used(token.token)
+
+ data = %{
+ "nickname" => "GrimReaper",
+ "email" => "death@reapers.afterlife",
+ "fullname" => "Reaper Grim",
+ "bio" => "Your time has come",
+ "password" => "scythe",
+ "confirm" => "scythe",
+ "token" => token.token
+ }
+
+ {:error, msg} = TwitterAPI.register_user(data)
+
+ assert msg == "Expired token"
+ refute Repo.get_by(User, nickname: "GrimReaper")
+ end
+
test "it returns the error on registration problems" do
data = %{
"nickname" => "lain",
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 5b2a7466b..a101e4ae8 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -48,7 +48,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user}),
- "visibility" => "direct"
+ "visibility" => "direct",
+ "summary" => nil
}
assert result == expected
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 9f8bf4cdc..fefb6bdcc 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -20,6 +20,30 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
assert represented["profile_image_url"] == image
end
+ test "A user with emoji in username", %{user: user} do
+ expected =
+ "<img height='32px' width='32px' alt='karjalanpiirakka' title='karjalanpiirakka' src='/file.png' /> man"
+
+ user = %{
+ user
+ | info: %{
+ "source_data" => %{
+ "tag" => [
+ %{
+ "type" => "Emoji",
+ "icon" => %{"url" => "/file.png"},
+ "name" => ":karjalanpiirakka:"
+ }
+ ]
+ }
+ }
+ }
+
+ user = %{user | name: ":karjalanpiirakka: man"}
+ represented = UserView.render("show.json", %{user: user})
+ assert represented["name_html"] == expected
+ end
+
test "A user" do
note_activity = insert(:note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
@@ -40,7 +64,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"id" => user.id,
"name" => user.name,
"screen_name" => user.nickname,
+ "name_html" => user.name,
"description" => HtmlSanitizeEx.strip_tags(user.bio),
+ "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"favourites_count" => 0,
"statuses_count" => 1,
@@ -59,7 +85,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"background_image" => nil,
- "is_local" => true
+ "is_local" => true,
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: user})
@@ -75,7 +103,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"id" => user.id,
"name" => user.name,
"screen_name" => user.nickname,
+ "name_html" => user.name,
"description" => HtmlSanitizeEx.strip_tags(user.bio),
+ "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"favourites_count" => 0,
"statuses_count" => 0,
@@ -94,7 +124,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"background_image" => nil,
- "is_local" => true
+ "is_local" => true,
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -111,7 +143,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"id" => follower.id,
"name" => follower.name,
"screen_name" => follower.nickname,
+ "name_html" => follower.name,
"description" => HtmlSanitizeEx.strip_tags(follower.bio),
+ "description_html" => HtmlSanitizeEx.strip_tags(follower.bio),
"created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
"favourites_count" => 0,
"statuses_count" => 0,
@@ -130,7 +164,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"statusnet_profile_url" => follower.ap_id,
"cover_photo" => banner,
"background_image" => nil,
- "is_local" => true
+ "is_local" => true,
+ "locked" => false,
+ "default_scope" => "public"
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -154,7 +190,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"id" => user.id,
"name" => user.name,
"screen_name" => user.nickname,
+ "name_html" => user.name,
"description" => HtmlSanitizeEx.strip_tags(user.bio),
+ "description_html" => HtmlSanitizeEx.strip_tags(user.bio),
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
"favourites_count" => 0,
"statuses_count" => 0,
@@ -173,7 +211,9 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"background_image" => nil,
- "is_local" => true
+ "is_local" => true,
+ "locked" => false,
+ "default_scope" => "public"
}
blocker = Repo.get(User, blocker.id)