the browser-facing portion of osu!
at master 49 lines 1.5 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace Tests\Commands; 7 8use App\Models\User; 9use DB; 10use Laravel\Passport\Token; 11use Tests\TestCase; 12 13class OAuthDeleteExpiredTokensTest extends TestCase 14{ 15 public function testDeleteAccessTokens() 16 { 17 config_set('osu.oauth.retain_expired_tokens_days', 0); 18 19 $user = User::factory()->create(); 20 $tokenAttributes = [ 21 'client_id' => 1, // irrelevant. 22 'expires_at' => now()->subDays(1), 23 'revoked' => false, 24 'scopes' => ['identify'], 25 'user_id' => $user->getKey(), 26 ]; 27 $token1 = Token::create(array_merge(['id' => 1], $tokenAttributes)); 28 $token2 = Token::create(array_merge(['id' => 2], $tokenAttributes)); 29 30 DB::table('oauth_refresh_tokens')->insert([ 31 'access_token_id' => $token1->id, 32 'expires_at' => now()->subDays(1), 33 'id' => 1, 34 'revoked' => 0, 35 ]); 36 37 DB::table('oauth_refresh_tokens')->insert([ 38 'access_token_id' => $token2->id, 39 'expires_at' => now()->addDays(1), 40 'id' => 2, 41 'revoked' => 0, 42 ]); 43 44 $this->artisan('oauth:delete-expired-tokens'); 45 46 $this->assertNull(Token::find($token1->id)); 47 $this->assertNotNull(Token::find($token2->id)); 48 } 49}