summaryrefslogtreecommitdiff
path: root/ext/session/tests
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2013-07-22 08:22:22 +0200
committerOndřej Surý <ondrej@sury.org>2013-07-22 08:22:22 +0200
commitd837b4550418036e76d6adb3c7dad94b1e3a5a6a (patch)
tree1f1c808039c898d7d891975d3788531a2a6550f1 /ext/session/tests
parent706ac6417162d94eb701952d40df136cd9528b56 (diff)
downloadphp-d837b4550418036e76d6adb3c7dad94b1e3a5a6a.tar.gz
New upstream version 5.5.1+dfsgupstream/5.5.1+dfsg
Diffstat (limited to 'ext/session/tests')
-rw-r--r--ext/session/tests/bug50308.phpt30
-rw-r--r--ext/session/tests/session_name_error.phpt100
-rw-r--r--ext/session/tests/session_name_variation1.phpt12
-rw-r--r--ext/session/tests/session_set_save_handler_class_016.phpt90
-rw-r--r--ext/session/tests/session_set_save_handler_class_017.phpt90
-rw-r--r--ext/session/tests/session_set_save_handler_iface_003.phpt90
-rw-r--r--ext/session/tests/session_set_save_handler_sid_001.phpt85
-rw-r--r--ext/session/tests/session_set_save_handler_sid_002.phpt77
-rw-r--r--ext/session/tests/session_status_disabled.phpt2
9 files changed, 551 insertions, 25 deletions
diff --git a/ext/session/tests/bug50308.phpt b/ext/session/tests/bug50308.phpt
new file mode 100644
index 000000000..110277ce3
--- /dev/null
+++ b/ext/session/tests/bug50308.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #50308 (session id not appended properly for empty anchor tags)
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--INI--
+session.name=PHPSESSID
+session.save_handler=files
+session.use_trans_sid=1
+session.use_only_cookies=0
+--FILE--
+<?php
+@session_start();
+?>
+<a href=""/>
+<a href="" />
+<a href="foo"/>
+<a href="foo" />
+<a href=foo/>
+<a href=/>
+<a href=?foo=bar/>
+<a href="?foo=bar"/>
+--EXPECTF--
+<a href="?PHPSESSID=%s"/>
+<a href="?PHPSESSID=%s" />
+<a href="foo?PHPSESSID=%s"/>
+<a href="foo?PHPSESSID=%s" />
+<a href=foo/?PHPSESSID=%s>
+<a href=/?PHPSESSID=%s>
+<a href=?foo=bar/&PHPSESSID=%s>
+<a href="?foo=bar&PHPSESSID=%s"/>
diff --git a/ext/session/tests/session_name_error.phpt b/ext/session/tests/session_name_error.phpt
index 2ed10d92a..1b99d4ea3 100644
--- a/ext/session/tests/session_name_error.phpt
+++ b/ext/session/tests/session_name_error.phpt
@@ -86,7 +86,7 @@ $inputs = array(
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
- var_dump(session_name($input));
+ var_dump($input, session_name($input));
$iterator++;
};
@@ -98,77 +98,139 @@ ob_end_flush();
*** Testing session_name() : error functionality ***
-- Iteration 1 --
+
+Warning: session_name(): session.name cannot be a numeric or empty '0' in %s on line %d
+int(0)
string(9) "PHPSESSID"
-- Iteration 2 --
-string(1) "0"
+
+Warning: session_name(): session.name cannot be a numeric or empty '1' in %s on line %d
+int(1)
+string(9) "PHPSESSID"
-- Iteration 3 --
-string(1) "1"
+
+Warning: session_name(): session.name cannot be a numeric or empty '12345' in %s on line %d
+int(12345)
+string(9) "PHPSESSID"
-- Iteration 4 --
-string(5) "12345"
+
+Warning: session_name(): session.name cannot be a numeric or empty '-2345' in %s on line %d
+int(-2345)
+string(9) "PHPSESSID"
-- Iteration 5 --
-string(5) "-2345"
+
+Warning: session_name(): session.name cannot be a numeric or empty '10.5' in %s on line %d
+float(10.5)
+string(9) "PHPSESSID"
-- Iteration 6 --
-string(4) "10.5"
+
+Warning: session_name(): session.name cannot be a numeric or empty '-10.5' in %s on line %d
+float(-10.5)
+string(9) "PHPSESSID"
-- Iteration 7 --
-string(5) "-10.5"
+
+Warning: session_name(): session.name cannot be a numeric or empty '123456789000' in %s on line %d
+float(123456789000)
+string(9) "PHPSESSID"
-- Iteration 8 --
-string(12) "123456789000"
+
+Warning: session_name(): session.name cannot be a numeric or empty '1.23456789E-9' in %s on line %d
+float(1.23456789E-9)
+string(9) "PHPSESSID"
-- Iteration 9 --
-string(13) "1.23456789E-9"
+
+Warning: session_name(): session.name cannot be a numeric or empty '0.5' in %s on line %d
+float(0.5)
+string(9) "PHPSESSID"
-- Iteration 10 --
-string(3) "0.5"
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
+NULL
+string(9) "PHPSESSID"
-- Iteration 11 --
-string(0) ""
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
+NULL
+string(9) "PHPSESSID"
-- Iteration 12 --
-string(0) ""
+
+Warning: session_name(): session.name cannot be a numeric or empty '1' in %s on line %d
+bool(true)
+string(9) "PHPSESSID"
-- Iteration 13 --
-string(1) "1"
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
+bool(false)
+string(9) "PHPSESSID"
-- Iteration 14 --
-string(0) ""
+
+Warning: session_name(): session.name cannot be a numeric or empty '1' in %s on line %d
+bool(true)
+string(9) "PHPSESSID"
-- Iteration 15 --
-string(1) "1"
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
+bool(false)
+string(9) "PHPSESSID"
-- Iteration 16 --
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
string(0) ""
+string(9) "PHPSESSID"
-- Iteration 17 --
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
string(0) ""
+string(9) "PHPSESSID"
-- Iteration 18 --
-string(0) ""
+string(7) "Nothing"
+string(9) "PHPSESSID"
-- Iteration 19 --
string(7) "Nothing"
+string(7) "Nothing"
-- Iteration 20 --
+string(12) "Hello World!"
string(7) "Nothing"
-- Iteration 21 --
+object(classA)#1 (0) {
+}
string(12) "Hello World!"
-- Iteration 22 --
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
+NULL
string(12) "Hello World!"
-- Iteration 23 --
-string(0) ""
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
+NULL
+string(12) "Hello World!"
-- Iteration 24 --
Warning: session_name() expects parameter 1 to be string, resource given in %s on line %d
+resource(5) of type (stream)
NULL
-Done
-
+Done \ No newline at end of file
diff --git a/ext/session/tests/session_name_variation1.phpt b/ext/session/tests/session_name_variation1.phpt
index 16d6ad462..b0de3ee36 100644
--- a/ext/session/tests/session_name_variation1.phpt
+++ b/ext/session/tests/session_name_variation1.phpt
@@ -43,18 +43,20 @@ ob_end_flush();
*** Testing session_name() : variation ***
string(9) "PHPSESSID"
bool(true)
-string(0) ""
+string(9) "PHPSESSID"
bool(true)
-string(0) ""
-string(0) ""
+string(9) "PHPSESSID"
+string(9) "PHPSESSID"
bool(true)
string(1) " "
bool(true)
string(1) " "
+
+Warning: session_name(): session.name cannot be a numeric or empty '' in %s on line %d
string(1) " "
bool(true)
-string(0) ""
+string(1) " "
bool(true)
-string(0) ""
+string(1) " "
Done
diff --git a/ext/session/tests/session_set_save_handler_class_016.phpt b/ext/session/tests/session_set_save_handler_class_016.phpt
new file mode 100644
index 000000000..2de03c068
--- /dev/null
+++ b/ext/session/tests/session_set_save_handler_class_016.phpt
@@ -0,0 +1,90 @@
+--TEST--
+Test session_set_save_handler() function: class with create_sid
+--INI--
+session.save_handler=files
+session.name=PHPSESSID
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+
+ob_start();
+
+/*
+ * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true])
+ * Description : Sets user-level session storage functions
+ * Source code : ext/session/session.c
+ */
+
+echo "*** Testing session_set_save_handler() function: class with create_sid ***\n";
+
+class MySession2 extends SessionHandler {
+ public $path;
+
+ public function open($path, $name) {
+ if (!$path) {
+ $path = sys_get_temp_dir();
+ }
+ $this->path = $path . '/u_sess_' . $name;
+ return true;
+ }
+
+ public function close() {
+ return true;
+ }
+
+ public function read($id) {
+ return @file_get_contents($this->path . $id);
+ }
+
+ public function write($id, $data) {
+ return file_put_contents($this->path . $id, $data);
+ }
+
+ public function destroy($id) {
+ @unlink($this->path . $id);
+ }
+
+ public function gc($maxlifetime) {
+ foreach (glob($this->path . '*') as $filename) {
+ if (filemtime($filename) + $maxlifetime < time()) {
+ @unlink($filename);
+ }
+ }
+ return true;
+ }
+
+ public function create_sid() {
+ return parent::create_sid();
+ }
+}
+
+$handler = new MySession2;
+session_set_save_handler($handler);
+session_start();
+
+$_SESSION['foo'] = "hello";
+
+var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
+
+session_write_close();
+session_unset();
+
+session_start();
+var_dump($_SESSION);
+
+session_write_close();
+session_unset();
+
+--EXPECTF--
+*** Testing session_set_save_handler() function: class with create_sid ***
+string(%d) "%s"
+string(4) "user"
+array(1) {
+ ["foo"]=>
+ string(5) "hello"
+}
+array(1) {
+ ["foo"]=>
+ string(5) "hello"
+}
diff --git a/ext/session/tests/session_set_save_handler_class_017.phpt b/ext/session/tests/session_set_save_handler_class_017.phpt
new file mode 100644
index 000000000..756dc55d0
--- /dev/null
+++ b/ext/session/tests/session_set_save_handler_class_017.phpt
@@ -0,0 +1,90 @@
+--TEST--
+Test session_set_save_handler() function: class with create_sid
+--INI--
+session.save_handler=files
+session.name=PHPSESSID
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+
+ob_start();
+
+/*
+ * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true])
+ * Description : Sets user-level session storage functions
+ * Source code : ext/session/session.c
+ */
+
+echo "*** Testing session_set_save_handler() function: class with create_sid ***\n";
+
+class MySession2 extends SessionHandler {
+ public $path;
+
+ public function open($path, $name) {
+ if (!$path) {
+ $path = sys_get_temp_dir();
+ }
+ $this->path = $path . '/u_sess_' . $name;
+ return true;
+ }
+
+ public function close() {
+ return true;
+ }
+
+ public function read($id) {
+ return @file_get_contents($this->path . $id);
+ }
+
+ public function write($id, $data) {
+ return file_put_contents($this->path . $id, $data);
+ }
+
+ public function destroy($id) {
+ @unlink($this->path . $id);
+ }
+
+ public function gc($maxlifetime) {
+ foreach (glob($this->path . '*') as $filename) {
+ if (filemtime($filename) + $maxlifetime < time()) {
+ @unlink($filename);
+ }
+ }
+ return true;
+ }
+
+ public function create_sid() {
+ return 'my_sid';
+ }
+}
+
+$handler = new MySession2;
+session_set_save_handler($handler);
+session_start();
+
+$_SESSION['foo'] = "hello";
+
+var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
+
+session_write_close();
+session_unset();
+
+session_start();
+var_dump($_SESSION);
+
+session_write_close();
+session_unset();
+
+--EXPECTF--
+*** Testing session_set_save_handler() function: class with create_sid ***
+string(%d) "my_sid"
+string(4) "user"
+array(1) {
+ ["foo"]=>
+ string(5) "hello"
+}
+array(1) {
+ ["foo"]=>
+ string(5) "hello"
+}
diff --git a/ext/session/tests/session_set_save_handler_iface_003.phpt b/ext/session/tests/session_set_save_handler_iface_003.phpt
new file mode 100644
index 000000000..bd757dce6
--- /dev/null
+++ b/ext/session/tests/session_set_save_handler_iface_003.phpt
@@ -0,0 +1,90 @@
+--TEST--
+Test session_set_save_handler() function: id interface
+--INI--
+session.save_handler=files
+session.name=PHPSESSID
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+
+ob_start();
+
+/*
+ * Prototype : bool session_set_save_handler(SessionHandlerInterface $handler [, bool $register_shutdown_function = true])
+ * Description : Sets user-level session storage functions
+ * Source code : ext/session/session.c
+ */
+
+echo "*** Testing session_set_save_handler() function: id interface ***\n";
+
+class MySession2 implements SessionHandlerInterface, SessionIdInterface {
+ public $path;
+
+ public function open($path, $name) {
+ if (!$path) {
+ $path = sys_get_temp_dir();
+ }
+ $this->path = $path . '/u_sess_' . $name;
+ return true;
+ }
+
+ public function close() {
+ return true;
+ }
+
+ public function read($id) {
+ return @file_get_contents($this->path . $id);
+ }
+
+ public function write($id, $data) {
+ return file_put_contents($this->path . $id, $data);
+ }
+
+ public function destroy($id) {
+ @unlink($this->path . $id);
+ }
+
+ public function gc($maxlifetime) {
+ foreach (glob($this->path . '*') as $filename) {
+ if (filemtime($filename) + $maxlifetime < time()) {
+ @unlink($filename);
+ }
+ }
+ return true;
+ }
+
+ public function create_sid() {
+ return 'my_sid';
+ }
+}
+
+$handler = new MySession2;
+session_set_save_handler($handler);
+session_start();
+
+$_SESSION['foo'] = "hello";
+
+var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
+
+session_write_close();
+session_unset();
+
+session_start();
+var_dump($_SESSION);
+
+session_write_close();
+session_unset();
+
+--EXPECTF--
+*** Testing session_set_save_handler() function: id interface ***
+string(%d) "my_sid"
+string(4) "user"
+array(1) {
+ ["foo"]=>
+ string(5) "hello"
+}
+array(1) {
+ ["foo"]=>
+ string(5) "hello"
+}
diff --git a/ext/session/tests/session_set_save_handler_sid_001.phpt b/ext/session/tests/session_set_save_handler_sid_001.phpt
new file mode 100644
index 000000000..0dc4fc11c
--- /dev/null
+++ b/ext/session/tests/session_set_save_handler_sid_001.phpt
@@ -0,0 +1,85 @@
+--TEST--
+Test session_set_save_handler() function: create_sid
+--INI--
+session.save_handler=files
+session.name=PHPSESSID
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+
+ob_start();
+
+echo "*** Testing session_set_save_handler() function: create_sid ***\n";
+
+class MySession2 {
+ public $path;
+
+ public function open($path, $name) {
+ if (!$path) {
+ $path = sys_get_temp_dir();
+ }
+ $this->path = $path . '/u_sess_' . $name;
+ return true;
+ }
+
+ public function close() {
+ return true;
+ }
+
+ public function read($id) {
+ return @file_get_contents($this->path . $id);
+ }
+
+ public function write($id, $data) {
+ return file_put_contents($this->path . $id, $data);
+ }
+
+ public function destroy($id) {
+ @unlink($this->path . $id);
+ }
+
+ public function gc($maxlifetime) {
+ foreach (glob($this->path . '*') as $filename) {
+ if (filemtime($filename) + $maxlifetime < time()) {
+ @unlink($filename);
+ }
+ }
+ return true;
+ }
+
+ public function create_sid() {
+ return 'my_sid';
+ }
+}
+
+$handler = new MySession2;
+session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
+ array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'), array($handler, 'create_sid'));
+session_start();
+
+$_SESSION['foo'] = "hello";
+
+var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
+
+session_write_close();
+session_unset();
+
+session_start();
+var_dump($_SESSION);
+
+session_write_close();
+session_unset();
+
+--EXPECTF--
+*** Testing session_set_save_handler() function: create_sid ***
+string(%d) "my_sid"
+string(4) "user"
+array(1) {
+ ["foo"]=>
+ string(5) "hello"
+}
+array(1) {
+ ["foo"]=>
+ string(5) "hello"
+}
diff --git a/ext/session/tests/session_set_save_handler_sid_002.phpt b/ext/session/tests/session_set_save_handler_sid_002.phpt
new file mode 100644
index 000000000..f9a72aebc
--- /dev/null
+++ b/ext/session/tests/session_set_save_handler_sid_002.phpt
@@ -0,0 +1,77 @@
+--TEST--
+Test session_set_save_handler() function: create_sid
+--INI--
+session.save_handler=files
+session.name=PHPSESSID
+--SKIPIF--
+<?php include('skipif.inc'); ?>
+--FILE--
+<?php
+
+ob_start();
+
+echo "*** Testing session_set_save_handler() function: create_sid ***\n";
+
+class MySession2 {
+ public $path;
+
+ public function open($path, $name) {
+ if (!$path) {
+ $path = sys_get_temp_dir();
+ }
+ $this->path = $path . '/u_sess_' . $name;
+ return true;
+ }
+
+ public function close() {
+ return true;
+ }
+
+ public function read($id) {
+ return @file_get_contents($this->path . $id);
+ }
+
+ public function write($id, $data) {
+ return file_put_contents($this->path . $id, $data);
+ }
+
+ public function destroy($id) {
+ @unlink($this->path . $id);
+ }
+
+ public function gc($maxlifetime) {
+ foreach (glob($this->path . '*') as $filename) {
+ if (filemtime($filename) + $maxlifetime < time()) {
+ @unlink($filename);
+ }
+ }
+ return true;
+ }
+
+ public function create_sid() {
+ return null;
+ }
+}
+
+$handler = new MySession2;
+session_set_save_handler(array($handler, 'open'), array($handler, 'close'),
+ array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'), array($handler, 'create_sid'));
+session_start();
+
+$_SESSION['foo'] = "hello";
+
+var_dump(session_id(), ini_get('session.save_handler'), $_SESSION);
+
+session_write_close();
+session_unset();
+
+session_start();
+var_dump($_SESSION);
+
+session_write_close();
+session_unset();
+
+--EXPECTF--
+*** Testing session_set_save_handler() function: create_sid ***
+
+Fatal error: session_start(): Session id must be a string in %s on line %d
diff --git a/ext/session/tests/session_status_disabled.phpt b/ext/session/tests/session_status_disabled.phpt
index 24e0ecd7b..c4d1f2192 100644
--- a/ext/session/tests/session_status_disabled.phpt
+++ b/ext/session/tests/session_status_disabled.phpt
@@ -3,7 +3,7 @@ Test session_status() function : disabled
--SKIPIF--
<?php include('skipif.inc'); ?>
--INI--
-session.save_handler=non-existant
+session.save_handler=non-existent
--FILE--
<?php