Skip to content

Commit 632e35f

Browse files
committed
Rewrite test for SSL with no host/cert verification
1 parent f7e2b09 commit 632e35f

File tree

4 files changed

+56
-97
lines changed

4 files changed

+56
-97
lines changed

tests/connect/standalone-ssl-0001.phpt

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/connect/standalone-ssl-0003.phpt

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Connect to MongoDB with SSL and no host/cert verification
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; NEEDS("STANDALONE_SSL"); ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$driverOptions = [
10+
'allow_invalid_hostname' => true,
11+
"weak_cert_validation" => true,
12+
];
13+
14+
$manager = new MongoDB\Driver\Manager(STANDALONE_SSL, ['ssl' => true], $driverOptions);
15+
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
16+
var_dump($cursor->toArray()[0]);
17+
18+
?>
19+
===DONE===
20+
<?php exit(0); ?>
21+
--EXPECTF--
22+
object(stdClass)#%d (%d) {
23+
["ok"]=>
24+
float(1)
25+
}
26+
===DONE===
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Connect to MongoDB with SSL and no host/cert verification (context options)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; NEEDS("STANDALONE_SSL"); ?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$driverOptions = [
10+
'context' => stream_context_create([
11+
'ssl' => [
12+
'allow_invalid_hostname' => true,
13+
'allow_self_signed' => true, // "weak_cert_validation" alias
14+
],
15+
]),
16+
];
17+
18+
$manager = new MongoDB\Driver\Manager(STANDALONE_SSL, ['ssl' => true], $driverOptions);
19+
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
20+
var_dump($cursor->toArray()[0]);
21+
22+
?>
23+
===DONE===
24+
<?php exit(0); ?>
25+
--EXPECTF--
26+
object(stdClass)#%d (%d) {
27+
["ok"]=>
28+
float(1)
29+
}
30+
===DONE===

0 commit comments

Comments
 (0)