Issues (15)

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/Functional/Command/UpgradeCommandTest.php (4 issues)

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 Modera\UpgradeBundle\Tests\Functional\Command;
4
5
use Modera\UpgradeBundle\Json\JsonFile;
6
use Modera\FoundationBundle\Testing\FunctionalTestCase;
7
use Symfony\Bundle\FrameworkBundle\Console\Application;
8
use Symfony\Component\Console\Input\StringInput;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Output\BufferedOutput;
11
use Symfony\Component\Console\Output\NullOutput;
12
13
/**
14
 * @author    Sergei Vizel <[email protected]>
15
 * @copyright 2014 Modera Foundation
16
 */
17
class UpgradeCommandTest extends FunctionalTestCase
18
{
19
    /**
20
     * @var string
21
     */
22
    private static $basePath;
23
24
    /**
25
     * @var JsonFile
26
     */
27
    private static $composerFile;
28
29
    /**
30
     * @var array
31
     */
32
    private static $composerBackup;
33
34
    /**
35
     * @var string
36
     */
37
    private static $versionFilePath;
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public static function doSetUpBeforeClass()
43
    {
44
        self::$basePath = dirname(self::$kernel->getRootdir());
45
        self::$composerFile = new JsonFile(self::$basePath.'/composer.json');
46
        self::$composerBackup = self::$composerFile->read();
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$composerFile->read() of type * is incompatible with the declared type array of property $composerBackup.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
48
        self::$versionFilePath = getcwd().'/modera-version.txt';
49
        if (file_exists(self::$versionFilePath)) {
50
            unlink(self::$versionFilePath);
51
        }
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public static function doTearDownAfterClass()
58
    {
59
        self::$composerFile->write(self::$composerBackup);
60
        unlink(self::$versionFilePath);
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    private function getCurrentVersion()
67
    {
68
        return @file_get_contents(self::$versionFilePath);
69
    }
70
71
    /**
72
     * @param null|string|array $config
0 ignored issues
show
There is no parameter named $config. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
73
     */
74
    private function getApplication()
75
    {
76
        $app = new Application(self::$kernel);
77
        $app->setAutoExit(false);
78
79
        return $app;
80
    }
81
82 View Code Duplication
    private function runUpdateDependenciesCommand(OutputInterface $output = null)
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...
83
    {
84
        $input = new StringInput('modera:upgrade --dependencies '.__DIR__.'/versions.json');
85
        $input->setInteractive(false);
86
        $app = $this->getApplication();
87
        $result = $app->run($input, $output ?: new NullOutput());
88
        $this->assertEquals(0, $result);
89
    }
90
91 View Code Duplication
    private function runCommandsCommand(OutputInterface $output = null)
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...
92
    {
93
        $input = new StringInput('modera:upgrade --run-commands '.__DIR__.'/versions.json');
94
        $input->setInteractive(false);
95
        $app = $this->getApplication();
96
        $result = $app->run($input, $output ?: new NullOutput());
97
        $this->assertEquals(0, $result);
98
    }
99
100
    public function testUpgrade()
101
    {
102
        $output = new BufferedOutput();
103
104
        // null version check
105
        $expectedData = array(
106
            'name' => 'modera/upgrade-bundle-test',
107
            'repositories' => array(
108
                array(
109
                    'type' => 'composer',
110
                    'url' => 'http://packages.org',
111
                ),
112
            ),
113
            'require' => array(
114
                'test/dependency_1' => 'dev-master',
115
            ),
116
        );
117
        $this->assertEquals($expectedData, self::$composerFile->read());
118
119
        // 0.1.0 version check
120
        $expectedData['require'] = array(
121
            'test/dependency_1' => '0.1.0',
122
            'test/dependency_2' => '0.1.0',
123
            'test/dependency_3' => '0.1.0',
124
        );
125
        $expectedData['repositories'][] = array(
126
            'type' => 'vcs',
127
            'url' => 'ssh://[email protected]',
128
        );
129
        $this->runUpdateDependenciesCommand($output);
130
        $str = $output->fetch();
131
        $this->assertEquals('0.1.0', $this->getCurrentVersion());
132
        $this->assertEquals(1, substr_count($str, 'new Test\AddBundle\TestAddBundle()'));
133
        $this->assertEquals(0, substr_count($str, 'new Test\RemoveBundle\TestRemoveBundle()'));
134
        $this->assertEquals($expectedData, self::$composerFile->read());
135
        $this->assertTrue(is_file(self::$basePath.'/composer.backup.json'));
136
        unlink(self::$basePath.'/composer.backup.json');
137
138
        // 0.1.0 version run commands
139
        $this->runCommandsCommand($output);
140
        $str = $output->fetch();
141
        $this->assertEquals(0, substr_count($str, 'help --format=json'));
142
        $this->assertEquals(0, substr_count($str, 'help --format=txt'));
143
144
        // emulate composer.json changes
145
        $tmp = self::$composerFile->read();
146
        $tmp['require']['test/dependency_1'] = 'dev-master';
147
        self::$composerFile->write($tmp);
148
149
        // 0.1.1 version check
150
        $expectedData['require'] = array(
151
            'test/dependency_1' => '0.1.1',
152
            'test/dependency_2' => '0.1.0',
153
        );
154
        unset($expectedData['repositories'][1]);
155
        $expectedData['repositories'] = array_values($expectedData['repositories']);
156
        $this->runUpdateDependenciesCommand($output);
157
        $str = $output->fetch();
158
        $this->assertEquals('0.1.1', $this->getCurrentVersion());
159
        $this->assertEquals(0, substr_count($str, 'new Test\AddBundle\TestAddBundle()'));
160
        $this->assertEquals(1, substr_count($str, 'new Test\RemoveBundle\TestRemoveBundle()'));
161
        $this->assertEquals($expectedData, self::$composerFile->read());
162
        $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.0.backup.json'));
163
        unlink(self::$basePath.'/composer.v0.1.0.backup.json');
164
165
        // 0.1.1 version run commands
166
        $this->runCommandsCommand($output);
167
        $str = $output->fetch();
168
        $this->assertEquals(1, substr_count($str, 'help --format=json'));
169
        $this->assertEquals(0, substr_count($str, 'help --format=txt'));
170
171
        // emulate composer.json changes
172
        $tmp = self::$composerFile->read();
173
        $tmp['require']['test/dependency_2'] = 'dev-master';
174
        self::$composerFile->write($tmp);
175
176
        // 0.1.2 version check
177
        $expectedData['require'] = array(
178
            'test/dependency_1' => '0.1.1',
179
            'test/dependency_2' => '0.1.0',
180
            'test/dependency_4' => '0.1.0',
181
        );
182
        $this->runUpdateDependenciesCommand($output);
183
        $str = $output->fetch();
184
        $this->assertEquals('0.1.2', $this->getCurrentVersion());
185
        $this->assertEquals(0, substr_count($str, 'new Test\AddBundle\TestAddBundle()'));
186
        $this->assertEquals(0, substr_count($str, 'new Test\RemoveBundle\TestRemoveBundle()'));
187
        $this->assertEquals($expectedData, self::$composerFile->read());
188
        $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.1.backup.json'));
189
        unlink(self::$basePath.'/composer.v0.1.1.backup.json');
190
191
        // 0.1.2 version run commands
192
        $this->runCommandsCommand($output);
193
        $str = $output->fetch();
194
        $this->assertEquals(0, substr_count($str, 'help --format=json'));
195
        $this->assertEquals(1, substr_count($str, 'help --format=txt'));
196
197
        // 0.1.3 version check
198
        $this->runUpdateDependenciesCommand($output);
199
        $str = $output->fetch();
200
        $this->assertEquals('0.1.3', $this->getCurrentVersion());
201
        $this->assertEquals(1, substr_count($str, 'Some foo instruction'));
202
        $this->assertEquals(0, substr_count($str, 'Some bar instruction'));
203
        $this->assertEquals(0, substr_count($str, 'Some baz instruction'));
204
        $this->assertEquals($expectedData, self::$composerFile->read());
205
        $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.2.backup.json'));
206
        unlink(self::$basePath.'/composer.v0.1.2.backup.json');
207
208
        // 0.1.4 version check
209
        $this->runUpdateDependenciesCommand($output);
210
        $str = $output->fetch();
211
        $this->assertEquals('0.1.4', $this->getCurrentVersion());
212
        $this->assertEquals(0, substr_count($str, 'Some foo instruction'));
213
        $this->assertEquals(1, substr_count($str, 'Some bar instruction'));
214
        $this->assertEquals(0, substr_count($str, 'Some baz instruction'));
215
        $this->assertEquals($expectedData, self::$composerFile->read());
216
        $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.3.backup.json'));
217
        unlink(self::$basePath.'/composer.v0.1.3.backup.json');
218
219
        // 0.1.5 version check
220
        $expectedData['require'] = array(
221
            'test/dependency_1' => '0.1.1',
222
            'test/dependency_4' => '0.1.1',
223
        );
224
        $this->runUpdateDependenciesCommand($output);
225
        $str = $output->fetch();
226
        $this->assertEquals('0.1.5', $this->getCurrentVersion());
227
        $this->assertEquals(0, substr_count($str, 'Some foo instruction'));
228
        $this->assertEquals(0, substr_count($str, 'Some bar instruction'));
229
        $this->assertEquals(1, substr_count($str, 'Some baz instruction'));
230
        $this->assertEquals($expectedData, self::$composerFile->read());
231
        $this->assertTrue(is_file(self::$basePath.'/composer.v0.1.4.backup.json'));
232
        unlink(self::$basePath.'/composer.v0.1.4.backup.json');
233
    }
234
}
235