diff options
-rw-r--r-- | application/Updater.php | 26 | ||||
-rw-r--r-- | index.php | 7 | ||||
-rw-r--r-- | tests/Updater/UpdaterTest.php | 64 |
3 files changed, 96 insertions, 1 deletions
diff --git a/application/Updater.php b/application/Updater.php index f07e7697..dece2c02 100644 --- a/application/Updater.php +++ b/application/Updater.php | |||
@@ -457,6 +457,32 @@ class Updater | |||
457 | } | 457 | } |
458 | return true; | 458 | return true; |
459 | } | 459 | } |
460 | |||
461 | /** | ||
462 | * Add download size and timeout to the configuration file | ||
463 | * | ||
464 | * @return bool true if the update is successful, false otherwise. | ||
465 | */ | ||
466 | public function updateMethodDownloadSizeAndTimeoutConf() | ||
467 | { | ||
468 | if ($this->conf->exists('general.download_max_size') | ||
469 | && $this->conf->exists('general.download_timeout') | ||
470 | ) { | ||
471 | return true; | ||
472 | } | ||
473 | |||
474 | if (! $this->conf->exists('general.download_max_size')) { | ||
475 | $this->conf->set('general.download_max_size', 1024*1024*4); | ||
476 | } | ||
477 | |||
478 | if (! $this->conf->exists('general.download_timeout')) { | ||
479 | $this->conf->set('general.download_timeout', 30); | ||
480 | } | ||
481 | |||
482 | $this->conf->write($this->isLoggedIn); | ||
483 | |||
484 | return true; | ||
485 | } | ||
460 | } | 486 | } |
461 | 487 | ||
462 | /** | 488 | /** |
@@ -1376,7 +1376,12 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
1376 | if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) { | 1376 | if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) { |
1377 | // Short timeout to keep the application responsive | 1377 | // Short timeout to keep the application responsive |
1378 | // The callback will fill $charset and $title with data from the downloaded page. | 1378 | // The callback will fill $charset and $title with data from the downloaded page. |
1379 | get_http_response($url, 25, 4194304, get_curl_download_callback($charset, $title)); | 1379 | get_http_response( |
1380 | $url, | ||
1381 | $conf->get('general.download_max_size', 4194304), | ||
1382 | $conf->get('general.download_timeout', 30), | ||
1383 | get_curl_download_callback($charset, $title) | ||
1384 | ); | ||
1380 | if (! empty($title) && strtolower($charset) != 'utf-8') { | 1385 | if (! empty($title) && strtolower($charset) != 'utf-8') { |
1381 | $title = mb_convert_encoding($title, 'utf-8', $charset); | 1386 | $title = mb_convert_encoding($title, 'utf-8', $charset); |
1382 | } | 1387 | } |
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index fed175df..94e3c7d3 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -620,4 +620,68 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; | |||
620 | $this->assertTrue($updater->updateMethodAtomDefault()); | 620 | $this->assertTrue($updater->updateMethodAtomDefault()); |
621 | $this->assertTrue($this->conf->get('feed.show_atom')); | 621 | $this->assertTrue($this->conf->get('feed.show_atom')); |
622 | } | 622 | } |
623 | |||
624 | /** | ||
625 | * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined. | ||
626 | */ | ||
627 | public function testUpdateMethodDownloadSizeAndTimeoutConf() | ||
628 | { | ||
629 | $sandboxConf = 'sandbox/config'; | ||
630 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
631 | $this->conf = new ConfigManager($sandboxConf); | ||
632 | $updater = new Updater([], [], $this->conf, true); | ||
633 | $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf()); | ||
634 | $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); | ||
635 | $this->assertEquals(30, $this->conf->get('general.download_timeout')); | ||
636 | |||
637 | $this->conf = new ConfigManager($sandboxConf); | ||
638 | $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); | ||
639 | $this->assertEquals(30, $this->conf->get('general.download_timeout')); | ||
640 | } | ||
641 | |||
642 | /** | ||
643 | * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined. | ||
644 | */ | ||
645 | public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore() | ||
646 | { | ||
647 | $sandboxConf = 'sandbox/config'; | ||
648 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
649 | $this->conf = new ConfigManager($sandboxConf); | ||
650 | $this->conf->set('general.download_max_size', 38); | ||
651 | $this->conf->set('general.download_timeout', 70); | ||
652 | $updater = new Updater([], [], $this->conf, true); | ||
653 | $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf()); | ||
654 | $this->assertEquals(38, $this->conf->get('general.download_max_size')); | ||
655 | $this->assertEquals(70, $this->conf->get('general.download_timeout')); | ||
656 | } | ||
657 | |||
658 | /** | ||
659 | * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here. | ||
660 | */ | ||
661 | public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize() | ||
662 | { | ||
663 | $sandboxConf = 'sandbox/config'; | ||
664 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
665 | $this->conf = new ConfigManager($sandboxConf); | ||
666 | $this->conf->set('general.download_max_size', 38); | ||
667 | $updater = new Updater([], [], $this->conf, true); | ||
668 | $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf()); | ||
669 | $this->assertEquals(38, $this->conf->get('general.download_max_size')); | ||
670 | $this->assertEquals(30, $this->conf->get('general.download_timeout')); | ||
671 | } | ||
672 | |||
673 | /** | ||
674 | * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here. | ||
675 | */ | ||
676 | public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout() | ||
677 | { | ||
678 | $sandboxConf = 'sandbox/config'; | ||
679 | copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); | ||
680 | $this->conf = new ConfigManager($sandboxConf); | ||
681 | $this->conf->set('general.download_timeout', 3); | ||
682 | $updater = new Updater([], [], $this->conf, true); | ||
683 | $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf()); | ||
684 | $this->assertEquals(4194304, $this->conf->get('general.download_max_size')); | ||
685 | $this->assertEquals(3, $this->conf->get('general.download_timeout')); | ||
686 | } | ||
623 | } | 687 | } |