|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +/* |
| 4 | + * This file is part of the Laudis Neo4j package. |
| 5 | + * |
| 6 | + * (c) Laudis technologies <http://laudis.tech> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
3 | 12 | namespace Laudis\Neo4j\Tests\Unit;
|
4 | 13 |
|
5 |
| -class SslConfiguratorTest |
| 14 | +use Laudis\Neo4j\Bolt\SslConfigurator; |
| 15 | +use Laudis\Neo4j\Common\Uri; |
| 16 | +use Laudis\Neo4j\Databags\DriverConfiguration; |
| 17 | +use Laudis\Neo4j\Databags\SslConfiguration; |
| 18 | +use Laudis\Neo4j\Enum\SslMode; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +/** |
| 22 | + * @psalm-suppress PossiblyUndefinedStringArrayOffset |
| 23 | + */ |
| 24 | +final class SslConfiguratorTest extends TestCase |
6 | 25 | {
|
| 26 | + private SslConfigurator $configurator; |
| 27 | + |
| 28 | + public function setUp(): void |
| 29 | + { |
| 30 | + $this->configurator = new SslConfigurator(); |
| 31 | + } |
| 32 | + |
| 33 | + public function testDisablePeerVerification(): void |
| 34 | + { |
| 35 | + $config = DriverConfiguration::default() |
| 36 | + ->withSslConfiguration( |
| 37 | + SslConfiguration::default() |
| 38 | + ->withVerifyPeer(false) |
| 39 | + ->withMode(SslMode::ENABLE()) |
| 40 | + ); |
| 41 | + |
| 42 | + $uri = Uri::create(''); |
| 43 | + $array = $this->configurator->configure($uri, $uri, null, $config); |
| 44 | + |
| 45 | + self::assertNotNull($array); |
| 46 | + self::assertArrayHasKey('verify_peer', $array); |
| 47 | + self::assertArrayNotHasKey('allow_self_signed', $array); |
| 48 | + self::assertFalse($array['verify_peer']); |
| 49 | + } |
| 50 | + |
| 51 | + public function testEnablePeerVerification(): void |
| 52 | + { |
| 53 | + $config = DriverConfiguration::default() |
| 54 | + ->withSslConfiguration( |
| 55 | + SslConfiguration::default() |
| 56 | + ->withVerifyPeer(true) |
| 57 | + ->withMode(SslMode::ENABLE()) |
| 58 | + ); |
| 59 | + |
| 60 | + $uri = Uri::create(''); |
| 61 | + $array = $this->configurator->configure($uri, $uri, null, $config); |
| 62 | + |
| 63 | + self::assertNotNull($array); |
| 64 | + self::assertArrayHasKey('verify_peer', $array); |
| 65 | + self::assertArrayNotHasKey('allow_self_signed', $array); |
| 66 | + self::assertTrue($array['verify_peer']); |
| 67 | + } |
| 68 | + |
| 69 | + public function testSelfSigned(): void |
| 70 | + { |
| 71 | + $config = DriverConfiguration::default() |
| 72 | + ->withSslConfiguration( |
| 73 | + SslConfiguration::default() |
| 74 | + ->withVerifyPeer(true) |
| 75 | + ->withMode(SslMode::ENABLE_WITH_SELF_SIGNED()) |
| 76 | + ); |
| 77 | + |
| 78 | + $uri = Uri::create(''); |
| 79 | + $array = $this->configurator->configure($uri, $uri, null, $config); |
| 80 | + |
| 81 | + self::assertNotNull($array); |
| 82 | + self::assertArrayHasKey('allow_self_signed', $array); |
| 83 | + self::assertTrue($array['allow_self_signed']); |
| 84 | + } |
| 85 | + |
| 86 | + public function testFromUriNull(): void |
| 87 | + { |
| 88 | + $config = DriverConfiguration::default() |
| 89 | + ->withSslConfiguration( |
| 90 | + SslConfiguration::default() |
| 91 | + ->withVerifyPeer(true) |
| 92 | + ->withMode(SslMode::FROM_URL()) |
| 93 | + ); |
| 94 | + |
| 95 | + $uri = Uri::create('neo4j://localhost'); |
| 96 | + $array = $this->configurator->configure($uri, $uri, null, $config); |
| 97 | + |
| 98 | + self::assertNull($array); |
| 99 | + } |
| 100 | + |
| 101 | + public function testFromUri(): void |
| 102 | + { |
| 103 | + $config = DriverConfiguration::default() |
| 104 | + ->withSslConfiguration( |
| 105 | + SslConfiguration::default() |
| 106 | + ->withMode(SslMode::FROM_URL()) |
| 107 | + ); |
| 108 | + |
| 109 | + $uri = Uri::create('neo4j+s://localhost'); |
| 110 | + $array = $this->configurator->configure($uri, $uri, null, $config); |
7 | 111 |
|
| 112 | + self::assertNotNull($array); |
| 113 | + self::assertArrayHasKey('verify_peer', $array); |
| 114 | + self::assertArrayNotHasKey('allow_self_signed', $array); |
| 115 | + self::assertTrue($array['verify_peer']); |
| 116 | + } |
8 | 117 | }
|
0 commit comments