Skip to content

Commit 7bc9446

Browse files
authored
Merge pull request #177 from iMattPro/updates
Trivial fixes
2 parents d9c6182 + b91b148 commit 7bc9446

5 files changed

Lines changed: 64 additions & 3 deletions

File tree

‎controller/main.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,16 @@ public function handle()
9494
throw new http_exception(403, 'NOT_AUTHORISED');
9595
}
9696

97+
$form_key = 'phpbb_skeleton';
98+
add_form_key($form_key);
99+
97100
if ($this->request->is_set_post('submit'))
98101
{
102+
if (!check_form_key($form_key))
103+
{
104+
throw new http_exception(403, 'FORM_INVALID');
105+
}
106+
99107
try
100108
{
101109
$this->get_composer_data();

‎skeleton/service.php.twig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class service
4040
*/
4141
public function get_user()
4242
{
43-
var_dump($this->table_name);
4443
return $this->user;
4544
}
4645
}

‎styles/prosilver/template/skeleton_body.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{% INCLUDECSS '@phpbb_skeleton/skeleton.css' %}
1212

1313
<script>
14-
var warningMsg = '{{ lang('SKELETON_RESERVED_NAME_WARNING_UI') }}';
14+
var warningMsg = '{{ lang('SKELETON_RESERVED_NAME_WARNING_UI')|e('js') }}';
1515
</script>
1616

1717
<h2>{{ lang('PHPBB_CREATE_SKELETON_EXT') }}</h2>
@@ -132,7 +132,7 @@ <h3 class="skeleton-components">{{ lang('SKELETON_COMPONENT_GROUP_' ~ group) }}<
132132
<div class="panel">
133133
<div class="inner">
134134
<fieldset class="submit-buttons">
135-
{{ S_HIDDEN_FIELDS }}
135+
{{ S_FORM_TOKEN }}
136136
<input type="submit" accesskey="s" name="submit" value="{{ lang('SUBMIT') }}" class="button1">
137137
</fieldset>
138138
</div>

‎tests/controller/main_test.php‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use phpbb\skeleton\ext;
1919
use Symfony\Component\DependencyInjection\ContainerInterface;
2020

21+
require_once __DIR__ . '/test_helpers.php';
22+
2123
class main_test extends \phpbb_test_case
2224
{
2325
/** @var \phpbb\template\template|\PHPUnit\Framework\MockObject\MockObject */
@@ -50,6 +52,9 @@ class main_test extends \phpbb_test_case
5052
protected function setUp(): void
5153
{
5254
global $phpbb_root_path;
55+
global $phpbb_skeleton_form_key_valid;
56+
57+
$phpbb_skeleton_form_key_valid = true;
5358

5459
// Mocks are dummy implementations that provide the API of components we depend on //
5560
$this->template = $this->getMockBuilder('\phpbb\template\template')
@@ -272,6 +277,30 @@ public function test_handle_unauthorised()
272277
$this->get_controller($this->packager_mock)->handle();
273278
}
274279

280+
public function test_submit_invalid_form_key()
281+
{
282+
global $phpbb_skeleton_form_key_valid;
283+
284+
$this->user->data['is_bot'] = false;
285+
$phpbb_skeleton_form_key_valid = false;
286+
287+
$this->request->expects($this->once())
288+
->method('is_set_post')
289+
->with('submit')
290+
->willReturn(true);
291+
292+
$this->packager_mock->expects($this->never())
293+
->method('create_extension');
294+
295+
$this->packager_mock->expects($this->never())
296+
->method('create_zip');
297+
298+
$this->expectException(http_exception::class);
299+
$this->expectExceptionMessage('FORM_INVALID');
300+
301+
$this->get_controller($this->packager_mock)->handle();
302+
}
303+
275304
public function test_submit_success()
276305
{
277306
$this->user->data['is_bot'] = false;

‎tests/controller/test_helpers.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
namespace phpbb\skeleton\controller;
15+
16+
function add_form_key($form_name)
17+
{
18+
}
19+
20+
function check_form_key($form_name)
21+
{
22+
global $phpbb_skeleton_form_key_valid;
23+
24+
return $phpbb_skeleton_form_key_valid;
25+
}

0 commit comments

Comments
 (0)