From afae9421f6987c6c9ab0309bc2602949196c9d47 Mon Sep 17 00:00:00 2001 From: kasimi Date: Tue, 2 Jun 2020 19:08:07 +0200 Subject: [PATCH 1/9] [ticket/16510] Added config values to schema_data.sql PHPBB3-16510 --- phpBB/install/schemas/schema_data.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 3aa907fb29..c01c22e545 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -103,6 +103,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_last_subje INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_order', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('edit_time', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_search_return_chars', '300'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_unapproved_posts', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('email_check_mx', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('email_enable', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('email_force_sender', '0'); From e05876a5f6268523eaafdcce21a9cf99331b76ef Mon Sep 17 00:00:00 2001 From: kasimi Date: Wed, 3 Jun 2020 17:59:25 +0200 Subject: [PATCH 2/9] [ticket/16510] Test if all config options exist in schema_data.sql PHPBB3-16510 --- .../migrations_check_config_added_test.php | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 tests/migrations/migrations_check_config_added_test.php diff --git a/tests/migrations/migrations_check_config_added_test.php b/tests/migrations/migrations_check_config_added_test.php new file mode 100644 index 0000000000..25898778e8 --- /dev/null +++ b/tests/migrations/migrations_check_config_added_test.php @@ -0,0 +1,133 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class migrations_check_config_added_test extends phpbb_test_case +{ + public function setUp(): void + { + global $phpbb_root_path; + + // Get schema data from file + $this->schema_data = file_get_contents($phpbb_root_path . 'install/schemas/schema_data.sql'); + } + + public function get_config_options_from_migrations() + { + global $phpbb_root_path, $phpEx; + + $this->config = new \phpbb\config\config([ + 'search_type' => '\phpbb\search\fulltext_mysql', + ]); + + $this->db = $this->createMock('\phpbb\db\driver\driver_interface'); + $factory = new \phpbb\db\tools\factory(); + $this->db_tools = $factory->get($this->db); + $this->table_prefix = 'phpbb_'; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $phpEx; + + $this->container = new phpbb_mock_container_builder(); + + $this->migrator = new \phpbb\db\migrator( + $this->container, + $this->config, + $this->db, + $this->db_tools, + 'phpbb_migrations', + $this->phpbb_root_path, + $this->php_ext, + $this->table_prefix, + [], + new \phpbb\db\migration\helper() + ); + + $this->extension_manager = new phpbb_mock_extension_manager( + $this->phpbb_root_path, + [], + $this->container + ); + + // Get all migrations + $migrations = $this->extension_manager + ->get_finder() + ->core_path('phpbb/db/migration/data/') + ->extension_directory('/migrations') + ->get_classes(); + + $config_names = $config_removed = []; + foreach ($migrations as $key => $class) + { + // Filter non-migration files + if (!$this->migrator::is_migration($class)) + { + unset($migrations[$key]); + continue; + } + + // Create migration object instance + $migration = new $class($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); + + // $step[0] - action (config.*|if|custom|etc), $step[1][1] - action when wrapped with 'if' action + // $step[1] - action parameters for non-'if'-wrapped actions (0 => config_name and 1 => config_value) + // $step[1][0] - configuration option to add/update/remove (config_name) + foreach ($migration->update_data() as $migration_name => $step) + { + if ($step[0] == 'if') + { + $step = $step[1][1]; + } + + // Filter out actions different from config.* + if ($step[0] == 'custom' || strpos($step[0], 'config') === false) + { + continue; + } + + // Exclude removed configuration options and filter them out + if ($step[0] == 'config.remove') + { + if (!isset($config_removed[$step[1][0]])) + { + $config_removed[$step[1][0]] = true; + } + + continue; + } + + $action = explode('.', $step[0]); + $method = $action[1]; + $config_name = $step[1][0]; + + // Fill error entries for configuration options which were not added to shema_data.sql + if (!isset($config_names[$config_name]) && !isset($config_removed[$config_name])) + { + $config_names[$config_name] = [$config_name, $class]; + } + } + } + + return $config_names; + } + + /** + * @dataProvider get_config_options_from_migrations + */ + public function test_config_option_exists_in_schema_data($config_name, $class) + { + $message = 'Migration: %1$s, config_name: %2$s; not added to shema_data.sql'; + + $this->assertNotFalse(strpos($this->schema_data, $config_name), + sprintf($message, $class, $config_name) + ); + } +} From 9ba05606962d45d4a1bdbf43903114b8cefdeb4c Mon Sep 17 00:00:00 2001 From: kasimi Date: Tue, 2 Jun 2020 19:08:07 +0200 Subject: [PATCH 3/9] [ticket/16510] Added config values to schema_data.sql PHPBB3-16510 --- phpBB/install/schemas/schema_data.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index c01c22e545..2aeca4cd02 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -96,14 +96,14 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('coppa_mail', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('database_gc', '604800'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('dbms_version', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_dateformat', 'D M d, Y g:i a'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_search_return_chars', '300'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_style', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('delete_time', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_last_edited', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_last_subject', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_order', '0'); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('edit_time', '0'); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_search_return_chars', '300'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('display_unapproved_posts', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('edit_time', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('email_check_mx', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('email_enable', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('email_force_sender', '0'); From b33e95f1e7d766ea93e2d7c4be639c3c018d83fe Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 6 Jun 2020 17:39:19 +0200 Subject: [PATCH 4/9] [ticket/16510] Added config values for recaptchav3 to schema_data.sql PHPBB3-16510 --- phpBB/install/schemas/schema_data.sql | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 2aeca4cd02..2f1a84cd7b 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -257,6 +257,15 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('queue_trigger_post INSERT INTO phpbb_config (config_name, config_value) VALUES ('ranks_path', 'images/ranks'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('read_notification_expire_days', '30'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('read_notification_gc', '86400'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_domain', 'google.com'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_key', ''); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_method', 'post'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_secret', ''); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_threshold_default', '0.5'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_threshold_login', '0.5'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_threshold_post', '0.5'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_threshold_register', '0.5'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('recaptcha_v3_threshold_report', '0.5'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('referer_validation', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('remote_upload_verify', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('require_activation', '0'); From 5ae963cb344f0a700f661503fe21477c2bce4cde Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 6 Jun 2020 17:42:48 +0200 Subject: [PATCH 5/9] [ticket/16510] Added .htaccess to v330 & v33x migration folders PHPBB3-16510 --- phpBB/phpbb/db/migration/data/v330/.htaccess | 33 ++++++++++++++++++++ phpBB/phpbb/db/migration/data/v33x/.htaccess | 33 ++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v330/.htaccess create mode 100644 phpBB/phpbb/db/migration/data/v33x/.htaccess diff --git a/phpBB/phpbb/db/migration/data/v330/.htaccess b/phpBB/phpbb/db/migration/data/v330/.htaccess new file mode 100644 index 0000000000..44242b5418 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v330/.htaccess @@ -0,0 +1,33 @@ +# With Apache 2.4 the "Order, Deny" syntax has been deprecated and moved from +# module mod_authz_host to a new module called mod_access_compat (which may be +# disabled) and a new "Require" syntax has been introduced to mod_authz_host. +# We could just conditionally provide both versions, but unfortunately Apache +# does not explicitly tell us its version if the module mod_version is not +# available. In this case, we check for the availability of module +# mod_authz_core (which should be on 2.4 or higher only) as a best guess. + + + + Order Allow,Deny + Deny from All + + + = 2.4> + + Require all denied + + + + + + + Order Allow,Deny + Deny from All + + + + + Require all denied + + + diff --git a/phpBB/phpbb/db/migration/data/v33x/.htaccess b/phpBB/phpbb/db/migration/data/v33x/.htaccess new file mode 100644 index 0000000000..44242b5418 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v33x/.htaccess @@ -0,0 +1,33 @@ +# With Apache 2.4 the "Order, Deny" syntax has been deprecated and moved from +# module mod_authz_host to a new module called mod_access_compat (which may be +# disabled) and a new "Require" syntax has been introduced to mod_authz_host. +# We could just conditionally provide both versions, but unfortunately Apache +# does not explicitly tell us its version if the module mod_version is not +# available. In this case, we check for the availability of module +# mod_authz_core (which should be on 2.4 or higher only) as a best guess. + + + + Order Allow,Deny + Deny from All + + + = 2.4> + + Require all denied + + + + + + + Order Allow,Deny + Deny from All + + + + + Require all denied + + + From 5e23959e121ae5525ed1506ab66e664dbd80cddf Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 6 Jun 2020 21:01:58 +0200 Subject: [PATCH 6/9] [ticket/16510] Fixed test PHPBB3-16510 --- tests/migrations/migrations_check_config_added_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/migrations/migrations_check_config_added_test.php b/tests/migrations/migrations_check_config_added_test.php index 25898778e8..aa37d6945b 100644 --- a/tests/migrations/migrations_check_config_added_test.php +++ b/tests/migrations/migrations_check_config_added_test.php @@ -50,6 +50,7 @@ class migrations_check_config_added_test extends phpbb_test_case [], new \phpbb\db\migration\helper() ); + $this->container->set('migrator', $this->migrator); $this->extension_manager = new phpbb_mock_extension_manager( $this->phpbb_root_path, @@ -75,7 +76,7 @@ class migrations_check_config_added_test extends phpbb_test_case } // Create migration object instance - $migration = new $class($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); + $migration = $this->migrator->get_migration($class); // $step[0] - action (config.*|if|custom|etc), $step[1][1] - action when wrapped with 'if' action // $step[1] - action parameters for non-'if'-wrapped actions (0 => config_name and 1 => config_value) From b5a1c54ab2bf47c131bb37ea550f08011e768c92 Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 6 Jun 2020 21:48:15 +0200 Subject: [PATCH 7/9] [ticket/16510] Exclude deleted config entries in test PHPBB3-16510 --- .../migrations_check_config_added_test.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/migrations/migrations_check_config_added_test.php b/tests/migrations/migrations_check_config_added_test.php index aa37d6945b..9c34428dae 100644 --- a/tests/migrations/migrations_check_config_added_test.php +++ b/tests/migrations/migrations_check_config_added_test.php @@ -94,29 +94,28 @@ class migrations_check_config_added_test extends phpbb_test_case continue; } + $config_name = $step[1][0]; // Exclude removed configuration options and filter them out if ($step[0] == 'config.remove') { - if (!isset($config_removed[$step[1][0]])) + if (!isset($config_removed[$config_name])) { - $config_removed[$step[1][0]] = true; + $config_removed[$config_name] = true; } continue; } - $action = explode('.', $step[0]); - $method = $action[1]; - $config_name = $step[1][0]; - // Fill error entries for configuration options which were not added to shema_data.sql - if (!isset($config_names[$config_name]) && !isset($config_removed[$config_name])) + if (!isset($config_names[$config_name])) { $config_names[$config_name] = [$config_name, $class]; } } } + // Drop configuration options which were removed by config.remove + $config_names = array_diff_key($config_names, $config_removed); return $config_names; } From 2d1e8dc8a05cefb1fd786739ca9e7c38df57353c Mon Sep 17 00:00:00 2001 From: kasimi Date: Sat, 6 Jun 2020 21:48:43 +0200 Subject: [PATCH 8/9] [ticket/16510] Run feed test without displaying unapproved posts PHPBB3-16510 --- tests/test_framework/phpbb_functional_test_case.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 94a7d4e7af..8901766930 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -55,6 +55,8 @@ class phpbb_functional_test_case extends phpbb_test_case // installed, and also before each test case is run. self::$config['table_prefix'] = 'phpbb_'; + self::$config['display_unapproved_posts'] = false; + if (!isset(self::$config['phpbb_functional_url'])) { self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); From 8ab866e7f40ed11ea6248e266d95f32cf18846e3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 7 Jun 2020 10:14:30 +0200 Subject: [PATCH 9/9] [ticket/16510] Disable showing unapproved posts to users in feed test PHPBB3-16510 --- tests/functional/feed_test.php | 7 +++++++ tests/test_framework/phpbb_functional_test_case.php | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php index 8f6fc25650..b26a228523 100644 --- a/tests/functional/feed_test.php +++ b/tests/functional/feed_test.php @@ -63,6 +63,13 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $crawler = self::submit($form); self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); + // Disable showing unapproved posts to users + $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=features"); + $form = $crawler->selectButton('Submit')->form(); + $form->setValues(['config[display_unapproved_posts]' => false]); + $crawler = self::submit($form); + self::assertContainsLang('CONFIG_UPDATED', $crawler->filter('.successbox')->text()); + // Special config (Guest can't see attachments) $this->add_lang('acp/permissions'); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8901766930..94a7d4e7af 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -55,8 +55,6 @@ class phpbb_functional_test_case extends phpbb_test_case // installed, and also before each test case is run. self::$config['table_prefix'] = 'phpbb_'; - self::$config['display_unapproved_posts'] = false; - if (!isset(self::$config['phpbb_functional_url'])) { self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');