This commit is contained in:
Meghdad committed 2026-08-24 19:44:24 +03:30
commit 8d5446f466
232 files changed
+25416

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
<?php
use App\Models\MobileApp;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
beforeEach(function () {
Http::preventStrayRequests();
});
it('builds a state-bound Bazaar authorization URL', function () {
$app = MobileApp::factory()->create([
'package_name' => 'ir.example.login',
'bazaar_login_client_id' => 'client-id',
'bazaar_login_client_secret' => 'client-secret',
'bazaar_login_redirect_url' => 'https://api.example.test/callback',
]);
$this->withHeaders(appApiHeaders($app))
->getJson('/api/v1/apps/ir.example.login/bazaar/login/authorization-url?state=csrf-state')
->assertSuccessful()
->assertJsonPath('data.state', 'csrf-state')
->assertJsonPath('data.authorization_url', fn (string $url): bool => str_contains($url, 'client_id=client-id') && str_contains($url, 'state=csrf-state'));
});
it('exchanges Bazaar authorization codes without logging secrets', function () {
$app = MobileApp::factory()->create([
'package_name' => 'ir.example.oauth',
'bazaar_login_client_id' => 'client-id',
'bazaar_login_client_secret' => 'client-secret',
'bazaar_login_redirect_url' => 'https://api.example.test/callback',
]);
Http::fake([
'account.cafebazaar.ir/api/v0/tokens' => Http::response([
'access_token' => 'access-token',
'token_type' => 'Bearer',
'expires_in' => 3600,
'refresh_token' => 'refresh-token',
]),
]);
$this->withHeaders(appApiHeaders($app))
->postJson('/api/v1/apps/ir.example.oauth/bazaar/login/exchange', ['code' => 'authorization-code'])
->assertSuccessful()
->assertJsonPath('data.access_token', 'access-token');
Http::assertSent(fn (Request $request): bool => $request['client_id'] === 'client-id' && $request['client_secret'] === 'client-secret');
expect($app->bazaarApiRequests()->firstOrFail()->response_body['access_token'])->toBe('[REDACTED]');
});