Skip to content

Commit 2f431c0

Browse files
authored
PHPLIB-1008: Test crypt_shared with older server versions (#1127)
* Print test configuration before running * Test all CSFLE server versions with crypt_shared * Remove SKIP_CRYPT_SHARED from run_tests.sh
1 parent 3e2e42f commit 2f431c0

File tree

4 files changed

+85
-19
lines changed

4 files changed

+85
-19
lines changed

.evergreen/config.yml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ functions:
175175
params:
176176
script: |
177177
${PREPARE_SHELL}
178-
SKIP_LEGACY_SHELL=true MONGODB_VERSION=${MONGODB_VERSION} ORCHESTRATION_FILE=${ORCHESTRATION_FILE} TOPOLOGY=${TOPOLOGY} AUTH=${AUTH} SSL=${SSL} STORAGE_ENGINE=${STORAGE_ENGINE} LOAD_BALANCER=${LOAD_BALANCER} REQUIRE_API_VERSION=${REQUIRE_API_VERSION} sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
178+
SKIP_CRYPT_SHARED=${SKIP_CRYPT_SHARED} SKIP_LEGACY_SHELL=true MONGODB_VERSION=${MONGODB_VERSION} ORCHESTRATION_FILE=${ORCHESTRATION_FILE} TOPOLOGY=${TOPOLOGY} AUTH=${AUTH} SSL=${SSL} STORAGE_ENGINE=${STORAGE_ENGINE} LOAD_BALANCER=${LOAD_BALANCER} REQUIRE_API_VERSION=${REQUIRE_API_VERSION} sh ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
179179
# run-orchestration generates expansion file with MONGODB_URI and CRYPT_SHARED_LIB_PATH
180180
- command: expansions.update
181181
params:
@@ -304,7 +304,6 @@ functions:
304304
MONGODB_SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}" \
305305
MONGODB_MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}" \
306306
PHP_VERSION=${PHP_VERSION} \
307-
SKIP_CRYPT_SHARED=${SKIP_CRYPT_SHARED} \
308307
SSL=${SSL} \
309308
TESTS=${TESTS} \
310309
sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
@@ -352,7 +351,6 @@ functions:
352351
353352
CRYPT_SHARED_LIB_PATH=${CRYPT_SHARED_LIB_PATH} \
354353
MONGODB_URI="${SERVERLESS_URI}" \
355-
SKIP_CRYPT_SHARED=${SKIP_CRYPT_SHARED} \
356354
TESTS="serverless" \
357355
sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
358356
@@ -632,7 +630,7 @@ tasks:
632630
SSL: "yes"
633631
# Note: "stop load balancer" will be called from "post"
634632

635-
- name: "test-skip_crypt_shared"
633+
- name: "test-csfle-crypt_shared"
636634
commands:
637635
- func: "bootstrap mongo-orchestration"
638636
vars:
@@ -641,7 +639,18 @@ tasks:
641639
- func: "set aws temp creds"
642640
- func: "run tests"
643641
vars:
642+
TESTS: "csfle"
643+
644+
- name: "test-csfle-mongocryptd"
645+
commands:
646+
- func: "bootstrap mongo-orchestration"
647+
vars:
648+
TOPOLOGY: "replica_set"
644649
SKIP_CRYPT_SHARED: "yes"
650+
- func: "start kms servers"
651+
- func: "set aws temp creds"
652+
- func: "run tests"
653+
vars:
645654
TESTS: "csfle"
646655

647656
- name: "test-without_aws_creds"
@@ -788,6 +797,9 @@ axes:
788797
- id: rhel90
789798
display_name: "RHEL 9.0"
790799
run_on: rhel90-small
800+
- id: rhel80
801+
display_name: "RHEL 8.0"
802+
run_on: rhel80-small
791803

792804
# Ubuntu LTS
793805
- id: ubuntu2204
@@ -947,14 +959,25 @@ buildvariants:
947959
tasks:
948960
- name: "test-loadBalanced"
949961

950-
- matrix_name: "test-csfle-skip_crypt_shared"
951-
matrix_spec: { "os": "debian11", "mongodb-versions": "*", "php-edge-versions": "latest-stable", "driver-versions": "latest-stable" }
952-
display_name: "CSFLE skip_crypt_shared - ${mongodb-versions}"
962+
# CSFLE tests (crypt_shared and mongocryptd) are tested on RHEL 8 as it's the only version that supports
963+
# 4.2 AND 6.0 (which is required for crypt_shared), as well as a somewhat relevant PHP version.
964+
# Newer MongoDB version may require adding different operating systems here
965+
- matrix_name: "test-csfle-crypt_shared"
966+
matrix_spec: { "os": "rhel80", "mongodb-versions": "*", "php-versions": "8.0", "driver-versions": "latest-stable" }
967+
display_name: "CSFLE crypt_shared - ${mongodb-versions}"
953968
exclude_spec:
954-
# CSFLE crypt_shared is available from MongoDB 6.0+
955-
- { "os": "debian11", "mongodb-versions": ["3.6", "4.0", "4.2", "4.4", "5.0"], "php-edge-versions": "latest-stable", "driver-versions": "latest-stable" }
969+
# MongoDB < 4.2 does not need to be tested.
970+
- { "os": "rhel80", "mongodb-versions": ["3.6", "4.0"], "php-versions": "8.0", "driver-versions": "latest-stable" }
971+
tasks:
972+
- name: "test-csfle-crypt_shared"
973+
- matrix_name: "test-csfle-mongocryptd"
974+
matrix_spec: { "os": "rhel80", "mongodb-versions": "*", "php-versions": "8.0", "driver-versions": "latest-stable" }
975+
display_name: "CSFLE mongocryptd - ${mongodb-versions}"
976+
exclude_spec:
977+
# MongoDB < 4.2 does not need to be tested.
978+
- { "os": "rhel80", "mongodb-versions": ["3.6", "4.0"], "php-versions": "8.0", "driver-versions": "latest-stable" }
956979
tasks:
957-
- name: "test-skip_crypt_shared"
980+
- name: "test-csfle-mongocryptd"
958981

959982
# Run CSFLE tests without AWS credentials (for "On-demand AWS Credentials" prose test)
960983
- matrix_name: "test-csfle-without_aws_creds"

.evergreen/run-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ MONGODB_URI=${MONGODB_URI:-} # Connection string (including credentials and topo
1010
MONGODB_SINGLE_MONGOS_LB_URI=${MONGODB_SINGLE_MONGOS_LB_URI:-} # Single-mongos LB connection string
1111
MONGODB_MULTI_MONGOS_LB_URI=${MONGODB_MULTI_MONGOS_LB_URI:-} # Multi-mongos LB connection string
1212
MONGODB_VERSION=${MONGODB_VERSION:-} # Required if IS_MATRIX_TESTING is "true"
13-
SKIP_CRYPT_SHARED="${SKIP_CRYPT_SHARED:-no}" # Specify "yes" to ignore CRYPT_SHARED_LIB_PATH. Defaults to "no"
1413
SSL=${SSL:-no} # Specify "yes" to enable SSL. Defaults to "no"
1514
TESTS=${TESTS:-} # Optional test group. Defaults to all tests
1615

tests/TestCase.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
use function iterator_to_array;
2929
use function MongoDB\BSON\fromPHP;
3030
use function MongoDB\BSON\toJSON;
31+
use function preg_match;
32+
use function preg_replace;
3133
use function restore_error_handler;
3234
use function set_error_handler;
3335
use function sprintf;
36+
use function strtr;
3437

3538
use const E_USER_DEPRECATED;
3639

@@ -44,6 +47,44 @@ public static function getUri(): string
4447
return getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1:27017';
4548
}
4649

50+
public static function printConfiguration(): void
51+
{
52+
$template = <<<'OUTPUT'
53+
Test configuration:
54+
URI: %uri%
55+
Database: %database%
56+
API version: %apiVersion%
57+
58+
crypt_shared: %cryptSharedAvailable%
59+
mongocryptd: %mongocryptdAvailable%
60+
61+
OUTPUT;
62+
63+
// Redact credentials in the URI to be safe
64+
$uri = static::getUri();
65+
if (preg_match('#://.+:.+@#', $uri)) {
66+
$uri = preg_replace('#(.+://).+:.+@(.+)$#', '$1<redacted>@$2', $uri);
67+
}
68+
69+
$configuration = [
70+
'%uri%' => $uri,
71+
'%database%' => static::getDatabaseName(),
72+
'%apiVersion%' => getenv('MONGODB_API_VERSION') ?: 'Not configured',
73+
'%cryptSharedAvailable%' => FunctionalTestCase::isCryptSharedLibAvailable() ? 'Available' : 'Not available',
74+
'%mongocryptdAvailable%' => FunctionalTestCase::isMongocryptdAvailable() ? 'Available' : 'Not available',
75+
];
76+
77+
echo strtr($template, $configuration) . "\n";
78+
}
79+
80+
/**
81+
* Return the test database name.
82+
*/
83+
protected static function getDatabaseName(): string
84+
{
85+
return getenv('MONGODB_DATABASE') ?: 'phplib_test';
86+
}
87+
4788
/**
4889
* Asserts that a document has expected values for some fields.
4990
*
@@ -185,14 +226,6 @@ protected function getCollectionName(): string
185226
return sprintf('%s.%s', $class->getShortName(), hash('crc32b', $this->getName()));
186227
}
187228

188-
/**
189-
* Return the test database name.
190-
*/
191-
protected function getDatabaseName(): string
192-
{
193-
return getenv('MONGODB_DATABASE') ?: 'phplib_test';
194-
}
195-
196229
/**
197230
* Return a list of invalid array values.
198231
*/

tests/bootstrap.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
<?php
22

33
use MongoDB\Tests\Comparator\Int64Comparator;
4+
use MongoDB\Tests\TestCase;
45
use SebastianBergmann\Comparator\Factory as ComparatorFactory;
56

67
require __DIR__ . '/../vendor/autoload.php';
78

89
// Register custom comparators
910
ComparatorFactory::getInstance()->register(new Int64Comparator());
11+
12+
/* Ugly workaround for event system changes in PHPUnit
13+
* PHPUnit 10 introduces a new event system, and at the same time removes the
14+
* event system present in previous versions. This makes it near impossible to
15+
* support PHPUnit 8.5 (required for PHP 7.2) and PHPUnit 9 (PHP < 8.1)
16+
* alongside PHPUnit 10. For this reason, we use this bootstrap file to print
17+
* test configuration summary.
18+
* @todo PHP_VERSION_ID >= 80100: Remove this and use an extension
19+
*/
20+
TestCase::printConfiguration();

0 commit comments

Comments
 (0)