Issues (42)

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.

DependencyInjection/CustomHandlerPassTest.php (5 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
/*
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace JMS\SerializerBundle\Tests\DependencyInjection;
20
21
use JMS\Serializer\Exception\RuntimeException;
22
use JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersPass;
23
use JMS\SerializerBundle\DependencyInjection\JMSSerializerExtension;
24
use PHPUnit\Framework\TestCase;
25
use Symfony\Component\DependencyInjection\ContainerBuilder;
26
use Symfony\Component\DependencyInjection\Definition;
27
use Symfony\Component\DependencyInjection\Reference;
28
29
class CustomHandlerPassTest extends TestCase
30
{
31
    /**
32
     * @param array $configs
33
     * @return ContainerBuilder
34
     */
35 View Code Duplication
    private function getContainer(array $configs = array())
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...
36
    {
37
        $loader = new JMSSerializerExtension();
38
        $container = new ContainerBuilder();
39
40
        $container->setParameter('kernel.debug', true);
41
        $container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer');
42
        $container->setParameter('kernel.bundles', array());
43
        $container->setParameter('kernel.bundles', array());
44
45
        $loader->load(['jms_serializer' => $configs], $container);
46
47
        // remove other subscribers
48
        foreach (array_keys($container->findTaggedServiceIds('jms_serializer.handler')) as $id) {
49
            $container->removeDefinition($id);
50
        }
51
        foreach (array_keys($container->findTaggedServiceIds('jms_serializer.subscribing_handler')) as $id) {
52
            $container->removeDefinition($id);
53
        }
54
55
        return $container;
56
    }
57
58
    public function testHandler()
59
    {
60
        $container = $this->getContainer();
61
62
        $def = new Definition('Foo');
63
        $def->addTag('jms_serializer.handler', [
64
            'type' => 'DateTime',
65
            'format' => 'json',
66
        ]);
67
        $container->setDefinition('my_service', $def);
68
69
        $pass = new CustomHandlersPass();
70
        $pass->process($container);
71
72
        $args = $container->getDefinition('jms_serializer.handler_registry')->getArguments();
73
74
        $this->assertSame([
75
            2 => ['DateTime' => ['json' => ['my_service', 'deserializeDateTimeFromjson']]],
76
            1 => ['DateTime' => ['json' => ['my_service', 'serializeDateTimeTojson']]]
77
        ], $args[1]);
78
    }
79
80
    public function testHandlerCanBePrivate()
81
    {
82
        $container = $this->getContainer();
83
84
        $def = new Definition('Foo');
85
        $def->setPublic(false);
86
        $def->addTag('jms_serializer.handler', [
87
            'type' => 'DateTime',
88
            'format' => 'json',
89
        ]);
90
        $container->setDefinition('my_service', $def);
91
92
        $pass = new CustomHandlersPass();
93
        $pass->process($container);
94
95
        $args = $container->getDefinition('jms_serializer.handler_registry')->getArguments();
96
97
        $this->assertEquals([
98
            2 => ['DateTime' => ['json' => [new Reference('my_service'), 'deserializeDateTimeFromjson']]],
99
            1 => ['DateTime' => ['json' => [new Reference('my_service'), 'serializeDateTimeTojson']]]
100
        ], $args[1]);
101
    }
102
103
    public function testHandlerDirection()
104
    {
105
        $container = $this->getContainer();
106
107
        $def = new Definition('Foo');
108
        $def->addTag('jms_serializer.handler', [
109
            'type' => 'DateTime',
110
            'format' => 'json',
111
            'direction' => 'SERIALIZATION',
112
        ]);
113
        $container->setDefinition('my_service', $def);
114
115
        $pass = new CustomHandlersPass();
116
        $pass->process($container);
117
118
        $args = $container->getDefinition('jms_serializer.handler_registry')->getArguments();
119
120
        $this->assertSame([
121
            1 => ['DateTime' => ['json' => ['my_service', 'serializeDateTimeTojson']]]
122
        ], $args[1]);
123
    }
124
125
    /**
126
     * @expectedException RuntimeException
127
     * @expectedExceptionMessage The direction "bar" of tag "jms_serializer.handler" of service "my_service" does not exist
128
     */
129
    public function testHandlerIncorrectDirection()
130
    {
131
        $container = $this->getContainer();
132
133
        $def = new Definition('Foo');
134
        $def->addTag('jms_serializer.handler', [
135
            'type' => 'DateTime',
136
            'format' => 'json',
137
            'direction' => 'bar',
138
        ]);
139
        $container->setDefinition('my_service', $def);
140
141
        $pass = new CustomHandlersPass();
142
        $pass->process($container);
143
    }
144
145
    /**
146
     * @expectedException RuntimeException
147
     * @expectedExceptionMessage Each tag named "jms_serializer.handler" of service "my_service" must have at least two attributes: "type" and "format"
148
     */
149 View Code Duplication
    public function testHandlerMustHaveTypeAndFormat()
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...
150
    {
151
        $container = $this->getContainer();
152
153
        $def = new Definition('Foo');
154
        $def->addTag('jms_serializer.handler');
155
        $container->setDefinition('my_service', $def);
156
157
        $pass = new CustomHandlersPass();
158
        $pass->process($container);
159
    }
160
161 View Code Duplication
    public function testSubscribingHandler()
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...
162
    {
163
        $container = $this->getContainer();
164
165
        $def = new Definition('JMS\SerializerBundle\Tests\DependencyInjection\Fixture\SubscribingHandler');
166
        $def->addTag('jms_serializer.subscribing_handler');
167
        $container->setDefinition('my_service', $def);
168
169
        $pass = new CustomHandlersPass();
170
        $pass->process($container);
171
172
        $args = $container->getDefinition('jms_serializer.handler_registry')->getArguments();
173
174
        $this->assertSame([
175
            1 => ['DateTime' => ['json' => ['my_service', 'onDateTime']]]
176
        ], $args[1]);
177
    }
178
179 View Code Duplication
    public function testSubscribingHandlerCanBePrivate()
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...
180
    {
181
        $container = $this->getContainer();
182
183
        $def = new Definition('JMS\SerializerBundle\Tests\DependencyInjection\Fixture\SubscribingHandler');
184
        $def->addTag('jms_serializer.subscribing_handler');
185
        $def->setPublic(false);
186
        $container->setDefinition('my_service', $def);
187
188
        $pass = new CustomHandlersPass();
189
        $pass->process($container);
190
191
        $args = $container->getDefinition('jms_serializer.handler_registry')->getArguments();
192
193
        $this->assertEquals([
194
            1 => ['DateTime' => ['json' => [new Reference('my_service'), 'onDateTime']]]
195
        ], $args[1]);
196
    }
197
198
    /**
199
     * @expectedException RuntimeException
200
     * @expectedExceptionMessage The service "my_service" must implement the SubscribingHandlerInterface
201
     */
202 View Code Duplication
    public function testSubscribingHandlerInterface()
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...
203
    {
204
        $container = $this->getContainer();
205
206
        $def = new Definition('JMS\SerializerBundle\Tests\DependencyInjection\Fixture\SimpleObject');
207
        $def->addTag('jms_serializer.subscribing_handler');
208
        $container->setDefinition('my_service', $def);
209
210
        $pass = new CustomHandlersPass();
211
        $pass->process($container);
212
    }
213
}
214