Skip to content

Commit 08bac1e

Browse files
committed
PHPC-1498: Throw exception when configuring autoEncryption options without FLE
1 parent 123f9b0 commit 08bac1e

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

php_phongo.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,18 @@ static bool phongo_manager_set_auto_encryption_opts(php_phongo_manager_t* manage
28412841
return retval;
28422842
}
28432843
/* }}} */
2844+
#else /* MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION */
2845+
static bool phongo_manager_set_auto_encryption_opts(php_phongo_manager_t* manager, zval* driverOptions TSRMLS_DC) /* {{{ */
2846+
{
2847+
if (!driverOptions || !php_array_existsc(driverOptions, "autoEncryption")) {
2848+
return true;
2849+
}
2850+
2851+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Cannot enable automatic field-level encryption. Please recompile with support for libmongocrypt using the with-mongodb-client-side-encryption configure switch.");
2852+
2853+
return false;
2854+
}
2855+
/* }}} */
28442856
#endif
28452857

28462858
void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string, zval* options, zval* driverOptions TSRMLS_DC) /* {{{ */
@@ -2921,12 +2933,10 @@ void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string,
29212933
}
29222934
#endif
29232935

2924-
#ifdef MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION
29252936
if (!phongo_manager_set_auto_encryption_opts(manager, driverOptions TSRMLS_CC)) {
29262937
/* Exception should already have been thrown */
29272938
goto cleanup;
29282939
}
2929-
#endif
29302940

29312941
MONGOC_DEBUG("Created client hash: %s\n", manager->client_hash);
29322942
php_phongo_persist_client(manager->client_hash, manager->client_hash_len, manager->client TSRMLS_CC);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::__construct(): auto encryption when compiling without libmongocrypt
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_libmongocrypt(); ?>
6+
--FILE--
7+
<?php
8+
9+
require_once __DIR__ . '/../utils/tools.php';
10+
11+
echo throws(function () {
12+
$manager = new MongoDB\Driver\Manager(null, [], ['autoEncryption' => []]);
13+
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n";
14+
15+
?>
16+
===DONE===
17+
<?php exit(0); ?>
18+
--EXPECT--
19+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
20+
Cannot enable automatic field-level encryption. Please recompile with support for libmongocrypt using the with-mongodb-client-side-encryption configure switch.
21+
===DONE===

0 commit comments

Comments
 (0)