Skip to content

Commit cf3fc45

Browse files
committed
[bundle] add amqps: support to Symfony bundle.
1 parent 3db1e75 commit cf3fc45

6 files changed

Lines changed: 99 additions & 7 deletions

File tree

‎pkg/amqp-tools/ConnectionConfig.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* ssl_verify - This option determines whether ssl client verifies that the server cert is for the server it is known as. True by default.
2525
* ssl_cacert - Location of Certificate Authority file on local filesystem which should be used with the verify_peer context option to authenticate the identity of the remote peer. A string.
2626
* ssl_cert - Path to local certificate file on filesystem. It must be a PEM encoded file which contains your certificate and private key. A string
27-
* ssl_key - A string.
27+
* ssl_key - Path to local private key file on filesystem in case of separate files for certificate (local_cert) and private key. A string.
2828
*
2929
* 2. null - in this case it tries to connect to localhost with default settings
3030
* 3. amqp: same as 2.

‎pkg/amqp-tools/Tests/ConnectionConfigTest.php‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,5 +429,33 @@ public static function provideConfigs()
429429
'ssl_key' => null,
430430
],
431431
];
432+
433+
yield [
434+
[
435+
'ssl_on' => false,
436+
'dsn' => 'amqps:',
437+
],
438+
[
439+
'host' => 'localhost',
440+
'port' => 5672,
441+
'vhost' => '/',
442+
'user' => 'guest',
443+
'pass' => 'guest',
444+
'read_timeout' => 3.,
445+
'write_timeout' => 3.,
446+
'connection_timeout' => 3.,
447+
'persisted' => false,
448+
'lazy' => true,
449+
'qos_prefetch_size' => 0,
450+
'qos_prefetch_count' => 1,
451+
'qos_global' => false,
452+
'heartbeat' => 0.0,
453+
'ssl_on' => true,
454+
'ssl_verify' => true,
455+
'ssl_cacert' => null,
456+
'ssl_cert' => null,
457+
'ssl_key' => null,
458+
],
459+
];
432460
}
433461
}

‎pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ public function setUp()
2323

2424
public function provideEnqueueConfigs()
2525
{
26+
$baseDir = realpath(__DIR__.'/../../../../');
27+
28+
// guard
29+
$this->assertNotEmpty($baseDir);
30+
31+
$certDir = $baseDir.'/var/rabbitmq_certificates';
32+
$this->assertDirectoryExists($certDir);
33+
2634
yield 'amqp' => [[
2735
'transport' => [
2836
'default' => 'amqp',
@@ -45,6 +53,19 @@ public function provideEnqueueConfigs()
4553
],
4654
]];
4755

56+
yield 'amqps_dsn' => [[
57+
'transport' => [
58+
'default' => 'amqp',
59+
'amqp' => [
60+
'dsn' => getenv('AMQPS_DSN'),
61+
'ssl_verify' => false,
62+
'ssl_cacert' => $certDir.'/cacert.pem',
63+
'ssl_cert' => $certDir.'/cert.pem',
64+
'ssl_key' => $certDir.'/key.pem',
65+
],
66+
],
67+
]];
68+
4869
yield 'default_amqp_as_dsn' => [[
4970
'transport' => [
5071
'default' => getenv('AMQP_DSN'),

‎pkg/enqueue/Symfony/AmqpTransportFactory.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ public function addConfiguration(ArrayNodeDefinition $builder)
116116
->variableNode('driver_options')
117117
->info('The options that are specific to the amqp transport you chose. For example amqp+lib have insist, keepalive, stream options. amqp+bunny has tcp_nodelay extra option.')
118118
->end()
119+
->booleanNode('ssl_on')
120+
->info('Should be true if you want to use secure connections. False by default')
121+
->end()
122+
->booleanNode('ssl_verify')
123+
->info('This option determines whether ssl client verifies that the server cert is for the server it is known as. True by default.')
124+
->end()
125+
->scalarNode('ssl_cacert')
126+
->info('Location of Certificate Authority file on local filesystem which should be used with the verify_peer context option to authenticate the identity of the remote peer. A string.')
127+
->end()
128+
->scalarNode('ssl_cert')
129+
->info('Path to local certificate file on filesystem. It must be a PEM encoded file which contains your certificate and private key. A string')
130+
->end()
131+
->scalarNode('ssl_key')
132+
->info('Path to local private key file on filesystem in case of separate files for certificate (local_cert) and private key. A string.')
133+
->end()
119134
;
120135
}
121136

‎pkg/enqueue/Tests/Functions/DsnToConnectionFactoryFunctionTest.php‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Enqueue\Tests\Functions;
44

5-
use Enqueue\AmqpExt\AmqpConnectionFactory;
5+
use Enqueue\AmqpBunny\AmqpConnectionFactory as AmqpBunnyConnectionFactory;
6+
use Enqueue\AmqpExt\AmqpConnectionFactory as AmqpExtConnectionFactory;
67
use Enqueue\AmqpLib\AmqpConnectionFactory as AmqpLibConnectionFactory;
78
use Enqueue\Dbal\DbalConnectionFactory;
89
use Enqueue\Fs\FsConnectionFactory;
@@ -57,19 +58,21 @@ public function testReturnsExpectedFactoryInstance($dsn, $expectedFactoryClass)
5758

5859
public static function provideDSNs()
5960
{
60-
yield ['amqp:', AmqpConnectionFactory::class];
61+
yield ['amqp:', AmqpExtConnectionFactory::class];
6162

62-
yield ['amqps:', AmqpConnectionFactory::class];
63+
yield ['amqps:', AmqpExtConnectionFactory::class];
6364

64-
yield ['amqp+ext:', AmqpConnectionFactory::class];
65+
yield ['amqp+ext:', AmqpExtConnectionFactory::class];
6566

66-
yield ['amqps+ext:', AmqpConnectionFactory::class];
67+
yield ['amqps+ext:', AmqpExtConnectionFactory::class];
6768

6869
yield ['amqp+lib:', AmqpLibConnectionFactory::class];
6970

7071
yield ['amqps+lib:', AmqpLibConnectionFactory::class];
7172

72-
yield ['amqp://user:pass@foo/vhost', AmqpConnectionFactory::class];
73+
yield ['amqp+bunny:', AmqpBunnyConnectionFactory::class];
74+
75+
yield ['amqp://user:pass@foo/vhost', AmqpExtConnectionFactory::class];
7376

7477
yield ['file:', FsConnectionFactory::class];
7578

‎pkg/enqueue/Tests/Symfony/AmqpTransportFactoryTest.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,31 @@ public function testShouldAllowAddConfigurationWithDriverOptions()
112112
], $config);
113113
}
114114

115+
public function testShouldAllowAddSslOptions()
116+
{
117+
$transport = new AmqpTransportFactory();
118+
$tb = new TreeBuilder();
119+
$rootNode = $tb->root('foo');
120+
121+
$transport->addConfiguration($rootNode);
122+
$processor = new Processor();
123+
$config = $processor->process($tb->buildTree(), [[
124+
'ssl_on' => true,
125+
'ssl_verify' => false,
126+
'ssl_cacert' => '/path/to/cacert.pem',
127+
'ssl_cert' => '/path/to/cert.pem',
128+
'ssl_key' => '/path/to/key.pem',
129+
]]);
130+
131+
$this->assertEquals([
132+
'ssl_on' => true,
133+
'ssl_verify' => false,
134+
'ssl_cacert' => '/path/to/cacert.pem',
135+
'ssl_cert' => '/path/to/cert.pem',
136+
'ssl_key' => '/path/to/key.pem',
137+
], $config);
138+
}
139+
115140
public function testShouldAllowAddConfigurationAsString()
116141
{
117142
$transport = new AmqpTransportFactory();

0 commit comments

Comments
 (0)