|
@@ 294-337 (lines=44) @@
|
| 291 |
|
$this->assertFalse($check && $check->exists()); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
public function testSpamComment() |
| 295 |
|
{ |
| 296 |
|
// Test anonymous user |
| 297 |
|
if ($member = Member::currentUser()) { |
| 298 |
|
$member->logOut(); |
| 299 |
|
} |
| 300 |
|
$comment = $this->objFromFixture(Comment::class, 'firstComA'); |
| 301 |
|
$commentID = $comment->ID; |
| 302 |
|
$this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link'); |
| 303 |
|
$spam = $this->get('comments/spam/'.$comment->ID.'?ajax=1'); |
| 304 |
|
$this->assertEquals(403, $spam->getStatusCode()); |
| 305 |
|
$check = DataObject::get_by_id(Comment::class, $commentID); |
| 306 |
|
$this->assertEquals(0, $check->IsSpam, 'No permission to mark as spam'); |
| 307 |
|
|
| 308 |
|
// Test non-authenticated user |
| 309 |
|
$this->logInAs('visitor'); |
| 310 |
|
$this->assertNull($comment->SpamLink(), 'No permission to see mark as spam link'); |
| 311 |
|
|
| 312 |
|
// Test authenticated user |
| 313 |
|
$this->logInAs('commentadmin'); |
| 314 |
|
$comment = $this->objFromFixture(Comment::class, 'firstComA'); |
| 315 |
|
$commentID = $comment->ID; |
| 316 |
|
$adminComment1Link = $comment->SpamLink(); |
| 317 |
|
$this->assertContains('comments/spam/' . $commentID . '?t=', $adminComment1Link); |
| 318 |
|
|
| 319 |
|
// Test that this link can't be shared / XSS exploited |
| 320 |
|
$this->logInAs('commentadmin2'); |
| 321 |
|
$spam = $this->get($adminComment1Link); |
| 322 |
|
$this->assertEquals(400, $spam->getStatusCode()); |
| 323 |
|
$check = DataObject::get_by_id(Comment::class, $comment->ID); |
| 324 |
|
$this->assertEquals(0, $check->IsSpam, 'No permission to mark as spam'); |
| 325 |
|
|
| 326 |
|
// Test that this other admin can spam the comment with their own link |
| 327 |
|
$adminComment2Link = $comment->SpamLink(); |
| 328 |
|
$this->assertNotEquals($adminComment2Link, $adminComment1Link); |
| 329 |
|
$this->autoFollowRedirection = false; |
| 330 |
|
$spam = $this->get($adminComment2Link); |
| 331 |
|
$this->assertEquals(302, $spam->getStatusCode()); |
| 332 |
|
$check = DataObject::get_by_id(Comment::class, $commentID); |
| 333 |
|
$this->assertEquals(1, $check->IsSpam); |
| 334 |
|
|
| 335 |
|
// Cannot re-spam spammed comment |
| 336 |
|
$this->assertNull($check->SpamLink()); |
| 337 |
|
} |
| 338 |
|
|
| 339 |
|
public function testHamComment() |
| 340 |
|
{ |
|
@@ 339-382 (lines=44) @@
|
| 336 |
|
$this->assertNull($check->SpamLink()); |
| 337 |
|
} |
| 338 |
|
|
| 339 |
|
public function testHamComment() |
| 340 |
|
{ |
| 341 |
|
// Test anonymous user |
| 342 |
|
if ($member = Member::currentUser()) { |
| 343 |
|
$member->logOut(); |
| 344 |
|
} |
| 345 |
|
$comment = $this->objFromFixture(Comment::class, 'secondComC'); |
| 346 |
|
$commentID = $comment->ID; |
| 347 |
|
$this->assertNull($comment->HamLink(), 'No permission to see mark as ham link'); |
| 348 |
|
$ham = $this->get('comments/ham/' . $comment->ID . '?ajax=1'); |
| 349 |
|
$this->assertEquals(403, $ham->getStatusCode()); |
| 350 |
|
$check = DataObject::get_by_id(Comment::class, $commentID); |
| 351 |
|
$this->assertEquals(1, $check->IsSpam, 'No permission to mark as ham'); |
| 352 |
|
|
| 353 |
|
// Test non-authenticated user |
| 354 |
|
$this->logInAs('visitor'); |
| 355 |
|
$this->assertNull($comment->HamLink(), 'No permission to see mark as ham link'); |
| 356 |
|
|
| 357 |
|
// Test authenticated user |
| 358 |
|
$this->logInAs('commentadmin'); |
| 359 |
|
$comment = $this->objFromFixture(Comment::class, 'secondComC'); |
| 360 |
|
$commentID = $comment->ID; |
| 361 |
|
$adminComment1Link = $comment->HamLink(); |
| 362 |
|
$this->assertContains('comments/ham/' . $commentID . '?t=', $adminComment1Link); |
| 363 |
|
|
| 364 |
|
// Test that this link can't be shared / XSS exploited |
| 365 |
|
$this->logInAs('commentadmin2'); |
| 366 |
|
$ham = $this->get($adminComment1Link); |
| 367 |
|
$this->assertEquals(400, $ham->getStatusCode()); |
| 368 |
|
$check = DataObject::get_by_id(Comment::class, $comment->ID); |
| 369 |
|
$this->assertEquals(1, $check->IsSpam, 'No permission to mark as ham'); |
| 370 |
|
|
| 371 |
|
// Test that this other admin can ham the comment with their own link |
| 372 |
|
$adminComment2Link = $comment->HamLink(); |
| 373 |
|
$this->assertNotEquals($adminComment2Link, $adminComment1Link); |
| 374 |
|
$this->autoFollowRedirection = false; |
| 375 |
|
$ham = $this->get($adminComment2Link); |
| 376 |
|
$this->assertEquals(302, $ham->getStatusCode()); |
| 377 |
|
$check = DataObject::get_by_id(Comment::class, $commentID); |
| 378 |
|
$this->assertEquals(0, $check->IsSpam); |
| 379 |
|
|
| 380 |
|
// Cannot re-ham hammed comment |
| 381 |
|
$this->assertNull($check->HamLink()); |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
public function testApproveComment() |
| 385 |
|
{ |
|
@@ 384-427 (lines=44) @@
|
| 381 |
|
$this->assertNull($check->HamLink()); |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
public function testApproveComment() |
| 385 |
|
{ |
| 386 |
|
// Test anonymous user |
| 387 |
|
if ($member = Member::currentUser()) { |
| 388 |
|
$member->logOut(); |
| 389 |
|
} |
| 390 |
|
$comment = $this->objFromFixture(Comment::class, 'secondComB'); |
| 391 |
|
$commentID = $comment->ID; |
| 392 |
|
$this->assertNull($comment->ApproveLink(), 'No permission to see approve link'); |
| 393 |
|
$approve = $this->get('comments/approve/' . $comment->ID . '?ajax=1'); |
| 394 |
|
$this->assertEquals(403, $approve->getStatusCode()); |
| 395 |
|
$check = DataObject::get_by_id(Comment::class, $commentID); |
| 396 |
|
$this->assertEquals(0, $check->Moderated, 'No permission to approve'); |
| 397 |
|
|
| 398 |
|
// Test non-authenticated user |
| 399 |
|
$this->logInAs('visitor'); |
| 400 |
|
$this->assertNull($comment->ApproveLink(), 'No permission to see approve link'); |
| 401 |
|
|
| 402 |
|
// Test authenticated user |
| 403 |
|
$this->logInAs('commentadmin'); |
| 404 |
|
$comment = $this->objFromFixture(Comment::class, 'secondComB'); |
| 405 |
|
$commentID = $comment->ID; |
| 406 |
|
$adminComment1Link = $comment->ApproveLink(); |
| 407 |
|
$this->assertContains('comments/approve/' . $commentID . '?t=', $adminComment1Link); |
| 408 |
|
|
| 409 |
|
// Test that this link can't be shared / XSS exploited |
| 410 |
|
$this->logInAs('commentadmin2'); |
| 411 |
|
$approve = $this->get($adminComment1Link); |
| 412 |
|
$this->assertEquals(400, $approve->getStatusCode()); |
| 413 |
|
$check = DataObject::get_by_id(Comment::class, $comment->ID); |
| 414 |
|
$this->assertEquals(0, $check->Moderated, 'No permission to approve'); |
| 415 |
|
|
| 416 |
|
// Test that this other admin can approve the comment with their own link |
| 417 |
|
$adminComment2Link = $comment->ApproveLink(); |
| 418 |
|
$this->assertNotEquals($adminComment2Link, $adminComment1Link); |
| 419 |
|
$this->autoFollowRedirection = false; |
| 420 |
|
$approve = $this->get($adminComment2Link); |
| 421 |
|
$this->assertEquals(302, $approve->getStatusCode()); |
| 422 |
|
$check = DataObject::get_by_id(Comment::class, $commentID); |
| 423 |
|
$this->assertEquals(1, $check->Moderated); |
| 424 |
|
|
| 425 |
|
// Cannot re-approve approved comment |
| 426 |
|
$this->assertNull($check->ApproveLink()); |
| 427 |
|
} |
| 428 |
|
|
| 429 |
|
public function testCommenterURLWrite() |
| 430 |
|
{ |