1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Firesphere\GraphQLJWT\tests; |
4
|
|
|
|
5
|
|
|
use Firesphere\GraphQLJWT\CreateTokenMutationCreator; |
6
|
|
|
use Firesphere\GraphQLJWT\JWTAuthenticationHandler; |
7
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
|
|
|
8
|
|
|
use SilverStripe\Control\Director; |
9
|
|
|
use SilverStripe\Control\HTTPRequest; |
10
|
|
|
use SilverStripe\Core\Injector\Injector; |
11
|
|
|
use SilverStripe\Dev\SapphireTest; |
12
|
|
|
use SilverStripe\Security\Member; |
13
|
|
|
|
14
|
|
|
class JWTAuthenticationHandlerTest extends SapphireTest |
15
|
|
|
{ |
16
|
|
|
protected static $fixture_file = '../fixtures/JWTAuthenticatorTest.yml'; |
17
|
|
|
|
18
|
|
|
protected $member; |
19
|
|
|
|
20
|
|
|
protected $token; |
21
|
|
|
|
22
|
|
View Code Duplication |
public function setUp() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
putenv('JWT_SIGNER_KEY=test_signer'); |
25
|
|
|
|
26
|
|
|
parent::setUp(); |
27
|
|
|
$this->member = $this->objFromFixture(Member::class, 'admin'); |
28
|
|
|
$createToken = Injector::inst()->get(CreateTokenMutationCreator::class); |
29
|
|
|
|
30
|
|
|
$response = $createToken->resolve( |
31
|
|
|
null, |
32
|
|
|
['Email' => '[email protected]', 'Password' => 'error'], |
33
|
|
|
[], |
34
|
|
|
new ResolveInfo([]) |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$this->token = $response->Token; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function tearDown() |
41
|
|
|
{ |
42
|
|
|
parent::tearDown(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function testInvalidAuthenticateRequest() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
putenv('JWT_SIGNER_KEY=string'); |
48
|
|
|
|
49
|
|
|
$request = new HTTPRequest('POST', Director::absoluteBaseURL() . '/graphql'); |
50
|
|
|
$request->addHeader('Authorization', 'Bearer ' . $this->token); |
51
|
|
|
|
52
|
|
|
$handler = Injector::inst()->get(JWTAuthenticationHandler::class); |
53
|
|
|
|
54
|
|
|
$result = $handler->authenticateRequest($request); |
55
|
|
|
putenv('JWT_SIGNER_KEY=test_signer'); |
56
|
|
|
|
57
|
|
|
$this->assertNull($result); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testAuthenticateRequest() |
61
|
|
|
{ |
62
|
|
|
$request = new HTTPRequest('POST', Director::absoluteBaseURL() . '/graphql'); |
63
|
|
|
$request->addHeader('Authorization', 'Bearer ' . $this->token); |
64
|
|
|
|
65
|
|
|
$handler = Injector::inst()->get(JWTAuthenticationHandler::class); |
66
|
|
|
|
67
|
|
|
$result = $handler->authenticateRequest($request); |
68
|
|
|
|
69
|
|
|
$this->assertInstanceOf(Member::class, $result); |
70
|
|
|
$this->assertGreaterThan(0, $result->ID); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths