Skip to content

Commit b449a6e

Browse files
author
Luca Degasperi
committed
Resource Server filters are now tested, enjoy!
1 parent 24358dd commit b449a6e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/LucaDegasperi/OAuth2Server/Filters/OAuthOwnerFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace LucaDegasperi\OAuth2Server\Filters;
22

3+
use ResourceServer;
34
use Response;
45

56
class OAuthOwnerFilter {

tests/OAuthFilterTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,27 @@ public function test_invalid_filter_with_no_scope()
2626

2727
$response = $this->getFilter()->filter('', '', null);
2828
$this->assertTrue($response instanceof Illuminate\Http\JsonResponse);
29+
$this->assertTrue($response->isForbidden());
2930

30-
// to check te status code and the json payload
31+
}
32+
33+
public function test_valid_filter_with_existing_scope()
34+
{
35+
ResourceServer::shouldReceive('isValid')->once()->andReturn(true);
36+
ResourceServer::shouldReceive('hasScope')->twice()->andReturn(true);
3137

38+
$response = $this->getFilter()->filter('', '', 'scope1,scope2');
39+
$this->assertNull($response);
40+
}
41+
42+
public function test_valid_filter_with_unexisting_scope()
43+
{
44+
ResourceServer::shouldReceive('isValid')->once()->andReturn(true);
45+
ResourceServer::shouldReceive('hasScope')->once()->andReturn(false);
46+
47+
$response = $this->getFilter()->filter('', '', 'scope1,scope2');
48+
$this->assertTrue($response instanceof Illuminate\Http\JsonResponse);
49+
$this->assertTrue($response->isForbidden());
3250
}
3351

3452
public function tearDown() {

tests/OAuthOwnerFilterTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use \Mockery as m;
4+
5+
class OAuthOwnerFilterTest extends TestCase {
6+
7+
public function getFilter()
8+
{
9+
return new LucaDegasperi\OAuth2Server\Filters\OAuthOwnerFilter;
10+
}
11+
12+
public function test_with_existing_owner_type()
13+
{
14+
ResourceServer::shouldReceive('getOwnerType')->once()->andReturn('foo');
15+
16+
$response = $this->getFilter()->filter('', '', 'foo');
17+
$this->assertNull($response);
18+
}
19+
20+
public function test_with_unexisting_owner_type()
21+
{
22+
ResourceServer::shouldReceive('getOwnerType')->once()->andReturn('foo');
23+
24+
$response = $this->getFilter()->filter('', '', 'bar');
25+
$this->assertTrue($response instanceof Illuminate\Http\JsonResponse);
26+
$this->assertTrue($response->isForbidden());
27+
}
28+
29+
}

0 commit comments

Comments
 (0)