• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RonasIT / laravel-helpers / 14260163152

04 Apr 2025 07:20AM UTC coverage: 77.591% (-1.5%) from 79.092%
14260163152

Pull #111

github

web-flow
Merge 630f28118 into 38fbefe16
Pull Request #111: #98 assertEqualsFixture add reference to assertable fixture to error message

7 of 7 new or added lines in 1 file covered. (100.0%)

34 existing lines in 2 files now uncovered.

1108 of 1428 relevant lines covered (77.59%)

12.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Http/Middleware/SecurityMiddleware.php
1
<?php
2

3
namespace RonasIT\Support\Http\Middleware;
4

5
use Closure;
6
use Illuminate\Cache\Repository;
7
use Symfony\Component\HttpFoundation\Response;
8

9
class SecurityMiddleware
10
{
11
    protected $cache;
12

13
    public const MAINTENANCE_MODE_KEY = 'maintenance_activated';
14
    public const MAINTENANCE_MODE_HEADER = 'maintenance';
15

16
    public function __construct(Repository $cache)
17
    {
18
        $this->cache = $cache;
×
19
    }
20

21
    public function handle($request, Closure $next)
22
    {
23
        if ($this->needToEnable($request)) {
×
24
            $this->cache->forever(self::MAINTENANCE_MODE_KEY, true);
×
25
        }
26

27
        if ($this->needToDisable($request)) {
×
28
            $this->cache->forget(self::MAINTENANCE_MODE_KEY);
×
29
        }
30

31
        if ($this->cache->get(self::MAINTENANCE_MODE_KEY)) {
×
32
            return $this->getFailResponse();
×
33
        }
34

35
        return $next($request);
×
36
    }
37

38
    protected function needToEnable($request): bool
39
    {
40
        return ($request->header(self::MAINTENANCE_MODE_HEADER) === 'activate') && ($request->header('App-Key') === config('app.key'));
×
41
    }
42

43
    protected function needToDisable($request): bool
44
    {
45
        return ($request->header(self::MAINTENANCE_MODE_HEADER) === 'deactivate') && ($request->header('App-Key') === config('app.key'));
×
46
    }
47

48
    //To hide the reason from attackers
49
    protected function getFailResponse()
50
    {
51
        $code = array_rand($this->codeVariations());
×
52

53
        return response(view("errors.{$code}")->render(), $code);
×
54
    }
55

56
    protected function codeVariations(): array
57
    {
58
        return [
×
59
            Response::HTTP_INTERNAL_SERVER_ERROR,
×
60
            Response::HTTP_NOT_IMPLEMENTED,
×
61
            Response::HTTP_BAD_GATEWAY,
×
62
            Response::HTTP_SERVICE_UNAVAILABLE,
×
63
            Response::HTTP_GATEWAY_TIMEOUT,
×
64
            Response::HTTP_VERSION_NOT_SUPPORTED,
×
65
            Response::HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL,
×
66
            Response::HTTP_INSUFFICIENT_STORAGE,
×
67
            Response::HTTP_LOOP_DETECTED,
×
68
            Response::HTTP_NOT_EXTENDED,
×
69
            Response::HTTP_NETWORK_AUTHENTICATION_REQUIRED,
×
70
        ];
×
71
    }
72
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc