-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicProviderTest.php
62 lines (45 loc) · 1.88 KB
/
BasicProviderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Dingo\Api\Tests\Auth;
use Mockery;
use Illuminate\Http\Request;
use Dingo\Api\Routing\Route;
use Illuminate\Http\Response;
use PHPUnit_Framework_TestCase;
use Dingo\Api\Auth\BasicProvider;
class BasicProviderTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->auth = Mockery::mock('Illuminate\Auth\AuthManager');
$this->provider = new BasicProvider($this->auth);
}
public function tearDown()
{
Mockery::close();
}
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
*/
public function testInvalidBasicCredentialsThrowsException()
{
$request = Request::create('GET', '/', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic 12345']);
$this->auth->shouldReceive('onceBasic')->once()->with('email', $request)->andReturn(new Response('', 401));
$this->provider->authenticate($request, new Route(['GET'], '/', []));
}
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
*/
public function testNullResponseFromAuthManagerThrowsException()
{
$request = Request::create('GET', '/', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic 12345']);
$this->auth->shouldReceive('onceBasic')->once()->with('email', $request)->andReturn(null);
$this->provider->authenticate($request, new Route(['GET'], '/', []));
}
public function testValidCredentialsReturnsUser()
{
$request = Request::create('GET', '/', [], [], [], ['HTTP_AUTHORIZATION' => 'Basic 12345']);
$this->auth->shouldReceive('onceBasic')->once()->with('email', $request)->andReturn(new Response('', 200));
$this->auth->shouldReceive('user')->once()->andReturn('foo');
$this->assertEquals('foo', $this->provider->authenticate($request, new Route(['GET'], '/', [])));
}
}