Skip to content

Commit 607b91c

Browse files
committed
PHPC-1533: Handle OCSP URI options
1 parent 3f275ee commit 607b91c

7 files changed

+173
-8
lines changed

php_phongo.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,8 +1446,29 @@ static bool php_phongo_uri_finalize_tls(mongoc_uri_t* uri) /* {{{ */
14461446

14471447
if (bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSINSECURE) &&
14481448
(bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSALLOWINVALIDCERTIFICATES) ||
1449-
bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSALLOWINVALIDHOSTNAMES))) {
1450-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Failed to parse URI options: %s may not be combined with %s or %s.", MONGOC_URI_TLSINSECURE, MONGOC_URI_TLSALLOWINVALIDCERTIFICATES, MONGOC_URI_TLSALLOWINVALIDHOSTNAMES);
1449+
bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSALLOWINVALIDHOSTNAMES) ||
1450+
bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK) ||
1451+
bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK))) {
1452+
phongo_throw_exception(
1453+
PHONGO_ERROR_INVALID_ARGUMENT,
1454+
"Failed to parse URI options: %s may not be combined with %s, %s, %s, or %s.",
1455+
MONGOC_URI_TLSINSECURE,
1456+
MONGOC_URI_TLSALLOWINVALIDCERTIFICATES,
1457+
MONGOC_URI_TLSALLOWINVALIDHOSTNAMES,
1458+
MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK,
1459+
MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK);
1460+
return false;
1461+
}
1462+
1463+
if (bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSALLOWINVALIDCERTIFICATES) &&
1464+
(bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK) ||
1465+
bson_iter_init_find_case(&iter, options, MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK))) {
1466+
phongo_throw_exception(
1467+
PHONGO_ERROR_INVALID_ARGUMENT,
1468+
"Failed to parse URI options: %s may not be combined with %s or %s.",
1469+
MONGOC_URI_TLSALLOWINVALIDCERTIFICATES,
1470+
MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK,
1471+
MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK);
14511472
return false;
14521473
}
14531474

tests/manager/manager-ctor-tls-error-001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ echo throws(function() {
2828
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
2929
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsInsecure=true&tlsAllowInvalidHostnames=true'. tlsinsecure may not be specified with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3030
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
31-
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
31+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3232
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
33-
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
33+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3434
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
35-
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
35+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3636
===DONE===

tests/manager/manager-ctor-tls-error-002.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ echo throws(function() {
2828
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
2929
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsInsecure=true&tlsAllowInvalidCertificates=true'. tlsinsecure may not be specified with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3030
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
31-
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
31+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3232
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
33-
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
33+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3434
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
35-
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates or tlsallowinvalidhostnames.
35+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
3636
===DONE===
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): tlsInsecure cannot be combined with tlsDisableOCSPEndpointCheck
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/tools.php';
7+
8+
echo throws(function() {
9+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsInsecure=true&tlsDisableOCSPEndpointCheck=true');
10+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
11+
12+
echo throws(function() {
13+
new MongoDB\Driver\Manager('mongodb://localhost:27017/', ['tlsInsecure' => true, 'tlsDisableOCSPEndpointCheck' => true]);
14+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
15+
16+
echo throws(function() {
17+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsInsecure=true', ['tlsDisableOCSPEndpointCheck' => true]);
18+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
19+
20+
echo throws(function() {
21+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsDisableOCSPEndpointCheck=true', ['tlsInsecure' => true]);
22+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29+
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsInsecure=true&tlsDisableOCSPEndpointCheck=true'. tlsinsecure may not be specified with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
30+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
31+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
32+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
33+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
34+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
35+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
36+
===DONE===
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): tlsInsecure cannot be combined with tlsDisableCertificateRevocationCheck
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/tools.php';
7+
8+
echo throws(function() {
9+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsInsecure=true&tlsDisableCertificateRevocationCheck=true');
10+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
11+
12+
echo throws(function() {
13+
new MongoDB\Driver\Manager('mongodb://localhost:27017/', ['tlsInsecure' => true, 'tlsDisableCertificateRevocationCheck' => true]);
14+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
15+
16+
echo throws(function() {
17+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsInsecure=true', ['tlsDisableCertificateRevocationCheck' => true]);
18+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
19+
20+
echo throws(function() {
21+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsDisableCertificateRevocationCheck=true', ['tlsInsecure' => true]);
22+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29+
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsInsecure=true&tlsDisableCertificateRevocationCheck=true'. tlsinsecure may not be specified with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
30+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
31+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
32+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
33+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
34+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
35+
Failed to parse URI options: tlsinsecure may not be combined with tlsallowinvalidcertificates, tlsallowinvalidhostnames, tlsdisableocspendpointcheck, or tlsdisablecertificaterevocationcheck.
36+
===DONE===
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): tlsAllowInvalidCertificates cannot be combined with tlsDisableOCSPEndpointCheck
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/tools.php';
7+
8+
echo throws(function() {
9+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsAllowInvalidCertificates=true&tlsDisableOCSPEndpointCheck=true');
10+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
11+
12+
echo throws(function() {
13+
new MongoDB\Driver\Manager('mongodb://localhost:27017/', ['tlsAllowInvalidCertificates' => true, 'tlsDisableOCSPEndpointCheck' => true]);
14+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
15+
16+
echo throws(function() {
17+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsAllowInvalidCertificates=true', ['tlsDisableOCSPEndpointCheck' => true]);
18+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
19+
20+
echo throws(function() {
21+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsDisableOCSPEndpointCheck=true', ['tlsAllowInvalidCertificates' => true]);
22+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29+
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsAllowInvalidCertificates=true&tlsDisableOCSPEndpointCheck=true'. tlsallowinvalidcertificates may not be specified with tlsdisableocspendpointcheck or tlsdisablecertificaterevocationcheck.
30+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
31+
Failed to parse URI options: tlsallowinvalidcertificates may not be combined with tlsdisableocspendpointcheck or tlsdisablecertificaterevocationcheck.
32+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
33+
Failed to parse URI options: tlsallowinvalidcertificates may not be combined with tlsdisableocspendpointcheck or tlsdisablecertificaterevocationcheck.
34+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
35+
Failed to parse URI options: tlsallowinvalidcertificates may not be combined with tlsdisableocspendpointcheck or tlsdisablecertificaterevocationcheck.
36+
===DONE===
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): tlsAllowInvalidCertificates cannot be combined with tlsDisableCertificateRevocationCheck
3+
--FILE--
4+
<?php
5+
6+
require_once __DIR__ . '/../utils/tools.php';
7+
8+
echo throws(function() {
9+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsAllowInvalidCertificates=true&tlsDisableCertificateRevocationCheck=true');
10+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
11+
12+
echo throws(function() {
13+
new MongoDB\Driver\Manager('mongodb://localhost:27017/', ['tlsAllowInvalidCertificates' => true, 'tlsDisableCertificateRevocationCheck' => true]);
14+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
15+
16+
echo throws(function() {
17+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsAllowInvalidCertificates=true', ['tlsDisableCertificateRevocationCheck' => true]);
18+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
19+
20+
echo throws(function() {
21+
new MongoDB\Driver\Manager('mongodb://localhost:27017/?tlsDisableCertificateRevocationCheck=true', ['tlsAllowInvalidCertificates' => true]);
22+
}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n";
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29+
Failed to parse MongoDB URI: 'mongodb://localhost:27017/?tlsAllowInvalidCertificates=true&tlsDisableCertificateRevocationCheck=true'. tlsallowinvalidcertificates may not be specified with tlsdisableocspendpointcheck or tlsdisablecertificaterevocationcheck.
30+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
31+
Failed to parse URI options: tlsallowinvalidcertificates may not be combined with tlsdisableocspendpointcheck or tlsdisablecertificaterevocationcheck.
32+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
33+
Failed to parse URI options: tlsallowinvalidcertificates may not be combined with tlsdisableocspendpointcheck or tlsdisablecertificaterevocationcheck.
34+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
35+
Failed to parse URI options: tlsallowinvalidcertificates may not be combined with tlsdisableocspendpointcheck or tlsdisablecertificaterevocationcheck.
36+
===DONE===

0 commit comments

Comments
 (0)