Skip to content

Commit 228494f

Browse files
committed
Improve fuzzing
1 parent 3e61f57 commit 228494f

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

examples/bot.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function getReportPeers()
104104
*/
105105
public function onStart(): void
106106
{
107+
$this->account->updateUsername(username: 'test');
107108
$this->logger("The bot was started!");
108109
$this->logger($this->getFullInfo('MadelineProto'));
109110

tools/fuzzer.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use danog\MadelineProto\Logger;
77
use danog\MadelineProto\Magic;
88
use danog\MadelineProto\PTSException;
9+
use danog\MadelineProto\RPCError\BusinessConnectionNotAllowedError;
910
use danog\MadelineProto\RPCErrorException;
1011
use danog\MadelineProto\Settings;
1112
use danog\MadelineProto\Settings\Logger as SettingsLogger;
@@ -69,10 +70,11 @@ function getTL(TLSchema $schema)
6970
}
7071
Assert::true(preg_match('/^[a-zA-Z0-9_-]*$/', $auth) === 1, 'TELERPC_AUTH_TOKEN can only contain a-z, A-Z, 0-9, _ and -');
7172

73+
$client = HttpClientBuilder::buildDefault();
7274
if ($auth) {
7375
$res = json_decode(
7476
(
75-
HttpClientBuilder::buildDefault()
77+
$client
7678
->request(new Request('https://report-rpc-error.madelineproto.xyz/?auth='.$auth.'&cleanup=1'))
7779
)->getBody()->buffer(),
7880
true,
@@ -205,10 +207,24 @@ function call(API $API, string $method, array $args = []): void
205207
}
206208
unset($methods["user $name"]);
207209
});
208-
$methods["business $name"] = async(static function () use ($bot, $name, $cId, &$methods): void {
210+
$methods["business $name"] = async(static function () use ($bot, $name, $cId, $client, $auth, &$methods): void {
211+
$ok = true;
209212
try {
210213
call($bot, $name, ['businessConnectionId' => $cId]);
211-
} catch (RPCErrorException|PTSException) {
214+
} catch (PTSException|BusinessConnectionNotAllowedError) {
215+
$ok = false;
216+
} catch (RPCErrorException $e) {
217+
echo "Got ".$e->getMessage()." for business $name".PHP_EOL;
218+
}
219+
220+
if ($ok && $auth) {
221+
$res = json_decode(
222+
(
223+
$client
224+
->request(new Request('https://report-rpc-error.madelineproto.xyz/?auth='.$auth.'&error=BUSINESS_CONNECTION_INVALID&method='.urlencode($name).'&code=400'))
225+
)->getBody()->buffer(),
226+
true,
227+
);
212228
}
213229
unset($methods["business $name"]);
214230
});

0 commit comments

Comments
 (0)