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