404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.116.88.132: ~ $
<?php

namespace Laravel\Sanctum\Tests;

use Laravel\Sanctum\Http\Middleware\CheckForAnyScope as CheckScopes;
use Mockery;
use PHPUnit\Framework\TestCase;

class CheckForAnyScopeTest extends TestCase
{
    protected function tearDown(): void
    {
        parent::tearDown();

        Mockery::close();
    }

    public function test_request_is_passed_along_if_scopes_are_present_on_token()
    {
        $middleware = new CheckScopes;
        $request = Mockery::mock();
        $request->shouldReceive('user')->andReturn($user = Mockery::mock());
        $user->shouldReceive('currentAccessToken')->andReturn($token = Mockery::mock());
        $user->shouldReceive('tokenCan')->with('foo')->andReturn(true);
        $user->shouldReceive('tokenCan')->with('bar')->andReturn(false);

        $response = $middleware->handle($request, function () {
            return 'response';
        }, 'foo', 'bar');

        $this->assertSame('response', $response);
    }

    public function test_exception_is_thrown_if_token_doesnt_have_scope()
    {
        $this->expectException('Laravel\Sanctum\Exceptions\MissingScopeException');

        $middleware = new CheckScopes;
        $request = Mockery::mock();
        $request->shouldReceive('user')->andReturn($user = Mockery::mock());
        $user->shouldReceive('currentAccessToken')->andReturn($token = Mockery::mock());
        $user->shouldReceive('tokenCan')->with('foo')->andReturn(false);
        $user->shouldReceive('tokenCan')->with('bar')->andReturn(false);

        $middleware->handle($request, function () {
            return 'response';
        }, 'foo', 'bar');
    }

    public function test_exception_is_thrown_if_no_authenticated_user()
    {
        $this->expectException('Illuminate\Auth\AuthenticationException');

        $middleware = new CheckScopes;
        $request = Mockery::mock();
        $request->shouldReceive('user')->once()->andReturn(null);

        $middleware->handle($request, function () {
            return 'response';
        }, 'foo', 'bar');
    }

    public function test_exception_is_thrown_if_no_token()
    {
        $this->expectException('Illuminate\Auth\AuthenticationException');

        $middleware = new CheckScopes;
        $request = Mockery::mock();
        $request->shouldReceive('user')->andReturn($user = Mockery::mock());
        $user->shouldReceive('currentAccessToken')->andReturn(null);

        $middleware->handle($request, function () {
            return 'response';
        }, 'foo', 'bar');
    }
}

Filemanager

Name Type Size Permission Actions
ActingAsTest.php File 4.66 KB 0644
CheckAbilitiesTest.php File 2.47 KB 0644
CheckForAnyAbilityTest.php File 2.56 KB 0644
CheckForAnyScopeTest.php File 2.54 KB 0644
CheckScopesTest.php File 2.44 KB 0644
DefaultConfigContainsAppUrlTest.php File 1.53 KB 0644
EnsureFrontendRequestsAreStatefulTest.php File 2.65 KB 0644
GuardTest.php File 18.88 KB 0644
HasApiTokensTest.php File 1.52 KB 0644
PersonalAccessTokenTest.php File 766 B 0644
PruneExpiredTest.php File 5.55 KB 0644
TransientTokenTest.php File 482 B 0644