1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Firesphere\GraphQLJWT\Tests; |
4
|
|
|
|
5
|
|
|
use Firesphere\GraphQLJWT\CreateTokenMutationCreator; |
6
|
|
|
use Firesphere\GraphQLJWT\JWTAuthenticator; |
7
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
|
|
|
8
|
|
|
use SilverStripe\Core\Config\Config; |
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
11
|
|
|
use SilverStripe\Security\Member; |
12
|
|
|
|
13
|
|
|
class CreateTokenMutationCreatorTest extends SapphireTest |
14
|
|
|
{ |
15
|
|
|
protected static $fixture_file = '../fixtures/JWTAuthenticatorTest.yml'; |
16
|
|
|
|
17
|
|
|
protected $member; |
18
|
|
|
|
19
|
|
|
public function setUp() |
20
|
|
|
{ |
21
|
|
|
putenv('JWT_SIGNER_KEY=test_signer'); |
22
|
|
|
|
23
|
|
|
parent::setUp(); |
24
|
|
|
$this->member = $this->objFromFixture(Member::class, 'admin'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function tearDown() |
28
|
|
|
{ |
29
|
|
|
parent::tearDown(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testResolveValid() |
33
|
|
|
{ |
34
|
|
|
$createToken = Injector::inst()->get(CreateTokenMutationCreator::class); |
35
|
|
|
|
36
|
|
|
$response = $createToken->resolve(null, ['Email' => '[email protected]', 'Password' => 'error'], [], |
37
|
|
|
new ResolveInfo([])); |
38
|
|
|
|
39
|
|
|
$this->assertTrue($response instanceof Member); |
40
|
|
|
$this->assertNotNull($response->Token); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function testResolveInvalidWithAllowedAnonymous() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
Config::modify()->set(JWTAuthenticator::class, 'anonymous_allowed', true); |
46
|
|
|
$authenticator = Injector::inst()->get(CreateTokenMutationCreator::class); |
47
|
|
|
|
48
|
|
|
$response = $authenticator->resolve(null, ['Email' => '[email protected]', 'Password' => 'wrong'], [], |
49
|
|
|
new ResolveInfo([])); |
50
|
|
|
|
51
|
|
|
$this->assertTrue($response instanceof Member); |
52
|
|
|
$this->assertEquals(0, $response->ID); |
53
|
|
|
$this->assertNotNull($response->Token); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function testResolveInvalidWithoutAllowedAnonymous() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
Config::modify()->set(JWTAuthenticator::class, 'anonymous_allowed', false); |
59
|
|
|
$authenticator = Injector::inst()->get(CreateTokenMutationCreator::class); |
60
|
|
|
|
61
|
|
|
$response = $authenticator->resolve(null, ['Email' => '[email protected]', 'Password' => 'wrong'], [], |
62
|
|
|
new ResolveInfo([])); |
63
|
|
|
|
64
|
|
|
$this->assertTrue($response instanceof Member); |
65
|
|
|
$this->assertNull($response->Token); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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