Fix FLEXIAPI-347 Allow IPv4 and IPv6 in the External Account domain attribute

This commit is contained in:
Timothée Jaussoin 2026-01-20 14:46:59 +01:00
parent 6a1f3471d6
commit 6550a9082c
6 changed files with 35 additions and 7 deletions

View file

@ -3,7 +3,7 @@ variables:
ROCKY_9_IMAGE_VERSION: 20250702_171314_update_rocky9_dockerhub
ROCKY_10_IMAGE_VERSION: 20250908_164454_rocky10_first
DEBIAN_12_IMAGE_VERSION: 20250908_154742_refresh_dependencies
DEBIAN_13_IMAGE_VERSION: 20251204_115628_update_packages
DEBIAN_13_IMAGE_VERSION: 20260120_152506_update_packages
PHP_REDIS_REMI_VERSION: php-pecl-redis6-6.1.0-1
PHP_IGBINARY_REMI_VERSION: php-pecl-igbinary-3.2.16-2
PHP_MSGPACK_REMI_VERSION: php-pecl-msgpack-2.2.0-3

View file

@ -1 +1 @@
* * * * * apache /opt/belledonne-communications/share/flexisip-account-manager/flexiapi/artisan schedule:run >> /dev/null 2>&1
* * * * * apache /opt/belledonne-communications/share/flexisip-account-manager/flexiapi/artisan schedule:run >> /dev/null 2>&1

View file

@ -22,8 +22,6 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\ExternalAccount\CreateUpdate;
use App\Services\AccountService;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use App\ExternalAccount;
use App\Account;

View file

@ -19,12 +19,12 @@
namespace App\Http\Requests\ExternalAccount;
use App\Rules\DomainOrIp;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use App\ExternalAccount;
use App\Rules\SIPUsername;
use App\Rules\Domain;
class CreateUpdate extends FormRequest
{
@ -40,7 +40,7 @@ class CreateUpdate extends FormRequest
return [
'username' => ['required', $usernameValidation, new SIPUsername()],
'domain' => ['required', new Domain()],
'domain' => ['required', new DomainOrIp()],
'realm' => 'different:domain',
'registrar' => 'different:domain',
'outbound_proxy' => 'different:domain',

View file

@ -0,0 +1,22 @@
<?php
namespace App\Rules;
use App\Space;
use Illuminate\Contracts\Validation\Rule;
use Respect\Validation\Validator;
class DomainOrIp implements Rule
{
public function passes($attribute, $value)
{
return Validator::regex('/' . Space::DOMAIN_REGEX . '/')->validate($value)
|| Validator::ip()->validate($value);
}
public function message()
{
return 'The :attribute should be a valid domain';
}
}

View file

@ -77,7 +77,7 @@ class ApiAccountExternalAccountTest extends TestCase
$this->keyAuthenticated($admin)
->json($this->method, $this->route . '/' . $account->id . '/external/', [
'username' => $username . '3',
'domain' => 'bar.dev',
'domain' => '127.0.0.1', // IPv4
'realm' => 'newrealm',
'protocol' => 'UDP'
])->assertJsonValidationErrors(['password']);
@ -96,5 +96,13 @@ class ApiAccountExternalAccountTest extends TestCase
$this->keyAuthenticated($admin)
->get($this->route . '/' . $account->id . '/external/')
->assertStatus(404);
$this->keyAuthenticated($admin)
->json($this->method, $this->route . '/' . $account->id . '/external/', [
'username' => $username,
'domain' => '2345:425:2CA1:0000:0000:567:5673:23b5', // IPv6
'password' => 'password',
'protocol' => 'UDP'
])->assertStatus(201);
}
}