Skip to content

Commit f420087

Browse files
bjorijmikola
authored andcommitted
PHPC-415: Add testcase
1 parent 3a91948 commit f420087

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Connect to MongoDB with using X509 retrieving username from certificate #002
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; NEEDS("STANDALONE_X509"); ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
function connect($dsn, $opts) {
10+
try {
11+
$manager = new MongoDB\Driver\Manager($dsn, array(), $opts);
12+
13+
$bulk = new MongoDB\Driver\BulkWrite();
14+
$bulk->insert(array("very" => "important"));
15+
$manager->executeBulkWrite(NS, $bulk);
16+
echo "Connected\n";
17+
} catch(Exception $e) {
18+
echo get_class($e), ": ", $e->getMessage(), "\n";
19+
}
20+
return $manager;
21+
22+
}
23+
$SSL_DIR = realpath(__DIR__ . "/" . "./../../scripts/ssl/");
24+
25+
$opts = array(
26+
"peer_name" => "server",
27+
"verify_peer" => true,
28+
"verify_peer_name" => true,
29+
"allow_self_signed" => false,
30+
"cafile" => $SSL_DIR . "/ca.pem", /* Defaults to openssl.cafile */
31+
"capath" => $SSL_DIR, /* Defaults to openssl.capath */
32+
"local_cert" => $SSL_DIR . "/src/libmongoc/tests/certificates/client.pem",
33+
);
34+
$parsed = parse_url(STANDALONE_X509);
35+
$dsn = sprintf("mongodb://username@%s:%d/%s?ssl=true&authMechanism=MONGODB-X509", $parsed["host"], $parsed["port"], DATABASE_NAME);
36+
37+
38+
$m1 = connect($dsn, $opts);
39+
$m2 = connect($dsn, $opts);
40+
41+
echo "Both should have failed with auth failure - without reusing previous stream\n";
42+
?>
43+
===DONE===
44+
<?php exit(0); ?>
45+
--EXPECTF--
46+
MongoDB\Driver\Exception\AuthenticationException: auth failed
47+
MongoDB\Driver\Exception\AuthenticationException: auth failed
48+
Both should have failed with auth failure - without reusing previous stream
49+
===DONE===

0 commit comments

Comments
 (0)