404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.21.106.118: ~ $
<?php

namespace Laravel\Sanctum\Tests;

use Illuminate\Foundation\Auth\User;
use Laravel\Sanctum\Contracts\HasApiTokens as HasApiTokensContract;
use Laravel\Sanctum\HasApiTokens;
use Laravel\Sanctum\PersonalAccessToken;
use Laravel\Sanctum\SanctumServiceProvider;
use Orchestra\Testbench\TestCase;

class PruneExpiredTest extends TestCase
{
    protected function getEnvironmentSetUp($app)
    {
        $app['config']->set('database.default', 'testbench');

        $app['config']->set('database.connections.testbench', [
            'driver'   => 'sqlite',
            'database' => ':memory:',
            'prefix'   => '',
        ]);
    }

    public function test_can_delete_expired_tokens_with_integer_expiration()
    {
        $this->loadLaravelMigrations(['--database' => 'testbench']);
        $this->artisan('migrate', ['--database' => 'testbench'])->run();

        config(['sanctum.expiration' => 60]);

        $user = UserForPruneExpiredTest::forceCreate([
            'name' => 'Taylor Otwell',
            'email' => 'taylor@laravel.com',
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
        ]);

        $token_1 = PersonalAccessToken::forceCreate([
            'tokenable_id' => $user->id,
            'tokenable_type' => get_class($user),
            'name' => 'Test_1',
            'token' => hash('sha256', 'test_1'),
            'created_at' => now()->subMinutes(181),
        ]);

        $token_2 = PersonalAccessToken::forceCreate([
            'tokenable_id' => $user->id,
            'tokenable_type' => get_class($user),
            'name' => 'Test_2',
            'token' => hash('sha256', 'test_2'),
            'created_at' => now()->subMinutes(179),
        ]);

        $token_3 = PersonalAccessToken::forceCreate([
            'tokenable_id' => $user->id,
            'tokenable_type' => get_class($user),
            'name' => 'Test_3',
            'token' => hash('sha256', 'test_3'),
            'created_at' => now()->subMinutes(121),
        ]);

        $this->artisan('sanctum:prune-expired --hours=2')
            ->expectsOutputToContain('Tokens expired for more than [2 hours] pruned successfully.');

        $this->assertDatabaseMissing('personal_access_tokens', ['name' => 'Test_1']);
        $this->assertDatabaseHas('personal_access_tokens', ['name' => 'Test_2']);
        $this->assertDatabaseHas('personal_access_tokens', ['name' => 'Test_3']);
    }

    public function test_cant_delete_expired_tokens_with_null_expiration()
    {
        $this->loadLaravelMigrations(['--database' => 'testbench']);
        $this->artisan('migrate', ['--database' => 'testbench'])->run();

        config(['sanctum.expiration' => null]);

        $user = UserForPruneExpiredTest::forceCreate([
            'name' => 'Taylor Otwell',
            'email' => 'taylor@laravel.com',
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
        ]);

        $token = PersonalAccessToken::forceCreate([
            'tokenable_id' => $user->id,
            'tokenable_type' => get_class($user),
            'name' => 'Test',
            'token' => hash('sha256', 'test'),
            'created_at' => now()->subMinutes(70),
        ]);

        $this->artisan('sanctum:prune-expired --hours=2')
            ->expectsOutputToContain('Expiration value not specified in configuration file.');

        $this->assertDatabaseHas('personal_access_tokens', ['name' => 'Test']);
    }

    public function test_can_delete_expired_tokens_with_expires_at_expiration()
    {
        $this->loadLaravelMigrations(['--database' => 'testbench']);
        $this->artisan('migrate', ['--database' => 'testbench'])->run();

        config(['sanctum.expiration' => 60]);

        $user = UserForPruneExpiredTest::forceCreate([
            'name' => 'Taylor Otwell',
            'email' => 'taylor@laravel.com',
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
        ]);

        $token_1 = PersonalAccessToken::forceCreate([
            'tokenable_id' => $user->id,
            'tokenable_type' => get_class($user),
            'name' => 'Test_1',
            'token' => hash('sha256', 'test_1'),
            'expires_at' => now()->subMinutes(121),
        ]);

        $token_2 = PersonalAccessToken::forceCreate([
            'tokenable_id' => $user->id,
            'tokenable_type' => get_class($user),
            'name' => 'Test_2',
            'token' => hash('sha256', 'test_2'),
            'expires_at' => now()->subMinutes(119),
        ]);

        $token_3 = PersonalAccessToken::forceCreate([
            'tokenable_id' => $user->id,
            'tokenable_type' => get_class($user),
            'name' => 'Test_3',
            'token' => hash('sha256', 'test_3'),
            'expires_at' => null,
        ]);

        $this->artisan('sanctum:prune-expired --hours=2')
            ->expectsOutputToContain('Tokens expired for more than [2 hours] pruned successfully.');

        $this->assertDatabaseMissing('personal_access_tokens', ['name' => 'Test_1']);
        $this->assertDatabaseHas('personal_access_tokens', ['name' => 'Test_2']);
        $this->assertDatabaseHas('personal_access_tokens', ['name' => 'Test_3']);
    }

    protected function getPackageProviders($app)
    {
        return [SanctumServiceProvider::class];
    }
}

class UserForPruneExpiredTest extends User implements HasApiTokensContract
{
    use HasApiTokens;

    protected $table = 'users';
}

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