-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize the parameter validation logic in Client::enableSSL()
- Loading branch information
Showing
5 changed files
with
106 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
swoole_client_async: enableSSL with bad callback | ||
--SKIPIF-- | ||
<?php require __DIR__ . '/../include/skipif.inc'; ?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
$cli = new Swoole\Async\Client(SWOOLE_SOCK_TCP); | ||
try { | ||
$res = $cli->enableSSL(); | ||
} catch (Exception $e) { | ||
Assert::contains($e->getMessage(), 'require `onSslReady` callback'); | ||
} | ||
?> | ||
--EXPECTF-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--TEST-- | ||
swoole_client_async: enableSSL | ||
--SKIPIF-- | ||
<?php require __DIR__ . '/../include/skipif.inc'; ?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
$cli = new Swoole\Client(SWOOLE_SOCK_TCP); | ||
Assert::true($cli->connect("www.baidu.com", 443, 2.0)); | ||
|
||
if ($cli->enableSSL()) { | ||
echo "SSL READY\n"; | ||
$cli->send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\nUser-Agent: curl/7.50.1-DEV\r\nAccept: */*\r\n\r\n"); | ||
} | ||
|
||
$resp = ''; | ||
while (true) { | ||
$data = $cli->recv(); | ||
if ($data == false) { | ||
break; | ||
} | ||
$resp .= $data; | ||
} | ||
|
||
Assert::assert(strlen($resp) > 0); | ||
Assert::contains($resp, 'www.baidu.com'); | ||
$cli->close(); | ||
echo "DONE\n"; | ||
?> | ||
--EXPECT-- | ||
SSL READY | ||
DONE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--TEST-- | ||
swoole_client_async: enableSSL | ||
--SKIPIF-- | ||
<?php require __DIR__ . '/../include/skipif.inc'; ?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/../include/bootstrap.php'; | ||
|
||
$cli = new Swoole\Client(SWOOLE_SOCK_TCP); | ||
Assert::true($cli->connect("www.baidu.com", 443, 2.0)); | ||
|
||
try { | ||
$cli->enableSSL(function (){}); | ||
} catch (\Throwable $e) { | ||
Assert::contains($e->getMessage(), 'not support `onSslReady` callback'); | ||
} | ||
?> | ||
--EXPECT-- |