diff options
| author | Francis Dinh <normandy@firemail.cc> | 2018-05-19 21:23:52 -0400 | 
|---|---|---|
| committer | Francis Dinh <normandy@firemail.cc> | 2018-05-19 21:23:52 -0400 | 
| commit | 1e43de0f86ea632a313f9bf7434183a6db38f0b6 (patch) | |
| tree | 0cf215887945a855d49034dd6956e402dce9bb30 /test | |
| parent | da9744eb8481b4df527d0e360aa30be9ca6b5a3a (diff) | |
| download | pleroma-1e43de0f86ea632a313f9bf7434183a6db38f0b6.tar.gz pleroma-1e43de0f86ea632a313f9bf7434183a6db38f0b6.zip | |
Formatting and add tests for blocks/unblocks
Diffstat (limited to 'test')
| -rw-r--r-- | test/fixtures/mastodon-block-activity.json | 29 | ||||
| -rw-r--r-- | test/fixtures/mastodon-unblock-activity.json | 33 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 46 | 
3 files changed, 108 insertions, 0 deletions
| diff --git a/test/fixtures/mastodon-block-activity.json b/test/fixtures/mastodon-block-activity.json new file mode 100644 index 000000000..186719d2c --- /dev/null +++ b/test/fixtures/mastodon-block-activity.json @@ -0,0 +1,29 @@ +{ +  "type": "Block", +  "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" +    } +  ] +} diff --git a/test/fixtures/mastodon-unblock-activity.json b/test/fixtures/mastodon-unblock-activity.json new file mode 100644 index 000000000..53b2f42a8 --- /dev/null +++ b/test/fixtures/mastodon-unblock-activity.json @@ -0,0 +1,33 @@ +{ +    "@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" +            } +          ], +    "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" +      }, +    "type": "Undo", +    "object": { +      "type": "Block",  +      "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"  +    }, +    "actor": "http://mastodon.example.org/users/admin" +} diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 8ed7147f4..0ca00a07e 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -280,10 +280,56 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert data["type"] == "Undo"        assert data["object"]["type"] == "Follow" +      assert data["object"]["object"] == user.ap_id        assert data["actor"] == "http://mastodon.example.org/users/admin"        refute User.following?(User.get_by_ap_id(data["actor"]), user)      end + +    test "it works for incoming blocks" do +      user = insert(:user) + +      data = +        File.read!("test/fixtures/mastodon-block-activity.json") +        |> Poison.decode!() +        |> Map.put("object", user.ap_id) + +      {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + +      assert data["type"] == "Block" +      assert data["object"] == user.ap_id +      assert data["actor"] == "https://mastodon.example.org/users/admin" + +      blocker = User.get_by_ap_id(data["actor"]) + +      assert User.blocks?(blocker, user.ap_id) +    end + +    test "it works for incoming unblocks" do +      user = insert(:user) + +      block_data = +        File.read!("test/fixtures/mastodon-block-activity.json") +        |> Poison.decode!() +        |> Map.put("object", user.ap_id) + +      {:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data) + +      data = +        File.read!("test/fixtures/mastodon-unblock-activity.json") +        |> Poison.decode!() +        |> Map.put("object", block_data) + +      {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) +      assert data["type"] == "Undo" +      assert data["object"]["type"] == "Block" +      assert data["object"]["object"] == user.ap_id +      assert data["actor"] == "https://mastodon.example.org/users/admin" + +      blocker = User.get_by_ap_id(data["actor"]) + +      refute User.blocks?(blocker, user.ap_id) +    end    end    describe "prepare outgoing" do | 
