AnnounceTest.php 6.5 KB

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