summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/httpoison_mock/admin@mastdon.example.org.json1
-rw-r--r--test/fixtures/httpoison_mock/hellpie.json1
-rw-r--r--test/fixtures/httpoison_mock/rye.json1
-rw-r--r--test/fixtures/mastodon-accept-activity.json34
-rw-r--r--test/fixtures/mastodon-announce.json37
-rw-r--r--test/fixtures/mastodon-create-with-attachment.json63
-rw-r--r--test/fixtures/mastodon-follow-activity.json29
-rw-r--r--test/fixtures/mastodon-like.json29
-rw-r--r--test/fixtures/mastodon-note-object.json9
-rw-r--r--test/fixtures/mastodon-post-activity.json65
-rw-r--r--test/support/factory.ex3
-rw-r--r--test/support/httpoison_mock.ex28
-rw-r--r--test/user_test.exs11
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs46
-rw-r--r--test/web/activity_pub/activity_pub_test.exs40
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs181
-rw-r--r--test/web/activity_pub/views/object_view_test.exs17
-rw-r--r--test/web/activity_pub/views/user_view_test.exs18
-rw-r--r--test/web/http_sigs/http_sig_test.exs154
-rw-r--r--test/web/http_sigs/priv.key15
-rw-r--r--test/web/http_sigs/pub.key6
-rw-r--r--test/web/ostatus/ostatus_test.exs7
-rw-r--r--test/web/twitter_api/representers/object_representer_test.exs20
23 files changed, 806 insertions, 9 deletions
diff --git a/test/fixtures/httpoison_mock/admin@mastdon.example.org.json b/test/fixtures/httpoison_mock/admin@mastdon.example.org.json
new file mode 100644
index 000000000..2c7629bd0
--- /dev/null
+++ b/test/fixtures/httpoison_mock/admin@mastdon.example.org.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"http://mastodon.example.org/users/admin","type":"Person","following":"http://mastodon.example.org/users/admin/following","followers":"http://mastodon.example.org/users/admin/followers","inbox":"http://mastodon.example.org/users/admin/inbox","outbox":"http://mastodon.example.org/users/admin/outbox","preferredUsername":"admin","name":null,"summary":"\u003cp\u003e\u003c/p\u003e","url":"http://mastodon.example.org/@admin","manuallyApprovesFollowers":false,"publicKey":{"id":"http://mastodon.example.org/users/admin#main-key","owner":"http://mastodon.example.org/users/admin","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"},"endpoints":{"sharedInbox":"http://mastodon.example.org/inbox"}}
diff --git a/test/fixtures/httpoison_mock/hellpie.json b/test/fixtures/httpoison_mock/hellpie.json
new file mode 100644
index 000000000..e228ba394
--- /dev/null
+++ b/test/fixtures/httpoison_mock/hellpie.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"https://masto.quad.moe/users/_HellPie","type":"Person","following":"https://masto.quad.moe/users/_HellPie/following","followers":"https://masto.quad.moe/users/_HellPie/followers","inbox":"https://masto.quad.moe/users/_HellPie/inbox","outbox":"https://masto.quad.moe/users/_HellPie/outbox","preferredUsername":"_HellPie","name":"_HellPie","summary":"\u003cp\u003eAndroid (Java) Developer, Linux addict. Often an asshole. Usually mentally ill, sometimes just retarded.\u003c/p\u003e\u003cp\u003eGitHub: \u003ca href=\"https://github.com/HellPie\" rel=\"nofollow noopener\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003egithub.com/HellPie\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e\u003c/p\u003e","url":"https://masto.quad.moe/@_HellPie","manuallyApprovesFollowers":false,"publicKey":{"id":"https://masto.quad.moe/users/_HellPie#main-key","owner":"https://masto.quad.moe/users/_HellPie","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1fIReYnqpap6e3sIskIx\ni7q130EvfkSOTBTBe01w3Xb/7/JwzWgkmSp+sK5s/ImO2oZb3ljmKZ3iTg4ETtVa\nCrT98/5p4Hlw/Oozb0kTx+tUazrucr023u8lTmn5sVgksKue59gPzKEuJJT1Te7H\nPJg2frz4QZWEY9nuygJoDaWgLvq1aa4oRfctlpo2C4d4oKRZFx2wtgeGVpahsikX\nKFBWuvEMFL2LUWb44BkvN6bTmXL9ryQY2oRsWn0yZHnTvFItq4vkFSNNe6sK13pM\nOHu1rVJrKg2hNVpBowds9YqZM8zP9F0GS7SEARbwPRCaAGLJGNwLjfJolJ/231eU\nKQIDAQAB\n-----END PUBLIC KEY-----\n"},"endpoints":{"sharedInbox":"https://masto.quad.moe/inbox"},"icon":{"type":"Image","mediaType":"image/png","url":"https://masto.quad.moe/system/accounts/avatars/000/012/255/original/39b907e6b169191d.png"},"image":{"type":"Image","mediaType":"image/png","url":"https://masto.quad.moe/system/accounts/headers/000/012/255/original/8d3ace0025bdda431e07230668303945.png"}} \ No newline at end of file
diff --git a/test/fixtures/httpoison_mock/rye.json b/test/fixtures/httpoison_mock/rye.json
new file mode 100644
index 000000000..f31d1ddd8
--- /dev/null
+++ b/test/fixtures/httpoison_mock/rye.json
@@ -0,0 +1 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"https://niu.moe/users/rye","type":"Person","following":"https://niu.moe/users/rye/following","followers":"https://niu.moe/users/rye/followers","inbox":"https://niu.moe/users/rye/inbox","outbox":"https://niu.moe/users/rye/outbox","preferredUsername":"rye","name":"♡ rye ♡","summary":"\u003cp\u003elettuce club champion\u003c/p\u003e\u003cp\u003eicon by gomigomipomi\u003c/p\u003e","url":"https://niu.moe/@rye","manuallyApprovesFollowers":false,"publicKey":{"id":"https://niu.moe/users/rye#main-key","owner":"https://niu.moe/users/rye","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA83uRWjCFO35FwfA38mzv\nEL0TUaXB7+2hYvPwNrn1WY6me5DRbqB5zzMrzWMGr0HSooqNqEYBafGsmVTWUqIk\nKM9ehtIBraJI+mT5X7DPR3LrXOJF4a9EEslg8XvAk8MN9IrAhm6UljnvB67RtDcA\nTNB01VWy9yWnxFRtz9o/EMoBPyw5giOaXE2ibVNP8lQIqGKuuBKPzPjSJygdvQ5q\nxfow2z1TpKRqdsNDqn4n6U6zCXYTzkr0J71/tGw7fsgfv78l0Wjrc7EcuBk74OaG\nC65UDiu3X4Q6kxCfCEhPSfuwLN+UZkzxcn6goWR0iYpWs57+4tFKu9nJYP4QJ0K9\nTwIDAQAB\n-----END PUBLIC KEY-----\n"},"endpoints":{"sharedInbox":"https://niu.moe/inbox"},"icon":{"type":"Image","mediaType":"image/jpeg","url":"https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"},"image":{"type":"Image","mediaType":"image/png","url":"https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}} \ No newline at end of file
diff --git a/test/fixtures/mastodon-accept-activity.json b/test/fixtures/mastodon-accept-activity.json
new file mode 100644
index 000000000..b661ed6da
--- /dev/null
+++ b/test/fixtures/mastodon-accept-activity.json
@@ -0,0 +1,34 @@
+{
+ "type": "Accept",
+ "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#accepts/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"
+ }
+ ]
+} \ No newline at end of file
diff --git a/test/fixtures/mastodon-announce.json b/test/fixtures/mastodon-announce.json
new file mode 100644
index 000000000..9d4861292
--- /dev/null
+++ b/test/fixtures/mastodon-announce.json
@@ -0,0 +1,37 @@
+{
+ "type": "Announce",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "signature": {
+ "type": "RsaSignature2017",
+ "signatureValue": "T95DRE0eAligvMuRMkQA01lsoz2PKi4XXF+cyZ0BqbrO12p751TEWTyyRn5a+HH0e4kc77EUhQVXwMq80WAYDzHKVUTf2XBJPBa68vl0j6RXw3+HK4ef5hR4KWFNBU34yePS7S1fEmc1mTG4Yx926wtmZwDpEMTp1CXOeVEjCYzmdyHpepPPH2ZZettiacmPRSqBLPGWZoot7kH/SioIdnrMGY0I7b+rqkIdnnEcdhu9N1BKPEO9Sr+KmxgAUiidmNZlbBXX6gCxp8BiIdH4ABsIcwoDcGNkM5EmWunGW31LVjsEQXhH5c1Wly0ugYYPCg/0eHLNBOhKkY/teSM8Lg==",
+ "creator": "http://mastodon.example.org/users/admin#main-key",
+ "created": "2018-02-17T19:39:15Z"
+ },
+ "published": "2018-02-17T19:39:15Z",
+ "object": "http://mastodon.example.org/@admin/99541947525187367",
+ "id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
+ "cc": [
+ "http://mastodon.example.org/users/admin",
+ "http://mastodon.example.org/users/admin/followers"
+ ],
+ "atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
+ "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/mastodon-create-with-attachment.json b/test/fixtures/mastodon-create-with-attachment.json
new file mode 100644
index 000000000..fb270b13f
--- /dev/null
+++ b/test/fixtures/mastodon-create-with-attachment.json
@@ -0,0 +1,63 @@
+{
+ "type": "Create",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "signature": {
+ "type": "RsaSignature2017",
+ "signatureValue": "KnaBoP7C4XYgzTFbM+CpGlx4p59ahWvNNo4reRGDlb/DmxL3OF1/WugNl0xHCOA3aoIX2rrkHniw+z4Yb+wOBf9ZOxgM+IHTKj69AEcm/4NxGXxStRv603JZNyboY371w8g/mIKmLLtL6dgUI3n2Laam2rYh//8aelEWQ240TxiJi/WcKuOT2DNInWOpfArgxJ4MA11n4tb4xX65RkxInTCFa1kaJG8L+A+EoXtIhTa4rCQDv/BH3a8x7vOJxHfEosEnkk/yVEqG+ccgoTvc+5/kK+TKk3S3GuXch0ro9RKqxfPAHkyg8eetRhNhKWZ/rgPNfcF6bGJKFA0i8TzjHw==",
+ "creator": "http://mastodon.example.org/users/admin#main-key",
+ "created": "2018-02-17T17:14:26Z"
+ },
+ "published": "2018-02-17T17:14:26Z",
+ "object": {
+ "url": "http://mastodon.example.org/@admin/99541822081679796",
+ "type": "Note",
+ "to": [
+ "https://www.w3.org/ns/activitystreams#Public"
+ ],
+ "tag": [],
+ "summary": null,
+ "sensitive": false,
+ "published": "2018-02-17T17:14:26Z",
+ "inReplyToAtomUri": null,
+ "inReplyTo": null,
+ "id": "http://mastodon.example.org/users/admin/statuses/99541822081679796",
+ "conversation": "tag:mastodon.example.org,2018-02-17:objectId=10:objectType=Conversation",
+ "content": "<p><a href=\"http://mastodon.example.org/media/hw4nrZmV5DPbW2z_hao\" rel=\"nofollow noopener\" target=\"_blank\"><span class=\"invisible\">http://</span><span class=\"ellipsis\">mastodon.example.org/media/hw4</span><span class=\"invisible\">nrZmV5DPbW2z_hao</span></a></p>",
+ "cc": [
+ "http://mastodon.example.org/users/admin/followers"
+ ],
+ "attributedTo": "http://mastodon.example.org/users/admin",
+ "attachment": [
+ {
+ "url": "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
+ "type": "Document",
+ "name": null,
+ "mediaType": "image/jpeg"
+ }
+ ],
+ "atomUri": "http://mastodon.example.org/users/admin/statuses/99541822081679796"
+ },
+ "id": "http://mastodon.example.org/users/admin/statuses/99541822081679796/activity",
+ "cc": [
+ "http://mastodon.example.org/users/admin/followers"
+ ],
+ "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"
+ }
+ ]
+} \ No newline at end of file
diff --git a/test/fixtures/mastodon-follow-activity.json b/test/fixtures/mastodon-follow-activity.json
new file mode 100644
index 000000000..7a6de6996
--- /dev/null
+++ b/test/fixtures/mastodon-follow-activity.json
@@ -0,0 +1,29 @@
+{
+ "type": "Follow",
+ "signature": {
+ "type": "RsaSignature2017",
+ "signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==",
+ "creator": "http://mastodon.example.org/users/admin#main-key",
+ "created": "2018-02-17T13:29:31Z"
+ },
+ "object": "http://localtesting.pleroma.lol/users/lain",
+ "nickname": "lain",
+ "id": "http://mastodon.example.org/users/admin#follows/2",
+ "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"
+ }
+ ]
+} \ No newline at end of file
diff --git a/test/fixtures/mastodon-like.json b/test/fixtures/mastodon-like.json
new file mode 100644
index 000000000..39fb44c4a
--- /dev/null
+++ b/test/fixtures/mastodon-like.json
@@ -0,0 +1,29 @@
+{
+ "type": "Like",
+ "signature": {
+ "type": "RsaSignature2017",
+ "signatureValue": "fdxMfQSMwbC6wP6sh6neS/vM5879K67yQkHTbiT5Npr5wAac0y6+o3Ij+41tN3rL6wfuGTosSBTHOtta6R4GCOOhCaCSLMZKypnp1VltCzLDoyrZELnYQIC8gpUXVmIycZbREk22qWUe/w7DAFaKK4UscBlHDzeDVcA0K3Se5Sluqi9/Zh+ldAnEzj/rSEPDjrtvf5wGNf3fHxbKSRKFt90JvKK6hS+vxKUhlRFDf6/SMETw+EhwJSNW4d10yMUakqUWsFv4Acq5LW7l+HpYMvlYY1FZhNde1+uonnCyuQDyvzkff8zwtEJmAXC4RivO/VVLa17SmqheJZfI8oluVg==",
+ "creator": "http://mastodon.example.org/users/admin#main-key",
+ "created": "2018-02-17T18:57:49Z"
+ },
+ "object": "http://localtesting.pleroma.lol/objects/eb92579d-3417-42a8-8652-2492c2d4f454",
+ "nickname": "lain",
+ "id": "http://mastodon.example.org/users/admin#likes/2",
+ "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"
+ }
+ ]
+} \ No newline at end of file
diff --git a/test/fixtures/mastodon-note-object.json b/test/fixtures/mastodon-note-object.json
new file mode 100644
index 000000000..75bed9625
--- /dev/null
+++ b/test/fixtures/mastodon-note-object.json
@@ -0,0 +1,9 @@
+{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"http://mastodon.example.org/users/admin/statuses/99541947525187367","type":"Note","summary":null,"content":"\u003cp\u003eyeah.\u003c/p\u003e","inReplyTo":null,"published":"2018-02-17T17:46:20Z","url":"http://mastodon.example.org/@admin/99541947525187367","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/99541947525187367","inReplyToAtomUri":null,"conversation":"tag:mastodon.example.org,2018-02-17:objectId=59:objectType=Conversation","tag":[],
+ "attachment": [
+ {
+ "url": "http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
+ "type": "Document",
+ "name": null,
+ "mediaType": "image/jpeg"
+ }
+ ]}
diff --git a/test/fixtures/mastodon-post-activity.json b/test/fixtures/mastodon-post-activity.json
new file mode 100644
index 000000000..693e0ce39
--- /dev/null
+++ b/test/fixtures/mastodon-post-activity.json
@@ -0,0 +1,65 @@
+{
+ "@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"
+ ],
+ "content": "<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/support/factory.ex b/test/support/factory.ex
index 7f378915e..1445fe828 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -52,7 +52,8 @@ defmodule Pleroma.Factory do
%Pleroma.Activity{
data: data,
- actor: data["actor"]
+ actor: data["actor"],
+ recipients: data["to"]
}
end
diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex
index 21607ba95..b8f2422f6 100644
--- a/test/support/httpoison_mock.ex
+++ b/test/support/httpoison_mock.ex
@@ -366,6 +366,34 @@ defmodule HTTPoisonMock do
}}
end
+ def get("http://mastodon.example.org/users/admin", ["Accept": "application/activity+json"], _) do
+ {:ok, %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/admin@mastdon.example.org.json")
+ }}
+ end
+
+ def get("https://masto.quad.moe/users/_HellPie", ["Accept": "application/activity+json"], _) do
+ {:ok, %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/httpoison_mock/hellpie.json")
+ }}
+ end
+
+ def get("https://niu.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("http://mastodon.example.org/@admin/99541947525187367", ["Accept": "application/activity+json"], _) do
+ {:ok, %Response{
+ status_code: 200,
+ body: File.read!("test/fixtures/mastodon-note-object.json")
+ }}
+ end
+
def get(url, body, headers) do
{:error, "Not implemented the mock response for get #{inspect(url)}, #{inspect(body)}, #{inspect(headers)}"}
end
diff --git a/test/user_test.exs b/test/user_test.exs
index 0c87b778c..058b67c6d 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -370,4 +370,15 @@ defmodule Pleroma.UserTest do
refute Repo.get(Activity, activity.id)
end
+
+ test "get_public_key_for_ap_id fetches a user that's not in the db" do
+ assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
+ end
+
+ test "insert or update a user from given data" do
+ user = insert(:user, %{nickname: "nick@name.de"})
+ data = %{ ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname }
+
+ assert {:ok, %User{}} = User.insert_or_update_user(data)
+ end
end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
new file mode 100644
index 000000000..957687c43
--- /dev/null
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -0,0 +1,46 @@
+defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
+ use Pleroma.Web.ConnCase
+ import Pleroma.Factory
+ alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
+ alias Pleroma.{Repo, User}
+
+ describe "/users/:nickname" do
+ test "it returns a json representation of the user", %{conn: conn} do
+ user = insert(:user)
+
+ conn = conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}")
+
+ user = Repo.get(User, user.id)
+
+ assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
+ end
+ end
+
+ describe "/object/:uuid" do
+ test "it returns a json representation of the object", %{conn: conn} do
+ note = insert(: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, 200) == ObjectView.render("object.json", %{object: note})
+ end
+ end
+
+ describe "/users/:nickname/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!
+
+ conn = conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/users/doesntmatter/inbox", data)
+
+ assert "ok" == json_response(conn, 200)
+ end
+ end
+end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index f423ea8be..4aeabc596 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -7,6 +7,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
import Pleroma.Factory
+ describe "building a user from his ap id" do
+ test "it returns a user" do
+ user_id = "http://mastodon.example.org/users/admin"
+ {:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
+ assert user.ap_id == user_id
+ assert user.nickname == "admin@mastodon.example.org"
+ assert user.info["source_data"]
+ assert user.info["ap_enabled"]
+ assert user.follower_address == "http://mastodon.example.org/users/admin/followers"
+ end
+ end
+
describe "insertion" do
test "returns the activity if one with the same id is already in" do
activity = insert(:note_activity)
@@ -50,9 +62,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
describe "create activities" do
test "removes doubled 'to' recipients" do
- {:ok, activity} = ActivityPub.create(["user1", "user1", "user2"], %User{ap_id: "1"}, "", %{})
+ {:ok, activity} = ActivityPub.create(%{to: ["user1", "user1", "user2"], actor: %User{ap_id: "1"}, context: "", object: %{}})
assert activity.data["to"] == ["user1", "user2"]
assert activity.actor == "1"
+ assert activity.recipients == ["user1", "user2"]
end
end
@@ -252,6 +265,31 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
+ describe "fetching an object" do
+ test "it fetches an object" do
+ {:ok, object} = ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+ assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ assert activity.data["id"]
+
+ {:ok, object_again} = ActivityPub.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert [attachment] = object.data["attachment"]
+ assert is_list(attachment["url"])
+
+ assert object == object_again
+ end
+
+ test "it works with objects only available via Ostatus" do
+ {:ok, object} = ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
+ assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ assert activity.data["id"]
+
+ {:ok, object_again} = ActivityPub.fetch_object_from_id("https://shitposter.club/notice/2827873")
+
+ assert object == object_again
+ end
+ end
+
describe "following / unfollowing" do
test "creates a follow activity" do
follower = insert(:user)
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
new file mode 100644
index 000000000..96dd63057
--- /dev/null
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -0,0 +1,181 @@
+defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Repo
+ import Ecto.Query
+
+ import Pleroma.Factory
+ alias Pleroma.Web.CommonAPI
+
+ describe "handle_incoming" do
+ test "it ignores an incoming notice if we already have it" do
+ activity = insert(:note_activity)
+
+ data = File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!
+ |> Map.put("object", activity.data["object"])
+
+ {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
+
+ assert activity == returned_activity
+ end
+
+ test "it fetches replied-to activities if we don't have them" do
+ data = File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!
+
+ object = data["object"]
+ |> Map.put("inReplyTo", "https://shitposter.club/notice/2827873")
+
+ data = data
+ |> Map.put("object", object)
+
+ {:ok, returned_activity} = Transmogrifier.handle_incoming(data)
+
+ assert Activity.get_create_activity_by_object_ap_id("tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment")
+ end
+
+ test "it works for incoming notices" do
+ data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ assert data["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822/activity"
+ assert data["context"] == "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
+ assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
+ assert data["cc"] == [
+ "http://mastodon.example.org/users/admin/followers",
+ "http://localtesting.pleroma.lol/users/lain"
+ ]
+ assert data["actor"] == "http://mastodon.example.org/users/admin"
+
+ object = data["object"]
+ assert object["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822"
+
+ assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
+ assert object["cc"] == [
+ "http://mastodon.example.org/users/admin/followers",
+ "http://localtesting.pleroma.lol/users/lain"
+ ]
+ assert object["actor"] == "http://mastodon.example.org/users/admin"
+ assert object["attributedTo"] == "http://mastodon.example.org/users/admin"
+ assert object["context"] == "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation"
+ assert object["sensitive"] == true
+ end
+
+ test "it works for incoming follow requests" do
+ user = insert(:user)
+ data = File.read!("test/fixtures/mastodon-follow-activity.json") |> Poison.decode!
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "http://mastodon.example.org/users/admin"
+ assert data["type"] == "Follow"
+ assert data["id"] == "http://mastodon.example.org/users/admin#follows/2"
+ assert User.following?(User.get_by_ap_id(data["actor"]), user)
+ end
+
+ test "it works for incoming likes" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
+
+ data = File.read!("test/fixtures/mastodon-like.json") |> Poison.decode!
+ |> Map.put("object", activity.data["object"]["id"])
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "http://mastodon.example.org/users/admin"
+ assert data["type"] == "Like"
+ assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
+ assert data["object"] == activity.data["object"]["id"]
+ end
+
+ test "it works for incoming announces" do
+ data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "http://mastodon.example.org/users/admin"
+ assert data["type"] == "Announce"
+ assert data["id"] == "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
+ assert data["object"] == "http://mastodon.example.org/users/admin/statuses/99541947525187367"
+
+ assert Activity.get_create_activity_by_object_ap_id(data["object"])
+ end
+
+ test "it works for incoming announces with an existing activity" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+
+ data = File.read!("test/fixtures/mastodon-announce.json")
+ |> Poison.decode!
+ |> Map.put("object", activity.data["object"]["id"])
+
+ {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+
+ assert data["actor"] == "http://mastodon.example.org/users/admin"
+ assert data["type"] == "Announce"
+ assert data["id"] == "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
+ assert data["object"] == activity.data["object"]["id"]
+
+ assert Activity.get_create_activity_by_object_ap_id(data["object"]).id == activity.id
+ end
+ end
+
+ describe "prepare outgoing" do
+ test "it turns mentions into tags" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey, @#{other_user.nickname}, how are ya? #2hu"})
+
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+ object = modified["object"]
+
+ expected_mention = %{
+ "href" => other_user.ap_id,
+ "name" => "@#{other_user.nickname}",
+ "type" => "Mention"
+ }
+
+ expected_tag = %{
+ "href" => Pleroma.Web.Endpoint.url <> "/tags/2hu",
+ "type" => "Hashtag",
+ "name" => "#2hu"
+ }
+
+ assert Enum.member?(object["tag"], expected_tag)
+ assert Enum.member?(object["tag"], expected_mention)
+ end
+
+ test "it adds the sensitive property" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "#nsfw hey"})
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert modified["object"]["sensitive"]
+ end
+
+ test "it adds the json-ld context and the conversation property" do
+ user = insert(:user)
+
+ {: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["object"]["conversation"] == modified["context"]
+ end
+
+ test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
+
+ assert modified["object"]["actor"] == modified["object"]["attributedTo"]
+ end
+ end
+end
diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs
new file mode 100644
index 000000000..6a1311be7
--- /dev/null
+++ b/test/web/activity_pub/views/object_view_test.exs
@@ -0,0 +1,17 @@
+defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.Web.ActivityPub.ObjectView
+
+ test "renders a note object" do
+ note = insert(:note)
+
+ result = ObjectView.render("object.json", %{object: note})
+
+ assert result["id"] == note.data["id"]
+ assert result["to"] == note.data["to"]
+ assert result["content"] == note.data["content"]
+ assert result["type"] == "Note"
+ end
+end
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
new file mode 100644
index 000000000..0c64e62c3
--- /dev/null
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -0,0 +1,18 @@
+defmodule Pleroma.Web.ActivityPub.UserViewTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.Web.ActivityPub.UserView
+
+ test "Renders a user, including the public key" do
+ user = insert(:user)
+ {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+ result = UserView.render("user.json", %{user: user})
+
+ assert result["id"] == user.ap_id
+ assert result["preferredUsername"] == user.nickname
+
+ assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN RSA PUBLIC KEY")
+ end
+end
diff --git a/test/web/http_sigs/http_sig_test.exs b/test/web/http_sigs/http_sig_test.exs
new file mode 100644
index 000000000..fd568a67a
--- /dev/null
+++ b/test/web/http_sigs/http_sig_test.exs
@@ -0,0 +1,154 @@
+# http signatures
+# Test data from https://tools.ietf.org/html/draft-cavage-http-signatures-08#appendix-C
+defmodule Pleroma.Web.HTTPSignaturesTest do
+ use Pleroma.DataCase
+ alias Pleroma.Web.HTTPSignatures
+ import Pleroma.Factory
+
+ @private_key (hd(:public_key.pem_decode(File.read!("test/web/http_sigs/priv.key")))
+ |> :public_key.pem_entry_decode())
+
+ @public_key (hd(:public_key.pem_decode(File.read!("test/web/http_sigs/pub.key")))
+ |> :public_key.pem_entry_decode())
+
+ @headers %{
+ "(request-target)" => "post /foo?param=value&pet=dog",
+ "host" => "example.com",
+ "date" => "Thu, 05 Jan 2014 21:31:40 GMT",
+ "content-type" => "application/json",
+ "digest" => "SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=",
+ "content-length" => "18"
+ }
+
+ @body "{\"hello\": \"world\"}"
+
+ @default_signature """
+ keyId="Test",algorithm="rsa-sha256",signature="jKyvPcxB4JbmYY4mByyBY7cZfNl4OW9HpFQlG7N4YcJPteKTu4MWCLyk+gIr0wDgqtLWf9NLpMAMimdfsH7FSWGfbMFSrsVTHNTk0rK3usrfFnti1dxsM4jl0kYJCKTGI/UWkqiaxwNiKqGcdlEDrTcUhhsFsOIo8VhddmZTZ8w="
+ """
+
+ @basic_signature """
+ keyId="Test",algorithm="rsa-sha256",headers="(request-target) host date",signature="HUxc9BS3P/kPhSmJo+0pQ4IsCo007vkv6bUm4Qehrx+B1Eo4Mq5/6KylET72ZpMUS80XvjlOPjKzxfeTQj4DiKbAzwJAb4HX3qX6obQTa00/qPDXlMepD2JtTw33yNnm/0xV7fQuvILN/ys+378Ysi082+4xBQFwvhNvSoVsGv4="
+ """
+
+ @all_headers_signature """
+ keyId="Test",algorithm="rsa-sha256",headers="(request-target) host date content-type digest content-length",signature="Ef7MlxLXoBovhil3AlyjtBwAL9g4TN3tibLj7uuNB3CROat/9KaeQ4hW2NiJ+pZ6HQEOx9vYZAyi+7cmIkmJszJCut5kQLAwuX+Ms/mUFvpKlSo9StS2bMXDBNjOh4Auj774GFj4gwjS+3NhFeoqyr/MuN6HsEnkvn6zdgfE2i0="
+ """
+
+ test "split up a signature" do
+ expected = %{
+ "keyId" => "Test",
+ "algorithm" => "rsa-sha256",
+ "signature" => "jKyvPcxB4JbmYY4mByyBY7cZfNl4OW9HpFQlG7N4YcJPteKTu4MWCLyk+gIr0wDgqtLWf9NLpMAMimdfsH7FSWGfbMFSrsVTHNTk0rK3usrfFnti1dxsM4jl0kYJCKTGI/UWkqiaxwNiKqGcdlEDrTcUhhsFsOIo8VhddmZTZ8w=",
+ "headers" => ["date"]
+ }
+
+ assert HTTPSignatures.split_signature(@default_signature) == expected
+ end
+
+ test "validates the default case" do
+ signature = HTTPSignatures.split_signature(@default_signature)
+ assert HTTPSignatures.validate(@headers, signature, @public_key)
+ end
+
+ test "validates the basic case" do
+ signature = HTTPSignatures.split_signature(@basic_signature)
+ assert HTTPSignatures.validate(@headers, signature, @public_key)
+ end
+
+ test "validates the all-headers case" do
+ signature = HTTPSignatures.split_signature(@all_headers_signature)
+ assert HTTPSignatures.validate(@headers, signature, @public_key)
+ end
+
+ test "it contructs a signing string" do
+ expected = "date: Thu, 05 Jan 2014 21:31:40 GMT\ncontent-length: 18"
+ assert expected == HTTPSignatures.build_signing_string(@headers, ["date", "content-length"])
+ end
+
+ test "it validates a conn" do
+ public_key_pem = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnGb42rPZIapY4Hfhxrgn\nxKVJczBkfDviCrrYaYjfGxawSw93dWTUlenCVTymJo8meBlFgIQ70ar4rUbzl6GX\nMYvRdku072d1WpglNHXkjKPkXQgngFDrh2sGKtNB/cEtJcAPRO8OiCgPFqRtMiNM\nc8VdPfPdZuHEIZsJ/aUM38EnqHi9YnVDQik2xxDe3wPghOhqjxUM6eLC9jrjI+7i\naIaEygUdyst9qVg8e2FGQlwAeS2Eh8ygCxn+bBlT5OyV59jSzbYfbhtF2qnWHtZy\nkL7KOOwhIfGs7O9SoR2ZVpTEQ4HthNzainIe/6iCR5HGrao/T8dygweXFYRv+k5A\nPQIDAQAB\n-----END PUBLIC KEY-----\n"
+ [public_key] = :public_key.pem_decode(public_key_pem)
+
+ public_key = public_key
+ |> :public_key.pem_entry_decode()
+
+ conn = %{
+ req_headers: [
+ {"host", "localtesting.pleroma.lol"},
+ {"connection", "close"},
+ {"content-length", "2316"},
+ {"user-agent", "http.rb/2.2.2 (Mastodon/2.1.0.rc3; +http://mastodon.example.org/)"},
+ {"date", "Sun, 10 Dec 2017 14:23:49 GMT"},
+ {"digest", "SHA-256=x/bHADMW8qRrq2NdPb5P9fl0lYpKXXpe5h5maCIL0nM="},
+ {"content-type", "application/activity+json"},
+ {"(request-target)", "post /users/demiurge/inbox"},
+ {"signature", "keyId=\"http://mastodon.example.org/users/admin#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) user-agent host date digest content-type\",signature=\"i0FQvr51sj9BoWAKydySUAO1RDxZmNY6g7M62IA7VesbRSdFZZj9/fZapLp6YSuvxUF0h80ZcBEq9GzUDY3Chi9lx6yjpUAS2eKb+Am/hY3aswhnAfYd6FmIdEHzsMrpdKIRqO+rpQ2tR05LwiGEHJPGS0p528NvyVxrxMT5H5yZS5RnxY5X2HmTKEgKYYcvujdv7JWvsfH88xeRS7Jlq5aDZkmXvqoR4wFyfgnwJMPLel8P/BUbn8BcXglH/cunR0LUP7sflTxEz+Rv5qg+9yB8zgBsB4C0233WpcJxjeD6Dkq0EcoJObBR56F8dcb7NQtUDu7x6xxzcgSd7dHm5w==\""}]
+ }
+
+ assert HTTPSignatures.validate_conn(conn, public_key)
+ end
+
+ test "it validates a conn and fetches the key" do
+ conn = %{
+ params: %{"actor" => "http://mastodon.example.org/users/admin"},
+ req_headers: [
+ {"host", "localtesting.pleroma.lol"},
+ {"x-forwarded-for", "127.0.0.1"},
+ {"connection", "close"},
+ {"content-length", "2307"},
+ {"user-agent", "http.rb/2.2.2 (Mastodon/2.1.0.rc3; +http://mastodon.example.org/)"},
+ {"date", "Sun, 11 Feb 2018 17:12:01 GMT"},
+ {"digest", "SHA-256=UXsAnMtR9c7mi1FOf6HRMtPgGI1yi2e9nqB/j4rZ99I="},
+ {"content-type", "application/activity+json"},
+ {"signature", "keyId=\"http://mastodon.example.org/users/admin#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) user-agent host date digest content-type\",signature=\"qXKqpQXUpC3d9bZi2ioEeAqP8nRMD021CzH1h6/w+LRk4Hj31ARJHDwQM+QwHltwaLDUepshMfz2WHSXAoLmzWtvv7xRwY+mRqe+NGk1GhxVZ/LSrO/Vp7rYfDpfdVtkn36LU7/Bzwxvvaa4ZWYltbFsRBL0oUrqsfmJFswNCQIG01BB52BAhGSCORHKtQyzo1IZHdxl8y80pzp/+FOK2SmHkqWkP9QbaU1qTZzckL01+7M5btMW48xs9zurEqC2sM5gdWMQSZyL6isTV5tmkTZrY8gUFPBJQZgihK44v3qgfWojYaOwM8ATpiv7NG8wKN/IX7clDLRMA8xqKRCOKw==\""},
+ {"(request-target)", "post /users/demiurge/inbox"}
+ ]
+ }
+
+ assert HTTPSignatures.validate_conn(conn)
+ end
+
+ test "validate this" do
+ conn = %{
+ params: %{"actor" => "https://niu.moe/users/rye"},
+ req_headers: [
+ {"x-forwarded-for", "149.202.73.191"},
+ {"host", "testing.pleroma.lol"},
+ {"x-cluster-client-ip", "149.202.73.191"},
+ {"connection", "upgrade"},
+ {"content-length", "2396"},
+ {"user-agent", "http.rb/3.0.0 (Mastodon/2.2.0; +https://niu.moe/)"},
+ {"date", "Sun, 18 Feb 2018 20:31:51 GMT"},
+ {"digest", "SHA-256=dzH+vLyhxxALoe9RJdMl4hbEV9bGAZnSfddHQzeidTU="},
+ {"content-type", "application/activity+json"},
+ {"signature", "keyId=\"https://niu.moe/users/rye#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) user-agent host date digest content-type\",signature=\"wtxDg4kIpW7nsnUcVJhBk6SgJeDZOocr8yjsnpDRqE52lR47SH6X7G16r7L1AUJdlnbfx7oqcvomoIJoHB3ghP6kRnZW6MyTMZ2jPoi3g0iC5RDqv6oAmDSO14iw6U+cqZbb3P/odS5LkbThF0UNXcfenVNfsKosIJycFjhNQc54IPCDXYq/7SArEKJp8XwEgzmiC2MdxlkVIUSTQYfjM4EG533cwlZocw1mw72e5mm/owTa80BUZAr0OOuhoWARJV9btMb02ZyAF6SCSoGPTA37wHyfM1Dk88NHf7Z0Aov/Fl65dpRM+XyoxdkpkrhDfH9qAx4iuV2VEWddQDiXHA==\""},
+ {"(request-target)", "post /inbox"}
+ ]
+ }
+ assert HTTPSignatures.validate_conn(conn)
+ end
+
+ test "validate this too" do
+ conn = %{
+ params: %{"actor" => "https://niu.moe/users/rye"},
+ req_headers: [
+ {"x-forwarded-for", "149.202.73.191"},
+ {"host", "testing.pleroma.lol"},
+ {"x-cluster-client-ip", "149.202.73.191"},
+ {"connection", "upgrade"},
+ {"content-length", "2342"},
+ {"user-agent", "http.rb/3.0.0 (Mastodon/2.2.0; +https://niu.moe/)"},
+ {"date", "Sun, 18 Feb 2018 21:44:46 GMT"},
+ {"digest", "SHA-256=vS8uDOJlyAu78cF3k5EzrvaU9iilHCX3chP37gs5sS8="},
+ {"content-type", "application/activity+json"},
+ {"signature", "keyId=\"https://niu.moe/users/rye#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) user-agent host date digest content-type\",signature=\"IN6fHD8pLiDEf35dOaRHzJKc1wBYh3/Yq0ItaNGxUSbJTd2xMjigZbcsVKzvgYYjglDDN+disGNeD+OBKwMqkXWaWe/lyMc9wHvCH5NMhpn/A7qGLY8yToSt4vh8ytSkZKO6B97yC+Nvy6Fz/yMbvKtFycIvSXCq417cMmY6f/aG+rtMUlTbKO5gXzC7SUgGJCtBPCh1xZzu5/w0pdqdjO46ePNeR6JyJSLLV4hfo3+p2n7SRraxM4ePVCUZqhwS9LPt3Zdhy3ut+IXCZgMVIZggQFM+zXLtcXY5HgFCsFQr5WQDu+YkhWciNWtKFnWfAsnsg5sC330lZ/0Z8Z91yA==\""},
+ {"(request-target)", "post /inbox"}
+ ]}
+ assert HTTPSignatures.validate_conn(conn)
+ end
+
+ test "it generates a signature" do
+ user = insert(:user)
+ assert HTTPSignatures.sign(user, %{host: "mastodon.example.org"}) =~ "keyId=\""
+ end
+end
diff --git a/test/web/http_sigs/priv.key b/test/web/http_sigs/priv.key
new file mode 100644
index 000000000..425518a06
--- /dev/null
+++ b/test/web/http_sigs/priv.key
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXgIBAAKBgQDCFENGw33yGihy92pDjZQhl0C36rPJj+CvfSC8+q28hxA161QF
+NUd13wuCTUcq0Qd2qsBe/2hFyc2DCJJg0h1L78+6Z4UMR7EOcpfdUE9Hf3m/hs+F
+UR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJwoYi+1hqp1fIekaxsyQIDAQAB
+AoGBAJR8ZkCUvx5kzv+utdl7T5MnordT1TvoXXJGXK7ZZ+UuvMNUCdN2QPc4sBiA
+QWvLw1cSKt5DsKZ8UETpYPy8pPYnnDEz2dDYiaew9+xEpubyeW2oH4Zx71wqBtOK
+kqwrXa/pzdpiucRRjk6vE6YY7EBBs/g7uanVpGibOVAEsqH1AkEA7DkjVH28WDUg
+f1nqvfn2Kj6CT7nIcE3jGJsZZ7zlZmBmHFDONMLUrXR/Zm3pR5m0tCmBqa5RK95u
+412jt1dPIwJBANJT3v8pnkth48bQo/fKel6uEYyboRtA5/uHuHkZ6FQF7OUkGogc
+mSJluOdc5t6hI1VsLn0QZEjQZMEOWr+wKSMCQQCC4kXJEsHAve77oP6HtG/IiEn7
+kpyUXRNvFsDE0czpJJBvL/aRFUJxuRK91jhjC68sA7NsKMGg5OXb5I5Jj36xAkEA
+gIT7aFOYBFwGgQAQkWNKLvySgKbAZRTeLBacpHMuQdl1DfdntvAyqpAZ0lY0RKmW
+G6aFKaqQfOXKCyWoUiVknQJAXrlgySFci/2ueKlIE1QqIiLSZ8V8OlpFLRnb1pzI
+7U1yQXnTAEFYM560yJlzUpOb1V4cScGd365tiSMvxLOvTA==
+-----END RSA PRIVATE KEY-----
diff --git a/test/web/http_sigs/pub.key b/test/web/http_sigs/pub.key
new file mode 100644
index 000000000..b3bbf6cb9
--- /dev/null
+++ b/test/web/http_sigs/pub.key
@@ -0,0 +1,6 @@
+-----BEGIN PUBLIC KEY-----
+MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCFENGw33yGihy92pDjZQhl0C3
+6rPJj+CvfSC8+q28hxA161QFNUd13wuCTUcq0Qd2qsBe/2hFyc2DCJJg0h1L78+6
+Z4UMR7EOcpfdUE9Hf3m/hs+FUR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJw
+oYi+1hqp1fIekaxsyQIDAQAB
+-----END PUBLIC KEY-----
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 1f10ea4d2..1dd381ac4 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -355,13 +355,6 @@ defmodule Pleroma.Web.OStatusTest do
end
end
- test "insert or update a user from given data" do
- user = insert(:user, %{nickname: "nick@name.de"})
- data = %{ ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname }
-
- assert {:ok, %User{}} = OStatus.insert_or_update_user(data)
- end
-
test "it doesn't add nil in the do field" do
incoming = File.read!("test/fixtures/nil_mention_entry.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
diff --git a/test/web/twitter_api/representers/object_representer_test.exs b/test/web/twitter_api/representers/object_representer_test.exs
index 791b30237..ac8184407 100644
--- a/test/web/twitter_api/representers/object_representer_test.exs
+++ b/test/web/twitter_api/representers/object_representer_test.exs
@@ -28,4 +28,24 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
assert expected_object == ObjectRepresenter.to_map(object)
end
+
+ test "represents mastodon-style attachments" do
+ object = %Object{
+ id: nil,
+ data: %{
+ "mediaType" => "image/png",
+ "name" => "blabla", "type" => "Document",
+ "url" => "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
+ }
+ }
+
+ expected_object = %{
+ url: "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
+ mimetype: "image/png",
+ oembed: false,
+ id: nil
+ }
+
+ assert expected_object == ObjectRepresenter.to_map(object)
+ end
end