|
<?php |
|
|
|
namespace JustPark\Tests\Unit\Auth; |
|
|
|
use JustPark\Auth\ShareableLinkAuth; |
|
|
|
class ShareableLinkAuthTest extends \PHPUnit_Framework_TestCase |
|
{ |
|
public function test_it_generates_working_link() |
|
{ |
|
$listing = \Mockery::mock('Listing')->makePartial(); |
|
$listing->id = 10; |
|
|
|
$auth = new ShareableLinkAuth('anthony'); |
|
$url = '/listings/something'; |
|
|
|
$shareableUrl = $auth->getLink($url, $listing); |
|
|
|
$this->assertTrue($auth->check($shareableUrl, $listing)); |
|
$this->assertContains('auth=', $shareableUrl); |
|
} |
|
|
|
public function test_it_cares_about_querystring() |
|
{ |
|
$listing = \Mockery::mock('Listing')->makePartial(); |
|
$listing->id = 10; |
|
|
|
$auth = new ShareableLinkAuth('anthony'); |
|
$url = '/listings/something?x=1&y=2'; |
|
|
|
$shareableUrl = $auth->getLink($url, $listing); |
|
|
|
// ensure link has parameters. |
|
$this->assertContains('?x=1&y=2', $shareableUrl); |
|
$this->assertContains('&auth=', $shareableUrl); |
|
|
|
// ensure it validates with changed parameters. |
|
$shareableUrl = str_replace('&y=2', '', $shareableUrl); |
|
|
|
$this->assertTrue($auth->check($shareableUrl, $listing)); |
|
} |
|
|
|
public function test_check_it_fails_check_with_dummy_auth() |
|
{ |
|
$listing = \Mockery::mock('Listing')->makePartial(); |
|
$listing->id = 10; |
|
|
|
$auth = new ShareableLinkAuth('anthony'); |
|
|
|
$this->assertFalse( |
|
$auth->check('/listings/something?x=1&y=2auth=bjksvdjkndvsjkbsdjsdfjkfsdhjkfsdjhkf', $listing) |
|
); |
|
} |
|
|
|
public function test_it_fails_with_wrong_model() |
|
{ |
|
$listing = \Mockery::mock('Listing')->makePartial(); |
|
$listing->id = 10; |
|
|
|
$auth = new ShareableLinkAuth('anthony'); |
|
$url = '/listings/something?x=1&y=2'; |
|
|
|
$shareableUrl = $auth->getLink($url, $listing); |
|
|
|
$listing->id = 11; |
|
|
|
$this->assertFalse($auth->check($shareableUrl, $listing)); |
|
} |
|
} |