Skip to content

Commit c771ba1

Browse files
p-mongop
authored andcommitted
RUBY-1824 Run "Local TLS" tests in Evergreen (#1370)
1 parent 94a7c15 commit c771ba1

File tree

11 files changed

+275
-97
lines changed

11 files changed

+275
-97
lines changed

.evergreen/.evg.yml

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,16 @@ functions:
347347
${PREPARE_SHELL}
348348
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests.sh
349349
350+
"run local tls tests":
351+
- command: shell.exec
352+
type: test
353+
params:
354+
shell: bash
355+
working_dir: "src"
356+
script: |
357+
${PREPARE_SHELL}
358+
MONGODB_URI="${MONGODB_URI}" .evergreen/run-local-tls-tests.sh
359+
350360
"run enterprise auth tests":
351361
- command: shell.exec
352362
type: test
@@ -370,7 +380,7 @@ functions:
370380
371381
ENTERPRISE_AUTH_TESTS=1 IP_ADDR=$IP_ADDR SASL_HOST=${sasl_host} SASL_PORT=${sasl_port} SASL_USER=${sasl_user} SASL_PASS=${sasl_pass} SASL_DB=${sasl_db} PRINCIPAL=${principal} KERBEROS_DB=${kerberos_db} KEYTAB_BASE64=${keytab_base64} PROJECT_DIRECTORY=${PROJECT_DIRECTORY} RVM_RUBY="${RVM_RUBY}" ${PROJECT_DIRECTORY}/.evergreen/run-enterprise-auth-tests.sh
372382
373-
"cleanup":
383+
"cleanup mo":
374384
- command: shell.exec
375385
params:
376386
script: |
@@ -383,8 +393,20 @@ functions:
383393
. venv/Scripts/activate
384394
fi
385395
mongo-orchestration stop
386-
cd -
387-
rm -rf $DRIVERS_TOOLS || true
396+
397+
"cleanup mo if running":
398+
- command: shell.exec
399+
params:
400+
script: |
401+
${PREPARE_SHELL}
402+
cd "$MONGO_ORCHESTRATION_HOME"
403+
# source the mongo-orchestration virtualenv if it exists
404+
if [ -f venv/bin/activate ]; then
405+
. venv/bin/activate
406+
elif [ -f venv/Scripts/activate ]; then
407+
. venv/Scripts/activate
408+
fi
409+
mongo-orchestration stop || true
388410
389411
"fix absolute paths":
390412
- command: shell.exec
@@ -422,13 +444,13 @@ functions:
422444
echo '{"results": [{ "status": "FAIL", "test_file": "Build", "log_raw": "No test-results.json found was created" } ]}' > ${PROJECT_DIRECTORY}/test-results.json
423445
424446
"install dependencies":
425-
type: test
426-
params:
427-
working_dir: "src"
428-
script: |
429-
${PREPARE_SHELL}
430-
file="${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh"
431-
[ -f ${file} ] && sh ${file} || echo "${file} not available, skipping"
447+
- command: shell.exec
448+
params:
449+
working_dir: "src"
450+
script: |
451+
${PREPARE_SHELL}
452+
file="${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh"
453+
[ -f $file ] && sh $file || echo "$file not available, skipping"
432454
433455
pre:
434456
- func: "fetch source"
@@ -445,7 +467,7 @@ post:
445467
- func: "upload mo artifacts"
446468
#- func: "upload test results"
447469
- func: "upload test results to s3"
448-
- func: "cleanup"
470+
- func: "cleanup mo if running"
449471

450472
tasks:
451473

@@ -464,6 +486,10 @@ tasks:
464486
commands:
465487
- func: "bootstrap mongo-orchestration"
466488
- func: "run tests"
489+
#- func: "cleanup mo"
490+
- name: "local-tls-tests"
491+
commands:
492+
- func: "run local tls tests"
467493
- name: "enterprise-auth-tests"
468494
commands:
469495
- func: "run enterprise auth tests"
@@ -825,6 +851,19 @@ buildvariants:
825851
tasks:
826852
- name: "test"
827853

854+
-
855+
matrix_name: "local-tls"
856+
matrix_spec:
857+
# No JRuby due to https://jira.mongodb.org/browse/RUBY-1830
858+
ruby: ["ruby-2.6", "ruby-1.9"]
859+
mongodb-version: '4.0'
860+
topology: standalone
861+
display_name: "Local TLS ${ruby}"
862+
run_on:
863+
- ubuntu1404-test
864+
tasks:
865+
- name: "local-tls-tests"
866+
828867
-
829868
matrix_name: "enterprise-auth-tests-ubuntu"
830869
matrix_spec:

.evergreen/functions.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,22 @@ kill_jruby() {
151151
for pid in $(ps -ef | grep "jruby" | grep -v grep | awk '{print $2}'); do kill -9 $pid; done
152152
fi
153153
}
154+
155+
prepare_server() {
156+
arch=$1
157+
version=$2
158+
159+
url=http://downloads.10gen.com/linux/mongodb-linux-x86_64-enterprise-$arch-$version.tgz
160+
mongodb_dir="$MONGO_ORCHESTRATION_HOME"/mdb
161+
mkdir -p "$mongodb_dir"
162+
curl $url |tar xz -C "$mongodb_dir" -f -
163+
BINDIR="$mongodb_dir"/`basename $url |sed -e s/.tgz//`/bin
164+
export PATH="$BINDIR":$PATH
165+
}
166+
167+
install_mlaunch() {
168+
pythonpath="$MONGO_ORCHESTRATION_HOME"/python
169+
pip install -t "$pythonpath" 'mtools[mlaunch]'
170+
export PATH="$pythonpath/bin":$PATH
171+
export PYTHONPATH="$pythonpath"
172+
}

.evergreen/install-dependencies.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
set -o xtrace # Write all commands first to stderr
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
# Inspiration:
7+
# https://github.com/mongodb/mongo-python-driver/blob/3.8.0/.evergreen/install-dependencies.sh#L5-L9
8+
9+
# Copy our test certificates over driver-evergreen-tools
10+
cp ${PROJECT_DIRECTORY}/spec/support/certificates/client.crt \
11+
${DRIVERS_TOOLS}/.evergreen/x509gen/client-public.pem
12+
cp ${PROJECT_DIRECTORY}/spec/support/certificates/client.key \
13+
${DRIVERS_TOOLS}/.evergreen/x509gen/client-private.pem
14+
cp ${PROJECT_DIRECTORY}/spec/support/certificates/ca.crt \
15+
${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem
16+
cp ${PROJECT_DIRECTORY}/spec/support/certificates/server-second-level-bundle.pem \
17+
${DRIVERS_TOOLS}/.evergreen/x509gen/server.pem
18+
19+
# Replace MongoOrchestration's client certificate.
20+
cp ${PROJECT_DIRECTORY}/spec/support/certificates/client.pem \
21+
${MONGO_ORCHESTRATION_HOME}/lib/client.pem

.evergreen/run-local-tls-tests.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
set -o xtrace # Write all commands first to stderr
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
# Supported/used environment variables:
7+
# AUTH Set to enable authentication. Values are: "auth" / "noauth" (default)
8+
# SSL Set to enable SSL. Values are "ssl" / "nossl" (default)
9+
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
10+
# TOPOLOGY Allows you to modify variables and the MONGODB_URI based on test topology
11+
# Supported values: "server", "replica_set", "sharded_cluster"
12+
# RVM_RUBY Define the Ruby version to test with, using its RVM identifier.
13+
# For example: "ruby-2.3" or "jruby-9.1"
14+
# DRIVER_TOOLS Path to driver tools.
15+
16+
. `dirname "$0"`/functions.sh
17+
18+
set_fcv
19+
set_env_vars
20+
21+
setup_ruby
22+
23+
install_deps
24+
25+
arch=ubuntu1404
26+
version=4.0.9
27+
prepare_server $arch $version
28+
29+
install_mlaunch
30+
31+
# Launching mongod under $MONGO_ORCHESTRATION_HOME
32+
# makes its long available through log collecting machinery
33+
34+
export dbdir="$MONGO_ORCHESTRATION_HOME"/db
35+
mkdir -p "$dbdir"
36+
mlaunch --dir "$dbdir" --binarypath "$BINDIR" --single \
37+
--sslMode requireSSL \
38+
--sslPEMKeyFile spec/support/certificates/server-second-level-bundle.pem \
39+
--sslCAFile spec/support/certificates/ca.crt \
40+
--sslClientCertificate spec/support/certificates/client.pem
41+
42+
echo "Running specs"
43+
export MONGODB_URI="mongodb://localhost:27017/?tls=true&serverSelectionTimeoutMS=30000&"\
44+
"tlsCAFile=spec/support/certificates/ca.crt&"\
45+
"tlsCertificateKeyFile=spec/support/certificates/client-second-level-bundle.pem"
46+
bundle exec rake spec:prepare
47+
48+
export MONGODB_URI="mongodb://localhost:27017/?tls=true&"\
49+
"tlsCAFile=spec/support/certificates/ca.crt&"\
50+
"tlsCertificateKeyFile=spec/support/certificates/client-second-level-bundle.pem"
51+
bundle exec rspec spec/mongo/socket*
52+
test_status=$?
53+
echo "TEST STATUS"
54+
echo ${test_status}
55+
56+
kill_jruby
57+
58+
mlaunch stop --dir "$dbdir"
59+
60+
exit ${test_status}

.evergreen/run-tests.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ set -o errexit # Exit the script with error if any of the commands fail
1818
set_fcv
1919
set_env_vars
2020

21-
export DRIVER_TOOLS_CLIENT_CERT_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/client-public.pem"
22-
export DRIVER_TOOLS_CLIENT_KEY_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/client-private.pem"
23-
export DRIVER_TOOLS_CLIENT_CERT_KEY_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem"
24-
export DRIVER_TOOLS_CA_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem"
25-
export DRIVER_TOOLS_CLIENT_KEY_ENCRYPTED_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/password_protected.pem"
21+
#export DRIVER_TOOLS_CLIENT_CERT_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/client-public.pem"
22+
#export DRIVER_TOOLS_CLIENT_KEY_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/client-private.pem"
23+
#export DRIVER_TOOLS_CLIENT_CERT_KEY_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem"
24+
#export DRIVER_TOOLS_CA_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem"
25+
#export DRIVER_TOOLS_CLIENT_KEY_ENCRYPTED_PEM="${DRIVERS_TOOLS}/.evergreen/x509gen/password_protected.pem"
2626

2727
setup_ruby
2828

spec/integration/ssl_uri_options_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require 'spec_helper'
22

33
describe 'SSL connections with URI options' do
4-
# SpecConfig currently creates clients exclusively through non-URI options. Because we don't
5-
# currently have a way to create what the URI would look like for a given client, it's simpler
6-
# just to test the that TLS works when configured from a URI on a standalone server without auth
7-
# required, since that allows us to build the URI more easily.
4+
# SpecConfig currently creates clients exclusively through non-URI options.
5+
# Because we don't currently have a way to create what the URI would look
6+
# like for a given client, it's simpler just to test the that TLS works when
7+
# configured from a URI on a standalone server without auth required, since
8+
# that allows us to build the URI more easily.
89
require_no_auth
910
require_topology :single
1011
require_ssl
@@ -14,7 +15,7 @@
1415
end
1516

1617
let(:uri) do
17-
"mongodb://#{hosts}/?tls=true&tlsInsecure=true&tlsCertificateKeyFile=#{SpecConfig.instance.client_cert_key_pem}"
18+
"mongodb://#{hosts}/?tls=true&tlsInsecure=true&tlsCertificateKeyFile=#{SpecConfig.instance.client_pem_path}"
1819
end
1920

2021
it 'successfully connects and runs an operation' do

spec/lite_spec_helper.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,6 @@
1818
CHANGE_STREAMS_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/change_streams/*.yml")
1919
CMAP_TESTS = Dir.glob("#{CURRENT_PATH}/spec_tests/data/cmap/*.yml")
2020

21-
if ENV['DRIVERS_TOOLS']
22-
CLIENT_CERT_PEM = ENV['DRIVER_TOOLS_CLIENT_CERT_PEM']
23-
CLIENT_KEY_PEM = ENV['DRIVER_TOOLS_CLIENT_KEY_PEM']
24-
CA_PEM = ENV['DRIVER_TOOLS_CA_PEM']
25-
CLIENT_KEY_ENCRYPTED_PEM = ENV['DRIVER_TOOLS_CLIENT_KEY_ENCRYPTED_PEM']
26-
else
27-
SSL_CERTS_DIR = "#{CURRENT_PATH}/support/certificates"
28-
CLIENT_PEM = "#{SSL_CERTS_DIR}/client.pem"
29-
CA_PEM = "#{SSL_CERTS_DIR}/ca.crt"
30-
CRL_PEM = "#{SSL_CERTS_DIR}/crl.pem"
31-
CLIENT_KEY_PEM = "#{SSL_CERTS_DIR}/client.key"
32-
CLIENT_CERT_PEM = "#{SSL_CERTS_DIR}/client.crt"
33-
CLIENT_KEY_ENCRYPTED_PEM = "#{SSL_CERTS_DIR}/client-encrypted.key"
34-
CLIENT_KEY_PASSPHRASE = "passphrase"
35-
end
36-
3721
require 'mongo'
3822

3923
unless ENV['CI']

spec/mongo/client_construction_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -318,23 +318,23 @@
318318

319319
let(:options) do
320320
{
321-
:ssl => true,
322-
:ssl_ca_cert => CA_PEM,
323-
:ssl_ca_cert_string => 'ca cert string',
324-
:ssl_ca_cert_object => 'ca cert object',
325-
:ssl_cert => CLIENT_CERT_PEM,
326-
:ssl_cert_string => 'cert string',
327-
:ssl_cert_object => 'cert object',
328-
:ssl_key => CLIENT_KEY_PEM,
329-
:ssl_key_string => 'key string',
330-
:ssl_key_object => 'key object',
331-
:ssl_key_pass_phrase => 'passphrase',
332-
:ssl_verify => true
321+
:ssl => true,
322+
:ssl_ca_cert => SpecConfig.instance.ca_cert_path,
323+
:ssl_ca_cert_string => 'ca cert string',
324+
:ssl_ca_cert_object => 'ca cert object',
325+
:ssl_cert => SpecConfig.instance.client_cert_path,
326+
:ssl_cert_string => 'cert string',
327+
:ssl_cert_object => 'cert object',
328+
:ssl_key => SpecConfig.instance.client_key_path,
329+
:ssl_key_string => 'key string',
330+
:ssl_key_object => 'key object',
331+
:ssl_key_pass_phrase => 'passphrase',
332+
:ssl_verify => true
333333
}
334334
end
335335

336336
let(:client) do
337-
new_local_client_nmio(['127.0.0.1:27017'], SpecConfig.instance.test_options.merge(options))
337+
new_local_client_nmio(['127.0.0.1:27017'], options)
338338
end
339339

340340
it 'sets the ssl option' do

0 commit comments

Comments
 (0)