Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/FreeDSx/Socket/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/SocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
Loading