Skip to content

Commit 7412e4e

Browse files
committed
Make SSL certificate path configurable for tests
Since mongo-orchestration will always bring its own certificates, we need to set the correct SSL certificate directory for our tests. This is skipped on GitHub Actions as we don't test SSL builds there (yet). If SSL_DIR was not set, tests requiring SSL will be skipped.
1 parent bf9c308 commit 7412e4e

16 files changed

+35
-163
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ functions:
9797
export TMPDIR="$MONGO_ORCHESTRATION_HOME/db"
9898
export PATH="$MONGODB_BINARIES:$PATH"
9999
export PROJECT="${project}"
100+
export SSL_DIR="$DRIVERS_TOOLS/.evergreen/x509gen"
100101
EOT
101102
# See what we've done
102103
cat expansion.yml
@@ -393,8 +394,6 @@ functions:
393394
cat $i | tr -d '\r' > $i.new
394395
mv $i.new $i
395396
done
396-
# Copy client certificate because symlinks do not work on Windows.
397-
cp ${PROJECT_DIRECTORY}/scripts/ssl/client.pem ${MONGO_ORCHESTRATION_HOME}/lib/client.pem
398397
399398
"make files executable":
400399
- command: shell.exec

bin/prep-release.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function get_files() {
7171
"Vagrantfile",
7272

7373
"scripts/*/*.{sh}",
74-
"scripts/ssl/*.pem",
7574
"scripts/*.{json,php,py,sh}",
7675
"tests/utils/*.{inc,json.gz,php}",
7776
"tests/**/*.{phpt}",

scripts/ssl/ca.pem

Lines changed: 0 additions & 21 deletions
This file was deleted.

scripts/ssl/client.pem

Lines changed: 0 additions & 48 deletions
This file was deleted.

scripts/ssl/crl.pem

Lines changed: 0 additions & 13 deletions
This file was deleted.

scripts/ssl/server.pem

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/connect/bug0720.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ PHPC-720: Do not persist SSL streams to avoid SSL reinitialization errors
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_ssl(); ?>
66
<?php skip_if_not_ssl(); ?>
7+
<?php skip_if_no_ssl_dir(); ?>
78
--FILE--
89
<?php
910
require_once __DIR__ . "/../utils/basic.inc";
1011

11-
$SSL_DIR = realpath(__DIR__ . '/../../scripts/ssl/');
12-
1312
$driverOptions = [
1413
// libmongoc does not allow the hostname to be overridden as "server"
1514
'allow_invalid_hostname' => true,
16-
'ca_file' => $SSL_DIR . '/ca.pem',
15+
'ca_file' => SSL_DIR . '/ca.pem',
1716
];
1817

1918
$manager = new MongoDB\Driver\Manager(URI, [], $driverOptions);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ Connect to MongoDB with SSL and cert verification
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_ssl(); ?>
66
<?php skip_if_not_ssl(); ?>
7+
<?php skip_if_no_ssl_dir(); ?>
78
--FILE--
89
<?php
910
require_once __DIR__ . "/../utils/basic.inc";
1011

11-
$SSL_DIR = realpath(__DIR__ . '/../../scripts/ssl/');
12-
1312
$driverOptions = [
1413
// libmongoc does not allow the hostname to be overridden as "server"
1514
'allow_invalid_hostname' => true,
1615
'weak_cert_validation' => false,
17-
'ca_file' => $SSL_DIR . '/ca.pem',
16+
'ca_file' => SSL_DIR . '/ca.pem',
1817
];
1918

2019
$manager = new MongoDB\Driver\Manager(URI, [], $driverOptions);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ Connect to MongoDB with SSL and cert verification (context options)
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_ssl(); ?>
66
<?php skip_if_not_ssl(); ?>
7+
<?php skip_if_no_ssl_dir(); ?>
78
--FILE--
89
<?php
910
require_once __DIR__ . "/../utils/basic.inc";
1011

11-
$SSL_DIR = realpath(__DIR__ . '/../../scripts/ssl/');
12-
1312
$driverOptions = [
1413
'context' => stream_context_create([
1514
'ssl' => [
1615
// libmongoc does not allow the hostname to be overridden as "server"
1716
'allow_invalid_hostname' => true,
1817
'allow_self_signed' => false, // "weak_cert_validation" alias
19-
'cafile' => $SSL_DIR . '/ca.pem', // "ca_file" alias
18+
'cafile' => SSL_DIR . '/ca.pem', // "ca_file" alias
2019
],
2120
]),
2221
];

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ Connect to MongoDB with SSL and X509 auth
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_ssl(); ?>
66
<?php skip_if_not_ssl(); ?>
7+
<?php skip_if_no_ssl_dir(); ?>
78
<?php skip_if_not_auth_mechanism('MONGODB-X509'); ?>
89
--FILE--
910
<?php
1011
require_once __DIR__ . "/../utils/basic.inc";
1112

12-
$SSL_DIR = realpath(__DIR__ . '/../../scripts/ssl/');
13-
1413
$driverOptions = [
1514
// libmongoc does not allow the hostname to be overridden as "server"
1615
'allow_invalid_hostname' => true,
1716
'weak_cert_validation' => false,
18-
'ca_file' => $SSL_DIR . '/ca.pem',
19-
'pem_file' => $SSL_DIR . '/client.pem',
17+
'ca_file' => SSL_DIR . '/ca.pem',
18+
'pem_file' => SSL_DIR . '/client.pem',
2019
];
2120

2221
$manager = new MongoDB\Driver\Manager(URI, [], $driverOptions);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ Connect to MongoDB with SSL and X509 auth (stream context)
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
55
<?php skip_if_not_libmongoc_ssl(); ?>
66
<?php skip_if_not_ssl(); ?>
7+
<?php skip_if_no_ssl_dir(); ?>
78
<?php skip_if_not_auth_mechanism('MONGODB-X509'); ?>
89
--FILE--
910
<?php
1011
require_once __DIR__ . "/../utils/basic.inc";
1112

12-
$SSL_DIR = realpath(__DIR__ . '/../../scripts/ssl/');
13-
1413
$driverOptions = [
1514
'context' => stream_context_create([
1615
'ssl' => [
1716
// libmongoc does not allow the hostname to be overridden as "server"
1817
'allow_invalid_hostname' => true,
1918
'allow_self_signed' => false, // "weak_cert_validation" alias
20-
'cafile' => $SSL_DIR . '/ca.pem', // "ca_file" alias
21-
'local_cert' => $SSL_DIR . '/client.pem', // "pem_file" alias
19+
'cafile' => SSL_DIR . '/ca.pem', // "ca_file" alias
20+
'local_cert' => SSL_DIR . '/client.pem', // "pem_file" alias
2221
],
2322
]),
2423
];

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ parse_url() tests must be reimplemented (PHPC-1177)
66
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
77
<?php skip_if_not_libmongoc_ssl(); ?>
88
<?php skip_if_not_ssl(); ?>
9+
<?php skip_if_no_ssl_dir(); ?>
910
<?php skip_if_not_auth_mechanism('MONGODB-X509'); ?>
1011
--FILE--
1112
<?php
1213
require_once __DIR__ . "/../utils/basic.inc";
1314

14-
$SSL_DIR = realpath(__DIR__ . '/../../scripts/ssl/');
15-
1615
$driverOptions = [
1716
// libmongoc does not allow the hostname to be overridden as "server"
1817
'allow_invalid_hostname' => true,
19-
'ca_file' => $SSL_DIR . '/ca.pem',
20-
'pem_file' => $SSL_DIR . '/client.pem',
18+
'ca_file' => SSL_DIR . '/ca.pem',
19+
'pem_file' => SSL_DIR . '/client.pem',
2120
];
2221

2322
// Wrong username for X509 authentication

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ parse_url() tests must be reimplemented (PHPC-1177)
66
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
77
<?php skip_if_not_libmongoc_ssl(['OpenSSL', 'Secure Transport', 'Secure Channel']); ?>
88
<?php skip_if_not_ssl(); ?>
9+
<?php skip_if_no_ssl_dir(); ?>
910
<?php skip_if_not_auth_mechanism('MONGODB-X509'); ?>
1011
--FILE--
1112
<?php
1213
require_once __DIR__ . "/../utils/basic.inc";
1314

14-
$SSL_DIR = realpath(__DIR__ . '/../../scripts/ssl/');
15-
1615
$driverOptions = [
1716
// libmongoc does not allow the hostname to be overridden as "server"
1817
'allow_invalid_hostname' => true,
1918
'weak_cert_validation' => false,
20-
'ca_file' => $SSL_DIR . '/ca.pem',
21-
'pem_file' => $SSL_DIR . '/client.pem',
19+
'ca_file' => SSL_DIR . '/ca.pem',
20+
'pem_file' => SSL_DIR . '/client.pem',
2221
];
2322

2423
$uriOptions = ['authMechanism' => 'MONGODB-X509', 'ssl' => true];

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ parse_url() tests must be reimplemented (PHPC-1177)
66
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
77
<?php skip_if_not_libmongoc_ssl(['OpenSSL', 'Secure Transport', 'Secure Channel']); ?>
88
<?php skip_if_not_ssl(); ?>
9+
<?php skip_if_no_ssl_dir(); ?>
910
<?php skip_if_not_auth_mechanism('MONGODB-X509'); ?>
1011
--FILE--
1112
<?php
1213
require_once __DIR__ . "/../utils/basic.inc";
1314

14-
$SSL_DIR = realpath(__DIR__ . '/../../scripts/ssl/');
15-
1615
$driverOptions = [
1716
'context' => stream_context_create([
1817
'ssl' => [
1918
// libmongoc does not allow the hostname to be overridden as "server"
2019
'allow_invalid_hostname' => true,
2120
'allow_self_signed' => false, // "weak_cert_validation" alias
22-
'cafile' => $SSL_DIR . '/ca.pem', // "ca_file" alias
23-
'local_cert' => $SSL_DIR . '/client.pem', // "pem_file" alias
21+
'cafile' => SSL_DIR . '/ca.pem', // "ca_file" alias
22+
'local_cert' => SSL_DIR . '/client.pem', // "pem_file" alias
2423
],
2524
]),
2625
];

tests/utils/basic.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ define('MONGO_ORCHESTRATION_URI', getenv('MONGO_ORCHESTRATION_URI') ?: 'http://l
77
define('DATABASE_NAME', getenv('MONGODB_DATABASE') ?: 'phongo');
88
define('COLLECTION_NAME', makeCollectionNameFromFilename($_SERVER['SCRIPT_FILENAME']));
99
define('NS', DATABASE_NAME . '.' . COLLECTION_NAME);
10+
define('SSL_DIR', realpath(getenv('SSL_DIR')));

tests/utils/skipif.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ function skip_if_not_ssl()
200200
is_ssl(URI) or exit('skip URI is not using SSL');
201201
}
202202

203+
/**
204+
* Skips the test if no SSL directory has been defined.
205+
*/
206+
function skip_if_no_ssl_dir()
207+
{
208+
$sslDir = getenv('SSL_DIR');
209+
$sslDir !== false or exit('skip SSL_DIR environment not set');
210+
211+
$sslDir = realpath($sslDir);
212+
($sslDir !== false && is_dir($sslDir)) or exit('skip SSL_DIR is not a valid directory');
213+
}
214+
203215
/**
204216
* Skips the test if the connection string is using auth.
205217
*/

0 commit comments

Comments
 (0)