From 9c6adbd24a2c37ee0fbc3701b0ac964e61ee8298 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 16 Sep 2023 17:23:03 +0200 Subject: [PATCH] Add handshake test --- .woodpecker/.test.yml | 1 + composer.json | 5 +++-- src/MTProto.php | 14 -------------- tests/handshake.php | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 tests/handshake.php diff --git a/.woodpecker/.test.yml b/.woodpecker/.test.yml index d572b4f37..7b4b4601e 100644 --- a/.woodpecker/.test.yml +++ b/.woodpecker/.test.yml @@ -35,4 +35,5 @@ steps: - TAG=${CI_COMMIT_TAG} commands: - apk add bash + - php tests/handshake.php - tests/test.sh \ No newline at end of file diff --git a/composer.json b/composer.json index aa7b3d719..f3fe4e46b 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "danog/ipc": "^1", "amphp/log": "^2", "danog/loop": "^1", - "phpseclib/phpseclib": "^3", + "phpseclib/phpseclib": "^3.0.22", "amphp/redis": "^2", "psr/http-factory": "^1.0", "psr/log": "^3", @@ -79,7 +79,8 @@ "ext-pdo": "Install the pdo extension to store session data on MySQL", "ext-openssl": "Install the openssl extension for faster crypto", "ext-uv": "Install the uv extension to greatly speed up MadelineProto!", - "ext-gmp": "Install the gmp extension to speed up authorization" + "ext-gmp": "Install the gmp extension to speed up authorization", + "ext-bcmath": "Install the bcmath extension to speed up authorization" }, "authors": [ { diff --git a/src/MTProto.php b/src/MTProto.php index 43d897e5d..a763a1b82 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -542,20 +542,6 @@ final class MTProto implements TLCallback, LoggerGetter $this->startLoops(); $this->datacenter->currentDatacenter = $this->settings->getConnection()->getTestMode() ? 10002 : 2; $this->getConfig(); - if ((!isset($this->authorization['user']['bot']) || !$this->authorization['user']['bot']) && $this->datacenter->getDataCenterConnection($this->datacenter->currentDatacenter)->hasTempAuthKey()) { - try { - $nearest_dc = $this->methodCallAsyncRead('help.getNearestDc', []); - $this->logger->logger(\sprintf(Lang::$current_lang['nearest_dc'], $nearest_dc['country'], $nearest_dc['nearest_dc']), Logger::NOTICE); - if ($nearest_dc['nearest_dc'] != $nearest_dc['this_dc']) { - $this->authorized_dc = $this->datacenter->currentDatacenter = (int) $nearest_dc['nearest_dc']; - } - } catch (RPCErrorException $e) { - if ($e->rpc !== 'BOT_METHOD_INVALID') { - throw $e; - } - } - } - $this->getConfig(); $this->startUpdateSystem(true); $this->v = self::V; diff --git a/tests/handshake.php b/tests/handshake.php new file mode 100644 index 000000000..a7713cfb3 --- /dev/null +++ b/tests/handshake.php @@ -0,0 +1,17 @@ +setApiId(4)->setApiHash('014b35b6184100b085b0d0572f9b5103'); + +$test = new API('/tmp/handshake_'.random_int(0, PHP_INT_MAX).'.madeline', $settings); +var_dump($test->help->getConfig([], ['datacenter' => 4])); +$test->logout();