Issues (2)

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/ProcessorTest.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
3
namespace Incenteev\ParameterHandler\Tests;
4
5
use Incenteev\ParameterHandler\Processor;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Filesystem\Filesystem;
8
use Symfony\Component\Yaml\Yaml;
9
10
class ProcessorTest extends TestCase
11
{
12
    private $io;
13
    private $environmentBackup = array();
14
15
    /**
16
     * @var Processor
17
     */
18
    private $processor;
19
20
    protected function setUp()
21
    {
22
        parent::setUp();
23
24
        $this->io = $this->prophesize('Composer\IO\IOInterface');
25
        $this->processor = new Processor($this->io->reveal());
26
    }
27
28
    protected function tearDown()
29
    {
30
        parent::tearDown();
31
32
        foreach ($this->environmentBackup as $var => $value) {
33
            if (false === $value) {
34
                putenv($var);
35
            } else {
36
                putenv($var.'='.$value);
37
            }
38
        }
39
    }
40
41
    /**
42
     * @dataProvider provideInvalidConfiguration
43
     */
44
    public function testInvalidConfiguration(array $config, $exceptionMessage)
45
    {
46
        chdir(__DIR__);
47
48 View Code Duplication
        if (method_exists($this, 'expectException')) {
0 ignored issues
show
This code seems to be duplicated across 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...
49
            $this->expectException('InvalidArgumentException');
50
            $this->expectExceptionMessage($exceptionMessage);
51
        } else {
52
            $this->setExpectedException('InvalidArgumentException', $exceptionMessage);
53
        }
54
55
        $this->processor->processFile($config);
56
    }
57
58
    public function provideInvalidConfiguration()
59
    {
60
        return array(
61
            'no file' => array(
62
                array(),
63
                'The extra.incenteev-parameters.file setting is required to use this script handler.',
64
            ),
65
            'missing default dist file' => array(
66
                array(
67
                    'file' => 'fixtures/invalid/missing.yml',
68
                ),
69
                'The dist file "fixtures/invalid/missing.yml.dist" does not exist. Check your dist-file config or create it.',
70
            ),
71
            'missing custom dist file' => array(
72
                array(
73
                    'file' => 'fixtures/invalid/missing.yml',
74
                    'dist-file' => 'fixtures/invalid/non-existent.dist.yml',
75
                ),
76
                'The dist file "fixtures/invalid/non-existent.dist.yml" does not exist. Check your dist-file config or create it.',
77
            ),
78
            'missing top level key in dist file' => array(
79
                array(
80
                    'file' => 'fixtures/invalid/missing_top_level.yml',
81
                ),
82
                'The top-level key parameters is missing.',
83
            ),
84
            'invalid values in the existing file' => array(
85
                array(
86
                    'file' => 'fixtures/invalid/invalid_existing_values.yml',
87
                ),
88
                'The existing "fixtures/invalid/invalid_existing_values.yml" file does not contain an array',
89
            ),
90
        );
91
    }
92
93
    /**
94
     * @dataProvider provideParameterHandlingTestCases
95
     */
96
    public function testParameterHandling($testCaseName)
97
    {
98
        $dataDir = __DIR__.'/fixtures/testcases/'.$testCaseName;
99
100
        $testCase = array_replace_recursive(
101
            array(
102
                'title' => 'unknown test',
103
                'config' => array(
104
                    'file' => 'parameters.yml',
105
                ),
106
                'dist-file' => 'parameters.yml.dist',
107
                'environment' => array(),
108
                'interactive' => false,
109
            ),
110
            (array) Yaml::parse(file_get_contents($dataDir.'/setup.yml'))
111
        );
112
113
        $workingDir = sys_get_temp_dir() . '/incenteev_parameter_handler';
114
        $exists = $this->initializeTestCase($testCase, $dataDir, $workingDir);
115
116
        $message = sprintf('<info>%s the "%s" file</info>', $exists ? 'Updating' : 'Creating', $testCase['config']['file']);
117
        $this->io->write($message)->shouldBeCalled();
118
119
        $this->setInteractionExpectations($testCase);
120
121
        $this->processor->processFile($testCase['config']);
122
123
        $this->assertFileEquals($dataDir.'/expected.yml', $workingDir.'/'.$testCase['config']['file'], $testCase['title']);
124
    }
125
126
    private function initializeTestCase(array $testCase, $dataDir, $workingDir)
127
    {
128
        $fs = new Filesystem();
129
130
        if (is_dir($workingDir)) {
131
            $fs->remove($workingDir);
132
        }
133
134
        $fs->copy($dataDir.'/dist.yml', $workingDir.'/'. $testCase['dist-file']);
135
136
        if ($exists = file_exists($dataDir.'/existing.yml')) {
137
            $fs->copy($dataDir.'/existing.yml', $workingDir.'/'.$testCase['config']['file']);
138
        }
139
140
        foreach ($testCase['environment'] as $var => $value) {
141
            $this->environmentBackup[$var] = getenv($var);
142
            putenv($var.'='.$value);
143
        };
144
145
        chdir($workingDir);
146
147
        return $exists;
148
    }
149
150
    private function setInteractionExpectations(array $testCase)
151
    {
152
        $this->io->isInteractive()->willReturn($testCase['interactive']);
153
154
        if (!$testCase['interactive']) {
155
            return;
156
        }
157
158
        if (!empty($testCase['requested_params'])) {
159
            $this->io->write('<comment>Some parameters are missing. Please provide them.</comment>')->shouldBeCalledTimes(1);
160
        }
161
162
        foreach ($testCase['requested_params'] as $param => $settings) {
163
            $this->io->ask(sprintf('<question>%s</question> (<comment>%s</comment>): ', $param, $settings['default']), $settings['default'])
164
                ->willReturn($settings['input'])
165
                ->shouldBeCalled();
166
        }
167
    }
168
169
    public function provideParameterHandlingTestCases()
170
    {
171
        $tests = array();
172
173
        foreach (glob(__DIR__.'/fixtures/testcases/*/') as $folder) {
174
            $tests[] = array(basename($folder));
175
        }
176
177
        return $tests;
178
    }
179
}
180