Issues (7)

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/Units/Event/EventBusTests.php (3 issues)

Severity

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 the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cubiche\Core\EventBus\Tests\Units\Event;
12
13
use Cubiche\Core\Bus\Exception\NotFoundException;
14
use Cubiche\Core\Bus\Middlewares\Locking\LockingMiddleware;
15
use Cubiche\Core\Bus\Tests\Fixtures\FooMessage;
16
use Cubiche\Core\Bus\Tests\Units\BusTests;
17
use Cubiche\Core\EventBus\Event\Event;
18
use Cubiche\Core\EventBus\Event\EventBus;
19
use Cubiche\Core\EventBus\Middlewares\EventDispatcher\EventDispatcherMiddleware;
20
use Cubiche\Core\EventBus\Tests\Fixtures\Event\LoginUserEvent;
21
use Cubiche\Core\EventBus\Tests\Fixtures\Event\LoginUserEventListener;
22
use Cubiche\Core\EventBus\Tests\Fixtures\Event\UserEventSubscriber;
23
24
/**
25
 * EventBusTests class.
26
 *
27
 * @author Ivannis Suárez Jerez <[email protected]>
28
 */
29
class EventBusTests extends BusTests
30
{
31
    /**
32
     * Test create without event dispatcher middleware.
33
     */
34
    public function testCreateWithoutEventDispatcherMiddleware()
35
    {
36
        $this
37
            ->given($middleware = new LockingMiddleware())
38
            ->and($eventBus = new EventBus([$middleware]))
39
            ->then()
40
                ->exception(function () use ($eventBus) {
41
                    $eventBus->dispatch(new LoginUserEvent('[email protected]'));
42
                })
43
                ->isInstanceOf(NotFoundException::class)
44
        ;
45
    }
46
47
    /**
48
     * Test dispatch chained middlewares.
49
     */
50
    public function testDispatchChainedMiddlewares()
51
    {
52
        $this
53
            ->given($eventBus = EventBus::create())
54
            ->and($event = new LoginUserEvent('[email protected]'))
55
            ->and($eventBus->addListener($event->eventName(), function (LoginUserEvent $event) {
56
                $this
57
                    ->string($event->email())
58
                    ->isEqualTo('[email protected]')
59
                ;
60
61
                $event->setEmail('[email protected]');
62
            }))
63
            ->and($eventBus->dispatch($event))
64
            ->then()
65
                ->string($event->email())
66
                    ->isEqualTo('[email protected]')
67
        ;
68
    }
69
70
    /**
71
     * Test dispatch with invalid event.
72
     */
73
    public function testDispatchWithInvalidEvent()
74
    {
75
        $this
76
            ->given($eventBus = EventBus::create())
77
            ->then()
78
                ->exception(function () use ($eventBus) {
79
                    $eventBus->dispatch(new FooMessage());
80
                })
81
                ->isInstanceOf(\InvalidArgumentException::class)
82
        ;
83
    }
84
85
    /**
86
     * Test dispatcherMiddleware method.
87
     */
88
    public function testDispatcherMiddleware()
89
    {
90
        $this
91
            ->given($eventBus = EventBus::create())
92
            ->when($middleware = $eventBus->dispatcherMiddleware())
93
            ->then()
94
                ->object($middleware)
95
                    ->isInstanceOf(EventDispatcherMiddleware::class)
96
        ;
97
    }
98
99
    /**
100
     * Test AddListener method.
101
     */
102
    public function testAddListener()
103
    {
104
        $this
105
            ->given($eventBus = EventBus::create())
106
            ->and($eventBus->addListener('event.foo', array(new LoginUserEventListener(), 'loginUser')))
107
            ->and($eventBus->addListener('event.foo', function (Event $event) {
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
108
109
            }))
110
            ->and($eventBus->addListener('event.bar', function (Event $event) {
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
112
            }))
113
            ->when($listeners = $eventBus->listeners())
114
            ->then()
115
                ->array($listeners->toArray())
116
                    ->hasKey('event.foo')
117
                    ->hasKey('event.bar')
118
                ->array($listeners->toArray())
119
                    ->hasSize(2)
120
                ->array($listeners->toArray())
121
                    ->array['event.foo']
122
                        ->hasSize(2)
123
        ;
124
    }
125
126
    /**
127
     * Test RemoveListener method.
128
     */
129
    public function testRemoveListener()
130
    {
131
        $this
132
            ->given($eventBus = EventBus::create())
133
            ->and($listener1 = array(new LoginUserEventListener(), 'loginUser'))
134
            ->and($listener2 = function (Event $event) {
135
                return $event->eventName();
136
            })
137
            ->and($listener3 = function (Event $event) {
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
138
139
            })
140
            ->and($eventBus->addListener('event.foo', $listener1, 100))
141
            ->and($eventBus->addListener('event.foo', $listener2, 50))
142
            ->and($eventBus->addListener('event.bar', $listener3))
143
            ->then()
144
                ->boolean($eventBus->hasEventListeners('event.foo'))
145
                    ->isTrue()
146
                ->and()
147
                ->when($eventBus->removeListener('event.foo', $listener1))
148
                ->then()
149
                    ->boolean($eventBus->hasEventListeners('event.foo'))
150
                        ->isTrue()
151
                ->and()
152
                ->when($eventBus->removeListener('event.unknow', $listener2))
153
                ->and($eventBus->removeListener('event.foo', $listener2))
154
                ->then()
155
                    ->boolean($eventBus->hasEventListeners('event.foo'))
156
                        ->isFalse()
157
        ;
158
    }
159
160
    /**
161
     * Test AddSubscriber method.
162
     */
163
    public function testAddSubscriber()
164
    {
165
        $this
166
            ->given($eventBus = EventBus::create())
167
            ->and($eventBus->addSubscriber(new UserEventSubscriber()))
168
            ->then()
169
                ->boolean($eventBus->hasListeners())
170
                    ->isTrue()
171
                ->boolean($eventBus->hasEventListeners(UserEventSubscriber::FOO_EVENT))
172
                    ->isTrue()
173
                ->boolean($eventBus->hasEventListeners(UserEventSubscriber::BAR_EVENT))
174
                    ->isTrue()
175
                ->boolean($eventBus->hasEventListeners(UserEventSubscriber::USER_LOGIN))
176
                    ->isTrue()
177
        ;
178
    }
179
180
    /**
181
     * Test RemoveSubscriber method.
182
     */
183
    public function testRemoveSubscriber()
184
    {
185
        $this
186
            ->given($eventBus = EventBus::create())
187
            ->and($subscriber = new UserEventSubscriber())
188
            ->and($eventBus->addSubscriber($subscriber))
189
            ->then()
190
                ->boolean($eventBus->hasEventListeners(UserEventSubscriber::FOO_EVENT))
191
                    ->isTrue()
192
                ->boolean($eventBus->hasEventListeners(UserEventSubscriber::BAR_EVENT))
193
                    ->isTrue()
194
                ->boolean($eventBus->hasEventListeners(UserEventSubscriber::USER_LOGIN))
195
                    ->isTrue()
196
                ->and()
197
                ->when($eventBus->removeSubscriber($subscriber))
198
                ->then()
199
                    ->boolean($eventBus->hasEventListeners(UserEventSubscriber::FOO_EVENT))
200
                        ->isFalse()
201
                    ->boolean($eventBus->hasEventListeners(UserEventSubscriber::BAR_EVENT))
202
                        ->isFalse()
203
                    ->boolean($eventBus->hasEventListeners(UserEventSubscriber::USER_LOGIN))
204
                        ->isFalse()
205
        ;
206
    }
207
}
208