Keep the compatibility with old deprecated endpoints and parameters

This commit is contained in:
Timothée Jaussoin 2022-06-28 14:32:17 +02:00
parent d09e8e5c37
commit 68aab1d130
4 changed files with 57 additions and 4 deletions

View file

@ -73,15 +73,23 @@ class AccountController extends Controller
'dtmf_protocol' => 'nullable|in:' . Account::dtmfProtocolsRule(),
'domain' => 'min:3',
'account_creation_token' => [
'required',
'required_without:token',
Rule::exists('account_creation_tokens', 'token')->where(function ($query) {
$query->where('used', false);
}),
'size:'.WebAuthenticateController::$emailCodeSize
]
],
// For retro-compatibility
'token' => [
'required_without:account_creation_token',
Rule::exists('account_creation_tokens', 'token')->where(function ($query) {
$query->where('used', false);
}),
'size:'.WebAuthenticateController::$emailCodeSize
],
]);
$token = AccountCreationToken::where('token', $request->get('account_creation_token'))->first();
$token = AccountCreationToken::where('token', $request->get('token') ?? $request->get('account_creation_token'))->first();
$token->used = true;
$token->save();

View file

@ -27,8 +27,12 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
Route::get('ping', 'Api\PingController@ping');
Route::post('account_creation_tokens/send-by-push', 'Api\AccountCreationTokenController@sendByPush');
// Old URL, for retro-compatibility
Route::post('tokens', 'Api\AccountCreationTokenController@sendByPush');
Route::get('accounts/{sip}/info', 'Api\AccountController@info');
Route::post('accounts/with-account-creation-token', 'Api\AccountController@store');
// Old URL, for retro-compatibility
Route::post('accounts/with-token', 'Api\AccountController@store');
Route::post('accounts/{sip}/activate/email', 'Api\AccountController@activateEmail');
Route::post('accounts/{sip}/activate/phone', 'Api\AccountController@activatePhone');

View file

@ -64,10 +64,51 @@ class AccountCreationTokenTest extends TestCase
$response->assertStatus(403);
}
/**
* For retro-compatibility only
*/
public function testRetrocopatibilityToken()
{
$token = AccountCreationToken::factory()->create();
$response = $this->json($this->method, '/api/tokens', [
'pn_provider' => $token->pn_provider,
'pn_param' => $token->pn_param,
'pn_prid' => $token->pn_prid
]);
$response->assertStatus(403);
}
public function testInvalidToken()
{
$token = AccountCreationToken::factory()->create();
// Valid token
$response = $this->json($this->method, '/api/accounts/with-token', [
'username' => 'username',
'algorithm' => 'SHA-256',
'password' => '2',
'token' => $token->token
]);
$response->assertStatus(200);
// Expired token
$response = $this->json($this->method, '/api/accounts/with-token', [
'username' => 'username2',
'algorithm' => 'SHA-256',
'password' => '2',
'token' => $token->token
]);
$response->assertStatus(422);
}
/**
* For retrocompatibility only
*/
public function testRetrocompatibilityInvalidToken()
{
$token = AccountCreationToken::factory()->create();
// Invalid token
$response = $this->json($this->method, $this->accountRoute, [
'username' => 'username',

View file

@ -8,7 +8,7 @@
#%define _datadir %{_datarootdir}
#%define _docdir %{_datadir}/doc
%define build_number 139
%define build_number 140
%define var_dir /var/opt/belledonne-communications
%define opt_dir /opt/belledonne-communications/share/flexisip-account-manager