generated from biigle/module
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
322 additions
and
2 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,30 @@ | ||
<?php | ||
|
||
namespace Biigle\Modules\AuthLSLogin\Database\Factories; | ||
|
||
use Biigle\Modules\AuthLSLogin\LsloginId; | ||
use Biigle\User; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class LsloginIdFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = LsloginId::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'id' => $this->faker->uuid(), | ||
'user_id' => User::factory(), | ||
]; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Database/migrations/2023_04_25_122133_create_lslogin_ids_table.php
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,38 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('lslogin_ids', function (Blueprint $table) { | ||
// The ID can be anything, really, but we hope that it's not longer than | ||
// 128 characters. | ||
$table->string('id', 128)->primary(); | ||
|
||
$table->timestamps(); | ||
|
||
$table->foreignId('user_id') | ||
->constrained() | ||
->cascadeOnDelete(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('lslogin_ids'); | ||
} | ||
}; |
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,13 @@ | ||
<?php | ||
|
||
namespace Biigle\Modules\AuthLSLogin\Http\Controllers; | ||
|
||
use Biigle\Http\Controllers\Auth\RegisterController as BaseController; | ||
use Laravel\Socialite\Facades\Socialite; | ||
|
||
class RegisterController extends BaseController | ||
{ | ||
// Handle disabled user registration (show error message) | ||
// | ||
// Reuse parent class code as much as possible (with optional required terms etc) | ||
} |
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,55 @@ | ||
<?php | ||
|
||
namespace Biigle\Modules\AuthLSLogin; | ||
|
||
use Biigle\Modules\AuthLSLogin\Database\Factories\LsloginIdFactory; | ||
use Biigle\User; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class LsloginId extends Model | ||
{ | ||
use HasFactory; | ||
|
||
/** | ||
* Indicates if the model's ID is auto-incrementing. | ||
* | ||
* @var bool | ||
*/ | ||
public $incrementing = false; | ||
|
||
/** | ||
* The data type of the auto-incrementing ID. | ||
* | ||
* @var string | ||
*/ | ||
protected $keyType = 'string'; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'id', | ||
'user_id', | ||
]; | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
*/ | ||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
/** | ||
* Create a new factory instance for the model. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Factories\Factory | ||
*/ | ||
protected static function newFactory() | ||
{ | ||
return LsloginIdFactory::new(); | ||
} | ||
} |
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,79 @@ | ||
<?php | ||
|
||
namespace Biigle\Tests\Modules\AuthLSLogin\Http\Controllers; | ||
|
||
use Biigle\Modules\AuthLSLogin\LsloginId; | ||
use Biigle\User; | ||
use Laravel\Socialite\Facades\Socialite; | ||
use Laravel\Socialite\Two\User as SocialiteUser; | ||
use Session; | ||
use TestCase; | ||
|
||
|
||
class LSLoginControllerTest extends TestCase | ||
{ | ||
public function testRedirect() | ||
{ | ||
$this->get('auth/lslogin/redirect') | ||
->assertRedirectContains('https://proxy.aai.lifescience-ri.eu'); | ||
} | ||
|
||
public function testCallbackNewUser() | ||
{ | ||
$user = new SocialiteUser; | ||
$user->setToken('mytoken'); | ||
Socialite::shouldReceive('driver->user')->andReturn($user); | ||
|
||
$this->get('auth/lslogin/callback') | ||
->assertSessionHas('lslogin-token', 'mytoken') | ||
->assertRedirectToRoute('lslogin-register-form'); | ||
} | ||
|
||
public function testCallbackConflictingNewEmail() | ||
{ | ||
// The LSLogin ID does not exist yet but a user with the email address exists. | ||
// Show an error message and suggest to connect the existing account | ||
// (i.e. log in to the account and then connect via settings). | ||
$this->markTestIncomplete(); | ||
} | ||
|
||
public function testCallbackExistingUser() | ||
{ | ||
$id = LsloginId::factory()->create(); | ||
$user = new SocialiteUser; | ||
$user->map(['id' => $id->id]); | ||
Socialite::shouldReceive('driver->user')->andReturn($user); | ||
|
||
$this->get('auth/lslogin/callback')->assertRedirectToRoute('home'); | ||
$this->assertAuthenticatedAs($id->user); | ||
} | ||
|
||
public function testCallbackConnectWithUser() | ||
{ | ||
|
||
$user = new SocialiteUser; | ||
$user->map(['id' => 'myspecialid']); | ||
Socialite::shouldReceive('driver->user')->andReturn($user); | ||
|
||
$user = User::factory()->create(); | ||
$this->be($user); | ||
$this->get('auth/lslogin/callback')->assertRedirectToRoute('home'); | ||
$this->assertAuthenticatedAs($user); | ||
$this->assertTrue(LsloginId::where('user_id', $user->id)->where('id', 'myspecialid')->exists()); | ||
$this->markTestIncomplete('redirect to the third party auth settings view'); | ||
} | ||
|
||
public function testCallbackConnectConflictingIDExists() | ||
{ | ||
// A user is already authenticated but the LSLogin ID is already connected to a | ||
// different user. Show an error message. | ||
$this->markTestIncomplete(); | ||
} | ||
|
||
public function testCallbackConnectAlreadyConnected() | ||
{ | ||
// A user is authenticated and the LSLogin ID is already connected to the user. | ||
// Redirect to the dashboard and do nothing. | ||
$this->markTestIncomplete(); | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
namespace Biigle\Tests\Modules\AuthLSLogin\Http\Controllers; | ||
|
||
use Biigle\User; | ||
use Laravel\Socialite\Facades\Socialite; | ||
use Laravel\Socialite\Two\User as SocialiteUser; | ||
use Session; | ||
use TestCase; | ||
|
||
|
||
class RegisterControllerTest extends TestCase | ||
{ | ||
public function testShowRegistrationForm() | ||
{ | ||
// user should enter affiliation and check terms/privacy | ||
} | ||
|
||
public function testShowRegistrationFormWithoutToken() | ||
{ | ||
// | ||
} | ||
|
||
public function testShowRegistrationFormAuthenticated() | ||
{ | ||
// | ||
} | ||
|
||
public function testShowRegistrationFormDisabledRegistration() | ||
{ | ||
// | ||
} | ||
|
||
public function testRegister() | ||
{ | ||
// should not require honeypot if the token is in the session | ||
} | ||
|
||
public function testRegisterEmailTaken() | ||
{ | ||
// case insensitive | ||
} | ||
|
||
public function testRegisterWithoutToken() | ||
{ | ||
// | ||
} | ||
|
||
public function testRegisterDisabledRegistration() | ||
{ | ||
// | ||
} | ||
|
||
public function testRegisterAuthenticated() | ||
{ | ||
// | ||
} | ||
|
||
public function testRegisterAdminConfirmationDisabled() | ||
{ | ||
// | ||
} | ||
|
||
public function testRegisterAdminConfirmationEnabled() | ||
{ | ||
// | ||
} | ||
} |