1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
--TEST--
Test for bug PHP-816: MongoCursor doesn't validate the namespace
--SKIPIF--
<?php require "tests/utils/standalone.inc";?>
--FILE--
<?php
require_once "tests/utils/server.inc";
$dsn = MongoShellServer::getStandaloneInfo();
class MyMongoClient extends MongoClient {
}
class MyDB extends MongoDB {
public function __construct() {}
}
$db = new MyDB;
$nss = array(
'test', '.test', 'test.', '', '.', 'xx', 'xxx', 'a.b', 'db.foo', 'foo.file.fs',
);
foreach ($nss as $ns) {
echo "NS: ", $ns, ": ";
try {
$c = new MongoCursor(new MyMongoClient($dsn), $ns);
$c->hasNext();
echo "OK\n";
} catch (MongoException $e) {
echo "FAIL\n";
var_dump($e->getCode());
var_dump($e->getMessage());
}
echo "\n";
}
?>
--EXPECT--
NS: test: FAIL
int(21)
string(40) "An invalid 'ns' argument is given (test)"
NS: .test: FAIL
int(21)
string(41) "An invalid 'ns' argument is given (.test)"
NS: test.: FAIL
int(21)
string(41) "An invalid 'ns' argument is given (test.)"
NS: : FAIL
int(21)
string(36) "An invalid 'ns' argument is given ()"
NS: .: FAIL
int(21)
string(37) "An invalid 'ns' argument is given (.)"
NS: xx: FAIL
int(21)
string(38) "An invalid 'ns' argument is given (xx)"
NS: xxx: FAIL
int(21)
string(39) "An invalid 'ns' argument is given (xxx)"
NS: a.b: OK
NS: db.foo: OK
NS: foo.file.fs: OK
|