Skip to content

Commit ee1c5f4

Browse files
committed
Add InfoController to check system variables
Signed-off-by: Daniel Metzner <daniiel.metzner@gmail.com>
1 parent 073ce23 commit ee1c5f4

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ jobs:
163163
- web-studio
164164
- web-top-bar
165165
- web-translation
166+
- web-system
166167

167168
steps:
168169
- name: Checkout

behat.yaml.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ default:
342342
- App\System\Testing\Behat\Context\CatrowebBrowserContext
343343
- App\System\Testing\Behat\Context\ApiContext
344344

345+
web-system:
346+
paths:
347+
- "tests/BehatFeatures/web/system"
348+
contexts:
349+
- App\System\Testing\Behat\Context\RefreshEnvironmentContext
350+
- App\System\Testing\Behat\Context\DataFixturesContext
351+
- App\System\Testing\Behat\Context\CatrowebBrowserContext
352+
- App\System\Testing\Behat\Context\ApiContext
353+
345354

346355
# --------------------------------------------------------------------------------------------------
347356
# Exclude specific tests based on their tags here:

config/packages/security.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@
271271
'path' => '^.*?/api/upload/upload.json',
272272
'roles' => 'IS_AUTHENTICATED_FULLY',
273273
],
274+
[
275+
'path' => '^/system/',
276+
'role' => [
277+
'ROLE_ADMIN',
278+
'ROLE_SONATA_ADMIN',
279+
],
280+
'requires_channel' => '%env(SECURE_SCHEME)%',
281+
],
274282
[
275283
'path' => '^/admin/',
276284
'role' => [

config/routes/routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
->requirements(['theme' => '%themeRoutes%'])
1111
;
1212

13+
$routingConfigurator->import('../../src/System/Controller', 'annotation')
14+
->prefix('/{theme}/')
15+
->requirements(['theme' => 'system'])
16+
;
17+
1318
$routingConfigurator->import('../../src/Admin/', 'annotation')
1419
->prefix('/admin/')
1520
->requirements(['theme' => 'admin'])

config/services.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@
272272
->public()
273273
;
274274

275+
$services->load('App\System\Controller\\', __DIR__.'/../src/System/Controller')
276+
->public()
277+
;
278+
275279
$services->load('App\Api_deprecated\Controller\\', __DIR__.'/../src/Api_deprecated/Controller')
276280
->public()
277281
;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\System\Controller;
4+
5+
use Doctrine\DBAL\Connection;
6+
use Doctrine\DBAL\Exception;
7+
use JetBrains\PhpStorm\NoReturn;
8+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
9+
use Symfony\Component\HttpFoundation\Response;
10+
use Symfony\Component\Routing\Attribute\Route;
11+
12+
class InfoController extends AbstractController
13+
{
14+
#[Route(path: 'info/php', methods: ['GET'])]
15+
public function phpInfo(): void
16+
{
17+
phpinfo();
18+
exit;
19+
}
20+
21+
/**
22+
* @throws Exception
23+
*/
24+
#[Route(path: '/info/db', methods: ['GET'])]
25+
public function databaseInfo(Connection $connection): Response
26+
{
27+
$sql = 'SHOW GLOBAL VARIABLES';
28+
$stmt = $connection->prepare($sql);
29+
$result = $stmt->executeQuery();
30+
echo '<table style="width: 100%;">';
31+
echo '<tr style="background-color: #f2f2f2;"><th>Database Variable</th><th>Value</th></tr>';
32+
$i = 0;
33+
while ($variable = $result->fetchAssociative()) {
34+
$color = (0 == $i % 2) ? '#f2f2f2' : '#ffffff';
35+
echo '<tr style="background-color: '.$color.';"><td>'.$variable['Variable_name'].'</td><td>'.$variable['Value'].'</td></tr>';
36+
++$i;
37+
}
38+
echo '</table>';
39+
exit;
40+
}
41+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@web @system
2+
Feature: Check system variables with admin rights
3+
4+
Background:
5+
And there are users:
6+
| id | name |
7+
| 3 | NewUser |
8+
And there are admins:
9+
| id | name |
10+
| 2 | Admin |
11+
12+
Scenario: Must not be able to see phpinfo if not logged in
13+
And I am on "/system/info/php"
14+
Then I should not see "PHP Version"
15+
16+
Scenario: Must not be able to see phpinfo if logged in as user
17+
Given I log in as "NewUser"
18+
And I am on "/system/info/php"
19+
Then I should not see "PHP Version"
20+
21+
Scenario: Must be able to see phpinfo if logged in as admin
22+
Given I log in as "Admin"
23+
And I am on "/system/info/php"
24+
Then I should see "PHP Version"
25+
26+
Scenario: Must not be able to see db if not logged in
27+
And I am on "/system/info/db"
28+
Then I should not see "Database"
29+
30+
Scenario: Must not be able to see db if logged in as user
31+
Given I log in as "NewUser"
32+
And I am on "/system/info/db"
33+
Then I should not see "Database"
34+
35+
Scenario: Must be able to see db if logged in as admin
36+
Given I log in as "Admin"
37+
And I am on "/system/info/db"
38+
Then I should see "Database Variable"

0 commit comments

Comments
 (0)