Issues (34)

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.

integration_tests/Provider/IronMqProviderTest.php (2 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
namespace Uecode\Bundle\QPushBundle\IntegrationTests\Provider;
4
5
use IronMQ\IronMQ;
6
use Uecode\Bundle\QPushBundle\Event\MessageEvent;
7
use Uecode\Bundle\QPushBundle\Event\NotificationEvent;
8
use Uecode\Bundle\QPushBundle\Message\Notification;
9
use Uecode\Bundle\QPushBundle\Provider\IronMqProvider;
10
11
class IronMqProviderTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * Mock Client
15
     *
16
     * @var IronMqProvider
17
     */
18
    protected $provider;
19
    private $project_id;
20
21
    /**
22
     * @var IronMQ
23
     */
24
    private $client;
25
26
    public function setUp()
27
    {
28
        if (!defined("IRONMQ_TOKEN") || IRONMQ_TOKEN == 'CHANGE_ME') {
29
            throw new \RuntimeException('"IRONMQ_TOKEN" must be defined in tests/bootstrap.php');
30
        }
31
        if (!defined("IRONMQ_PROJECT_ID") || IRONMQ_PROJECT_ID == 'CHANGE_ME') {
32
            throw new \RuntimeException('"IRONMQ_PROJECT_ID" must be defined in tests/bootstrap.php');
33
        }
34
        if (!defined("IRONMQ_HOST")) {
35
            throw new \RuntimeException('"IRONMQ_HOST" must be defined in tests/bootstrap.php');
36
        }
37
        $this->client = new IronMQ([
38
            'token'         => IRONMQ_TOKEN,
39
            'project_id'    => IRONMQ_PROJECT_ID,
40
            'host'          => IRONMQ_HOST
41
        ]);
42
43
        $this->provider = $this->getIronMqProvider();
44
    }
45
46
    public function tearDown()
47
    {
48
        if (!is_null($this->provider)) {
49
            $this->provider->destroy();
50
            $this->provider = null;
51
        }
52
    }
53
54
    private function getIronMqProvider(array $options = [])
55
    {
56
        $options = array_merge(
57
            [
58
                'logging_enabled'            => false,
59
                'push_notifications'         => true,
60
                'push_type'                  => 'multicast',
61
                'notification_retries'       => 3,
62
                'notification_retries_delay' => 60,
63
                'message_delay'              => 0,
64
                'message_timeout'            => 30,
65
                'message_expiration'         => 604800,
66
                'messages_to_receive'        => 1,
67
                'rate_limit'                 => -1,
68
                'receive_wait_time'          => 3,
69
                'subscribers'                => [
70
                    [ 'protocol' => 'http', 'endpoint' => 'http://fake.com' ]
71
                ]
72
            ],
73
            $options
74
        );
75
76
        return new IronMqProvider(
77
            'test',
78
            $options,
79
            $this->client,
80
            $this->getMock(
81
                'Doctrine\Common\Cache\PhpFileCache',
82
                [],
83
                ['/tmp', 'qpush.ironmq.test.php']
84
            ),
85
            $this->getMock(
86
                'Symfony\Bridge\Monolog\Logger',
87
                [],
88
                ['qpush.test']
89
            )
90
        );
91
    }
92
93
    public function testGetProviderReturnsTheNameOfTheProvider()
94
    {
95
        $provider = $this->provider->getProvider();
96
97
        $this->assertEquals('IronMQ', $provider);
98
    }
99
100
    public function testCreateWillCreateAQueue()
101
    {
102
        $this->assertFalse($this->provider->queueExists());
103
        $this->assertTrue($this->provider->create());
104
        $this->assertTrue($this->provider->queueExists());
105
    }
106
107
    public function testCreateFailsWithEmailTypeSubscriber()
108
    {
109
        $provider = $this->getIronMqProvider([
110
            'subscribers' => [
111
                [ 'protocol' => 'email', 'endpoint' => '[email protected]' ]
112
            ]
113
        ]);
114
115
        $this->setExpectedException('InvalidArgumentException', 'IronMQ only supports `http` or `https` subscribers!');
116
        $provider->create();
117
        $this->assertTrue($this->provider->queueExists());
118
119
    }
120
121
    public function testDestroyWillDestroyAQueue()
122
    {
123
        $this->provider->create();
124
        $this->assertTrue($this->provider->queueExists(), 'fail1');
125
126
        $this->assertTrue($this->provider->destroy(), 'fail2');
127
128
        $this->assertFalse($this->provider->queueExists(), 'fail3');
129
130
    }
131
132
    public function testPublishWillPublishAMessage()
133
    {
134
        $message = $this->provider->publish(['foo' => 'bar']);
135
        $this->assertInternalType("int", $message);
136
    }
137
138
    public function testReceiveWillReserveAndReturnAMessageFromTheQueue()
139
    {
140
        $this->provider = $this->getIronMqProvider(['push_notifications' => false]);
141
        $this->provider->publish(['baz' => 'bar']);
142
143
        $messages = $this->provider->receive();
144
145
        $this->assertInternalType('array', $messages);
146
        $this->assertCount(1, $messages);
147
        $this->assertEquals(['baz' => 'bar'], $messages[0]->getBody());
148
    }
149
150
    public function testDeleteAnUnreservedMessage()
151
    {
152
        $messageId = $this->provider->publish(['bat' => 'ball']);
153
154
        $this->assertTrue($this->provider->delete($messageId));
155
    }
156
157 View Code Duplication
    public function testDeleteAReservedMessage()
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...
158
    {
159
        $this->provider = $this->getIronMqProvider(['push_notifications' => false]);
160
        $this->provider->publish(['Hello' => 'World']);
161
        $messages = $this->provider->receive();
162
163
        $this->assertTrue($this->provider->delete($messages[0]->getId()));
164
    }
165
166
    public function testOnNotification()
167
    {
168
        $event = new NotificationEvent(
169
            'test',
170
            NotificationEvent::TYPE_MESSAGE,
171
            new Notification(123, "test", [])
172
        );
173
174
        $this->provider->onNotification(
175
            $event,
176
            NotificationEvent::TYPE_MESSAGE,
177
            $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface')
178
        );
179
    }
180
181 View Code Duplication
    public function testOnMessageReceived()
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...
182
    {
183
        $this->provider = $this->getIronMqProvider(['push_notifications' => false]);
184
        $this->provider->destroy();
185
        $this->provider->publish(['bob' => 'ball']);
186
        $messages = $this->provider->receive();
187
188
        $this->provider->onMessageReceived(new MessageEvent(
189
            'test',
190
            $messages[0]
191
        ));
192
    }
193
194
    public function testQueueInfo()
195
    {
196
        $this->provider->destroy();
197
        $this->assertNull($this->provider->queueInfo());
198
199
        $this->provider->create();
200
        $queue = $this->provider->queueInfo();
201
        $this->assertEquals('qpush_test', $queue->name);
202
        $this->assertEquals(IRONMQ_PROJECT_ID, $queue->project_id);
203
    }
204
}
205