Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test to check impersonation with guards using different provider…
…s & tables
- Loading branch information
Showing
4 changed files
with
151 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Support\Facades\DB; | ||
use Carbon\Carbon; | ||
|
||
class CreateOtherUsersTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('other_users', function (Blueprint $table) | ||
{ | ||
$table->increments('id'); | ||
$table->string('name'); | ||
$table->string('email')->unique(); | ||
$table->string('password'); | ||
$table->boolean('is_admin')->default(0)->index(); | ||
$table->boolean('can_be_impersonated')->default(1)->index(); | ||
$table->rememberToken(); | ||
$table->timestamps(); | ||
}); | ||
|
||
DB::table('other_users')->insert([ | ||
[ | ||
'name' => 'OtherAdmin', | ||
'email' => 'otheradmin@test.rocks', | ||
'password' => bcrypt('password'), | ||
'is_admin' => 1, | ||
'can_be_impersonated' => 1, | ||
'created_at' => Carbon::now()->toDateTimeString(), | ||
], | ||
[ | ||
'name' => 'OtherUser', | ||
'email' => 'otheruser@test.rocks', | ||
'password' => bcrypt('password'), | ||
'is_admin' => 0, | ||
'can_be_impersonated' => 1, | ||
'created_at' => Carbon::now()->toDateTimeString(), | ||
], | ||
[ | ||
'name' => 'OtherSuperAdmin', | ||
'email' => 'othersuperadmin@test.rocks', | ||
'password' => bcrypt('password'), | ||
'is_admin' => 1, | ||
'can_be_impersonated' => 0, | ||
'created_at' => Carbon::now()->toDateTimeString(), | ||
], | ||
]); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('other_users'); | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace Lab404\Tests\Stubs\Models; | ||
|
||
use Illuminate\Notifications\Notifiable; | ||
use Illuminate\Foundation\Auth\User as Authenticatable; | ||
use Lab404\Impersonate\Models\Impersonate; | ||
|
||
class OtherUser extends Authenticatable | ||
{ | ||
use Notifiable, Impersonate; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'name', 'email', 'password', | ||
]; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $hidden = [ | ||
'password', 'remember_token', | ||
]; | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function canImpersonate() | ||
{ | ||
return $this->attributes['is_admin'] == 1; | ||
} | ||
|
||
/* | ||
* @return bool | ||
*/ | ||
public function canBeImpersonated() | ||
{ | ||
return $this->attributes['can_be_impersonated'] == 1; | ||
} | ||
|
||
|
||
public function getAuthIdentifierName() | ||
{ | ||
return 'email'; | ||
} | ||
} |
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