Issues (63)

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.

tests/Backend/MessageManagerBackendTest.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\NotificationBundle\Tests\Notification;
15
16
use Laminas\Diagnostics\Result\Failure;
17
use Laminas\Diagnostics\Result\Success;
18
use Laminas\Diagnostics\Result\Warning;
19
use PHPUnit\Framework\TestCase;
20
use Sonata\NotificationBundle\Backend\MessageManagerBackend;
21
use Sonata\NotificationBundle\Exception\HandlingException;
22
use Sonata\NotificationBundle\Model\MessageInterface;
23
use Sonata\NotificationBundle\Model\MessageManagerInterface;
24
use Sonata\NotificationBundle\Tests\Entity\Message;
25
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
26
27
class MessageManagerBackendTest extends TestCase
28
{
29
    public function testCreateAndPublish(): void
30
    {
31
        $message = new Message();
32
        $modelManager = $this->createMock(MessageManagerInterface::class);
33
        $modelManager->expects($this->once())->method('save')->willReturn($message);
34
        $modelManager->expects($this->once())->method('create')->willReturn($message);
35
36
        $backend = new MessageManagerBackend($modelManager, []);
37
        $message = $backend->createAndPublish('foo', ['message' => 'salut']);
38
39
        $this->assertInstanceOf(MessageInterface::class, $message);
40
        $this->assertSame(MessageInterface::STATE_OPEN, $message->getState());
41
        $this->assertNotNull($message->getCreatedAt());
42
        $this->assertSame('foo', $message->getType());
43
        $this->assertSame(['message' => 'salut'], $message->getBody());
44
    }
45
46
    public function testHandleSuccess(): void
47
    {
48
        $message = new Message();
49
        $modelManager = $this->createMock(MessageManagerInterface::class);
50
        $modelManager->expects($this->exactly(2))->method('save')->willReturn($message);
51
52
        $dispatcher = $this->createMock(EventDispatcherInterface::class);
53
        $dispatcher->expects($this->once())->method('dispatch');
54
55
        $backend = new MessageManagerBackend($modelManager, []);
56
57
        $backend->handle($message, $dispatcher);
58
59
        $this->assertSame(MessageInterface::STATE_DONE, $message->getState());
60
        $this->assertNotNull($message->getCreatedAt());
61
        $this->assertNotNull($message->getCompletedAt());
62
    }
63
64
    public function testHandleError(): void
65
    {
66
        $message = new Message();
67
        $modelManager = $this->createMock(MessageManagerInterface::class);
68
        $modelManager->expects($this->exactly(2))->method('save')->willReturn($message);
69
70
        $dispatcher = $this->createMock(EventDispatcherInterface::class);
71
        $dispatcher->expects($this->once())->method('dispatch')->will($this->throwException(new \RuntimeException()));
72
        $backend = new MessageManagerBackend($modelManager, []);
73
74
        $e = false;
75
76
        try {
77
            $backend->handle($message, $dispatcher);
78
        } catch (HandlingException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
79
        }
80
81
        $this->assertInstanceOf(HandlingException::class, $e);
82
83
        $this->assertSame(MessageInterface::STATE_ERROR, $message->getState());
84
        $this->assertNotNull($message->getCreatedAt());
85
        $this->assertNotNull($message->getCompletedAt());
86
    }
87
88
    /**
89
     * @dataProvider statusProvider
90
     */
91
    public function testStatus($counts, $expectedStatus, $message): void
92
    {
93
        $modelManager = $this->createMock(MessageManagerInterface::class);
94
        $modelManager->expects($this->once())->method('countStates')->willReturn($counts);
95
96
        $backend = new MessageManagerBackend($modelManager, [
97
            MessageInterface::STATE_IN_PROGRESS => 10,
98
            MessageInterface::STATE_ERROR => 30,
99
            MessageInterface::STATE_OPEN => 100,
100
            MessageInterface::STATE_DONE => 10000,
101
        ]);
102
103
        $status = $backend->getStatus();
104
105
        $this->assertInstanceOf(\get_class($expectedStatus), $status);
106
        $this->assertSame($message, $status->getMessage());
107
    }
108
109
    public static function statusProvider(): array
110
    {
111
        if (!class_exists(Success::class)) {
112
            return [[1, 1, 1]];
113
        }
114
115
        $data = [];
116
117
        $data[] = [
118
            [
119
                MessageInterface::STATE_IN_PROGRESS => 11, //here
120
                MessageInterface::STATE_ERROR => 31,
121
                MessageInterface::STATE_OPEN => 100,
122
                MessageInterface::STATE_DONE => 10000,
123
            ],
124
            new Failure(),
125
            'Too many messages processed at the same time (Database)',
126
        ];
127
128
        $data[] = [
129
            [
130
                MessageInterface::STATE_IN_PROGRESS => 1,
131
                MessageInterface::STATE_ERROR => 31, //here
132
                MessageInterface::STATE_OPEN => 100,
133
                MessageInterface::STATE_DONE => 10000,
134
            ],
135
            new Failure(),
136
            'Too many errors (Database)',
137
        ];
138
139
        $data[] = [
140
            [
141
                MessageInterface::STATE_IN_PROGRESS => 1,
142
                MessageInterface::STATE_ERROR => 1,
143
                MessageInterface::STATE_OPEN => 101, //here
144
                MessageInterface::STATE_DONE => 10000,
145
            ],
146
            new Warning(),
147
            'Too many messages waiting to be processed (Database)',
148
        ];
149
150
        $data[] = [
151
            [
152
                MessageInterface::STATE_IN_PROGRESS => 1,
153
                MessageInterface::STATE_ERROR => 1,
154
                MessageInterface::STATE_OPEN => 100,
155
                MessageInterface::STATE_DONE => 10001, //here
156
            ],
157
                new Warning(),
158
            'Too many processed messages, please clean the database (Database)',
159
        ];
160
161
        $data[] = [
162
            [
163
                MessageInterface::STATE_IN_PROGRESS => 1,
164
                MessageInterface::STATE_ERROR => 1,
165
                MessageInterface::STATE_OPEN => 1,
166
                MessageInterface::STATE_DONE => 1,
167
            ],
168
            new Success(),
169
            'Ok (Database)',
170
        ];
171
172
        return $data;
173
    }
174
}
175