-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test Improvements Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
- Loading branch information
Showing
8 changed files
with
129 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
providers: | ||
- Laravel\Passport\PassportServiceProvider | ||
|
||
migrations: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,50 +4,26 @@ | |
|
||
use Carbon\CarbonImmutable; | ||
use Illuminate\Contracts\Hashing\Hasher; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
use Laravel\Passport\Client; | ||
use Laravel\Passport\Database\Factories\ClientFactory; | ||
use Laravel\Passport\HasApiTokens; | ||
use Laravel\Passport\Passport; | ||
use Laravel\Passport\PersonalAccessTokenFactory; | ||
use Laravel\Passport\Token; | ||
use Orchestra\Testbench\Concerns\WithLaravelMigrations; | ||
use Workbench\Database\Factories\UserFactory; | ||
|
||
class AccessTokenControllerTest extends PassportTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create('users', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('email')->unique(); | ||
$table->string('password'); | ||
$table->dateTime('created_at'); | ||
$table->dateTime('updated_at'); | ||
}); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
Schema::dropIfExists('users'); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
protected function getUserClass() | ||
{ | ||
return User::class; | ||
} | ||
use WithLaravelMigrations; | ||
|
||
public function testGettingAccessTokenWithClientCredentialsGrant() | ||
{ | ||
$this->withoutExceptionHandling(); | ||
|
||
$user = new User(); | ||
$user->email = '[email protected]'; | ||
$user->password = $this->app->make(Hasher::class)->make('foobar123'); | ||
$user->save(); | ||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => $this->app->make(Hasher::class)->make('foobar123'), | ||
]); | ||
|
||
/** @var Client $client */ | ||
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->getKey()]); | ||
|
@@ -87,10 +63,10 @@ public function testGettingAccessTokenWithClientCredentialsGrant() | |
|
||
public function testGettingAccessTokenWithClientCredentialsGrantInvalidClientSecret() | ||
{ | ||
$user = new User(); | ||
$user->email = '[email protected]'; | ||
$user->password = $this->app->make(Hasher::class)->make('foobar123'); | ||
$user->save(); | ||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => $this->app->make(Hasher::class)->make('foobar123'), | ||
]); | ||
|
||
/** @var Client $client */ | ||
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->getKey()]); | ||
|
@@ -131,10 +107,10 @@ public function testGettingAccessTokenWithPasswordGrant() | |
$this->withoutExceptionHandling(); | ||
|
||
$password = 'foobar123'; | ||
$user = new User(); | ||
$user->email = '[email protected]'; | ||
$user->password = $this->app->make(Hasher::class)->make($password); | ||
$user->save(); | ||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => $this->app->make(Hasher::class)->make($password), | ||
]); | ||
|
||
/** @var Client $client */ | ||
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->getKey()]); | ||
|
@@ -178,10 +154,10 @@ public function testGettingAccessTokenWithPasswordGrant() | |
public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword() | ||
{ | ||
$password = 'foobar123'; | ||
$user = new User(); | ||
$user->email = '[email protected]'; | ||
$user->password = $this->app->make(Hasher::class)->make($password); | ||
$user->save(); | ||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => $this->app->make(Hasher::class)->make($password), | ||
]); | ||
|
||
/** @var Client $client */ | ||
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->getKey()]); | ||
|
@@ -221,10 +197,10 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword() | |
public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret() | ||
{ | ||
$password = 'foobar123'; | ||
$user = new User(); | ||
$user->email = '[email protected]'; | ||
$user->password = $this->app->make(Hasher::class)->make($password); | ||
$user->save(); | ||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => $this->app->make(Hasher::class)->make($password), | ||
]); | ||
|
||
/** @var Client $client */ | ||
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->getKey()]); | ||
|
@@ -268,10 +244,10 @@ public function testGettingCustomResponseType() | |
$this->withoutExceptionHandling(); | ||
Passport::$authorizationServerResponseType = new IdTokenResponse('foo_bar_open_id_token'); | ||
|
||
$user = new User(); | ||
$user->email = '[email protected]'; | ||
$user->password = $this->app->make(Hasher::class)->make('foobar123'); | ||
$user->save(); | ||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => $this->app->make(Hasher::class)->make('foobar123'), | ||
]); | ||
|
||
/** @var Client $client */ | ||
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->getKey()]); | ||
|
@@ -294,11 +270,6 @@ public function testGettingCustomResponseType() | |
} | ||
} | ||
|
||
class User extends \Illuminate\Foundation\Auth\User | ||
{ | ||
use HasApiTokens; | ||
} | ||
|
||
class IdTokenResponse extends \League\OAuth2\Server\ResponseTypes\BearerTokenResponse | ||
{ | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Workbench\App\Models; | ||
|
||
use Illuminate\Foundation\Auth\User as Authenticatable; | ||
use Illuminate\Notifications\Notifiable; | ||
use Laravel\Passport\HasApiTokens; | ||
|
||
class User extends Authenticatable | ||
{ | ||
use HasApiTokens, Notifiable; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array<int, string> | ||
*/ | ||
protected $fillable = [ | ||
'name', | ||
'email', | ||
'password', | ||
]; | ||
|
||
/** | ||
* The attributes that should be hidden for serialization. | ||
* | ||
* @var array<int, string> | ||
*/ | ||
protected $hidden = [ | ||
'password', | ||
'remember_token', | ||
]; | ||
|
||
/** | ||
* The attributes that should be cast. | ||
* | ||
* @var array<string, string> | ||
*/ | ||
protected $casts = [ | ||
'email_verified_at' => 'datetime', | ||
]; | ||
} |
Oops, something went wrong.