Issues (655)

Security Analysis    not enabled

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.

Action/GetShortObjectDescriptionActionTest.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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Action;
15
16
use PHPUnit\Framework\TestCase;
17
use Prophecy\Argument;
18
use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction;
19
use Sonata\AdminBundle\Admin\AbstractAdmin;
20
use Sonata\AdminBundle\Admin\Pool;
21
use Sonata\AdminBundle\Templating\TemplateRegistry;
22
use Symfony\Component\DependencyInjection\Container;
23
use Symfony\Component\HttpFoundation\JsonResponse;
24
use Symfony\Component\HttpFoundation\Request;
25
use Symfony\Component\HttpFoundation\Response;
26
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
27
use Twig\Environment;
28
use Twig\Loader\ArrayLoader;
29
30
final class GetShortObjectDescriptionActionTest extends TestCase
31
{
32
    /**
33
     * @var Pool
34
     */
35
    private $pool;
36
37
    /**
38
     * @var Environment
39
     */
40
    private $twig;
41
42
    /**
43
     * @var GetShortObjectDescriptionAction
44
     */
45
    private $action;
46
47
    /**
48
     * @var AbstractAdmin
49
     */
50
    private $admin;
51
52
    protected function setUp(): void
53
    {
54
        $this->twig = new Environment(new ArrayLoader(['short_object_description' => 'renderedTemplate']));
55
        $this->pool = $this->prophesize(Pool::class);
56
        $this->admin = $this->prophesize(AbstractAdmin::class);
57
        $this->pool->getInstance(Argument::any())->willReturn($this->admin->reveal());
58
        $this->admin->setRequest(Argument::type(Request::class))->shouldBeCalled();
59
        $this->action = new GetShortObjectDescriptionAction(
60
            $this->twig,
61
            $this->pool->reveal()
62
        );
63
    }
64
65
    public function testGetShortObjectDescriptionActionInvalidAdmin(): void
66
    {
67
        $code = 'sonata.post.admin';
68
69
        $request = new Request([
70
            'code' => $code,
71
            'objectId' => 42,
72
            'uniqid' => 'asdasd123',
73
        ]);
74
75
        $this->pool->getInstance($code)->willThrow(\InvalidArgumentException::class);
76
        $this->admin->setRequest(Argument::type(Request::class))->shouldNotBeCalled();
77
78
        $this->expectException(NotFoundHttpException::class);
79
80
        ($this->action)($request);
81
    }
82
83
    public function testGetShortObjectDescriptionActionObjectDoesNotExist(): void
84
    {
85
        $this->expectException(\RuntimeException::class);
86
        $this->expectExceptionMessage('Invalid format');
87
88
        $request = new Request([
89
            'code' => 'sonata.post.admin',
90
            'objectId' => 42,
91
            'uniqid' => 'asdasd123',
92
        ]);
93
94
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
95
        $this->admin->getObject(42)->willReturn(null);
96
97
        ($this->action)($request);
98
    }
99
100
    public function testGetShortObjectDescriptionActionEmptyObjectId(): void
101
    {
102
        $request = new Request([
103
            'code' => 'sonata.post.admin',
104
            'objectId' => '',
105
            'uniqid' => 'asdasd123',
106
            '_format' => 'html',
107
        ]);
108
109
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
110
        $this->admin->getObject(null)->willReturn(null);
111
112
        $this->assertInstanceOf(Response::class, ($this->action)($request));
113
    }
114
115
    public function testGetShortObjectDescriptionActionObject(): void
116
    {
117
        $templateRegistry = new TemplateRegistry([
118
            'short_object_description' => 'short_object_description',
119
        ]);
120
        $container = new Container();
121
        $container->set('sonata.post.admin.template_registry', $templateRegistry);
122
        $this->pool->getContainer()->willReturn($container);
0 ignored issues
show
The method willReturn() does not seem to exist on object<Symfony\Component...ion\ContainerInterface>.

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...
123
124
        $request = new Request([
125
            'code' => 'sonata.post.admin',
126
            'objectId' => 42,
127
            'uniqid' => 'asdasd123',
128
            '_format' => 'html',
129
        ]);
130
        $object = new \stdClass();
131
132
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
133
        $this->admin->getObject(42)->willReturn($object);
134
        $this->admin->toString($object)->willReturn('bar');
135
        $this->admin->getCode()->willReturn('sonata.post.admin');
136
137
        $response = ($this->action)($request);
138
139
        $this->assertSame('renderedTemplate', $response->getContent());
140
    }
141
142
    public function testGetShortObjectDescriptionActionEmptyObjectIdAsJson(): void
143
    {
144
        $request = new Request([
145
            'code' => 'sonata.post.admin',
146
            'objectId' => '',
147
            'uniqid' => 'asdasd123',
148
            '_format' => 'json',
149
        ]);
150
151
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
152
        $this->admin->getObject(null)->willReturn(null);
153
        $this->admin->id(null)->willReturn('');
154
        $this->admin->toString(null)->willReturn('');
155
156
        $response = ($this->action)($request);
157
158
        $this->assertInstanceOf(JsonResponse::class, $response);
159
        $this->assertSame('{"result":{"id":"","label":""}}', $response->getContent());
160
    }
161
162
    public function testGetShortObjectDescriptionActionObjectAsJson(): void
163
    {
164
        $request = new Request([
165
            'code' => 'sonata.post.admin',
166
            'objectId' => 42,
167
            'uniqid' => 'asdasd123',
168
            '_format' => 'json',
169
        ]);
170
        $object = new \stdClass();
171
172
        $this->admin->setUniqid('asdasd123')->shouldBeCalled();
173
        $this->admin->id($object)->willReturn(42);
174
        $this->admin->getObject(42)->willReturn($object);
175
        $this->admin->toString($object)->willReturn('bar');
176
177
        $response = ($this->action)($request);
178
179
        $this->assertSame('{"result":{"id":"42","label":"bar"}}', $response->getContent());
180
    }
181
}
182