Fix FLEXIAPI-408 Adjustments to allow custom JWT tests and hooks

This commit is contained in:
Timothée Jaussoin 2025-12-09 15:03:52 +01:00
parent e0f33da4ac
commit 25ddd330c1
5 changed files with 21 additions and 20 deletions

View file

@ -5,7 +5,6 @@ namespace App\Http\Controllers\Account;
use App\ResetPasswordEmailToken;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ResetPasswordEmailController extends Controller
{

View file

@ -52,14 +52,14 @@ class AccountFactory extends Factory
public function fromSpace(Space $space)
{
return $this->state(fn (array $attributes) => [
return $this->state(fn(array $attributes) => [
'domain' => $space->domain
]);
}
public function admin()
{
return $this->state(fn (array $attributes) => [
return $this->state(fn(array $attributes) => [
'admin' => true,
]);
}
@ -79,21 +79,21 @@ class AccountFactory extends Factory
public function deactivated()
{
return $this->state(fn (array $attributes) => [
return $this->state(fn(array $attributes) => [
'activated' => false,
]);
}
public function withEmail()
{
return $this->state(fn (array $attributes) => [
return $this->state(fn(array $attributes) => [
'email' => $this->faker->email,
]);
}
public function withConsumedAccountCreationToken()
{
return $this->state(fn (array $attributes) => [])->afterCreating(function (Account $account) {
return $this->state(fn(array $attributes) => [])->afterCreating(function (Account $account) {
$accountCreationToken = new AccountCreationToken;
$accountCreationToken->token = 'test_token';
$accountCreationToken->account_id = $account->id;

View file

@ -33,7 +33,7 @@ class PasswordFactory extends Factory
return [
'account_id' => $account->id,
'password' => hash('md5', $account->username.':'.$account->resolvedRealm.':testtest'),
'password' => hash('md5', $account->username . ':' . $account->resolvedRealm . ':testtest'),
'algorithm' => 'MD5',
];
}
@ -55,7 +55,7 @@ class PasswordFactory extends Factory
$account = Account::find($attributes['account_id']);
return [
'password' => hash('sha256', $account->username.':'.$account->resolvedRealm.':testtest'),
'password' => hash('sha256', $account->username . ':' . $account->resolvedRealm . ':testtest'),
'account_id' => $account->id,
'algorithm' => 'SHA-256',
];
@ -64,7 +64,7 @@ class PasswordFactory extends Factory
public function clrtxt()
{
return $this->state(fn (array $attributes) => [
return $this->state(fn(array $attributes) => [
'password' => 'testtest',
'algorithm' => 'CLRTXT',
]);

View file

@ -0,0 +1,5 @@
@extends('errors::minimal')
@section('title', __('Bad Request'))
@section('code', '404')
@section('message', __($exception->getMessage() ?: 'Bad Request'))

View file

@ -19,7 +19,6 @@
namespace Tests\Feature;
use App\Account;
use App\Password;
use DateTimeImmutable;
use Lcobucci\Clock\FrozenClock;
@ -198,7 +197,7 @@ class AccountJWTAuthenticationTest extends TestCase
$value = 'authz_server="https://auth_bearer.com/" realm="realm"';
config()->set('app.account_authentication_bearer', $value);
$password = Password::factory()->create();
Password::factory()->create();
$response = $this->json($this->method, $this->routeAccountMe)
->assertStatus(401);
@ -209,8 +208,7 @@ class AccountJWTAuthenticationTest extends TestCase
);
// Wrong From
$reponse = $this
->withHeaders(['From' => 'sip:missing@username'])
$this->withHeaders(['From' => 'sip:missing@username'])
->json($this->method, $this->routeAccountMe)
->assertStatus(401);
@ -220,8 +218,7 @@ class AccountJWTAuthenticationTest extends TestCase
);
// Wrong bearer message
$reponse = $this
->withHeaders([
$this->withHeaders([
'Authorization' => 'Bearer 1234'
])
->json($this->method, $this->routeAccountMe)
@ -233,7 +230,7 @@ class AccountJWTAuthenticationTest extends TestCase
);
}
private function checkToken(UnencryptedToken $token): void
protected function checkToken(UnencryptedToken $token): void
{
$this->withHeaders([
'Authorization' => 'Bearer ' . $token->toString(),