diff --git a/src/FreeDSx/Socket/Socket.php b/src/FreeDSx/Socket/Socket.php index 8a236d1..63f0c3f 100644 --- a/src/FreeDSx/Socket/Socket.php +++ b/src/FreeDSx/Socket/Socket.php @@ -69,6 +69,7 @@ public function __construct( $this->socket = $resource; $this->writeTimeoutEnforcer = $writeTimeoutEnforcer ?? $this->options->getWriteTimeoutEnforcer(); if ($this->socket !== null) { + $this->isEncrypted = $this->options->isUseSsl(); $this->setStreamOpts(); } } diff --git a/tests/unit/SocketTest.php b/tests/unit/SocketTest.php index 69bc698..1a47507 100644 --- a/tests/unit/SocketTest.php +++ b/tests/unit/SocketTest.php @@ -358,6 +358,40 @@ private function makeCertificate(): OpenSSLCertificate return $certificate; } + public function test_a_socket_adopting_a_resource_under_ssl_options_is_encrypted(): void + { + [$local] = $this->createSocketPair(); + + $socket = new Socket( + $local, + (new SocketOptions())->setUseSsl(true), + ); + + self::assertTrue($socket->isEncrypted()); + } + + public function test_a_socket_adopting_a_resource_without_ssl_options_is_not_encrypted(): void + { + [$local] = $this->createSocketPair(); + + $socket = new Socket( + $local, + new SocketOptions(), + ); + + self::assertFalse($socket->isEncrypted()); + } + + public function test_an_unconnected_socket_is_not_encrypted_even_under_ssl_options(): void + { + $socket = new Socket( + null, + (new SocketOptions())->setUseSsl(true), + ); + + self::assertFalse($socket->isEncrypted()); + } + /** * @return array{0: resource, 1: resource} */