Skip to content

Commit 25fa81f

Browse files
authored
Merge pull request phpbb-extensions#61 from iMattPro/fixes
Fix some issues
2 parents 6d8a29e + 3c8eb7d commit 25fa81f

8 files changed

Lines changed: 165 additions & 35 deletions

File tree

.github/workflows/tests.yml

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ on:
2121
jobs:
2222
# START Basic Checks Job (EPV, code sniffer, images check, etc.)
2323
basic-checks:
24-
runs-on: ubuntu-18.04
24+
runs-on: ubuntu-20.04
2525
strategy:
2626
matrix:
2727
include:
28-
- php: '7.1'
28+
- php: '7.2'
2929
db: "none"
3030
NOTESTS: 1
3131

3232
name: PHP ${{ matrix.php }} - ${{ matrix.db }}
3333

3434
steps:
3535
- name: Checkout phpBB
36-
uses: actions/checkout@v2
36+
uses: actions/checkout@v3
3737
with:
3838
repository: phpbb/phpbb
3939
ref: ${{ env.PHPBB_BRANCH }}
4040
path: phpBB3
4141

4242
- name: Checkout extension
43-
uses: actions/checkout@v2
43+
uses: actions/checkout@v3
4444
with:
4545
path: phpBB3/phpBB/ext/${{ env.EXTNAME }}
4646

@@ -89,7 +89,7 @@ jobs:
8989

9090
# START MySQL and MariaDB Job
9191
mysql-tests:
92-
runs-on: ubuntu-18.04
92+
runs-on: ubuntu-20.04
9393
strategy:
9494
matrix:
9595
include:
@@ -123,6 +123,8 @@ jobs:
123123
db: "mysql:5.7"
124124
- php: '8.1'
125125
db: "mysql:5.7"
126+
- php: '8.2'
127+
db: "mysql:5.7"
126128

127129
name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}
128130

@@ -152,14 +154,14 @@ jobs:
152154

153155
steps:
154156
- name: Checkout phpBB
155-
uses: actions/checkout@v2
157+
uses: actions/checkout@v3
156158
with:
157159
repository: phpbb/phpbb
158160
ref: ${{ env.PHPBB_BRANCH }}
159161
path: phpBB3
160162

161163
- name: Checkout extension
162-
uses: actions/checkout@v2
164+
uses: actions/checkout@v3
163165
with:
164166
path: phpBB3/phpBB/ext/${{ env.EXTNAME }}
165167

@@ -168,7 +170,7 @@ jobs:
168170
MATRIX_DB: ${{ matrix.db }}
169171
run: |
170172
db=$(echo "${MATRIX_DB%%:*}")
171-
echo "::set-output name=db::$db"
173+
echo "db=$db" >> $GITHUB_OUTPUT
172174
173175
- name: Setup PHP
174176
uses: shivammathur/setup-php@v2
@@ -205,7 +207,7 @@ jobs:
205207

206208
# START PostgreSQL Job
207209
postgres-tests:
208-
runs-on: ubuntu-18.04
210+
runs-on: ubuntu-20.04
209211
strategy:
210212
matrix:
211213
include:
@@ -221,6 +223,20 @@ jobs:
221223
db: "postgres:12"
222224
- php: '7.1'
223225
db: "postgres:13"
226+
- php: '7.2'
227+
db: "postgres:13"
228+
- php: '7.3'
229+
db: "postgres:13"
230+
- php: '7.4'
231+
db: "postgres:13"
232+
- php: '8.0'
233+
db: "postgres:12"
234+
- php: '8.0'
235+
db: "postgres:13"
236+
- php: '8.1'
237+
db: "postgres:14"
238+
- php: '8.2'
239+
db: "postgres:14"
224240

225241
name: PHP ${{ matrix.php }} - ${{ matrix.db }}
226242

@@ -252,14 +268,14 @@ jobs:
252268

253269
steps:
254270
- name: Checkout phpBB
255-
uses: actions/checkout@v2
271+
uses: actions/checkout@v3
256272
with:
257273
repository: phpbb/phpbb
258274
ref: ${{ env.PHPBB_BRANCH }}
259275
path: phpBB3
260276

261277
- name: Checkout extension
262-
uses: actions/checkout@v2
278+
uses: actions/checkout@v3
263279
with:
264280
path: phpBB3/phpBB/ext/${{ env.EXTNAME }}
265281

@@ -268,7 +284,7 @@ jobs:
268284
MATRIX_DB: ${{ matrix.db }}
269285
run: |
270286
db=$(echo "${MATRIX_DB%%:*}")
271-
echo "::set-output name=db::$db"
287+
echo "db=$db" >> $GITHUB_OUTPUT
272288
273289
- name: Setup PHP
274290
uses: shivammathur/setup-php@v2
@@ -305,7 +321,7 @@ jobs:
305321

306322
# START Other Tests Job (SQLite 3 and mssql)
307323
other-tests:
308-
runs-on: ubuntu-18.04
324+
runs-on: ubuntu-20.04
309325
strategy:
310326
matrix:
311327
include:
@@ -347,14 +363,14 @@ jobs:
347363

348364
steps:
349365
- name: Checkout phpBB
350-
uses: actions/checkout@v2
366+
uses: actions/checkout@v3
351367
with:
352368
repository: phpbb/phpbb
353369
ref: ${{ env.PHPBB_BRANCH }}
354370
path: phpBB3
355371

356372
- name: Checkout extension
357-
uses: actions/checkout@v2
373+
uses: actions/checkout@v3
358374
with:
359375
path: phpBB3/phpBB/ext/${{ env.EXTNAME }}
360376

@@ -368,7 +384,7 @@ jobs:
368384
else
369385
db=$(echo "${MATRIX_DB%%:*}")
370386
fi
371-
echo "::set-output name=db::$db"
387+
echo "db=$db" >> $GITHUB_OUTPUT
372388
373389
- name: Setup PHP
374390
uses: shivammathur/setup-php@v2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ This extension adds passive security features to phpBB that allow the board's fo
1616
Note: This extension is currently under development and is not ready to install on any live forum.
1717

1818
## License
19-
[GNU General Public License v2](http://opensource.org/licenses/GPL-2.0)
19+
[GNU General Public License v2](https://opensource.org/licenses/GPL-2.0)

ext.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class ext extends \phpbb\extension\base
1717
{
1818
/**
19-
* Check whether or not the extension can be enabled.
19+
* Check whether the extension can be enabled.
2020
* The current phpBB version should meet or exceed
2121
* the minimum version required by this extension:
2222
*
@@ -27,8 +27,7 @@ class ext extends \phpbb\extension\base
2727
*/
2828
public function is_enableable()
2929
{
30-
$config = $this->container->get('config');
31-
return phpbb_version_compare($config['version'], '3.2.0', '>=');
30+
return phpbb_version_compare(PHPBB_VERSION, '3.2.0', '>=');
3231
}
3332

3433
/**
@@ -40,7 +39,6 @@ public function is_enableable()
4039
*/
4140
public function disable_step($old_state)
4241
{
43-
// Use hardcoded language here since the $user is not available
44-
trigger_error('Please remove ext.php from the filesystem, purge the board cache, and try again.', E_USER_WARNING);
42+
trigger_error('TEAM_SECURITY_DISABLE_MESSAGE', E_USER_WARNING);
4543
}
4644
}

language/en/info_acp_teamsecurity.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@
3636

3737
// EMAIL
3838
'ACP_CONTACT_ADMIN' => 'the board administrator or webmaster',
39+
40+
// EXT
41+
'TEAM_SECURITY_DISABLE_MESSAGE' => 'Please remove “ext.php” from the filesystem, purge the board cache, and try again.',
3942
));

migrations/m4_serialize_to_json.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ public function update_data()
3333
*/
3434
public function serialize_to_json($cfg)
3535
{
36+
// This check is needed to prevent errors when uninstalling this migration/extension
37+
json_decode($this->config[$cfg], false);
38+
if (json_last_error() === JSON_ERROR_NONE)
39+
{
40+
return '';
41+
}
42+
3643
$data = unserialize(trim($this->config[$cfg]), ['allowed_classes' => false]);
3744

3845
return $data ? json_encode($data) : '';

tests/event/delete_log_security_test.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,41 @@ class delete_log_security_test extends listener_base
1919
*/
2020
public function delete_logs_security_data()
2121
{
22-
return array(
23-
array('admin', true, false),
24-
array('mod', true, false),
25-
array('user', true, false),
26-
array('users', true, false),
27-
array('', true, true),
28-
array('', false, false),
29-
);
22+
return [
23+
['admin', LOG_ADMIN, [], false],
24+
['admin', LOG_ADMIN, ['keywords' => ['test']], false],
25+
['admin', LOG_ADMIN, ['log_id' => ['IN' => []]], false],
26+
['mod', LOG_MOD, [], false],
27+
['user', LOG_USER, [], false],
28+
['users', LOG_USERS, [], false],
29+
['', LOG_CRITICAL, [], true],
30+
['', false, [], false],
31+
];
3032
}
3133

3234
/**
3335
* Test the delete logs security event
3436
*
3537
* @dataProvider delete_logs_security_data
3638
*/
37-
public function test_delete_logs_security($mode, $log_type, $expected_log_type)
39+
public function test_delete_logs_security($mode, $log_type, $conditions, $expected_log_type)
3840
{
3941
// Set some user DateTime options
4042
$this->user->timezone = new \DateTimeZone('UTC');
41-
$this->lang->lang('datetime', array());
43+
$this->lang->lang('datetime', []);
4244

4345
$this->set_listener();
4446

47+
$this->listener->expects(self::exactly(count($conditions)))
48+
->method('send_message');
49+
4550
$dispatcher = new \phpbb\event\dispatcher();
46-
$dispatcher->addListener('core.delete_log', array($this->listener, 'delete_logs_security'));
51+
$dispatcher->addListener('core.delete_log', [$this->listener, 'delete_logs_security']);
4752

48-
$event_data = array('mode', 'log_type');
53+
$event_data = ['mode', 'log_type', 'conditions'];
4954
$event_data_after = $dispatcher->trigger_event('core.delete_log', compact($event_data));
5055
extract($event_data_after, EXTR_OVERWRITE);
5156

52-
self::assertSame($expected_log_type, $log_type);
57+
self::assertEquals($expected_log_type, $log_type);
5358
}
5459
}

tests/ext_test.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
*
4+
* Team Security Measures extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2015 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\teamsecurity\tests;
12+
13+
class ext_test extends \phpbb_database_test_case
14+
{
15+
protected const TEAM_SECURITY = 'phpbb/teamsecurity';
16+
protected $extension_manager;
17+
18+
public function getDataSet()
19+
{
20+
return $this->createXMLDataSet(__DIR__ . '/fixtures/extensions.xml');
21+
}
22+
23+
protected function setUp(): void
24+
{
25+
parent::setUp();
26+
27+
$this->db = null;
28+
$this->extension_manager = $this->create_extension_manager();
29+
}
30+
31+
public function test_enable()
32+
{
33+
// Enable it
34+
$this->extension_manager->enable(self::TEAM_SECURITY);
35+
36+
// Assert it's enabled
37+
$this->assertEquals([self::TEAM_SECURITY], array_keys($this->extension_manager->all_enabled()));
38+
$this->assertEquals([self::TEAM_SECURITY], array_keys($this->extension_manager->all_configured()));
39+
}
40+
41+
public function test_disable()
42+
{
43+
// Enable it
44+
$this->extension_manager->enable(self::TEAM_SECURITY);
45+
46+
// Assert it's Enabled
47+
$this->assertEquals([self::TEAM_SECURITY], array_keys($this->extension_manager->all_enabled()));
48+
49+
// Disable it and assert expected trigger error is called
50+
$this->setExpectedTriggerError(E_USER_WARNING, 'TEAM_SECURITY_DISABLE_MESSAGE');
51+
$this->extension_manager->disable(self::TEAM_SECURITY);
52+
}
53+
54+
protected function create_extension_manager()
55+
{
56+
global $phpbb_root_path, $php_ext;
57+
58+
$config = new \phpbb\config\config(['version' => PHPBB_VERSION]);
59+
$db = $this->new_dbal();
60+
$phpbb_dispatcher = new \phpbb_mock_event_dispatcher();
61+
$factory = new \phpbb\db\tools\factory();
62+
$db_tools = $factory->get($db);
63+
$table_prefix = 'phpbb_';
64+
65+
$container = new \phpbb_mock_container_builder();
66+
67+
$migrator = new \phpbb\db\migrator(
68+
$container,
69+
$config,
70+
$db,
71+
$db_tools,
72+
'phpbb_migrations',
73+
$phpbb_root_path,
74+
$php_ext,
75+
$table_prefix,
76+
[],
77+
new \phpbb\db\migration\helper()
78+
);
79+
$container->set('migrator', $migrator);
80+
$container->set('dispatcher', $phpbb_dispatcher);
81+
82+
return new \phpbb\extension\manager(
83+
$container,
84+
$db,
85+
$config,
86+
new \phpbb\filesystem\filesystem(),
87+
'phpbb_ext',
88+
$phpbb_root_path,
89+
$php_ext,
90+
null
91+
);
92+
}
93+
}

tests/fixtures/extensions.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<dataset>
3+
<table name="phpbb_ext">
4+
<column>ext_name</column>
5+
<column>ext_active</column>
6+
<column>ext_state</column>
7+
</table>
8+
</dataset>

0 commit comments

Comments
 (0)