Issues (387)

Branch: develop

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.

Configuration/ConfigurationFactoryTest.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
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2015 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Configuration;
14
15
use Mockery\Adapter\Phpunit\MockeryTestCase;
16
use Mockery as m;
17
use org\bovigo\vfs\vfsStream;
18
use phpDocumentor\Configuration\Factory\Strategy;
19
use phpDocumentor\Configuration\Factory\Version2;
20
use phpDocumentor\Configuration\Factory\Version3;
21
use phpDocumentor\Configuration\Exception\InvalidConfigPathException;
22
use phpDocumentor\Uri;
23
24
/**
25
 * Test case for ConfigurationFactory
26
 *
27
 * @coversDefaultClass \phpDocumentor\Configuration\ConfigurationFactory
28
 * @covers ::<private>
29
 * @covers ::__construct
30
 */
31
final class ConfigurationFactoryTest extends MockeryTestCase
32
{
33
    /**
34
     * @covers ::fromUri
35
     */
36
    public function testItLoadsASpecificConfigurationFileUsingTheCorrectStrategy()
37
    {
38
        $configurationFactory = new ConfigurationFactory(
39
            [
40
                new Version3('data/xsd/phpdoc.xsd'),
41
                new Version2()
42
            ],
43
            []
44
        );
45
46
        $content = '<phpdocumentor><title>My title</title></phpdocumentor>';
47
        $configuration = $configurationFactory->fromUri(
48
            new Uri($this->givenExampleConfigurationFileWithContent($content))
49
        );
50
51
        $this->assertSame('My title', $configuration['phpdocumentor']['title']);
52
    }
53
    /**
54
     * @covers ::fromUri
55
     */
56
    public function testLoadingFromUriFailsIfFileDoesNotExist()
57
    {
58
        $this->expectException(InvalidConfigPathException::class);
59
        $this->expectExceptionMessage('File file:///does-not-exist could not be found');
60
        $configurationFactory = new ConfigurationFactory([new Version2()], []);
61
        $configurationFactory->fromUri(new Uri('/does-not-exist'));
62
    }
63
64
    /**
65
     * @covers ::fromDefaultLocations()
66
     */
67
    public function testThatTheDefaultConfigurationFilesAreLoaded()
68
    {
69
        $file = $this->givenExampleConfigurationFileWithContent(
70
            '<phpdocumentor><title>My title</title></phpdocumentor>'
71
        );
72
        $configurationFactory = new ConfigurationFactory([new Version2()], [$file]);
73
74
        $configuration = $configurationFactory->fromDefaultLocations();
75
76
        $this->assertSame('My title', $configuration['phpdocumentor']['title']);
77
    }
78
79
    /**
80
     * @covers ::fromDefaultLocations()
81
     */
82
    public function testWhenNoneOfTheDefaultsExistThatTheBakedConfigIsUsed()
83
    {
84
        $configurationFactory = new ConfigurationFactory([new Version2()], ['does_not_exist.xml']);
85
86
        $configuration = $configurationFactory->fromDefaultLocations();
87
88
        $this->assertEquals(Version3::buildDefault(), $configuration->getArrayCopy());
89
    }
90
91
    /**
92
     * @covers ::fromDefaultLocations()
93
     */
94
    public function testWhenDefaultFileIsInvalidXMLThenAnExceptionIsRaised()
95
    {
96
        $file = $this->givenExampleConfigurationFileWithContent(
97
            '<?xml version="1.0" encoding="UTF-8" ?>' .
98
            '<phpdocumentor xmlns="http://www.phpdoc.org" version="3">' .
99
            '<foo/>' .
100
            '</phpdocumentor>'
101
        );
102
        $configurationFactory = new ConfigurationFactory(
103
            [new Version3(__DIR__ . '/../../../../data/xsd/phpdoc.xsd')],
104
            [$file]
105
        );
106
107
        $this->expectException(\InvalidArgumentException::class);
108
        $this->expectExceptionMessage(
109
            "Element '{http://www.phpdoc.org}foo': This element is not expected. "
110
            . "Expected is ( {http://www.phpdoc.org}paths )."
111
        );
112
        $configurationFactory->fromDefaultLocations();
113
    }
114
115
    /**
116
     * @covers ::addMiddleware
117
     */
118
    public function testThatMiddlewaresCanBeAddedAndAreThenApplied()
119
    {
120
        $inputValue = ['test'];
121
        $afterMiddleware1Value = ['test', 'test2'];
122
        $afterMiddleware2Value = ['test', 'test2', 'test3'];
123
124
        $middleWare1 = $this->givenAMiddlewareThatReturns($inputValue, $afterMiddleware1Value);
125
        $middleWare2 = $this->givenAMiddlewareThatReturns($afterMiddleware1Value, $afterMiddleware2Value);
126
127
        $factory = new ConfigurationFactory([$this->givenAValidStrategyThatReturns($inputValue)], []);
128
        $factory->addMiddleware($middleWare1);
129
        $factory->addMiddleware($middleWare2);
130
131
        $data = $factory->fromUri(new Uri($this->givenExampleConfigurationFileWithContent('<foo></foo>')));
132
133
        $this->assertSame($afterMiddleware2Value, $data->getArrayCopy());
134
    }
135
136
    /**
137
     * @covers ::fromUri
138
     * @expectedException \Exception
139
     * @expectedExceptionMessage No supported configuration files were found
140
     */
141
    public function testItHaltsIfNoMatchingStrategyCanBeFound()
142
    {
143
        $strategies = []; // No strategy means nothing could match ;)
144
        $configurationFactory = new ConfigurationFactory($strategies, []);
145
146
        $configurationFactory->fromUri(
147
            new Uri($this->givenExampleConfigurationFileWithContent('<foo></foo>'))
148
        );
149
    }
150
151
    /**
152
     * @covers ::__construct
153
     * @expectedException \TypeError
154
     */
155
    public function testItErrorsWhenTryingToInitializeWithSomethingOtherThanAStrategy()
156
    {
157
        new ConfigurationFactory(['this_is_not_a_strategy'], []);
0 ignored issues
show
array('this_is_not_a_strategy') is of type array<integer,string,{"0":"string"}>, but the function expects a array<integer,object<php...Configuration\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
158
    }
159
160
    private function givenExampleConfigurationFileWithContent($content): string
161
    {
162
        vfsStream::newFile('foo.xml')
163
            ->at(vfsStream::setup('dir'))
164
            ->withContent($content);
165
166
        return vfsStream::url('dir/foo.xml');
167
    }
168
169
    private function givenAMiddlewareThatReturns($expectedInputValue, $returnValue): \Closure
170
    {
171
        return function ($value) use ($expectedInputValue, $returnValue) {
172
            $this->assertSame($expectedInputValue, $value);
173
174
            return $returnValue;
175
        };
176
    }
177
178
    private function givenAValidStrategyThatReturns($result): Strategy
179
    {
180
        /** @var m\Mock $strategy */
181
        $strategy = m::mock(Strategy::class);
182
        $strategy->shouldReceive('supports')
183
            ->once()
184
            ->with(m::type(\SimpleXMLElement::class))
185
            ->andReturn(true);
186
        $strategy
187
            ->shouldReceive('convert')
188
            ->once()
189
            ->with(m::type(\SimpleXMLElement::class))->andReturn($result);
190
191
        return $strategy;
192
    }
193
}
194