Skip to content

Commit 5e3e86a

Browse files
authored
Merge pull request #21 from noplanman/loosen_requirements
Loosen requirements
2 parents f997e35 + d126fb3 commit 5e3e86a

File tree

8 files changed

+113
-77
lines changed

8 files changed

+113
-77
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
77
- Execute commands via cron, using `cron` action and `g` parameter.
88
### Changed
99
- Remodelled the config array to a more flexible structure.
10+
- `bot_username` and `secret` are no longer vital parameters.
1011
### Deprecated
1112
### Removed
1213
### Fixed
1314
- Initialise loggers before anything else, to allow logging of all errors.
1415
### Security
16+
- Enforce non-empty secret when using webhook.
1517

1618
## [0.43.0] - 2017-04-17
1719
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
],
2626
"require": {
2727
"php": "^7.0",
28-
"longman/telegram-bot": "^0.43",
28+
"longman/telegram-bot": "^0.44",
2929
"allty/utils-ip": "dev-master"
3030
},
3131
"require-dev": {

composer.lock

Lines changed: 84 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<ini name="error_reporting" value="-1" />
1818
<const name="PHPUNIT_TEST" value="true" />
1919
<const name="PHPUNIT_DB_HOST" value="127.0.0.1"/>
20-
<const name="PHPUNIT_DB_NAME" value="telegrambot"/>
2120
<const name="PHPUNIT_DB_USER" value="root"/>
22-
<const name="PHPUNIT_DB_PASS" value=""/>
21+
<const name="PHPUNIT_DB_PASSWORD" value=""/>
22+
<const name="PHPUNIT_DB_DATABASE" value="telegrambot"/>
2323
</php>
2424
</phpunit>

src/BotManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function validateSecret(bool $force = false): self
173173
if ($force || 'cli' !== PHP_SAPI) {
174174
$secret = $this->params->getBotParam('secret');
175175
$secret_get = $this->params->getScriptParam('s');
176-
if ($secret_get !== $secret) {
176+
if (!isset($secret, $secret_get) || $secret !== $secret_get) {
177177
throw new InvalidAccessException('Invalid access');
178178
}
179179
}

src/Params.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class Params
3030
*/
3131
private static $valid_vital_bot_params = [
3232
'api_key',
33-
'bot_username',
34-
'secret',
3533
];
3634

3735
/**
3836
* @var array List of valid extra parameters that can be passed.
3937
*/
4038
private static $valid_extra_bot_params = [
39+
'bot_username',
40+
'secret',
4141
'validate_request',
4242
'valid_ips',
4343
'webhook',
@@ -126,6 +126,11 @@ private function validateAndSetBotParams($params): self
126126
$this->bot_params[$vital_key] = $params[$vital_key];
127127
}
128128

129+
// Special case, where secret MUST be defined if we have a webhook.
130+
if (($params['webhook'] ?? null) && !($params['secret'] ?? null)) {
131+
throw new InvalidParamsException('Some vital info is missing: secret');
132+
}
133+
129134
// Set all extra params.
130135
foreach (self::$valid_extra_bot_params as $extra_key) {
131136
if (!array_key_exists($extra_key, $params)) {

0 commit comments

Comments
 (0)