From 6550a9082c714f95fac600a5ce3e8e11feb0d1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Tue, 20 Jan 2026 14:46:59 +0100 Subject: [PATCH] Fix FLEXIAPI-347 Allow IPv4 and IPv6 in the External Account domain attribute --- .gitlab-ci.yml | 2 +- cron/flexiapi.cron | 2 +- .../Admin/ExternalAccountController.php | 2 -- .../Requests/ExternalAccount/CreateUpdate.php | 4 ++-- flexiapi/app/Rules/DomainOrIp.php | 22 +++++++++++++++++++ .../Feature/ApiAccountExternalAccountTest.php | 10 ++++++++- 6 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 flexiapi/app/Rules/DomainOrIp.php diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c57ddf3..f83c71d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/cron/flexiapi.cron b/cron/flexiapi.cron index a11ed25..c4d68c8 100644 --- a/cron/flexiapi.cron +++ b/cron/flexiapi.cron @@ -1 +1 @@ -* * * * * apache /opt/belledonne-communications/share/flexisip-account-manager/flexiapi/artisan schedule:run >> /dev/null 2>&1 \ No newline at end of file +* * * * * apache /opt/belledonne-communications/share/flexisip-account-manager/flexiapi/artisan schedule:run >> /dev/null 2>&1 diff --git a/flexiapi/app/Http/Controllers/Admin/ExternalAccountController.php b/flexiapi/app/Http/Controllers/Admin/ExternalAccountController.php index cee9c86..6a922e1 100644 --- a/flexiapi/app/Http/Controllers/Admin/ExternalAccountController.php +++ b/flexiapi/app/Http/Controllers/Admin/ExternalAccountController.php @@ -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; diff --git a/flexiapi/app/Http/Requests/ExternalAccount/CreateUpdate.php b/flexiapi/app/Http/Requests/ExternalAccount/CreateUpdate.php index aacd771..1ca78a5 100644 --- a/flexiapi/app/Http/Requests/ExternalAccount/CreateUpdate.php +++ b/flexiapi/app/Http/Requests/ExternalAccount/CreateUpdate.php @@ -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', diff --git a/flexiapi/app/Rules/DomainOrIp.php b/flexiapi/app/Rules/DomainOrIp.php new file mode 100644 index 0000000..27acf4f --- /dev/null +++ b/flexiapi/app/Rules/DomainOrIp.php @@ -0,0 +1,22 @@ +validate($value) + || Validator::ip()->validate($value); + } + + public function message() + { + return 'The :attribute should be a valid domain'; + } +} diff --git a/flexiapi/tests/Feature/ApiAccountExternalAccountTest.php b/flexiapi/tests/Feature/ApiAccountExternalAccountTest.php index d1223a9..b484e76 100644 --- a/flexiapi/tests/Feature/ApiAccountExternalAccountTest.php +++ b/flexiapi/tests/Feature/ApiAccountExternalAccountTest.php @@ -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); } }