Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laruence committed Jan 31, 2022
1 parent ccec536 commit 6db1dfe
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 2 deletions.
3 changes: 3 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
<file name="041.phpt" role="test" />
<file name="042.phpt" role="test" />
<file name="043.phpt" role="test" />
<file name="045.phpt" role="test" />
<file name="046.phpt" role="test" />
<file name="047.phpt" role="test" />
<file name="bug74867.phpt" role="test" />
<file name="yar.inc" role="test" />
</dir>
Expand Down
63 changes: 63 additions & 0 deletions tests/045.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--TEST--
Check for yar server __info (public visiblity)
--SKIPIF--
<?php
if (!extension_loaded("yar")) {
print "skip";
}
?>
--FILE--
<?php
include "yar.inc";

yar_server_start(<<<'PHP'
<?php
error_reporting(-1);
class Service_Provider {
public function __info($markup) {
return "";
}
}
$yar = new Yar_Server(new Service_Provider());
$yar->handle();
PHP
);

$host = YAR_API_HOSTNAME;
$port = YAR_API_PORT;

if (!$port) {
$port = 80;
}

$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
if (!$fp) {
die("connect failed");
}

$uri = YAR_API_URI;

if(fwrite($fp, <<<HEADER
GET /{$uri} HTTP/1.1
Host: {$host}
HEADER
)) {
while (!feof($fp)) {
$line = trim(fgets($fp));
if (strpos($line, 'Service_Provider - Yar Server') != FALSE) {
echo "okay";
break;
}
}
}
?>
--CLEAN--
<?php
include 'yar.inc';
yar_server_cleanup();
?>
--EXPECT--
okay
40 changes: 40 additions & 0 deletions tests/046.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
Check for yar server __auth (public visiblity)
--SKIPIF--
<?php
if (!extension_loaded("yar")) {
print "skip";
}
?>
--FILE--
<?php
include "yar.inc";

yar_server_start(<<<'PHP'
<?php
error_reporting(-1);
class Service_Provider {
public function __auth($provider, $token) {
return false;
}
public function info() {
return "okay";
}
}
$yar = new Yar_Server(new Service_Provider());
$yar->handle();
PHP
);

$client = new Yar_Client(YAR_API_ADDRESS);
echo $client->info();
?>
--CLEAN--
<?php
include 'yar.inc';
yar_server_cleanup();
?>
--EXPECT--
okay
47 changes: 47 additions & 0 deletions tests/047.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
Check for yar server __auth (concurrent call)
--SKIPIF--
<?php
if (!extension_loaded("yar")) {
print "skip";
}
?>
--FILE--
<?php
include "yar.inc";

yar_server_start(<<<'PHP'
<?php
error_reporting(-1);
class Service_Provider {
protected function __auth($provider, $token) {
return ($provider == "Yar" && $token == md5("yar"));
}
public function info() {
return "okay";
}
}
$yar = new Yar_Server(new Service_Provider());
$yar->handle();
PHP
);

Yar_Concurrent_Client::call(YAR_API_ADDRESS, "info", array(), NULL, NULL, array(YAR_OPT_PROVIDER=>"Yar", YAR_OPT_TOKEN=>md5("yar")));
Yar_Concurrent_Client::call(YAR_API_ADDRESS, "info", array(), NULL, NULL, array(YAR_OPT_PROVIDER=>"Yar", YAR_OPT_TOKEN=>md5("yar")));
Yar_Concurrent_Client::call(YAR_API_ADDRESS, "info", array(), NULL, NULL, array(YAR_OPT_PROVIDER=>"Yar", YAR_OPT_TOKEN=>md5("yar")));
Yar_Concurrent_Client::call(YAR_API_ADDRESS, "info", array(), NULL, NULL, array(YAR_OPT_PROVIDER=>"Yar", YAR_OPT_TOKEN=>md5("yar")));
Yar_Concurrent_Client::call(YAR_API_ADDRESS, "info", array(), NULL, NULL, array(YAR_OPT_PROVIDER=>"Yar", YAR_OPT_TOKEN=>md5("yar")));

Yar_Concurrent_Client::loop(function($return, $callinfo) {
echo $return;
});
?>
--CLEAN--
<?php
include 'yar.inc';
yar_server_cleanup();
?>
--EXPECT--
okayokayokayokayokay
4 changes: 2 additions & 2 deletions yar_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ static inline int php_yar_server_auth(zval *obj, yar_header_t *header, yar_respo
YAR_TRY {
zval auth_params[2];

ZVAL_STRING(&auth_params[0], (char*)header->provider);
ZVAL_STRING(&auth_params[1], (char*)header->token);
ZVAL_STRINGL(&auth_params[0], (char*)header->provider, MIN(strlen(header->provider), 32));
ZVAL_STRINGL(&auth_params[1], (char*)header->token, MIN(strlen(header->token), 32));

#if PHP_VERSION_ID < 80000
zend_call_method_with_2_params(obj, ce, NULL, "__auth", &ret, auth_params, auth_params + 1);
Expand Down

0 comments on commit 6db1dfe

Please sign in to comment.