diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3fe0539..4abbcfa 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,9 +4,9 @@ env: EXTNAME: phpbb/teamsecurity # Your extension vendor/package name SNIFF: 1 # Run code sniffer on your code? 1 or 0 IMAGE_ICC: 1 # Run icc profile sniffer on your images? 1 or 0 - EPV: 1 # Run EPV (Extension Pre Validator) on your code? 1 or 0 + EPV: 0 # Run EPV (Extension Pre Validator) on your code? 1 or 0 EXECUTABLE_FILES: 1 # Run check for executable files? 1 or 0 - PHPBB_BRANCH: 3.3.x # The phpBB branch to run tests on + PHPBB_BRANCH: master # The phpBB branch to run tests on on: push: @@ -21,12 +21,12 @@ on: jobs: # START Basic Checks Job (EPV, code sniffer, images check, etc.) basic-checks: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: include: - - php: '7.2' - db: "none" + - db: 'none' + php: '8.1' NOTESTS: 1 name: PHP ${{ matrix.php }} - ${{ matrix.db }} @@ -48,7 +48,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap + extensions: dom, curl, libxml, mbstring, zip, pcntl, intl, gd, exif, iconv coverage: none - name: Setup environment for phpBB @@ -89,44 +89,42 @@ jobs: # START MySQL and MariaDB Job mysql-tests: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: include: - - php: '7.2' - db: "mariadb:10.1" - - php: '7.2' + - php: '8.1' db: "mariadb:10.2" - - php: '7.2' + - php: '8.1' db: "mariadb:10.3" - - php: '7.2' + - php: '8.1' db: "mariadb:10.4" - - php: '7.2' - db: "mariadb:10.5" - - php: '7.2' - db: "mysql:5.6" + - php: '8.1' + db: "mariadb:10.6" + - php: '8.1' + db: "mariadb:10.9" + - php: '8.1' + db: "mariadb:10.10" + - php: '8.1' + db: "mariadb:10.11" + - php: '8.1' + db: "mysql:5.7" db_alias: "MyISAM Tests" MYISAM: 1 - - php: '7.2' - db: "mysql:5.6" - - php: '7.2' - db: "mysql:5.7" - - php: '7.3' - db: "mysql:5.7" - - php: '7.4' - db: "mysql:5.7" - - php: '7.4' - db: "mysql:8.0" - - php: '8.0' - db: "mysql:5.7" - php: '8.1' - db: "mysql:5.7" + db: "mysql:8.1" - php: '8.2' - db: "mysql:5.7" + db: "mysql:8.0" + - php: '8.2' + db: "mariadb:10.2" - php: '8.3' db: "mysql:5.7" + - php: '8.3' + db: "mariadb:10.2" - php: '8.4' - db: "mysql:5.7" + db: "mysql:8.0" + - php: '8.4' + db: "mariadb:10.3" name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }} @@ -209,44 +207,38 @@ jobs: # START PostgreSQL Job postgres-tests: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: include: - - php: '7.2' + - php: '8.1' db: "postgres:9.5" - - php: '7.2' + - php: '8.1' db: "postgres:9.6" - - php: '7.2' + - php: '8.1' db: "postgres:10" - - php: '7.2' + - php: '8.1' db: "postgres:11" - - php: '7.2' - db: "postgres:12" - - php: '7.2' - db: "postgres:13" - - php: '7.3' - db: "postgres:13" - - php: '7.4' - db: "postgres:13" - - php: '8.0' + - php: '8.1' db: "postgres:12" - - php: '8.0' + - php: '8.1' db: "postgres:13" - php: '8.1' db: "postgres:14" + - php: '8.1' + db: "postgres:15" - php: '8.2' - db: "postgres:14" + db: "postgres:9.5" - php: '8.3' - db: "postgres:14" + db: "postgres:9.5" - php: '8.4' - db: "postgres:14" + db: "postgres:9.5" name: PHP ${{ matrix.php }} - ${{ matrix.db }} services: postgres: - image: ${{ matrix.db != 'postgres:9.5' && matrix.db != 'postgres:9.6' && matrix.db != 'postgres:10' && matrix.db != 'postgres:11' && matrix.db != 'postgres:12' && matrix.db != 'postgres:13' && 'postgres:10' || matrix.db }} + image: ${{ matrix.db != 'postgres:9.5' && matrix.db != 'postgres:9.6' && matrix.db != 'postgres:10' && matrix.db != 'postgres:11' && matrix.db != 'postgres:12' && matrix.db != 'postgres:13' && matrix.db != 'postgres:14' && matrix.db != 'postgres:15' && 'postgres:10' || matrix.db }} env: POSTGRES_HOST: localhost POSTGRES_USER: postgres @@ -294,7 +286,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap + extensions: dom, curl, libxml, mbstring, zip, pcntl, intl, gd, exif, iconv, pgsql, pdo, pdo_pgsql coverage: none - name: Setup environment for phpBB @@ -325,24 +317,27 @@ jobs: # START Other Tests Job (SQLite 3 and mssql) other-tests: - runs-on: ubuntu-22.04 + runs-on: ubuntu-20.04 strategy: matrix: include: - - php: '7.2' + - php: '8.1' db: "sqlite3" - - php: '7.2' + - php: '8.1' db: "mcr.microsoft.com/mssql/server:2017-latest" db_alias: 'MSSQL 2017' - - php: '7.2' - db: "mcr.microsoft.com/mssql/server:2019-latest" + - php: '8.1' + db: "mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04" db_alias: 'MSSQL 2019' + - php: '8.1' + db: "mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04" + db_alias: 'MSSQL 2022' name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }} services: mssql: - image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-latest' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }} + image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04' && matrix.db != 'mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }} env: SA_PASSWORD: "Pssw0rd_12" ACCEPT_EULA: "y" @@ -382,7 +377,7 @@ jobs: env: MATRIX_DB: ${{ matrix.db }} run: | - if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-latest' ] + if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-CU27-ubuntu-20.04' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2022-CU13-ubuntu-22.04' ] then db='mssql' else @@ -394,7 +389,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap + extensions: dom, curl, libxml, mbstring, zip, pcntl, intl, gd, exif, iconv, sqlsrv, pdo, pdo_sqlsrv coverage: none - name: Setup environment for phpBB diff --git a/README.md b/README.md index 367246a..365d47c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is the repository for the development of the Team Security extension for phpBB. -[![Build Status](https://github.com/phpbb-extensions/teamsecurity/workflows/Tests/badge.svg)](https://github.com/phpbb-extensions/teamsecurity/actions) +[![Build Status](https://github.com/phpbb-extensions/teamsecurity/actions/workflows/tests.yml/badge.svg)](https://github.com/phpbb-extensions/teamsecurity/actions) This extension adds passive security features to phpBB that allow the board's founder to watch for potential attacks against members of privileged groups, such as Administrators and Moderators. diff --git a/composer.json b/composer.json index 568ebb5..a437012 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "phpbb-extension", "description": "Security measures to help watch over team member accounts.", "homepage": "https://www.phpbb.com", - "version": "1.0.1", + "version": "1.1.0-dev", "license": "GPL-2.0-only", "authors": [ { @@ -19,13 +19,18 @@ } ], "require": { - "php": ">=5.4", + "php": ">=8.1", "composer/installers": "~1.0" }, "extra": { "display-name": "Team Security Measures", "soft-require": { - "phpbb/phpbb": ">=3.2.0" + "phpbb/phpbb": ">=4.0.0@dev,<4.1.0@dev" + } + }, + "config": { + "allow-plugins": { + "composer/installers": true } } } diff --git a/composer.lock b/composer.lock index 90e17fa..b4d2285 100644 --- a/composer.lock +++ b/composer.lock @@ -1,44 +1,50 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "hash": "e850460513ee3fc3b5ef50f07ae2122c", - "content-hash": "16d560f796d2f55cacc2ba4181c46e11", + "content-hash": "64ffa1585e09458ba10ee672ced8ce36", "packages": [ { "name": "composer/installers", - "version": "v1.0.20", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/composer/installers.git", - "reference": "1bff8aa77a18f3616f468ed8000cf86a5725bac3" + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/installers/zipball/1bff8aa77a18f3616f468ed8000cf86a5725bac3", - "reference": "1bff8aa77a18f3616f468ed8000cf86a5725bac3", + "url": "https://api.github.com/repos/composer/installers/zipball/d20a64ed3c94748397ff5973488761b22f6d3f19", + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19", "shasum": "" }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0" + }, "replace": { "roundcube/plugin-installer": "*", "shama/baton": "*" }, "require-dev": { - "composer/composer": "1.0.*@dev", - "phpunit/phpunit": "4.1.*" + "composer/composer": "1.6.* || ^2.0", + "composer/semver": "^1 || ^3", + "phpstan/phpstan": "^0.12.55", + "phpstan/phpstan-phpunit": "^0.12.16", + "symfony/phpunit-bridge": "^4.2 || ^5", + "symfony/process": "^2.3" }, - "type": "composer-installer", + "type": "composer-plugin", "extra": { - "class": "Composer\\Installers\\Installer", + "class": "Composer\\Installers\\Plugin", "branch-alias": { - "dev-master": "1.0-dev" + "dev-main": "1.x-dev" } }, "autoload": { - "psr-0": { - "Composer\\Installers\\": "src/" + "psr-4": { + "Composer\\Installers\\": "src/Composer/Installers" } }, "notification-url": "https://packagist.org/downloads/", @@ -53,53 +59,103 @@ } ], "description": "A multi-framework Composer library installer", - "homepage": "http://composer.github.com/installers/", + "homepage": "https://composer.github.io/installers/", "keywords": [ "Craft", "Dolibarr", + "Eliasis", "Hurad", + "ImageCMS", + "Kanboard", + "Lan Management System", "MODX Evo", + "MantisBT", + "Mautic", + "Maya", "OXID", + "Plentymarkets", + "Porto", + "RadPHP", "SMF", + "Starbug", "Thelia", + "Whmcs", "WolfCMS", "agl", + "aimeos", "annotatecms", + "attogram", "bitrix", "cakephp", "chef", + "cockpit", "codeigniter", "concrete5", "croogo", "dokuwiki", "drupal", + "eZ Platform", "elgg", + "expressionengine", "fuelphp", "grav", "installer", + "itop", "joomla", + "known", "kohana", "laravel", + "lavalite", "lithium", "magento", + "majima", "mako", "mediawiki", + "miaoxing", "modulework", + "modx", "moodle", + "osclass", + "pantheon", "phpbb", "piwik", "ppi", + "processwire", "puppet", + "pxcms", + "reindex", "roundcube", "shopware", "silverstripe", + "sydes", + "sylius", "symfony", + "tastyigniter", "typo3", "wordpress", + "yawik", "zend", "zikula" ], - "time": "2015-01-11 03:51:11" + "support": { + "issues": "https://github.com/composer/installers/issues", + "source": "https://github.com/composer/installers/tree/v1.12.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2021-09-13T08:19:44+00:00" } ], "packages-dev": [], @@ -109,7 +165,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.3" + "php": ">=8.1" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "2.6.0" } diff --git a/config/services.yml b/config/services.yml index a65569f..62c47cb 100644 --- a/config/services.yml +++ b/config/services.yml @@ -3,6 +3,7 @@ services: class: phpbb\teamsecurity\event\listener arguments: - '@config' + - '@messenger.method.email' - '@language' - '@log' - '@user' diff --git a/event/listener.php b/event/listener.php index 2c6ebc3..22b90ae 100644 --- a/event/listener.php +++ b/event/listener.php @@ -10,6 +10,11 @@ namespace phpbb\teamsecurity\event; +use phpbb\config\config; +use phpbb\language\language; +use phpbb\log\log; +use phpbb\messenger\method\email; +use phpbb\user; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -17,16 +22,19 @@ */ class listener implements EventSubscriberInterface { - /** @var \phpbb\config\config */ + /** @var config */ protected $config; - /** @var \phpbb\language\language */ + /** @var email */ + protected $email_method; + + /** @var language */ protected $language; - /** @var \phpbb\log\log */ + /** @var log */ protected $log; - /** @var \phpbb\user */ + /** @var user */ protected $user; /** @var string phpBB root path */ @@ -38,17 +46,19 @@ class listener implements EventSubscriberInterface /** * Constructor * - * @param \phpbb\config\config $config Config object - * @param \phpbb\language\language $language Language object - * @param \phpbb\log\log $log The phpBB log system - * @param \phpbb\user $user User object + * @param config $config Config object + * @param email $email_method Email method + * @param language $language Language object + * @param log $log The phpBB log system + * @param user $user User object * @param string $phpbb_root_path phpBB root path * @param string $phpEx phpEx * @access public */ - public function __construct(\phpbb\config\config $config, \phpbb\language\language $language, \phpbb\log\log $log, \phpbb\user $user, $phpbb_root_path, $phpEx) + public function __construct(config $config, email $email_method, language $language, log $log, user $user, string $phpbb_root_path, string $phpEx) { $this->config = $config; + $this->email_method = $email_method; $this->language = $language; $this->log = $log; $this->user = $user; @@ -283,16 +293,11 @@ protected function in_watch_group($user_id) */ protected function send_message($message_data, $template, $cc_user = '') { - if (!class_exists('messenger')) - { - include $this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext; - } - - $messenger = new \messenger(false); - $messenger->template('@phpbb_teamsecurity/' . $template); - $messenger->to(!empty($this->config['sec_contact']) ? $this->config['sec_contact'] : $this->config['board_contact'], $this->config['board_contact_name']); - $messenger->cc($cc_user); - $messenger->assign_vars($message_data); - $messenger->send(); + $this->email_method->set_use_queue(false); + $this->email_method->template('@phpbb_teamsecurity/' . $template); + $this->email_method->to(!empty($this->config['sec_contact']) ? $this->config['sec_contact'] : $this->config['board_contact'], $this->config['board_contact_name']); + $this->email_method->cc($cc_user); + $this->email_method->assign_vars($message_data); + $this->email_method->send(); } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 574c6b9..cd8d13a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,27 @@ - - + + + ./ + + + ./language/ + ./migrations/ + ./tests/ + + ./tests @@ -20,15 +31,4 @@ ./tests/functional/ - - - - ./ - - ./language/ - ./migrations/ - ./tests/ - - - diff --git a/tests/event/listener_base.php b/tests/event/listener_base.php index 68853a5..6991ce1 100644 --- a/tests/event/listener_base.php +++ b/tests/event/listener_base.php @@ -18,6 +18,9 @@ class listener_base extends \phpbb_test_case /** @var \phpbb\config\config */ protected $config; + /** @var hpbb\messenger\method\email */ + protected $email_method; + /** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\log\log */ protected $log; @@ -44,6 +47,7 @@ protected function setUp(): void // Load/Mock classes required by the event listener class $this->config = new \phpbb\config\config(array('default_dateformat' => 'D M d, Y H:i:s A')); + $this->email_method = $this->getMockBuilder('\phpbb\messenger\method\email')->disableOriginalConstructor()->getMock(); $this->log = $this->getMockBuilder('\phpbb\log\log') ->disableOriginalConstructor() ->getMock(); @@ -64,12 +68,13 @@ protected function setUp(): void protected function set_listener() { $this->listener = $this->getMockBuilder('\phpbb\teamsecurity\event\listener') - ->setMethods(array( + ->onlyMethods(array( 'in_watch_group', 'send_message' )) ->setConstructorArgs(array( $this->config, + $this->email_method, $this->lang, $this->log, $this->user, diff --git a/tests/ext_test.php b/tests/ext_test.php index 370c3ec..12dee45 100644 --- a/tests/ext_test.php +++ b/tests/ext_test.php @@ -24,7 +24,6 @@ protected function setUp(): void { parent::setUp(); - $this->db = null; $this->extension_manager = $this->create_extension_manager(); } @@ -53,16 +52,20 @@ public function test_disable() protected function create_extension_manager() { - global $phpbb_root_path, $php_ext; + $phpbb_root_path = __DIR__ . './../../../../'; + $php_ext = 'php'; $config = new \phpbb\config\config(['version' => PHPBB_VERSION]); $db = $this->new_dbal(); + $db_doctrine = $this->new_doctrine_dbal(); $phpbb_dispatcher = new \phpbb_mock_event_dispatcher(); $factory = new \phpbb\db\tools\factory(); - $db_tools = $factory->get($db); + $finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $php_ext); + $db_tools = $factory->get($db_doctrine); $table_prefix = 'phpbb_'; $container = new \phpbb_mock_container_builder(); + $container->set('event_dispatcher', $phpbb_dispatcher); $migrator = new \phpbb\db\migrator( $container, @@ -73,20 +76,19 @@ protected function create_extension_manager() $phpbb_root_path, $php_ext, $table_prefix, + self::get_core_tables(), [], new \phpbb\db\migration\helper() ); $container->set('migrator', $migrator); - $container->set('dispatcher', $phpbb_dispatcher); return new \phpbb\extension\manager( $container, $db, $config, - new \phpbb\filesystem\filesystem(), + $finder_factory, 'phpbb_ext', $phpbb_root_path, - $php_ext, null ); }