Herzen, Reichweite und App-Anbindung (0.30.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m10s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 6m3s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m33s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m25s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m28s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m27s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m26s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m27s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m12s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m10s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 6m3s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m33s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m25s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m28s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m27s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m26s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m27s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m12s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d9fcc7a9b4
commit
b3e2b525e1
161 changed files with 1249 additions and 342 deletions
104
tests/Feature/Mobile/AppConnectTest.php
Normal file
104
tests/Feature/Mobile/AppConnectTest.php
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Mobile;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use App\Push\AppDevice;
|
||||
use App\Push\ExpoPush;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AppConnectTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function pkce(): array
|
||||
{
|
||||
$verifier = str_repeat('a1B2c3D4', 6);
|
||||
|
||||
return [$verifier, rtrim(strtr(base64_encode(hash('sha256', $verifier, true)), '+/', '-_'), '=')];
|
||||
}
|
||||
|
||||
public function test_config_is_public(): void
|
||||
{
|
||||
$this->getJson('/api/v1/config')->assertOk()
|
||||
->assertJsonStructure(['name', 'primary_color', 'logo_url', 'icon_url', 'login' => ['password', 'browser', 'providers'], 'connect_url']);
|
||||
}
|
||||
|
||||
public function test_browser_connect_hands_out_a_one_time_code_for_the_app(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
[$verifier, $challenge] = $this->pkce();
|
||||
$query = ['redirect_uri' => 'inhaus://verbunden', 'device_name' => 'Pixel 9', 'code_challenge' => $challenge, 'state' => 'xyz'];
|
||||
|
||||
$this->get('/app/verbinden?'.http_build_query($query))->assertRedirect('/login');
|
||||
$this->actingAs($user)->get('/app/verbinden?'.http_build_query($query))->assertOk();
|
||||
|
||||
$location = $this->actingAs($user)->post('/app/verbinden', $query, ['X-Inertia' => 'true'])
|
||||
->assertStatus(409)->headers->get('X-Inertia-Location');
|
||||
$this->assertStringStartsWith('inhaus://verbunden?code=', $location);
|
||||
$this->assertStringContainsString('state=xyz', $location);
|
||||
$this->assertStringNotContainsString('|', $location);
|
||||
parse_str((string) parse_url($location, PHP_URL_QUERY), $params);
|
||||
|
||||
// Falscher Prüfwert: nichts – und der Code ist danach verbraucht
|
||||
$this->postJson('/api/v1/token/exchange', ['code' => $params['code'], 'code_verifier' => str_repeat('x', 48)])->assertUnprocessable();
|
||||
$this->postJson('/api/v1/token/exchange', ['code' => $params['code'], 'code_verifier' => $verifier])->assertUnprocessable();
|
||||
|
||||
$location = $this->actingAs($user)->post('/app/verbinden', $query, ['X-Inertia' => 'true'])->headers->get('X-Inertia-Location');
|
||||
parse_str((string) parse_url($location, PHP_URL_QUERY), $params);
|
||||
$this->postJson('/api/v1/token/exchange', ['code' => $params['code'], 'code_verifier' => $verifier])
|
||||
->assertCreated()->assertJsonPath('user.id', $user->id)->assertJsonStructure(['token']);
|
||||
$this->assertSame('Pixel 9', $user->tokens()->first()->name);
|
||||
}
|
||||
|
||||
public function test_only_app_schemes_are_accepted_as_redirect(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
[, $challenge] = $this->pkce();
|
||||
|
||||
foreach (['https://evil.example/cb', 'javascript:alert(1)', 'exp://192.168.0.2:8081'] as $uri) {
|
||||
$this->actingAs($user)->get('/app/verbinden?'.http_build_query(['redirect_uri' => $uri, 'code_challenge' => $challenge, 'state' => 's']))->assertStatus(400);
|
||||
}
|
||||
|
||||
config(['inhaus.app_schemes' => ['inhaus', 'exp']]);
|
||||
$this->actingAs($user)->get('/app/verbinden?'.http_build_query(['redirect_uri' => 'exp://192.168.0.2:8081/--/verbunden', 'code_challenge' => $challenge, 'state' => 's']))->assertOk();
|
||||
}
|
||||
|
||||
public function test_push_devices_receive_notifications_via_expo(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$headers = ['Authorization' => 'Bearer '.$user->createToken('App')->plainTextToken];
|
||||
|
||||
$this->postJson('/api/v1/push/devices', ['token' => 'kein-token'], $headers)->assertUnprocessable();
|
||||
$this->postJson('/api/v1/push/devices', ['token' => 'ExponentPushToken[abc123]', 'platform' => 'android'], $headers)->assertCreated();
|
||||
$this->postJson('/api/v1/push/devices', ['token' => 'ExponentPushToken[weg]', 'platform' => 'ios'], $headers)->assertCreated();
|
||||
|
||||
Http::fake([ExpoPush::ENDPOINT => Http::response(['data' => [
|
||||
['status' => 'ok', 'id' => '1'],
|
||||
['status' => 'error', 'details' => ['error' => 'DeviceNotRegistered']],
|
||||
]])]);
|
||||
|
||||
$user->notify(new PortalNotification('Neue Stelle', 'Pflegefachkraft', '/stellen/1'));
|
||||
|
||||
Http::assertSent(fn ($request) => $request->url() === ExpoPush::ENDPOINT
|
||||
&& $request[0]['to'] === 'ExponentPushToken[abc123]' && $request[0]['data']['url'] === '/stellen/1');
|
||||
$this->assertSame(['ExponentPushToken[abc123]'], AppDevice::query()->pluck('push_token')->all());
|
||||
|
||||
$this->deleteJson('/api/v1/push/devices', ['token' => 'ExponentPushToken[abc123]'], $headers)->assertOk();
|
||||
$this->assertSame(0, AppDevice::query()->count());
|
||||
}
|
||||
|
||||
public function test_revoking_access_removes_app_devices(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$token = $user->createToken('App');
|
||||
AppDevice::query()->create(['user_id' => $user->id, 'token_id' => $token->accessToken->id, 'push_token' => 'ExponentPushToken[x]']);
|
||||
|
||||
$token->accessToken->delete();
|
||||
|
||||
$this->assertSame(0, AppDevice::query()->count());
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ namespace Tests\Feature\Mobile;
|
|||
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use App\Push\ExpoPush;
|
||||
use App\Push\PushSubscription;
|
||||
use App\Push\SendWebPush;
|
||||
use App\Push\WebPush;
|
||||
|
|
@ -115,7 +116,7 @@ class WebPushTest extends TestCase
|
|||
PushSubscription::query()->create(['user_id' => $user->id, 'endpoint' => 'https://push.example.org/weg', 'endpoint_hash' => hash('sha256', 'weg'), 'public_key' => $uaPublic, 'auth_token' => $auth]);
|
||||
Http::fake(['*' => Http::response('', 410)]);
|
||||
|
||||
(new SendWebPush($user->id, ['title' => 'x']))->handle(app(WebPush::class));
|
||||
(new SendWebPush($user->id, ['title' => 'x']))->handle(app(WebPush::class), app(ExpoPush::class));
|
||||
|
||||
$this->assertSame(0, PushSubscription::query()->count());
|
||||
}
|
||||
|
|
|
|||
75
tests/Feature/News/LikesAndReachTest.php
Normal file
75
tests/Feature/News/LikesAndReachTest.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\News;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LikesAndReachTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_people_can_give_and_take_back_a_heart(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$post = NewsPost::factory()->create(['published_at' => now()->subHour()]);
|
||||
|
||||
$this->actingAs($user)->post("/neuigkeiten/{$post->slug}/herz")->assertRedirect();
|
||||
$this->actingAs($user)->post("/neuigkeiten/{$post->slug}/herz")->assertRedirect();
|
||||
$this->assertSame(1, DB::table('news_likes')->where('post_id', $post->id)->count());
|
||||
|
||||
$this->actingAs($user)->get("/neuigkeiten/{$post->slug}")->assertInertia(fn (Assert $page) => $page
|
||||
->where('post.likes', 1)->where('post.liked', true)->where('reach', null));
|
||||
|
||||
$this->actingAs($user)->delete("/neuigkeiten/{$post->slug}/herz")->assertRedirect();
|
||||
$this->assertSame(0, DB::table('news_likes')->count());
|
||||
}
|
||||
|
||||
public function test_hidden_or_unpublished_posts_cannot_get_hearts(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$draft = NewsPost::factory()->create(['status' => NewsPost::DRAFT, 'published_at' => null]);
|
||||
|
||||
$this->actingAs($user)->post("/neuigkeiten/{$draft->slug}/herz")->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_reach_is_anonymous_and_only_for_editors(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->create();
|
||||
$readers = User::factory()->count(3)->create();
|
||||
$post = NewsPost::factory()->create(['published_at' => now()->subHour()]);
|
||||
|
||||
foreach ($readers as $reader) {
|
||||
$this->actingAs($reader)->get("/neuigkeiten/{$post->slug}")->assertOk();
|
||||
$this->actingAs($reader)->get("/neuigkeiten/{$post->slug}")->assertOk();
|
||||
}
|
||||
|
||||
$this->actingAs($readers[0])->post("/neuigkeiten/{$post->slug}/herz");
|
||||
|
||||
// Gespeichert wird kein Personenbezug
|
||||
$this->assertSame(3, DB::table('news_reads')->where('post_id', $post->id)->count());
|
||||
$this->assertFalse(DB::table('news_reads')->whereIn('reader', $readers->pluck('id')->map(fn ($id) => (string) $id))->exists());
|
||||
|
||||
$this->actingAs($admin)->get("/neuigkeiten/{$post->slug}")->assertInertia(fn (Assert $page) => $page
|
||||
->where('reach.readers', 4)
|
||||
->where('reach.likes', 1)
|
||||
->where('reach.likers', [$readers[0]->name])
|
||||
->where('reach.share', 100));
|
||||
}
|
||||
|
||||
public function test_hearts_via_the_api(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$post = NewsPost::factory()->create(['published_at' => now()->subHour()]);
|
||||
$headers = ['Authorization' => 'Bearer '.$user->createToken('App')->plainTextToken];
|
||||
|
||||
$this->postJson("/api/v1/news/{$post->slug}/like", [], $headers)->assertOk()->assertJsonPath('data.likes', 1)->assertJsonPath('data.liked', true);
|
||||
$this->getJson('/api/v1/news', $headers)->assertJsonPath('data.0.likes', 1)->assertJsonPath('data.0.liked', true);
|
||||
$this->getJson("/api/v1/news/{$post->slug}", $headers)->assertJsonPath('data.liked', true);
|
||||
$this->deleteJson("/api/v1/news/{$post->slug}/like", [], $headers)->assertOk()->assertJsonPath('data.likes', 0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue