AnnounceTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. }
  118. /** @test */
  119. public function basic_accept()
  120. {
  121. $this->assertTrue(Announce::validate($this->validAnnounce));
  122. }
  123. /** @test */
  124. public function invalid_accept()
  125. {
  126. $this->assertFalse(Announce::validate($this->invalidAnnounce));
  127. }
  128. /** @test */
  129. public function invalid_date()
  130. {
  131. $this->assertFalse(Announce::validate($this->invalidDate));
  132. }
  133. /** @test */
  134. public function context_missing()
  135. {
  136. $this->assertFalse(Announce::validate($this->contextMissing));
  137. }
  138. /** @test */
  139. public function audience_missing()
  140. {
  141. $this->assertFalse(Announce::validate($this->audienceMissing));
  142. $this->assertFalse(Announce::validate($this->audienceMissing2));
  143. }
  144. /** @test */
  145. public function invalid_actor()
  146. {
  147. $this->assertFalse(Announce::validate($this->invalidActor));
  148. $this->assertFalse(Announce::validate($this->invalidActor2));
  149. }
  150. }