Skip to content

Commit

Permalink
Test index (LycheeOrg#558)
Browse files Browse the repository at this point in the history
* tentative to see crash on php 7.3
* crash succesfully discovered
  • Loading branch information
ildyria authored May 13, 2020
1 parent da9774c commit 6b32af6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
46 changes: 21 additions & 25 deletions bootstrap/PanicAttack.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
<?php

class PanicAttack {

private string $title = '';
private int $code = 0;
private string $message = '';
class PanicAttack
{
private $title = '';
private $code = 0;
private $message = '';

/**
* Check if all the elements of the array are in a string.
*
*
* @param string $haystack string to check against
* @param array $needles array of needles to check
*
* @return bool
* @param array $needles array of needles to check
*
* @return bool
*/
private function contains(string $haystack, array $needles)
{
foreach ($needles as $needle)
{
if (strpos($haystack, $needle) === false)
{
foreach ($needles as $needle) {
if (strpos($haystack, $needle) === false) {
return false;
}
}

return true;
}

/**
* Display errors as nice page.
*
*
* This function is an EXIT.
*/
private function displaySimpleError()
Expand All @@ -45,7 +44,7 @@ private function displaySimpleError()
}

/**
* Called from ../index.php
* Called from ../index.php.
*/
public function root()
{
Expand All @@ -57,17 +56,17 @@ public function root()
}

/**
* Called from bootstrap/initialize.php if apache rewrite is not enabled.
* Called from bootstrap/initialize.php if apache rewrite is not enabled.
*/
public function apacheRewrite()
{
$this->title = 'mod_rewrite is not enabled';
$this->code = 503;
$this->message = 'You are using apache but <code>mod_rewrite</code> is not enabled.<br>
Please do: <code>a2enmod rewrite</code>';
$this->displaySimpleError();
$this->displaySimpleError();
}

/*
|--------------------------------------------------------------------------
| Catch error where composer is loading properly.
Expand Down Expand Up @@ -100,20 +99,17 @@ public function checkAccessRightsViews()
}

/**
* dispatcher
* dispatcher.
*/
public function handle(string $error_message)
{

$handling = [
'composerVendorNotFound' => ['require', 'Failed opening required', 'vendor/autoload.php'],
'checkAccessRightsViews' => ['file_put_contents', 'storage/framework/views', 'Permission denied'],
];

foreach ($handling as $fun => $needles)
{
if ($this->contains($error_message, $needles))
{
foreach ($handling as $fun => $needles) {
if ($this->contains($error_message, $needles)) {
$this->$fun();
}
}
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
require __DIR__ . '/bootstrap/PanicAttack.php';

$oups = new PanicAttack();
$oups->root();
$oups->root();
22 changes: 22 additions & 0 deletions tests/Feature/RootTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/** @noinspection PhpUndefinedClassInspection */

namespace Tests\Feature;

use Tests\TestCase;

class RootTest extends TestCase
{
/**
* Test album functions.
*
* @return void
*/
public function test_root()
{
exec('php index.php 2>&1', $return);
$return = implode('', $return);
$this->assertStringContainsString('This is the root directory and it MUST NOT BE PUBLICALLY ACCESSIBLE', $return);
}
}

0 comments on commit 6b32af6

Please sign in to comment.