Skip to content

Commit 6f080aa

Browse files
committed
Add SSL tests using non-deprecated URI options
1 parent 31dcb61 commit 6f080aa

6 files changed

+85
-3
lines changed

tests/connect/standalone-ssl-no_verify-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Connect to MongoDB with SSL and no host/cert verification
2+
Connect to MongoDB with SSL and no host/cert verification (driver options)
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_ssl(); ?>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Connect to MongoDB with SSL and no host/cert verification (URI options)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_ssl(); ?>
6+
<?php skip_if_not_ssl(); ?>
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
$uriOptions = [
12+
'tlsAllowInvalidHostnames' => true,
13+
'tlsAllowInvalidCertificates' => true,
14+
];
15+
16+
$manager = create_test_manager(URI, $uriOptions);
17+
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
18+
printf("ping: %d\n", $cursor->toArray()[0]->ok);
19+
20+
?>
21+
===DONE===
22+
<?php exit(0); ?>
23+
--EXPECT--
24+
ping: 1
25+
===DONE===

tests/connect/standalone-ssl-verify_cert-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Connect to MongoDB with SSL and cert verification
2+
Connect to MongoDB with SSL and cert verification (driver options)
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_ssl(); ?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Connect to MongoDB with SSL and cert verification (URI options)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_ssl(); ?>
6+
<?php skip_if_not_ssl(); ?>
7+
<?php skip_if_no_ssl_dir(); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
12+
$uriOptions = [
13+
// libmongoc does not allow the hostname to be overridden as "server"
14+
'tlsAllowInvalidHostnames' => true,
15+
'tlsAllowInvalidCertificates' => false,
16+
'tlsCAFile' => SSL_DIR . '/ca.pem',
17+
];
18+
19+
$manager = create_test_manager(URI, $uriOptions);
20+
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
21+
printf("ping: %d\n", $cursor->toArray()[0]->ok);
22+
23+
?>
24+
===DONE===
25+
<?php exit(0); ?>
26+
--EXPECT--
27+
ping: 1
28+
===DONE===

tests/connect/standalone-ssl-verify_cert-error-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Connect to MongoDB with SSL and cert verification error
2+
Connect to MongoDB with SSL and cert verification error (driver options)
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_ssl(); ?>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Connect to MongoDB with SSL and cert verification error (URI options)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_ssl(); ?>
6+
<?php skip_if_not_ssl(); ?>
7+
--FILE--
8+
<?php
9+
require_once __DIR__ . "/../utils/basic.inc";
10+
11+
$uriOptions = [
12+
// libmongoc does not allow the hostname to be overridden as "server"
13+
'tlsAllowInvalidHostnames' => true,
14+
'tlsAllowInvalidCertificates' => false,
15+
];
16+
17+
echo throws(function() use ($uriOptions) {
18+
$manager = create_test_manager(URI, $uriOptions);
19+
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
20+
var_dump($cursor->toArray()[0]);
21+
}, MongoDB\Driver\Exception\ConnectionException::class, 'executeCommand'), "\n";
22+
23+
?>
24+
===DONE===
25+
<?php exit(0); ?>
26+
--EXPECTF--
27+
OK: Got MongoDB\Driver\Exception\ConnectionException thrown from executeCommand
28+
%sTLS handshake failed%s
29+
===DONE===

0 commit comments

Comments
 (0)