Issues (74)

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/UQL/InterpreterTest.php (13 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
namespace Netdudes\DataSourceryBundle\Tests\UQL;
3
4
use Netdudes\DataSourceryBundle\DataSource\Configuration\Field;
5
use Netdudes\DataSourceryBundle\DataSource\DataSourceInterface;
6
use Netdudes\DataSourceryBundle\DataType\NumberDataType;
7
use Netdudes\DataSourceryBundle\DataType\StringDataType;
8
use Netdudes\DataSourceryBundle\Extension\ContextFactory;
9
use Netdudes\DataSourceryBundle\Extension\UqlExtensionContainer;
10
use Netdudes\DataSourceryBundle\Query\Filter;
11
use Netdudes\DataSourceryBundle\Query\FilterCondition;
12
use Netdudes\DataSourceryBundle\Query\FilterConditionFactory;
13
use Netdudes\DataSourceryBundle\UQL\AST\ASTAssertion;
14
use Netdudes\DataSourceryBundle\UQL\AST\ASTGroup;
15
use Netdudes\DataSourceryBundle\UQL\Exception\UQLInterpreterException;
16
use Netdudes\DataSourceryBundle\UQL\InterpreterFactory;
17
use PHPUnit\Framework\TestCase;
18
19
class InterpreterTest extends TestCase
20
{
21
    /**
22
     * @var ContextFactory
23
     */
24
    private $contextFactoryProphecy;
25
26
    /**
27
     * @var UqlExtensionContainer
28
     */
29
    private $extensionContainerProphecy;
30
31
    public function testBuildFilter()
32
    {
33
        $astSubtree = new ASTGroup(
34
            'T_LOGIC_AND',
35
            [
36
                new ASTGroup(
37
                    'T_LOGIC_OR',
38
                    [
39
                        new ASTAssertion(
40
                            'test_dse_1',
41
                            'T_OP_EQ',
42
                            'value1'
43
                        ),
44
                        new ASTAssertion(
45
                            'test_dse_2',
46
                            'T_OP_LT',
47
                            'value2'
48
                        ),
49
                    ]
50
                ),
51
                new ASTAssertion(
52
                    'test_dse_3',
53
                    'T_OP_NEQ',
54
                    'value3'
55
                ),
56
            ]
57
        );
58
59
        $filterDefinition1 = new Filter();
60
        $filterDefinition1->setConditionType('OR');
61
        $filter1 = new FilterCondition('test_dse_1', FilterCondition::METHOD_NUMERIC_EQ, 'value1', 'value1');
62
        $filter2 = new FilterCondition('test_dse_2', FilterCondition::METHOD_NUMERIC_LT, 'value2', 'value2');
63
        $filterDefinition1[] = $filter1;
64
        $filterDefinition1[] = $filter2;
65
        $filter3 = new FilterCondition('test_dse_3', FilterCondition::METHOD_NUMERIC_NEQ, 'value3', 'value3');
66
        $filterDefinition2 = new Filter();
67
        $filterDefinition2->setConditionType('AND');
68
        $filterDefinition2[] = $filterDefinition1;
69
        $filterDefinition2[] = $filter3;
70
71
        $expectedFilter = $filterDefinition2;
72
73
        $dataSourceElements = [
74
            new Field('test_dse_1', '', '', new NumberDataType()),
75
            new Field('test_dse_2', '', '', new NumberDataType()),
76
            new Field('test_dse_3', '', '', new NumberDataType()),
77
        ];
78
79
        $dataSourceProphecy = $this->prophesize(DataSourceInterface::class);
80
        $dataSourceProphecy->getFields()->willReturn($dataSourceElements);
81
82
        $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal());
0 ignored issues
show
The method reveal() does not seem to exist on object<Netdudes\DataSour...\UqlExtensionContainer>.

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...
The method reveal() does not seem to exist on object<Netdudes\DataSour...tension\ContextFactory>.

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...
83
        $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal());
84
85
        $actualFilter = $interpreter->buildFilter($astSubtree);
86
        $this->assertEquals($expectedFilter, $actualFilter);
87
    }
88
89 View Code Duplication
    public function testTranslateOperator()
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...
90
    {
91
        // Manually set the data source element, mimic what the data source would do
92
        $dataSourceElement = new Field(
93
            'test_data_source_element_name',
94
            '',
95
            '',
96
            new StringDataType()
97
        );
98
99
        $dataSourceProphecy = $this->prophesize(DataSourceInterface::class);
100
        $dataSourceProphecy->getFields()->willReturn([$dataSourceElement]);
101
102
        $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal());
0 ignored issues
show
The method reveal() does not seem to exist on object<Netdudes\DataSour...\UqlExtensionContainer>.

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...
The method reveal() does not seem to exist on object<Netdudes\DataSour...tension\ContextFactory>.

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...
103
        $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal());
104
105
        // LIKE is valid for String type, should return LIKE
106
        $this->assertEquals(FilterCondition::METHOD_STRING_LIKE, $interpreter->translateOperator('T_OP_LIKE', $dataSourceElement), 'Failed to translate T_OP_LIKE into STRING_LIKE for type String');
107
108
        // EQ is valid for String, and should choose STRING_EQ as it's the default for the type
109
        $this->assertEquals(FilterCondition::METHOD_STRING_EQ, $interpreter->translateOperator('T_OP_EQ', $dataSourceElement), 'Failed to translate T_OP_EQ into STRING_EQ for type String');
110
    }
111
112 View Code Duplication
    public function testInStatementsOnlyAcceptArraysAsValues()
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...
113
    {
114
        $astSubtree = new ASTAssertion('field', 'T_OP_IN', '123');
115
        $field = new Field('field', '', '', new NumberDataType());
116
117
        $dataSourceProphecy = $this->prophesize(DataSourceInterface::class);
118
        $dataSourceProphecy->getFields()->willReturn([$field]);
119
120
        $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal());
0 ignored issues
show
The method reveal() does not seem to exist on object<Netdudes\DataSour...\UqlExtensionContainer>.

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...
The method reveal() does not seem to exist on object<Netdudes\DataSour...tension\ContextFactory>.

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...
121
        $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal());
122
123
        $this->expectException(UQLInterpreterException::class);
124
        $this->expectExceptionMessage('Only arrays are valid arguments for IN / NOT IN statements');
125
        $interpreter->buildFilter($astSubtree);
126
    }
127
128 View Code Duplication
    public function testNullValueCanBeCheckedOnlyWithIsOperator()
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...
129
    {
130
        $astSubtree = new ASTAssertion('field', 'T_OP_GT', null);
131
        $field = new Field('field', '', '', new NumberDataType());
132
133
        $dataSourceProphecy = $this->prophesize(DataSourceInterface::class);
134
        $dataSourceProphecy->getFields()->willReturn([$field]);
135
136
        $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal());
0 ignored issues
show
The method reveal() does not seem to exist on object<Netdudes\DataSour...\UqlExtensionContainer>.

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...
The method reveal() does not seem to exist on object<Netdudes\DataSour...tension\ContextFactory>.

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...
137
        $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal());
138
139
        $this->expectException(UQLInterpreterException::class);
140
        $this->expectExceptionMessage('Only IS / IS NOT operator can be used to compare against null value');
141
        $interpreter->buildFilter($astSubtree);
142
    }
143
144
    protected function setUp()
145
    {
146
        $this->extensionContainerProphecy = $this->prophesize(UqlExtensionContainer::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(\Netdu...ensionContainer::class) of type object<Prophecy\Prophecy\ObjectProphecy> is incompatible with the declared type object<Netdudes\DataSour...\UqlExtensionContainer> of property $extensionContainerProphecy.

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...
147
        $this->contextFactoryProphecy = $this->prophesize(ContextFactory::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(\Netdu...\ContextFactory::class) of type object<Prophecy\Prophecy\ObjectProphecy> is incompatible with the declared type object<Netdudes\DataSour...tension\ContextFactory> of property $contextFactoryProphecy.

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...
148
    }
149
}
150