Issues (3)

Security Analysis    no request data  

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/Helper/OpcacheResetCommandHelperTest.php (1 issue)

Labels
Severity

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
3
namespace Timegryd\OpcacheResetBundle\Tests\Helper;
4
5
use Symfony\Component\HttpKernel\KernelInterface;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\Filesystem\Filesystem;
8
use GuzzleHttp\Psr7\Response as HttpResponse;
9
use Timegryd\OpcacheResetBundle\Helper\OpcacheResetCommandHelper;
10
11
class OpcacheResetCommandHelperTest extends \PHPUnit\Framework\TestCase
12
{
13
    /**
14
     * @var KernelInterface
15
     */
16
    protected $kernel;
17
18
    /**
19
     * @var OpcacheResetCommandHelper
20
     */
21
    protected $helper;
22
23
    /**
24
     * @var Filesystem
25
     */
26
    protected $filesystem;
27
28
    /**
29
     * @var string
30
     */
31
    protected $workspace;
32
33
    protected function setUp()
34
    {
35
        $this->kernel = \Mockery::mock(KernelInterface::class);
36
        $this->helper = new OpcacheResetCommandHelper($this->kernel);
37
    }
38
39
    public function testGetFileName()
40
    {
41
        $fileName = $this->helper->getFileName('test');
42
43
        $this->assertEquals($fileName, 'opcache-reset-test.php');
44
    }
45
46
    public function testGetFilePath()
47
    {
48
        $filePath = $this->helper->getFilePath('dirtest', 'test');
49
50
        $this->assertEquals($filePath, 'dirtest/opcache-reset-test.php');
51
    }
52
53
    public function testGenerateUrl()
54
    {
55
        $url = $this->helper->generateUrl('timegryd.io', 'test');
56
57
        $this->assertEquals($url, 'timegryd.io/opcache-reset-test.php');
58
    }
59
60
    /**
61
     * @expectedException RuntimeException
62
     */
63
    public function testCreateFileDirNotExists()
64
    {
65
        $this->helper->createFile('dir-not-existing', 'token');
66
    }
67
68
    protected function setUpFilesystem()
69
    {
70
        $this->filesystem = new Filesystem();
71
        $this->workspace = sys_get_temp_dir().'/'.microtime(true).'.'.mt_rand();
72
73
        mkdir($this->workspace, 0777, true);
74
75
        $this->workspace = realpath($this->workspace);
76
    }
77
78
    protected function tearDownFilesystem()
79
    {
80
        $this->filesystem->remove($this->workspace);
81
    }
82
83
    public function testCreateFileDirExists()
84
    {
85
        $this->setUpFilesystem();
86
87
        $sourceFile = $this->workspace.DIRECTORY_SEPARATOR.'source_file';
88
89
        file_put_contents($sourceFile, 'SOURCE FILE');
90
91
        $this
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Symfony\Component...Kernel\KernelInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
            ->kernel
93
            ->shouldReceive('locateResource')
94
            ->andReturn($sourceFile)
95
        ;
96
97
        $return = $this->helper->createFile($this->workspace, 'token');
98
99
        $this->assertInstanceOf(OpcacheResetCommandHelper::class, $return);
100
101
        $targetFilePath = $this->workspace.DIRECTORY_SEPARATOR.'opcache-reset-token.php';
102
103
        $this->assertFileExists($targetFilePath);
104
        $this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
105
106
        $this->tearDownFilesystem();
107
    }
108
109
    public function testClean()
110
    {
111
        $this->setUpFilesystem();
112
113
        $fileToDelete1 = $this->workspace.DIRECTORY_SEPARATOR.'opcache-reset-1.php';
114
        touch($fileToDelete1);
115
116
        $fileToDelete2 = $this->workspace.DIRECTORY_SEPARATOR.'opcache-reset-2.php';
117
        touch($fileToDelete2);
118
119
        $fileNotToDelete = $this->workspace.DIRECTORY_SEPARATOR.'filenottodelete.php';
120
        touch($fileNotToDelete);
121
122
        $return = $this->helper->clean($this->workspace);
123
124
        $this->assertFileNotExists($fileToDelete1);
125
        $this->assertFileNotExists($fileToDelete2);
126
        $this->assertFileExists($fileNotToDelete);
127
128
        $this->assertInstanceOf(OpcacheResetCommandHelper::class, $return);
129
130
        $this->tearDownFilesystem();
131
    }
132
133
    /**
134
     * @expectedException RuntimeException
135
     */
136
    public function testHandleResponseBadStatusCode()
137
    {
138
        $response = $this->getMockedResponse(null, Response::HTTP_NOT_FOUND);
139
140
        $this->helper->handleResponse($response);
141
    }
142
143
    /**
144
     * @expectedException RuntimeException
145
     */
146
    public function testHandleResponseBadJson()
147
    {
148
        $response = $this->getMockedResponse('bad-json');
149
150
        $this->helper->handleResponse($response);
151
    }
152
153
    /**
154
     * @expectedException InvalidArgumentException
155
     */
156
    public function testHandleResponsePropertySuccessMissing()
157
    {
158
        $response = $this->getMockedResponse('{"message": "failure"}');
159
160
        $this->helper->handleResponse($response);
161
    }
162
163
    /**
164
     * @expectedException InvalidArgumentException
165
     */
166
    public function testHandleResponsePropertyMessageMissing()
167
    {
168
        $response = $this->getMockedResponse('{"success": true}');
169
170
        $this->helper->handleResponse($response);
171
    }
172
173
    /**
174
     * @expectedException RuntimeException
175
     */
176
    public function testHandleResponseFailure()
177
    {
178
        $response = $this->getMockedResponse('{"success": false, "message": "failure"}');
179
180
        $this->helper->handleResponse($response);
181
    }
182
183
    public function testHandleResponseSuccess()
184
    {
185
        $response = $this->getMockedResponse('{"success": "true", "message": "Success"}');
186
187
        $message = $this->helper->handleResponse($response);
188
189
        $this->assertEquals('Success', $message);
190
    }
191
192
    /**
193
     * Mock Response.
194
     *
195
     * @param string $body
196
     * @param int    $status
197
     *
198
     * @return HttpResponse
199
     */
200
    protected function getMockedResponse($body = null, $status = Response::HTTP_OK)
201
    {
202
        $response = \Mockery::mock(HttpResponse::class);
203
204
        $response
205
            ->shouldReceive('getStatusCode')
206
            ->andReturn($status)
207
        ;
208
209
        if (null !== $body) {
210
            $response
211
                ->shouldReceive('getBody')
212
                ->andReturn($body)
213
            ;
214
        }
215
216
        return $response;
217
    }
218
}
219