Issues (1752)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/FwlibTest/Web/AbstractViewWithCacheTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace FwlibTest\Web;
3
4
use Fwlib\Cache\Handler\PhpArray as PhpArrayCacheHandler;
5
use Fwlib\Util\Common\Env as EnvUtil;
6
use Fwlib\Util\UtilContainer;
7
use Fwlib\Web\AbstractViewWithCache;
8
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase;
9
use PHPUnit_Framework_MockObject_MockObject as MockObject;
10
11
/**
12
 * @copyright   Copyright 2013-2015 Fwolf
13
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
14
 */
15
class AbstractViewWithCacheTest extends PHPUnitTestCase
16
{
17
    /**
18
     * @var EnvUtil
19
     */
20
    protected static $envUtilBackup = null;
21
22
    /**
23
     * @var string
24
     */
25
    protected static $requestUri = '';
26
27
28
    /**
29
     * @return MockObject | AbstractViewWithCache
30
     */
31
    protected function buildMock()
32
    {
33
        $mock = $this->getMock(
34
            AbstractViewWithCache::class,
35
            ['getCacheLifetime', 'getOutputBody']
36
        );
37
38
        // Long enough lifetime for test
39
        $mock->expects($this->any())
40
            ->method('getCacheLifetime')
41
            ->willReturn(60);
42
43
        // Mock un-cached output, remove header and footer, only body part
44
        // left, and use microtime to simulate output content, because their
45
        // value are different each time run.
46
        $this->reflectionSet($mock, 'outputParts', ['body']);
47
        $mock->expects($this->any())
48
            ->method('getOutputBody')
49
            ->will($this->returnCallback(function () {
50
                $datetimeUtil = UtilContainer::getInstance()->getDatetime();
51
                return $datetimeUtil->getMicroTime();
52
            }));
53
54
        /** @var AbstractViewWithCache $mock */
55
        $mock->setCacheHandler(new PhpArrayCacheHandler);
56
57
        return $mock;
58
    }
59
60
61 View Code Duplication
    public static function setUpBeforeClass()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $utilContainer = UtilContainer::getInstance();
64
        self::$envUtilBackup = $utilContainer->getEnv();
65
66
        $testCase = new self;
67
        $envUtil = $testCase->getMock(EnvUtil::class, ['getServer']);
68
        $envUtil->expects($testCase->any())
69
            ->method('getServer')
70
            ->willReturnCallback(function() {
71
                return self::$requestUri;
72
            });
73
74
        $utilContainer->register('Env', $envUtil);
75
    }
76
77
78
    public static function tearDownAfterClass()
79
    {
80
        $utilContainer = UtilContainer::getInstance();
81
        $utilContainer->register('Env', self::$envUtilBackup);
82
    }
83
84
85
    public function testForceRefreshCache()
86
    {
87
        $view = $this->buildMock();
88
        $view->setUseCache(true);
89
90
        $view->setForceRefreshCache(false);
91
        $foo = $view->getOutput();
92
        $bar = $view->getOutput();
93
        $this->assertEquals($foo, $bar);
94
95
        $view->setForceRefreshCache(true);
96
        $bar = $view->getOutput();
97
        $this->assertNotEquals($foo, $bar);
98
    }
99
100
101
    public function testGetOutput()
102
    {
103
        $view = $this->buildMock();
104
105
        $view->setUseCache(false);
106
        $this->assertFalse($view->isUseCache());
107
108
        self::$requestUri = '';
109
110
        // Without cache
111
        $foo = $view->getOutput();
112
        $bar = $view->getOutput();
113
        $this->assertNotEquals($foo, $bar);
114
115
        // With cache
116
        $view->setUseCache(true);
117
        $this->assertTrue($view->isUseCache());
118
        $foo = $view->getOutput();
119
        $bar = $view->getOutput();
120
        $this->assertEquals($foo, $bar);
121
122
        // Change cache key, will got different result
123
        self::$requestUri = 'test.php?a=1&b=';
124
        $bar = $view->getOutput();
125
        $this->assertNotEquals($foo, $bar);
126
    }
127
}
128