die tenant admin oauth authentifizierung wurde implementiert und funktioniert jetzt. Zudem wurde das marketing frontend dashboard implementiert.
This commit is contained in:
@@ -3,11 +3,9 @@
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\VerifyEmail;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LoginTest extends TestCase
|
||||
{
|
||||
@@ -27,7 +25,8 @@ class LoginTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
$expectedDefault = rtrim(route('tenant.admin.app', absolute: false), '/').'/events';
|
||||
$response->assertRedirect($expectedDefault);
|
||||
$this->assertEquals('valid@example.com', Auth::user()->email);
|
||||
}
|
||||
|
||||
@@ -45,7 +44,8 @@ class LoginTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
$expectedDefault = rtrim(route('tenant.admin.app', absolute: false), '/').'/events';
|
||||
$response->assertRedirect($expectedDefault);
|
||||
$this->assertEquals('validuser', Auth::user()->username);
|
||||
}
|
||||
|
||||
@@ -82,10 +82,32 @@ class LoginTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect(route('dashboard', absolute: false));
|
||||
$expected = rtrim(route('tenant.admin.app', absolute: false), '/').'/events';
|
||||
$response->assertRedirect($expected);
|
||||
$response->assertSessionHas('success', 'Sie sind nun eingeloggt.');
|
||||
}
|
||||
|
||||
public function test_login_honors_return_to_parameter()
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'email' => 'return@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
'email_verified_at' => now(),
|
||||
]);
|
||||
|
||||
$target = route('tenant.admin.app', absolute: false);
|
||||
$encoded = rtrim(strtr(base64_encode($target), '+/', '-_'), '=');
|
||||
|
||||
$response = $this->post(route('login.store'), [
|
||||
'login' => 'return@example.com',
|
||||
'password' => 'password',
|
||||
'return_to' => $encoded,
|
||||
]);
|
||||
|
||||
$this->assertAuthenticated();
|
||||
$response->assertRedirect($target);
|
||||
}
|
||||
|
||||
public function test_login_redirects_unverified_user_to_verification_notice()
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
|
||||
102
tests/Feature/Auth/TenantAdminGoogleControllerTest.php
Normal file
102
tests/Feature/Auth/TenantAdminGoogleControllerTest.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
use Laravel\Socialite\Two\User as SocialiteUser;
|
||||
use Mockery;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TenantAdminGoogleControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_redirect_stores_return_to_and_issues_google_redirect(): void
|
||||
{
|
||||
$driver = Mockery::mock();
|
||||
Socialite::shouldReceive('driver')->once()->with('google')->andReturn($driver);
|
||||
$driver->shouldReceive('scopes')->once()->with(['openid', 'profile', 'email'])->andReturnSelf();
|
||||
$driver->shouldReceive('with')->once()->with(['prompt' => 'select_account'])->andReturnSelf();
|
||||
$driver->shouldReceive('redirect')->once()->andReturn(new RedirectResponse('https://accounts.google.com'));
|
||||
|
||||
$encodedReturn = rtrim(strtr(base64_encode('http://localhost/test'), '+/', '-_'), '=');
|
||||
|
||||
$response = $this->get('/event-admin/auth/google?return_to='.$encodedReturn);
|
||||
|
||||
$response->assertRedirect('https://accounts.google.com');
|
||||
$this->assertSame($encodedReturn, session('tenant_oauth_return_to'));
|
||||
}
|
||||
|
||||
public function test_callback_logs_in_tenant_admin_and_redirects_to_encoded_target(): void
|
||||
{
|
||||
$tenant = Tenant::factory()->create();
|
||||
$user = User::factory()->create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'role' => 'tenant_admin',
|
||||
]);
|
||||
|
||||
$socialiteUser = tap(new SocialiteUser)->map([
|
||||
'id' => 'google-id-123',
|
||||
'name' => 'Google Tenant Admin',
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
$driver = Mockery::mock();
|
||||
Socialite::shouldReceive('driver')->once()->with('google')->andReturn($driver);
|
||||
$driver->shouldReceive('user')->once()->andReturn($socialiteUser);
|
||||
|
||||
$targetUrl = 'http://localhost:8000/api/v1/oauth/authorize?foo=bar';
|
||||
$encodedReturn = rtrim(strtr(base64_encode($targetUrl), '+/', '-_'), '=');
|
||||
|
||||
$this->withSession([
|
||||
'tenant_oauth_return_to' => $encodedReturn,
|
||||
]);
|
||||
|
||||
$response = $this->get('/event-admin/auth/google/callback');
|
||||
|
||||
$response->assertRedirect($targetUrl);
|
||||
$this->assertAuthenticatedAs($user);
|
||||
}
|
||||
|
||||
public function test_callback_redirects_back_when_user_not_found(): void
|
||||
{
|
||||
$socialiteUser = tap(new SocialiteUser)->map([
|
||||
'id' => 'missing-user',
|
||||
'name' => 'Unknown User',
|
||||
'email' => 'unknown@example.com',
|
||||
]);
|
||||
|
||||
$driver = Mockery::mock();
|
||||
Socialite::shouldReceive('driver')->once()->with('google')->andReturn($driver);
|
||||
$driver->shouldReceive('user')->once()->andReturn($socialiteUser);
|
||||
|
||||
$response = $this->get('/event-admin/auth/google/callback');
|
||||
|
||||
$response->assertRedirect();
|
||||
$this->assertStringContainsString('error=google_no_match', $response->headers->get('Location'));
|
||||
$this->assertFalse(Auth::check());
|
||||
}
|
||||
|
||||
public function test_callback_handles_socialite_failure(): void
|
||||
{
|
||||
$driver = Mockery::mock();
|
||||
Socialite::shouldReceive('driver')->once()->with('google')->andReturn($driver);
|
||||
$driver->shouldReceive('user')->once()->andThrow(new \RuntimeException('boom'));
|
||||
|
||||
$response = $this->get('/event-admin/auth/google/callback');
|
||||
|
||||
$response->assertRedirect();
|
||||
$this->assertStringContainsString('error=google_failed', $response->headers->get('Location'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user