|
|
@@ -48,6 +48,7 @@ class ApiCryptoTest extends TestCase
|
|
|
'api_crypto.enabled' => true,
|
|
|
'api_crypto.key' => $key,
|
|
|
'api_crypto.allow_plaintext' => false,
|
|
|
+ 'api_crypto.plaintext_user_ids' => [],
|
|
|
'api_crypto.timestamp_tolerance' => 300,
|
|
|
'api_crypto.max_payload_bytes' => 2097152,
|
|
|
'cache.default' => 'array',
|
|
|
@@ -335,6 +336,69 @@ class ApiCryptoTest extends TestCase
|
|
|
self::assertSame('{"code":0}', $this->send('/api/wallet/probe')->getContent());
|
|
|
}
|
|
|
|
|
|
+ public function test_allowlisted_user_can_send_plaintext_and_receives_plaintext_for_encrypted_requests(): void
|
|
|
+ {
|
|
|
+ $this->createWalletFixture();
|
|
|
+ DB::table('users')->update(['user_id' => '9000000001', 'real_name' => 'Fixture Name']);
|
|
|
+ DB::table('user_session')->update(['user_id' => '9000000001']);
|
|
|
+ config(['api_crypto.plaintext_user_ids' => ['99', '9000000001']]);
|
|
|
+ $headers = ['HTTP_AUTHORIZATION' => self::TOKEN];
|
|
|
+
|
|
|
+ $response = $this->send('/api/wallet/withdrawChannel?lang=en', 'GET', $headers);
|
|
|
+ self::assertSame(200, $response->getStatusCode());
|
|
|
+ self::assertSame('0', $response->headers->get('X-Api-Encrypted'));
|
|
|
+ self::assertStringContainsString('no-store', $response->headers->get('Cache-Control'));
|
|
|
+ self::assertStringContainsString('X-Api-Encrypted', $response->headers->get('Access-Control-Expose-Headers'));
|
|
|
+ $body = json_decode($response->getContent(), true);
|
|
|
+ self::assertSame('Bank card', array_column($body['data'], 'label', 'value')['DF001']);
|
|
|
+
|
|
|
+ Schema::create('pc_issues', function (Blueprint $table) {
|
|
|
+ $table->id();
|
|
|
+ $table->integer('status');
|
|
|
+ $table->string('issue_no');
|
|
|
+ });
|
|
|
+ $response = $this->send('/api/newPc/yuanTou', 'GET', $headers);
|
|
|
+ self::assertSame('0', $response->headers->get('X-Api-Encrypted'));
|
|
|
+ self::assertSame(0, json_decode($response->getContent(), true)['code']);
|
|
|
+
|
|
|
+ $response = $this->sendEncrypted('/api/wallet/addBank', 'POST', [
|
|
|
+ 'channel' => 'DF001', 'bank_name' => 'Fixture Bank', 'bank_branch' => 'Fixture Branch', 'card_no' => '12345',
|
|
|
+ ], true);
|
|
|
+ self::assertSame('0', $response->headers->get('X-Api-Encrypted'));
|
|
|
+ self::assertSame(0, json_decode($response->getContent(), true)['code']);
|
|
|
+ self::assertSame('12345', DB::table('banks')->sole()->card_no);
|
|
|
+
|
|
|
+ $response = $this->send('/api/wallet/addBank', 'POST', $headers + ['HTTP_X_API_ENCRYPTED' => '1']);
|
|
|
+ self::assertSame(400, $response->getStatusCode());
|
|
|
+ self::assertSame('0', $response->headers->get('X-Api-Encrypted'));
|
|
|
+ self::assertSame(4002, json_decode($response->getContent(), true)['code']);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_allowlist_requires_the_matching_users_active_token(): void
|
|
|
+ {
|
|
|
+ $this->createWalletFixture();
|
|
|
+ DB::table('users')->update(['user_id' => '99']);
|
|
|
+ DB::table('user_session')->update(['user_id' => '99']);
|
|
|
+ $url = '/api/wallet/withdrawChannel?user_id=42';
|
|
|
+ $headers = ['HTTP_AUTHORIZATION' => self::TOKEN];
|
|
|
+ config(['api_crypto.plaintext_user_ids' => ['42']]);
|
|
|
+
|
|
|
+ // 42 is the member_id and the submitted parameter, but the token belongs to user_id 99.
|
|
|
+ self::assertSame(4001, $this->unwrap($this->send($url, 'GET', $headers))['code']);
|
|
|
+ self::assertSame(0, $this->unwrap($this->sendEncrypted($url, 'GET', (object) [], true))['code']);
|
|
|
+
|
|
|
+ config(['api_crypto.plaintext_user_ids' => ['99']]);
|
|
|
+ self::assertSame(4001, $this->unwrap($this->send($url))['code']);
|
|
|
+ self::assertSame(4001, $this->unwrap($this->send($url, 'GET', ['HTTP_AUTHORIZATION' => 'invalid-token']))['code']);
|
|
|
+
|
|
|
+ DB::table('users')->update(['is_banned' => 1]);
|
|
|
+ self::assertSame(4001, $this->unwrap($this->send($url, 'GET', $headers))['code']);
|
|
|
+
|
|
|
+ DB::table('users')->update(['is_banned' => 0]);
|
|
|
+ DB::table('user_session')->update(['create_time' => time() - 86401, 'update_time' => 0]);
|
|
|
+ self::assertSame(4001, $this->unwrap($this->send($url, 'GET', $headers))['code']);
|
|
|
+ }
|
|
|
+
|
|
|
public function test_withdrawal_account_and_address_apis_ignore_and_hide_aliases(): void
|
|
|
{
|
|
|
$this->createWalletFixture();
|
|
|
@@ -539,6 +603,7 @@ class ApiCryptoTest extends TestCase
|
|
|
$table->id();
|
|
|
$table->string('user_id');
|
|
|
$table->string('member_id');
|
|
|
+ $table->integer('is_banned')->default(0);
|
|
|
$table->string('account')->default('fixture-login');
|
|
|
$table->string('first_name')->nullable();
|
|
|
$table->string('admin_note')->nullable();
|