mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 10:08:05 +00:00
Fix FLEXIAPI-408 Adjustments to allow custom JWT tests and hooks
This commit is contained in:
parent
e0f33da4ac
commit
25ddd330c1
5 changed files with 21 additions and 20 deletions
|
|
@ -5,7 +5,6 @@ namespace App\Http\Controllers\Account;
|
||||||
use App\ResetPasswordEmailToken;
|
use App\ResetPasswordEmailToken;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
class ResetPasswordEmailController extends Controller
|
class ResetPasswordEmailController extends Controller
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,14 @@ class AccountFactory extends Factory
|
||||||
|
|
||||||
public function fromSpace(Space $space)
|
public function fromSpace(Space $space)
|
||||||
{
|
{
|
||||||
return $this->state(fn (array $attributes) => [
|
return $this->state(fn(array $attributes) => [
|
||||||
'domain' => $space->domain
|
'domain' => $space->domain
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function admin()
|
public function admin()
|
||||||
{
|
{
|
||||||
return $this->state(fn (array $attributes) => [
|
return $this->state(fn(array $attributes) => [
|
||||||
'admin' => true,
|
'admin' => true,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -79,21 +79,21 @@ class AccountFactory extends Factory
|
||||||
|
|
||||||
public function deactivated()
|
public function deactivated()
|
||||||
{
|
{
|
||||||
return $this->state(fn (array $attributes) => [
|
return $this->state(fn(array $attributes) => [
|
||||||
'activated' => false,
|
'activated' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withEmail()
|
public function withEmail()
|
||||||
{
|
{
|
||||||
return $this->state(fn (array $attributes) => [
|
return $this->state(fn(array $attributes) => [
|
||||||
'email' => $this->faker->email,
|
'email' => $this->faker->email,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withConsumedAccountCreationToken()
|
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 = new AccountCreationToken;
|
||||||
$accountCreationToken->token = 'test_token';
|
$accountCreationToken->token = 'test_token';
|
||||||
$accountCreationToken->account_id = $account->id;
|
$accountCreationToken->account_id = $account->id;
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ class PasswordFactory extends Factory
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'password' => hash('md5', $account->username.':'.$account->resolvedRealm.':testtest'),
|
'password' => hash('md5', $account->username . ':' . $account->resolvedRealm . ':testtest'),
|
||||||
'algorithm' => 'MD5',
|
'algorithm' => 'MD5',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,18 +55,18 @@ class PasswordFactory extends Factory
|
||||||
$account = Account::find($attributes['account_id']);
|
$account = Account::find($attributes['account_id']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'password' => hash('sha256', $account->username.':'.$account->resolvedRealm.':testtest'),
|
'password' => hash('sha256', $account->username . ':' . $account->resolvedRealm . ':testtest'),
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'algorithm' => 'SHA-256',
|
'algorithm' => 'SHA-256',
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clrtxt()
|
public function clrtxt()
|
||||||
{
|
{
|
||||||
return $this->state(fn (array $attributes) => [
|
return $this->state(fn(array $attributes) => [
|
||||||
'password' => 'testtest',
|
'password' => 'testtest',
|
||||||
'algorithm' => 'CLRTXT',
|
'algorithm' => 'CLRTXT',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
flexiapi/resources/views/errors/400.blade.php
Normal file
5
flexiapi/resources/views/errors/400.blade.php
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
@extends('errors::minimal')
|
||||||
|
|
||||||
|
@section('title', __('Bad Request'))
|
||||||
|
@section('code', '404')
|
||||||
|
@section('message', __($exception->getMessage() ?: 'Bad Request'))
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use App\Account;
|
|
||||||
use App\Password;
|
use App\Password;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Lcobucci\Clock\FrozenClock;
|
use Lcobucci\Clock\FrozenClock;
|
||||||
|
|
@ -198,7 +197,7 @@ class AccountJWTAuthenticationTest extends TestCase
|
||||||
$value = 'authz_server="https://auth_bearer.com/" realm="realm"';
|
$value = 'authz_server="https://auth_bearer.com/" realm="realm"';
|
||||||
config()->set('app.account_authentication_bearer', $value);
|
config()->set('app.account_authentication_bearer', $value);
|
||||||
|
|
||||||
$password = Password::factory()->create();
|
Password::factory()->create();
|
||||||
|
|
||||||
$response = $this->json($this->method, $this->routeAccountMe)
|
$response = $this->json($this->method, $this->routeAccountMe)
|
||||||
->assertStatus(401);
|
->assertStatus(401);
|
||||||
|
|
@ -209,8 +208,7 @@ class AccountJWTAuthenticationTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wrong From
|
// Wrong From
|
||||||
$reponse = $this
|
$this->withHeaders(['From' => 'sip:missing@username'])
|
||||||
->withHeaders(['From' => 'sip:missing@username'])
|
|
||||||
->json($this->method, $this->routeAccountMe)
|
->json($this->method, $this->routeAccountMe)
|
||||||
->assertStatus(401);
|
->assertStatus(401);
|
||||||
|
|
||||||
|
|
@ -220,8 +218,7 @@ class AccountJWTAuthenticationTest extends TestCase
|
||||||
);
|
);
|
||||||
|
|
||||||
// Wrong bearer message
|
// Wrong bearer message
|
||||||
$reponse = $this
|
$this->withHeaders([
|
||||||
->withHeaders([
|
|
||||||
'Authorization' => 'Bearer 1234'
|
'Authorization' => 'Bearer 1234'
|
||||||
])
|
])
|
||||||
->json($this->method, $this->routeAccountMe)
|
->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([
|
$this->withHeaders([
|
||||||
'Authorization' => 'Bearer ' . $token->toString(),
|
'Authorization' => 'Bearer ' . $token->toString(),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue