Upgrade to PHP 8.2 and Laravel 11

This commit is contained in:
Timothée Jaussoin 2025-08-18 09:15:08 +00:00
parent 4d0c713174
commit a5eeb06055
27 changed files with 991 additions and 782 deletions

View file

@ -73,7 +73,10 @@ class Account extends Authenticatable
return; return;
} }
$builder->where('domain', config('app.sip_domain')); /**
* config('app.sip_domain') is required for the Tests suit
*/
$builder->where('domain', config('app.sip_domain') ?? space()->domain);
}); });
} }

View file

@ -30,16 +30,9 @@ use Illuminate\Support\Facades\DB;
$hostSpace = null; $hostSpace = null;
function space($reload = false): ?Space function space(): ?Space
{ {
global $hostSpace; return request()->space;
if ($hostSpace != null && $reload == false) {
return $hostSpace;
}
$hostSpace = Space::where('host', request()->host())->first();
return $hostSpace;
} }
function passwordAlgorithms(): array function passwordAlgorithms(): array
@ -167,7 +160,7 @@ function resolveDomain(Request $request): string
&& $request->user() && $request->user()
&& $request->user()->superAdmin && $request->user()->superAdmin
? $request->get('domain') ? $request->get('domain')
: config('app.sip_domain'); : $request->space->domain;
} }
function captchaConfigured(): bool function captchaConfigured(): bool

View file

@ -151,7 +151,7 @@ class ProvisioningController extends Controller
private function checkProvisioningHeader(Request $request) private function checkProvisioningHeader(Request $request)
{ {
if (!$request->hasHeader('x-linphone-provisioning') if (!$request->hasHeader('x-linphone-provisioning')
&& space()?->provisioning_use_linphone_provisioning_header) { && $request->space->provisioning_use_linphone_provisioning_header) {
abort(400, 'x-linphone-provisioning header is missing'); abort(400, 'x-linphone-provisioning header is missing');
} }
} }
@ -172,8 +172,8 @@ class ProvisioningController extends Controller
$dom->appendChild($config); $dom->appendChild($config);
if (space()?->custom_provisioning_entries) { if ($request->space?->custom_provisioning_entries) {
$rc = parse_ini_string(space()->custom_provisioning_entries, true); $rc = parse_ini_string($request->space->custom_provisioning_entries, true);
foreach ($rc as $sectionName => $values) { foreach ($rc as $sectionName => $values) {
$section = $dom->createElement('section'); $section = $dom->createElement('section');
@ -297,7 +297,7 @@ class ProvisioningController extends Controller
} }
// Overwrite all the entries // Overwrite all the entries
if (space()?->custom_provisioning_overwrite_all) { if ($request->space?->custom_provisioning_overwrite_all) {
$xpath = new \DOMXpath($dom); $xpath = new \DOMXpath($dom);
$entries = $xpath->query("//section/entry"); $entries = $xpath->query("//section/entry");
if (!is_null($entries)) { if (!is_null($entries)) {

View file

@ -285,7 +285,7 @@ class AccountImportController extends Controller
'account_id' => $passwordAccount->id, 'account_id' => $passwordAccount->id,
'password' => bchash( 'password' => bchash(
$passwordAccount->username, $passwordAccount->username,
space()?->account_realm ?? $request->get('domain'), $request->space?->account_realm ?? $request->get('domain'),
$passwords[$passwordAccount->username], $passwords[$passwordAccount->username],
$algorithm $algorithm
), ),

View file

@ -52,13 +52,15 @@ class Kernel extends HttpKernel
\App\Http\Middleware\VerifyCsrfToken::class, \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\Localization::class, \App\Http\Middleware\Localization::class,
'space.check'
], ],
'api' => [ 'api' => [
'throttle:600,1', // move to 600 instead of 60 'throttle:600,1', // move to 600 instead of 60
'bindings', 'bindings',
'validate_json', 'validate_json',
'localization' 'localization',
'space.check'
], ],
]; ];

View file

@ -10,7 +10,7 @@ class IsIntercomFeatures
{ {
public function handle(Request $request, Closure $next): Response public function handle(Request $request, Closure $next): Response
{ {
if (space()?->intercom_features) { if ($request->space->intercom_features) {
return $next($request); return $next($request);
} }

View file

@ -27,7 +27,7 @@ class IsPhoneRegistration
{ {
public function handle(Request $request, Closure $next): Response public function handle(Request $request, Closure $next): Response
{ {
if (space()?->phone_registration) { if ($request->space->phone_registration) {
return $next($request); return $next($request);
} }

View file

@ -27,7 +27,7 @@ class IsPublicRegistration
{ {
public function handle(Request $request, Closure $next): Response public function handle(Request $request, Closure $next): Response
{ {
if (space()?->public_registration) { if ($request->space?->public_registration) {
return $next($request); return $next($request);
} }

View file

@ -27,7 +27,7 @@ class IsWebPanelEnabled
{ {
public function handle(Request $request, Closure $next) public function handle(Request $request, Closure $next)
{ {
if (!$request->expectsJson() && space()?->web_panel) { if (!$request->expectsJson() && $request->space->web_panel) {
return $next($request); return $next($request);
} }

View file

@ -3,6 +3,7 @@
namespace App\Http\Middleware; namespace App\Http\Middleware;
use Closure; use Closure;
use App\Space;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -15,17 +16,18 @@ class SpaceCheck
return abort(503, 'APP_ROOT_HOST is not configured'); return abort(503, 'APP_ROOT_HOST is not configured');
} }
$space = space(); $space = Space::where('host', config('app.sip_domain') ?? request()->host())->first();
if ($space != null) { if ($space != null) {
if (!str_ends_with($space->host, config('app.root_host'))) { if (!str_ends_with($space->host, config('app.root_host'))) {
return abort(503, 'The APP_ROOT_HOST configured does not match with the current root domain'); return abort(503, 'The APP_ROOT_HOST configured does not match with the current root domain');
} }
Config::set('app.url', '://' . $space->host); $request->merge(['space' => $space]);
Config::set('app.sip_domain', $space->domain);
if ($request->user() && !$request->user()->superAdmin && $space?->isExpired()) { Config::set('app.url', '://' . $space->host);
if ($space->isExpired()) {
abort($request->expectsJson() ? 403 : 490, 'The related Space has expired'); abort($request->expectsJson() ? 403 : 490, 'The related Space has expired');
} }

View file

@ -62,10 +62,10 @@ class AccountService
$account = new Account(); $account = new Account();
$account->username = $request->get('username'); $account->username = $request->get('username');
$account->activated = false; $account->activated = false;
$account->domain = space()->domain; $account->domain = $request->space->domain;
$account->ip_address = $request->ip(); $account->ip_address = $request->ip();
$account->created_at = Carbon::now(); $account->created_at = Carbon::now();
$account->user_agent = space()->name; $account->user_agent = $request->space->name;
$account->dtmf_protocol = $request->get('dtmf_protocol'); $account->dtmf_protocol = $request->get('dtmf_protocol');
if ($request->asAdmin) { if ($request->asAdmin) {
@ -73,7 +73,7 @@ class AccountService
$account->display_name = $request->get('display_name'); $account->display_name = $request->get('display_name');
$account->activated = $request->has('activated') ? (bool)$request->get('activated') : false; $account->activated = $request->has('activated') ? (bool)$request->get('activated') : false;
$account->domain = resolveDomain($request); $account->domain = resolveDomain($request);
$account->user_agent = $request->header('User-Agent') ?? space()->name; $account->user_agent = $request->header('User-Agent') ?? $request->space->name;
$account->admin = $request->has('admin') && (bool)$request->get('admin'); $account->admin = $request->has('admin') && (bool)$request->get('admin');
if (!$request->api && $request->has('role')) { if (!$request->api && $request->has('role')) {
@ -113,8 +113,8 @@ class AccountService
); );
if (!$request->api) { if (!$request->api) {
if (!empty(space()?->newsletter_registration_address) && $request->has('newsletter')) { if (!empty($request->space?->newsletter_registration_address) && $request->has('newsletter')) {
Mail::to(space()->newsletter_registration_address)->send(new NewsletterRegistration($account)); Mail::to($request->space->newsletter_registration_address)->send(new NewsletterRegistration($account));
} }
} }

View file

@ -8,33 +8,33 @@
], ],
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": ">=8.1", "php": ">=8.2",
"awobaz/compoships": "^2.3", "laravel/framework": "^11.45.1",
"doctrine/dbal": "^3.0", "awobaz/compoships": "^2.4.1",
"endroid/qr-code": "^5.0", "doctrine/dbal": "^3.10.1",
"fakerphp/faker": "^1.23", "endroid/qr-code": "^5.1",
"laravel/framework": "^10.0", "fakerphp/faker": "^1.24.1",
"laravel/tinker": "^2.9", "laravel/tinker": "^2.10.1",
"lcobucci/jwt": "^4.3", "lcobucci/jwt": "^4.3",
"namoshek/laravel-redis-sentinel": "^0.5", "namoshek/laravel-redis-sentinel": "^0.5",
"ovh/ovh": "^3.3", "ovh/ovh": "^3.5",
"parsedown/laravel": "^1.2", "parsedown/laravel": "^1.2.1",
"phpunit/phpunit": "^10.0", "phpunit/phpunit": "^10.5.50",
"propaganistas/laravel-phone": "^5.3", "propaganistas/laravel-phone": "^5.3.6",
"react/socket": "^1.16", "react/socket": "^1.16",
"respect/validation": "^2.3", "respect/validation": "^2.4.4",
"rvxlab/hcaptcha": "^5.2", "rvxlab/hcaptcha": "^5.2",
"sabre/vobject": "^4.5" "sabre/vobject": "^4.5.7"
}, },
"require-dev": { "require-dev": {
"mockery/mockery": "^1.6", "mockery/mockery": "^1.6.12",
"nunomaduro/collision": "^7.0", "nunomaduro/collision": "^8.5",
"phpmd/phpmd": "^2.15", "phpmd/phpmd": "^2.15",
"squizlabs/php_codesniffer": "^3.7" "squizlabs/php_codesniffer": "^3.13.2"
}, },
"config": { "config": {
"platform": { "platform": {
"php": "8.1" "php": "8.2"
}, },
"optimize-autoloader": true, "optimize-autoloader": true,
"preferred-install": "dist", "preferred-install": "dist",

1517
flexiapi/composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -36,13 +36,6 @@ class SpaceFactory extends Factory
]; ];
} }
public function local()
{
return $this->state(fn (array $attributes) => [
'host' => 'localhost',
]);
}
public function withoutProvisioningHeader() public function withoutProvisioningHeader()
{ {
return $this->state(fn (array $attributes) => [ return $this->state(fn (array $attributes) => [
@ -50,6 +43,14 @@ class SpaceFactory extends Factory
]); ]);
} }
public function domain(string $domain)
{
return $this->state(fn (array $attributes) => [
'domain' => $domain,
'host' => $domain,
]);
}
public function secondDomain() public function secondDomain()
{ {
return $this->state(fn (array $attributes) => [ return $this->state(fn (array $attributes) => [

View file

@ -54,7 +54,7 @@ Route::get('accounts/me/api_key/{auth_token}', 'Api\Account\ApiKeyController@gen
Route::get('phone_countries', 'Api\PhoneCountryController@index'); Route::get('phone_countries', 'Api\PhoneCountryController@index');
Route::group(['middleware' => ['auth.jwt', 'auth.digest_or_key', 'auth.check_blocked', 'space.check']], function () { Route::group(['middleware' => ['auth.jwt', 'auth.digest_or_key', 'auth.check_blocked']], function () {
Route::get('accounts/auth_token/{auth_token}/attach', 'Api\Account\AuthTokenController@attach'); Route::get('accounts/auth_token/{auth_token}/attach', 'Api\Account\AuthTokenController@attach');
Route::post('account_creation_tokens/consume', 'Api\Account\CreationTokenController@consume'); Route::post('account_creation_tokens/consume', 'Api\Account\CreationTokenController@consume');

View file

@ -48,12 +48,10 @@ use App\Http\Controllers\Admin\SpaceController;
use App\Http\Controllers\Admin\StatisticsController; use App\Http\Controllers\Admin\StatisticsController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::middleware(['space.check'])->group(function () {
Route::redirect('/', 'login')->name('account.home'); Route::redirect('/', 'login')->name('account.home');
Route::get('about', 'AboutController@about')->name('about'); Route::get('about', 'AboutController@about')->name('about');
});
Route::middleware(['web_panel_enabled', 'space.check'])->group(function () { Route::middleware(['web_panel_enabled'])->group(function () {
Route::get('wizard/{provisioning_token}', 'Account\ProvisioningController@wizard')->name('provisioning.wizard'); Route::get('wizard/{provisioning_token}', 'Account\ProvisioningController@wizard')->name('provisioning.wizard');
Route::get('login', 'Account\AuthenticateController@login')->name('account.login'); Route::get('login', 'Account\AuthenticateController@login')->name('account.login');
@ -90,7 +88,7 @@ Route::name('provisioning.')->prefix('provisioning')->controller(ProvisioningCon
Route::get('/', 'show')->name('show'); Route::get('/', 'show')->name('show');
}); });
Route::middleware(['web_panel_enabled', 'space.check'])->group(function () { Route::middleware(['web_panel_enabled'])->group(function () {
Route::middleware(['public_registration'])->group(function () { Route::middleware(['public_registration'])->group(function () {
Route::redirect('register', 'register/email')->name('account.register'); Route::redirect('register', 'register/email')->name('account.register');

View file

@ -56,11 +56,11 @@ class AccountJWTAuthenticationTest extends TestCase
if (!extension_loaded('sodium')) return; if (!extension_loaded('sodium')) return;
$password = Password::factory()->create(); $password = Password::factory()->create();
$domain = 'sip_provisioning.example.com';
\App\Space::where('domain', $password->account->domain)->update(['host' => 'localhost']);
$bearer = 'authz_server="https://sso.test/", realm="sip.test.org"'; $bearer = 'authz_server="https://sso.test/", realm="sip.test.org"';
\App\Space::where('domain', $password->account->domain)->update(['host' => $domain]);
config()->set('app.sip_domain', $domain);
config()->set('services.jwt.rsa_public_key_pem', $this->serverPublicKeyPem); config()->set('services.jwt.rsa_public_key_pem', $this->serverPublicKeyPem);
$this->get($this->route)->assertStatus(400); $this->get($this->route)->assertStatus(400);

View file

@ -39,9 +39,7 @@ class AccountProvisioningTest extends TestCase
public function testBaseProvisioning() public function testBaseProvisioning()
{ {
Space::truncate(); Space::factory()->create();
Space::factory()->local()->create();
space(reload: true);
$this->get($this->route)->assertStatus(400); $this->get($this->route)->assertStatus(400);
@ -55,9 +53,7 @@ class AccountProvisioningTest extends TestCase
public function testDisabledProvisioningHeader() public function testDisabledProvisioningHeader()
{ {
Space::truncate(); Space::factory()->withoutProvisioningHeader()->create();
Space::factory()->local()->withoutProvisioningHeader()->create();
space(reload: true);
$this->get($this->route) $this->get($this->route)
->assertStatus(200) ->assertStatus(200)
@ -67,10 +63,6 @@ class AccountProvisioningTest extends TestCase
public function testDontProvisionHeaderDisabled() public function testDontProvisionHeaderDisabled()
{ {
Space::truncate();
Space::factory()->local()->create();
space(reload: true);
$account = Account::factory()->deactivated()->create(); $account = Account::factory()->deactivated()->create();
$account->generateUserApiKey(); $account->generateUserApiKey();
@ -100,6 +92,8 @@ class AccountProvisioningTest extends TestCase
public function testXLinphoneProvisioningHeader() public function testXLinphoneProvisioningHeader()
{ {
Space::factory()->create();
$this->withHeaders([ $this->withHeaders([
'x-linphone-provisioning' => true, 'x-linphone-provisioning' => true,
])->get($this->accountRoute)->assertStatus(401); ])->get($this->accountRoute)->assertStatus(401);
@ -138,9 +132,9 @@ class AccountProvisioningTest extends TestCase
public function testUiSectionProvisioning() public function testUiSectionProvisioning()
{ {
$secondDomain = Space::factory()->create();
$password = Password::factory()->create(); $password = Password::factory()->create();
$secondDomain = Space::factory()->secondDomain()->create();
$password->account->generateUserApiKey(); $password->account->generateUserApiKey();
$password->account->domain = $secondDomain->domain; $password->account->domain = $secondDomain->domain;
$password->account->save(); $password->account->save();
@ -282,6 +276,9 @@ class AccountProvisioningTest extends TestCase
public function testAuthTokenProvisioning() public function testAuthTokenProvisioning()
{ {
$password = Password::factory()->create();
$password->account->generateUserApiKey();
// Generate a public auth_token and attach it // Generate a public auth_token and attach it
$response = $this->json('POST', '/api/accounts/auth_token') $response = $this->json('POST', '/api/accounts/auth_token')
->assertStatus(201) ->assertStatus(201)
@ -291,9 +288,6 @@ class AccountProvisioningTest extends TestCase
$authToken = $response->json('token'); $authToken = $response->json('token');
$password = Password::factory()->create();
$password->account->generateUserApiKey();
$this->keyAuthenticated($password->account) $this->keyAuthenticated($password->account)
->json($this->method, '/api/accounts/auth_token/' . $authToken . '/attach') ->json($this->method, '/api/accounts/auth_token/' . $authToken . '/attach')
->assertStatus(200); ->assertStatus(200);

View file

@ -21,6 +21,7 @@ namespace Tests\Feature;
use App\Account; use App\Account;
use App\Password; use App\Password;
use App\Space;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Tests\TestCase; use Tests\TestCase;
@ -89,6 +90,8 @@ class ApiAccountApiKeyTest extends TestCase
public function testAuthToken() public function testAuthToken()
{ {
Space::factory()->create();
// Generate a public auth_token // Generate a public auth_token
$response = $this->json('POST', '/api/accounts/auth_token') $response = $this->json('POST', '/api/accounts/auth_token')
->assertStatus(201) ->assertStatus(201)

View file

@ -65,6 +65,8 @@ class ApiAccountCreationTokenTest extends TestCase
public function testCorrectParameters() public function testCorrectParameters()
{ {
Space::factory()->create();
$this->assertSame(AccountCreationToken::count(), 0); $this->assertSame(AccountCreationToken::count(), 0);
$this->json($this->method, $this->tokenRoute, [ $this->json($this->method, $this->tokenRoute, [
'pn_provider' => 'wrong', 'pn_provider' => 'wrong',
@ -96,6 +98,8 @@ class ApiAccountCreationTokenTest extends TestCase
public function testMandatoryParameters() public function testMandatoryParameters()
{ {
Space::factory()->create();
$this->json($this->method, $this->tokenRoute)->assertStatus(422); $this->json($this->method, $this->tokenRoute)->assertStatus(422);
$this->json($this->method, $this->tokenRoute, [ $this->json($this->method, $this->tokenRoute, [
@ -107,6 +111,8 @@ class ApiAccountCreationTokenTest extends TestCase
public function testThrottling() public function testThrottling()
{ {
Space::factory()->create();
AccountCreationToken::factory()->create([ AccountCreationToken::factory()->create([
'pn_provider' => $this->pnProvider, 'pn_provider' => $this->pnProvider,
'pn_param' => $this->pnParam, 'pn_param' => $this->pnParam,
@ -235,6 +241,8 @@ class ApiAccountCreationTokenTest extends TestCase
public function testAccountCreationRequestToken() public function testAccountCreationRequestToken()
{ {
Space::factory()->create();
$response = $this->json($this->method, $this->tokenRequestRoute); $response = $this->json($this->method, $this->tokenRequestRoute);
$response->assertStatus(201); $response->assertStatus(201);
$creationRequestToken = $response->json()['token']; $creationRequestToken = $response->json()['token'];

View file

@ -28,6 +28,8 @@ use App\Http\Middleware\IsWebPanelEnabled;
class ApiAccountRecoveryTokenTest extends TestCase class ApiAccountRecoveryTokenTest extends TestCase
{ {
private Space $space;
protected $tokenRoute = '/api/account_recovery_tokens/send-by-push'; protected $tokenRoute = '/api/account_recovery_tokens/send-by-push';
protected $tokenRequestRoute = '/api/account_recovery_request_tokens'; protected $tokenRequestRoute = '/api/account_recovery_request_tokens';
protected $method = 'POST'; protected $method = 'POST';
@ -36,6 +38,12 @@ class ApiAccountRecoveryTokenTest extends TestCase
protected $pnParam = 'param'; protected $pnParam = 'param';
protected $pnPrid = 'id'; protected $pnPrid = 'id';
public function setUp(): void
{
parent::setUp();
$this->space = Space::factory()->create();
}
public function testMandatoryParameters() public function testMandatoryParameters()
{ {
$this->json($this->method, $this->tokenRoute)->assertStatus(422); $this->json($this->method, $this->tokenRoute)->assertStatus(422);
@ -73,23 +81,22 @@ class ApiAccountRecoveryTokenTest extends TestCase
public function testTokenRecoveryPage() public function testTokenRecoveryPage()
{ {
$token = AccountRecoveryToken::factory()->create(); $token = AccountRecoveryToken::factory()->create();
$space = Space::factory()->create();
$phone = '+3312345'; $phone = '+3312345';
$this->get($this->setSpaceOnRoute($space, route('account.recovery.show.phone', ['account_recovery_token' => 'bad_token']))) $this->get($this->setSpaceOnRoute($this->space, route('account.recovery.show.phone', ['account_recovery_token' => 'bad_token'])))
->assertStatus(404); ->assertStatus(404);
$this->get($this->setSpaceOnRoute($space, route('account.recovery.show.phone', ['account_recovery_token' => $token->token]))) $this->get($this->setSpaceOnRoute($this->space, route('account.recovery.show.phone', ['account_recovery_token' => $token->token])))
->assertDontSee($phone) ->assertDontSee($phone)
->assertStatus(200); ->assertStatus(200);
$this->get($this->setSpaceOnRoute($space, route('account.recovery.show.phone', ['account_recovery_token' => $token->token, 'phone' => $phone]))) $this->get($this->setSpaceOnRoute($this->space, route('account.recovery.show.phone', ['account_recovery_token' => $token->token, 'phone' => $phone])))
->assertSee($phone) ->assertSee($phone)
->assertStatus(200); ->assertStatus(200);
$token->consume(); $token->consume();
$this->get($this->setSpaceOnRoute($space, route('account.recovery.show.phone', ['account_recovery_token' => $token->token]))) $this->get($this->setSpaceOnRoute($this->space, route('account.recovery.show.phone', ['account_recovery_token' => $token->token])))
->assertStatus(404); ->assertStatus(404);
} }
} }

View file

@ -153,15 +153,15 @@ class ApiAccountTest extends TestCase
public function testDomain() public function testDomain()
{ {
$configDomain = 'sip.domain.com'; $configDomain = 'sip2.example.com';
Space::factory()->domain($configDomain)->create();
config()->set('app.sip_domain', $configDomain); config()->set('app.sip_domain', $configDomain);
$password = Password::factory()->admin()->create(); $password = Password::factory()->admin()->create();
$username = 'foobar'; $username = 'foobar';
$domain = Space::first()->domain; $domain = Space::first()->domain;
config()->set('app.admins_manage_multi_domains', false);
$response0 = $this->generateFirstResponse($password); $response0 = $this->generateFirstResponse($password);
$response1 = $this->generateSecondResponse($password, $response0) $response1 = $this->generateSecondResponse($password, $response0)
->json($this->method, $this->route, [ ->json($this->method, $this->route, [
@ -185,7 +185,7 @@ class ApiAccountTest extends TestCase
public function testAdminMultiDomains() public function testAdminMultiDomains()
{ {
$configDomain = 'sip.domain.com'; $configDomain = 'sip2.example.com';
config()->set('app.sip_domain', $configDomain); config()->set('app.sip_domain', $configDomain);
$account = Account::factory()->superAdmin()->create(); $account = Account::factory()->superAdmin()->create();
@ -300,7 +300,8 @@ class ApiAccountTest extends TestCase
public function testDomainInTestDeployment() public function testDomainInTestDeployment()
{ {
$configDomain = 'testdomain.com'; $configDomain = 'sip2.example.com';
Space::factory()->domain($configDomain)->create();
config()->set('app.sip_domain', $configDomain); config()->set('app.sip_domain', $configDomain);
$password = Password::factory()->admin()->create(); $password = Password::factory()->admin()->create();
@ -573,8 +574,7 @@ class ApiAccountTest extends TestCase
{ {
$realm = 'realm.com'; $realm = 'realm.com';
Space::factory()->local()->withRealm($realm)->create(); Space::factory()->withRealm($realm)->create();
space(reload: true);
$password = Password::factory()->create(); $password = Password::factory()->create();
$password->account->activated = false; $password->account->activated = false;

View file

@ -177,9 +177,7 @@ class ApiAuthenticationTest extends TestCase
public function testAuthenticationSHA265FromCLRTXT() public function testAuthenticationSHA265FromCLRTXT()
{ {
Space::truncate(); Space::factory()->create();
Space::factory()->local()->create();
space(reload: true);
$password = Password::factory()->clrtxt()->create(); $password = Password::factory()->clrtxt()->create();
$response = $this->generateFirstResponse($password); $response = $this->generateFirstResponse($password);
@ -211,8 +209,7 @@ class ApiAuthenticationTest extends TestCase
$realm = 'realm.com'; $realm = 'realm.com';
Space::truncate(); Space::truncate();
Space::factory()->local()->withRealm($realm)->create(); Space::factory()->withRealm($realm)->create();
space(reload: true);
$password = Password::factory()->clrtxt()->create(); $password = Password::factory()->clrtxt()->create();
$response = $this->generateFirstResponse($password); $response = $this->generateFirstResponse($password);

View file

@ -22,9 +22,9 @@ namespace Tests\Feature;
use App\Account; use App\Account;
use App\Space; use App\Space;
use Carbon\Carbon; use Carbon\Carbon;
use Tests\TestCaseWithSpaceMiddleware; use Tests\TestCase;
class ApiSpaceWithMiddlewareTest extends TestCaseWithSpaceMiddleware class ApiSpaceWithMiddlewareTest extends TestCase
{ {
protected $method = 'POST'; protected $method = 'POST';
protected $route = '/api/spaces'; protected $route = '/api/spaces';
@ -42,9 +42,7 @@ class ApiSpaceWithMiddlewareTest extends TestCaseWithSpaceMiddleware
// Try to create a new user as an admin // Try to create a new user as an admin
$admin->generateUserApiKey(); $admin->generateUserApiKey();
config()->set('app.root_host', $admin->domain); config()->set('app.sip_domain', $space->domain);
space(reload: true);
$this->keyAuthenticated($admin) $this->keyAuthenticated($admin)
->json($this->method, 'http://' . $admin->domain . $this->accountRoute, [ ->json($this->method, 'http://' . $admin->domain . $this->accountRoute, [
@ -54,6 +52,8 @@ class ApiSpaceWithMiddlewareTest extends TestCaseWithSpaceMiddleware
])->assertStatus(403); ])->assertStatus(403);
// Unexpire the space and try again // Unexpire the space and try again
config()->set('app.sip_domain', $superAdmin->domain);
$space = $this->keyAuthenticated($superAdmin) $space = $this->keyAuthenticated($superAdmin)
->get($this->route . '/' . $admin->domain) ->get($this->route . '/' . $admin->domain)
->json(); ->json();
@ -64,8 +64,6 @@ class ApiSpaceWithMiddlewareTest extends TestCaseWithSpaceMiddleware
->json('PUT', $this->route . '/' . $admin->domain, $space) ->json('PUT', $this->route . '/' . $admin->domain, $space)
->assertStatus(200); ->assertStatus(200);
space(reload: true);
$this->keyAuthenticated($admin) $this->keyAuthenticated($admin)
->json($this->method, $this->accountRoute, [ ->json($this->method, $this->accountRoute, [
'username' => 'new', 'username' => 'new',

View file

@ -39,7 +39,7 @@ class ApiStatisticsTest extends TestCase
$id = '1234'; $id = '1234';
$fromUsername = 'username'; $fromUsername = 'username';
$fromDomain = 'domain.com'; $fromDomain = $admin->domain;
$account = Account::factory()->create([ $account = Account::factory()->create([
'username' => $fromUsername, 'username' => $fromUsername,
@ -132,7 +132,7 @@ class ApiStatisticsTest extends TestCase
$id = '1234'; $id = '1234';
$fromUsername = 'username'; $fromUsername = 'username';
$fromDomain = 'domain.com'; $fromDomain = $admin->domain;
$toUsername = 'usernameto'; $toUsername = 'usernameto';
$toDomain = 'domainto.com'; $toDomain = 'domainto.com';

View file

@ -38,8 +38,7 @@ abstract class TestCase extends BaseTestCase
{ {
parent::setUp(); parent::setUp();
$this->withoutMiddleware([SpaceCheck::class]); config()->set('app.root_host', 'example.com');
config()->set('app.sip_domain', 'sip.example.com'); config()->set('app.sip_domain', 'sip.example.com');
PhoneCountry::truncate(); PhoneCountry::truncate();

View file

@ -1,37 +0,0 @@
<?php
/*
Flexisip Account Manager is a set of tools to manage SIP accounts.
Copyright (C) 2020 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
abstract class TestCaseWithSpaceMiddleware extends BaseTestCase
{
use CreatesApplication;
use RefreshDatabase;
use TestUtilsTrait;
public function setUp(): void
{
parent::setUp();
config()->set('app.sip_domain', 'sip.example.com');
}
}