AnnounceTest.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace Tests\Unit\ActivityPub\Verb;
  3. use App\Util\ActivityPub\Validator\Announce;
  4. use Tests\TestCase;
  5. class AnnounceTest extends TestCase
  6. {
  7. protected array $validAnnounce;
  8. protected array $invalidAnnounce;
  9. protected array $invalidDate;
  10. protected array $contextMissing;
  11. protected array $audienceMissing;
  12. protected array $audienceMissing2;
  13. protected array $invalidActor;
  14. protected array $invalidActor2;
  15. protected array $mastodonAnnounce;
  16. public function setUp(): void
  17. {
  18. parent::setUp();
  19. $this->validAnnounce = [
  20. '@context' => 'https://www.w3.org/ns/activitystreams',
  21. 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
  22. 'type' => 'Announce',
  23. 'actor' => 'https://example.org/users/alice',
  24. 'published' => '2018-12-31T23:59:59Z',
  25. 'to' => [
  26. 'https://www.w3.org/ns/activitystreams#Public'
  27. ],
  28. 'cc' => [
  29. 'https://example.org/users/bob',
  30. 'https://example.org/users/alice/followers'
  31. ],
  32. 'object' => 'https://example.org/p/bob/100000000000000',
  33. ];
  34. $this->invalidAnnounce = [
  35. '@context' => 'https://www.w3.org/ns/activitystreams',
  36. 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
  37. 'type' => 'Announce2',
  38. 'actor' => 'https://example.org/users/alice',
  39. 'published' => '2018-12-31T23:59:59Z',
  40. 'to' => [
  41. 'https://www.w3.org/ns/activitystreams#Public'
  42. ],
  43. 'cc' => [
  44. 'https://example.org/users/bob',
  45. 'https://example.org/users/alice/followers'
  46. ],
  47. 'object' => 'https://example.org/p/bob/100000000000000',
  48. ];
  49. $this->contextMissing = [
  50. 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
  51. 'type' => 'Announce',
  52. 'actor' => 'https://example.org/users/alice',
  53. 'published' => '2018-12-31T23:59:59Z',
  54. 'to' => [
  55. 'https://www.w3.org/ns/activitystreams#Public'
  56. ],
  57. 'cc' => [
  58. 'https://example.org/users/bob',
  59. 'https://example.org/users/alice/followers'
  60. ],
  61. 'object' => 'https://example.org/p/bob/100000000000000',
  62. ];
  63. $this->invalidActor = [
  64. '@context' => 'https://www.w3.org/ns/activitystreams',
  65. 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
  66. 'type' => 'Announce',
  67. 'actor' => '10000',
  68. 'published' => '2018-12-31T23:59:59Z',
  69. 'to' => [
  70. 'https://www.w3.org/ns/activitystreams#Public'
  71. ],
  72. 'cc' => [
  73. 'https://example.org/users/bob',
  74. 'https://example.org/users/alice/followers'
  75. ],
  76. 'object' => 'https://example.org/p/bob/100000000000000',
  77. ];
  78. $this->invalidActor2 = [
  79. '@context' => 'https://www.w3.org/ns/activitystreams',
  80. 'id' => 'https://example.org/users/alice/statuses/100000000000001/activity',
  81. 'type' => 'Announce',
  82. 'published' => '2018-12-31T23:59:59Z',
  83. 'to' => [
  84. 'https://www.w3.org/ns/activitystreams#Public'
  85. ],
  86. 'cc' => [
  87. 'https://example.org/users/bob',
  88. 'https://example.org/users/alice/followers'
  89. ],
  90. 'object' => 'https://example.org/p/bob/100000000000000',
  91. ];
  92. $this->mastodonAnnounce = [
  93. 'type' => 'Announce',
  94. 'to' => [
  95. 'https://www.w3.org/ns/activitystreams#Public',
  96. ],
  97. 'signature' => [
  98. 'type' => 'RsaSignature2017',
  99. 'signatureValue' => 'T95DRE0eAligvMuRMkQA01lsoz2PKi4XXF+cyZ0BqbrO12p751TEWTyyRn5a+HH0e4kc77EUhQVXwMq80WAYDzHKVUTf2XBJPBa68vl0j6RXw3+HK4ef5hR4KWFNBU34yePS7S1fEmc1mTG4Yx926wtmZwDpEMTp1CXOeVEjCYzmdyHpepPPH2ZZettiacmPRSqBLPGWZoot7kH/SioIdnrMGY0I7b+rqkIdnnEcdhu9N1BKPEO9Sr+KmxgAUiidmNZlbBXX6gCxp8BiIdH4ABsIcwoDcGNkM5EmWunGW31LVjsEQXhH5c1Wly0ugYYPCg/0eHLNBOhKkY/teSM8Lg==',
  100. 'creator' => 'https://mastodon.example.org/users/admin#main-key',
  101. 'created' => '2018-02-17T19:39:15Z',
  102. ],
  103. 'published' => '2018-02-17T19:39:15Z',
  104. 'object' => 'https://mastodon.example.org/@admin/99541947525187367',
  105. 'id' => 'https://mastodon.example.org/users/admin/statuses/99542391527669785/activity',
  106. 'cc' => [
  107. 'https://mastodon.example.org/users/admin',
  108. 'https://mastodon.example.org/users/admin/followers',
  109. ],
  110. 'atomUri' => 'https://mastodon.example.org/users/admin/statuses/99542391527669785/activity',
  111. 'actor' => 'https://mastodon.example.org/users/admin',
  112. '@context' => [
  113. 'https://www.w3.org/ns/activitystreams',
  114. 'https://w3id.org/security/v1',
  115. [
  116. 'toot' => 'https://joinmastodon.org/ns#',
  117. 'sensitive' => 'as:sensitive',
  118. 'ostatus' => 'https://ostatus.org#',
  119. 'movedTo' => 'as:movedTo',
  120. 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
  121. 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
  122. 'conversation' => 'ostatus:conversation',
  123. 'atomUri' => 'ostatus:atomUri',
  124. 'Hashtag' => 'as:Hashtag',
  125. 'Emoji' => 'toot:Emoji',
  126. ],
  127. ],
  128. ];
  129. }
  130. /** @test */
  131. public function basic_accept()
  132. {
  133. $this->assertTrue(Announce::validate($this->validAnnounce));
  134. }
  135. /** @test */
  136. public function invalid_accept()
  137. {
  138. $this->assertFalse(Announce::validate($this->invalidAnnounce));
  139. }
  140. /** @test */
  141. public function context_missing()
  142. {
  143. $this->assertFalse(Announce::validate($this->contextMissing));
  144. }
  145. /** @test */
  146. public function invalid_actor()
  147. {
  148. $this->assertFalse(Announce::validate($this->invalidActor));
  149. $this->assertFalse(Announce::validate($this->invalidActor2));
  150. }
  151. /** @test */
  152. public function mastodon_announce()
  153. {
  154. $this->assertTrue(Announce::validate($this->mastodonAnnounce));
  155. }
  156. }