Issues (33)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/AMQPConnectionTest.php (1 issue)

1
<?php
2
namespace NeedleProject\LaravelRabbitMq;
3
4
use PhpAmqpLib\Channel\AMQPChannel;
5
use PhpAmqpLib\Connection\AbstractConnection;
6
use PhpAmqpLib\Connection\AMQPStreamConnection;
7
use Tests\NeedleProject\LaravelRabbitMq\Stubs\ConnectionDetailsStub;
8
use PHPUnit\Framework\TestCase;
9
10
class AMQPConnectionTest extends TestCase
11
{
12
    public function testCreateWithEmptyDetails()
13
    {
14
        $connection = ConnectionDetailsStub::createConnection('foo', []);
15
        $details = $connection->getConnectionDetails();
16
17
        $this->assertEquals('127.0.0.1', $details['hostname']);
18
        $this->assertEquals(5672, $details['port']);
19
        $this->assertEquals('guest', $details['username']);
20
        $this->assertEquals('guest', $details['password']);
21
        $this->assertEquals('/', $details['vhost']);
22
        $this->assertEquals(true, $details['lazy']);
23
        $this->assertEquals(3, $details['read_write_timeout']);
24
        $this->assertEquals(3, $details['connect_timeout']);
25
        $this->assertEquals(0, $details['heartbeat']);
26
    }
27
28
    public function testCreateWithAllDetails()
29
    {
30
        $connection = ConnectionDetailsStub::createConnection(
31
            'foo',
32
            [
33
                'hostname' => 'foo',
34
                'port'     => 1,
35
                'username' => 'bar',
36
                'password' => 'baz',
37
                'vhost'    => 'ahost',
38
                'lazy'     => false,
39
                'read_write_timeout' => 99,
40
                'connect_timeout' => 98,
41
                'heartbeat'       => 97,
42
            ]
43
        );
44
45
        $details = $connection->getConnectionDetails();
46
47
        $this->assertEquals('foo', $details['hostname']);
48
        $this->assertEquals(1, $details['port']);
49
        $this->assertEquals('bar', $details['username']);
50
        $this->assertEquals('baz', $details['password']);
51
        $this->assertEquals('ahost', $details['vhost']);
52
        $this->assertEquals(false, $details['lazy']);
53
        $this->assertEquals(99, $details['read_write_timeout']);
54
        $this->assertEquals(98, $details['connect_timeout']);
55
        $this->assertEquals(97, $details['heartbeat']);
56
    }
57
58
    public function testCreateWithInvalidArgumentsDetails()
59
    {
60
        $this->expectException(\InvalidArgumentException::class);
61
        $this->expectExceptionMessage("Cannot create connection foo, received unknown arguments: foo, bar!");
62
        ConnectionDetailsStub::createConnection(
63
            'foo',
64
            [
65
                'foo' => 'bar',
66
                'bar' => 'baz'
67
            ]
68
        );
69
    }
70
71
    public function testConnectionGetChannel()
72
    {
73
        $channelMock = $this->createMock(AMQPChannel::class);
74
        $connectionMock = $this->createMock(AbstractConnection::class);
75
76
        $connectionMock->expects($this->once())
77
            ->method('channel')
78
            ->willReturn($channelMock);
79
80
        $amqpConnection = new class('foo', [], $connectionMock) extends AMQPConnection {
81
            /**
82
             * @var AMQPStreamConnection
83
             */
84
            private $mock;
85
86
            /**
87
             *  constructor.
88
             *
89
             * @param string $aliasName
90
             * @param array $connectionDetails
91
             * @param AMQPStreamConnection $mock
92
             */
93
            public function __construct($aliasName, array $connectionDetails = [], $mock = null)
94
            {
95
                $this->mock = $mock;
96
                parent::__construct($aliasName, $connectionDetails);
97
            }
98
99
            /**
100
             * @return AbstractConnection
101
             */
102
            protected function getConnection(): AbstractConnection
103
            {
104
                return $this->mock;
105
            }
106
        };
107
108
        $this->assertEquals($channelMock, $amqpConnection->getChannel());
109
    }
110
111
    public function testAliasName()
112
    {
113
        $amqpConnection = new AMQPConnection('foo', []);
114
        $this->assertEquals($amqpConnection->getAliasName(), 'foo');
115
    }
116
117
    public function testLazyConnection()
118
    {
119
        $tester = $this;
120
        $abstractConnectionMock = $this->createMock(AbstractConnection::class);
121
122
        new class('foo', ['lazy' => false], $tester, $abstractConnectionMock)  extends AMQPConnection {
123
            private $tester;
124
125
            private $abstractConnectionMock;
126
127
            /**
128
             *  constructor.
129
             *
130
             * @param string $aliasName
131
             * @param array $connectionDetails
132
             * @param null $tester
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $tester is correct as it would always require null to be passed?
Loading history...
133
             */
134
            public function __construct($aliasName, array $connectionDetails = [], $tester = null, $abstractConnectionMock = null)
135
            {
136
                $this->tester = $tester;
137
                $this->abstractConnectionMock = $abstractConnectionMock;
138
                parent::__construct($aliasName, $connectionDetails);
139
            }
140
141
            /**
142
             * @return AbstractConnection
143
             */
144
            protected function getConnection(): AbstractConnection
145
            {
146
                $this->tester->assertTrue(true);
147
                return $this->abstractConnectionMock;
148
            }
149
        };
150
    }
151
152
    public function testReconnect()
153
    {
154
        $channelMock = $this->createMock(AMQPChannel::class);
155
        $channelMock->expects($this->once())
156
            ->method('close')
157
            ->willReturn(null);
158
159
        $connectionMock = $this->createMock(AbstractConnection::class);
160
161
        $connectionMock->expects($this->once())
162
            ->method('channel')
163
            ->willReturn($channelMock);
164
        $connectionMock->expects($this->once())
165
            ->method('reconnect')
166
            ->willReturn(null);
167
168
        $amqpConnection = new class('foo', [], $connectionMock)  extends AMQPConnection {
169
            /**
170
             * @var AbstractConnection
171
             */
172
            private $mock;
173
174
            /**
175
             *  constructor.
176
             *
177
             * @param string $aliasName
178
             * @param array $connectionDetails
179
             * @param AbstractConnection $mock
180
             */
181
            public function __construct($aliasName, array $connectionDetails = [], $mock = null)
182
            {
183
                $this->mock = $mock;
184
                parent::__construct($aliasName, $connectionDetails);
185
            }
186
187
            /**
188
             * @return AbstractConnection
189
             */
190
            protected function getConnection(): AbstractConnection
191
            {
192
                return $this->mock;
193
            }
194
        };
195
196
        $amqpConnection->reconnect();
197
    }
198
}
199