Skip to content

Commit 767fd49

Browse files
committed
Use canonical TLS options in tests
1 parent ca01041 commit 767fd49

7 files changed

+39
-57
lines changed

tests/connect/bug0720.phpt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ PHPC-720: Do not persist SSL streams to avoid SSL reinitialization errors
1010
<?php
1111
require_once __DIR__ . "/../utils/basic.inc";
1212

13-
$driverOptions = [
13+
$uriOptions = [
1414
// libmongoc does not allow the hostname to be overridden as "server"
15-
'allow_invalid_hostname' => true,
16-
'ca_file' => SSL_DIR . '/ca.pem',
15+
'tlsAllowInvalidHostnames' => true,
16+
'tlsCAFile' => SSL_DIR . '/ca.pem',
1717
];
1818

19-
$manager = create_test_manager(URI, [], $driverOptions);
19+
$manager = create_test_manager(URI, $uriOptions);
2020
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
2121
printf("ping: %d\n", $cursor->toArray()[0]->ok);
2222

@@ -29,10 +29,7 @@ printf("ping: %d\n", $cursor->toArray()[0]->ok);
2929
?>
3030
===DONE===
3131
<?php exit(0); ?>
32-
--EXPECTF--
33-
Deprecated: MongoDB\Driver\Manager::__construct(): The "allow_invalid_hostname" driver option is deprecated. Please use the "tlsAllowInvalidHostnames" URI option instead.%s
34-
35-
Deprecated: MongoDB\Driver\Manager::__construct(): The "ca_file" driver option is deprecated. Please use the "tlsCAFile" URI option instead.%s
32+
--EXPECT--
3633
ping: 1
3734
ping: 1
3835
===DONE===

tests/connect/standalone-x509-auth-001.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Connect to MongoDB with SSL and X509 auth
1010
<?php
1111
require_once __DIR__ . "/../utils/basic.inc";
1212

13-
$driverOptions = [
13+
$uriOptions = [
1414
// libmongoc does not allow the hostname to be overridden as "server"
15-
'allow_invalid_hostname' => true,
16-
'weak_cert_validation' => false,
17-
'ca_file' => SSL_DIR . '/ca.pem',
18-
'pem_file' => SSL_DIR . '/client.pem',
15+
'tlsAllowInvalidHostnames' => true,
16+
'tlsAllowInvalidCertificates' => false,
17+
'tlsCAFile' => SSL_DIR . '/ca.pem',
18+
'tlsCertificateKeyFile' => SSL_DIR . '/client.pem',
1919
];
2020

21-
$manager = create_test_manager(URI, [], $driverOptions);
21+
$manager = create_test_manager(URI, $uriOptions);
2222
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
2323
var_dump($cursor->toArray()[0]);
2424

tests/connect/standalone-x509-error-0001.phpt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--TEST--
22
X509 connection should not reuse previous stream after an auth failure
33
--XFAIL--
4+
X509 tests must be reimplemented (PHPC-1262)
45
parse_url() tests must be reimplemented (PHPC-1177)
56
--SKIPIF--
67
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
@@ -12,11 +13,11 @@ parse_url() tests must be reimplemented (PHPC-1177)
1213
<?php
1314
require_once __DIR__ . "/../utils/basic.inc";
1415

15-
$driverOptions = [
16+
$uriOptions = [
1617
// libmongoc does not allow the hostname to be overridden as "server"
17-
'allow_invalid_hostname' => true,
18-
'ca_file' => SSL_DIR . '/ca.pem',
19-
'pem_file' => SSL_DIR . '/client.pem',
18+
'tlsAllowInvalidHostnames' => true,
19+
'tlsCAFile' => SSL_DIR . '/ca.pem',
20+
'tlsCertificateKeyFile' => SSL_DIR . '/client.pem',
2021
];
2122

2223
// Wrong username for X509 authentication
@@ -25,8 +26,8 @@ $dsn = sprintf('mongodb://username@%s:%d/?ssl=true&authMechanism=MONGODB-X509',
2526

2627
// Both should fail with auth failure, without reusing the previous stream
2728
for ($i = 0; $i < 2; $i++) {
28-
echo throws(function() use ($dsn, $driverOptions) {
29-
$manager = create_test_manager($dsn, [], $driverOptions);
29+
echo throws(function() use ($dsn, $uriOptions) {
30+
$manager = create_test_manager($dsn, $uriOptions);
3031
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
3132
var_dump($cursor->toArray()[0]);
3233
}, 'MongoDB\Driver\Exception\AuthenticationException', 'executeCommand'), "\n";

tests/connect/standalone-x509-extract_username-001.phpt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--TEST--
22
Connect to MongoDB with SSL and X509 auth and username retrieved from cert
33
--XFAIL--
4+
X509 tests must be reimplemented (PHPC-1262)
45
parse_url() tests must be reimplemented (PHPC-1177)
56
--SKIPIF--
67
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
@@ -12,20 +13,20 @@ parse_url() tests must be reimplemented (PHPC-1177)
1213
<?php
1314
require_once __DIR__ . "/../utils/basic.inc";
1415

15-
$driverOptions = [
16+
$uriOptions = [
17+
'authMechanism' => 'MONGODB-X509',
18+
'tls' => true,
1619
// libmongoc does not allow the hostname to be overridden as "server"
17-
'allow_invalid_hostname' => true,
18-
'weak_cert_validation' => false,
19-
'ca_file' => SSL_DIR . '/ca.pem',
20-
'pem_file' => SSL_DIR . '/client.pem',
20+
'tlsAllowInvalidHostnames' => true,
21+
'tlsAllowInvalidCertificates' => false,
22+
'tlsCAFile' => SSL_DIR . '/ca.pem',
23+
'tlsCertificateKeyFile' => SSL_DIR . '/client.pem',
2124
];
2225

23-
$uriOptions = ['authMechanism' => 'MONGODB-X509', 'ssl' => true];
24-
2526
$parsed = parse_url(URI);
2627
$uri = sprintf('mongodb://%s:%d', $parsed['host'], $parsed['port']);
2728

28-
$manager = create_test_manager($uri, $uriOptions, $driverOptions);
29+
$manager = create_test_manager($uri, $uriOptions);
2930
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1]));
3031
var_dump($cursor->toArray()[0]);
3132

tests/manager/bug0940-001.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ PHPC-940: php_phongo_free_ssl_opt() attempts to free interned strings
66
--FILE--
77
<?php
88

9-
var_dump(new MongoDB\Driver\Manager(null, [], ['ca_file' => false]));
9+
var_dump(new MongoDB\Driver\Manager(null, ['tlsCAFile' => false]));
1010

1111
?>
1212
===DONE===
1313
<?php exit(0); ?>
1414
--EXPECTF--
15-
Deprecated: MongoDB\Driver\Manager::__construct(): The "ca_file" driver option is deprecated. Please use the "tlsCAFile" URI option instead.%s
1615
object(MongoDB\Driver\Manager)#%d (%d) {
1716
["uri"]=>
1817
string(20) "mongodb://127.0.0.1/"

tests/manager/manager-set-uri-options-002.phpt

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,14 @@ MongoDB\Driver\Manager: Connecting to MongoDB using "ssl" from $options
99
<?php
1010
require_once __DIR__ . "/../utils/basic.inc";
1111

12-
$opts = array(
13-
"ssl" => array(
14-
"verify_peer" => false,
15-
"verify_peer_name" => false,
16-
"allow_self_signed" => true,
17-
),
18-
);
19-
$context = stream_context_create($opts);
20-
2112
$options = array(
2213
"ssl" => false,
2314
"serverselectiontimeoutms" => 100,
15+
'tlsAllowInvalidCertificates' => true,
16+
'tlsAllowInvalidHostnames' => true,
2417
);
2518
/* The server requires SSL */
26-
$manager = create_test_manager(URI, $options, array("context" => $context));
19+
$manager = create_test_manager(URI, $options);
2720

2821
$bulk = new MongoDB\Driver\BulkWrite;
2922
$bulk->insert(array("my" => "value"));
@@ -33,10 +26,9 @@ throws(function() use ($manager, $bulk) {
3326
printf("Inserted incorrectly: %d\n", $inserted);
3427
}, MongoDB\Driver\Exception\ConnectionException::class);
3528

36-
$options = array(
37-
"ssl" => true,
38-
);
39-
$manager = create_test_manager(URI, $options, array("context" => $context));
29+
// Enable SSL and reconnect
30+
$options['ssl'] = true;
31+
$manager = create_test_manager(URI, $options);
4032
$bulk = new MongoDB\Driver\BulkWrite;
4133

4234
$bulk->insert(array("my" => "value"));
@@ -45,14 +37,7 @@ printf("Inserted: %d\n", $inserted);
4537
?>
4638
===DONE===
4739
<?php exit(0); ?>
48-
--EXPECTF--
49-
Deprecated: MongoDB\Driver\Manager::__construct(): The "context" driver option is deprecated.%s
50-
51-
Deprecated: MongoDB\Driver\Manager::__construct(): The "allow_self_signed" context driver option is deprecated. Please use the "tlsAllowInvalidCertificates" URI option instead.%s
40+
--EXPECT--
5241
OK: Got MongoDB\Driver\Exception\ConnectionException
53-
54-
Deprecated: MongoDB\Driver\Manager::__construct(): The "context" driver option is deprecated.%s
55-
56-
Deprecated: MongoDB\Driver\Manager::__construct(): The "allow_self_signed" context driver option is deprecated. Please use the "tlsAllowInvalidCertificates" URI option instead.%s
5742
Inserted: 1
5843
===DONE===

tests/manager/manager-set-uri-options-003.phpt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ MongoDB\Driver\Manager: SSL options in URI and 'options' don't leak
88
<?php
99
require_once __DIR__ . "/../utils/basic.inc";
1010

11-
$options = array(
12-
"pem_pwd" => "does-not-matter",
11+
$manager = create_test_manager(
12+
URI . '&tlsCertificateKeyFilePassword=does-not-matter',
13+
['tlsCertificateKeyFilePassword' => 'also-does-not-matter'],
1314
);
1415

15-
$manager = create_test_manager(URI . '&sslclientcertificatekeypassword=does-also-not-matter', [], $options);
1616
?>
1717
===DONE===
1818
<?php exit(0); ?>
19-
--EXPECTF--
20-
Deprecated: MongoDB\Driver\Manager::__construct(): The "pem_pwd" driver option is deprecated. Please use the "tlsCertificateKeyFilePassword" URI option instead.%s
19+
--EXPECT-
2120
===DONE===

0 commit comments

Comments
 (0)