Skip to content

Commit 16c6307

Browse files
committed
Merge branch 'master' into 3115-remove-serverless
2 parents 5f8e7d0 + 56e37c1 commit 16c6307

File tree

8 files changed

+141
-266
lines changed

8 files changed

+141
-266
lines changed

.evergreen/config.yml

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,16 @@ functions:
410410
working_dir: "src"
411411
script: |
412412
${PREPARE_SHELL}
413-
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests-atlas.sh
413+
AUTH=${AUTH} SSL=${SSL} TOPOLOGY=${TOPOLOGY} RVM_RUBY="${RVM_RUBY}" \
414+
ATLAS_REPLICA_SET_URI=${atlas_replica_set_uri} ATLAS_SHARDED_URI=${atlas_sharded_uri} \
415+
ATLAS_FREE_TIER_URI=${atlas_free_tier_uri} ATLAS_TLS11_URI=${atlas_tls11_uri} \
416+
ATLAS_TLS12_URI=${atlas_tls12_uri} ATLAS_SERVERLESS_URI=${atlas_serverless_uri} \
417+
ATLAS_SERVERLESS_LB_URI=${atlas_serverless_lb_uri} \
418+
ATLAS_X509_CERT_BASE64="${atlas_x509_cert_base64}" \
419+
ATLAS_X509_URI="${atlas_x509}" \
420+
ATLAS_X509_DEV_CERT_BASE64="${atlas_x509_dev_cert_base64}" \
421+
ATLAS_X509_DEV_URI="${atlas_x509_dev}" \
422+
.evergreen/run-tests-atlas.sh
414423
415424
pre:
416425
- func: "fetch source"
@@ -425,56 +434,6 @@ post:
425434
- func: "upload test results to s3"
426435

427436
task_groups:
428-
- name: testatlas_task_group
429-
setup_group_can_fail_task: true
430-
setup_group_timeout_secs: 1800 # 30 minutes
431-
setup_group:
432-
- func: fetch source
433-
- func: create expansions
434-
- command: shell.exec
435-
params:
436-
shell: "bash"
437-
working_dir: "src"
438-
script: |
439-
${PREPARE_SHELL}
440-
441-
echo "Setting up Atlas cluster"
442-
443-
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
444-
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
445-
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
446-
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
447-
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
448-
DRIVERS_ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL}" \
449-
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
450-
MONGODB_VERSION="7.0" \
451-
task_id="${task_id}" \
452-
execution="${execution}" \
453-
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
454-
455-
echo "MONGODB_URI=${MONGODB_URI}"
456-
- command: expansions.update
457-
params:
458-
file: src/atlas-expansion.yml
459-
teardown_group:
460-
- command: shell.exec
461-
params:
462-
shell: "bash"
463-
working_dir: "src"
464-
script: |
465-
${PREPARE_SHELL}
466-
467-
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
468-
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
469-
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
470-
DRIVERS_ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL}" \
471-
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
472-
task_id="${task_id}" \
473-
execution="${execution}" \
474-
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
475-
tasks:
476-
- test-atlas
477-
478437
- name: testatlas_full_task_group
479438
setup_group_can_fail_task: true
480439
setup_group_timeout_secs: 1800 # 30 minutes
@@ -1835,9 +1794,9 @@ buildvariants:
18351794
matrix_spec:
18361795
ruby: ["ruby-3.3", "ruby-3.2", "ruby-3.1"]
18371796
os: ubuntu2204
1838-
display_name: "Atlas tests ${ruby}"
1797+
display_name: "Atlas connectivity tests ${ruby}"
18391798
tasks:
1840-
- name: testatlas_task_group
1799+
- name: test-atlas
18411800

18421801
- matrix_name: "aws-lambda"
18431802
matrix_spec:

.evergreen/config/common.yml.erb

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,16 @@ functions:
407407
working_dir: "src"
408408
script: |
409409
${PREPARE_SHELL}
410-
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests-atlas.sh
410+
AUTH=${AUTH} SSL=${SSL} TOPOLOGY=${TOPOLOGY} RVM_RUBY="${RVM_RUBY}" \
411+
ATLAS_REPLICA_SET_URI=${atlas_replica_set_uri} ATLAS_SHARDED_URI=${atlas_sharded_uri} \
412+
ATLAS_FREE_TIER_URI=${atlas_free_tier_uri} ATLAS_TLS11_URI=${atlas_tls11_uri} \
413+
ATLAS_TLS12_URI=${atlas_tls12_uri} ATLAS_SERVERLESS_URI=${atlas_serverless_uri} \
414+
ATLAS_SERVERLESS_LB_URI=${atlas_serverless_lb_uri} \
415+
ATLAS_X509_CERT_BASE64="${atlas_x509_cert_base64}" \
416+
ATLAS_X509_URI="${atlas_x509}" \
417+
ATLAS_X509_DEV_CERT_BASE64="${atlas_x509_dev_cert_base64}" \
418+
ATLAS_X509_DEV_URI="${atlas_x509_dev}" \
419+
.evergreen/run-tests-atlas.sh
411420

412421
pre:
413422
- func: "fetch source"
@@ -422,56 +431,6 @@ post:
422431
- func: "upload test results to s3"
423432

424433
task_groups:
425-
- name: testatlas_task_group
426-
setup_group_can_fail_task: true
427-
setup_group_timeout_secs: 1800 # 30 minutes
428-
setup_group:
429-
- func: fetch source
430-
- func: create expansions
431-
- command: shell.exec
432-
params:
433-
shell: "bash"
434-
working_dir: "src"
435-
script: |
436-
${PREPARE_SHELL}
437-
438-
echo "Setting up Atlas cluster"
439-
440-
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
441-
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
442-
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
443-
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
444-
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
445-
DRIVERS_ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL}" \
446-
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
447-
MONGODB_VERSION="7.0" \
448-
task_id="${task_id}" \
449-
execution="${execution}" \
450-
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
451-
452-
echo "MONGODB_URI=${MONGODB_URI}"
453-
- command: expansions.update
454-
params:
455-
file: src/atlas-expansion.yml
456-
teardown_group:
457-
- command: shell.exec
458-
params:
459-
shell: "bash"
460-
working_dir: "src"
461-
script: |
462-
${PREPARE_SHELL}
463-
464-
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
465-
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
466-
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
467-
DRIVERS_ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL}" \
468-
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
469-
task_id="${task_id}" \
470-
execution="${execution}" \
471-
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
472-
tasks:
473-
- test-atlas
474-
475434
- name: testatlas_full_task_group
476435
setup_group_can_fail_task: true
477436
setup_group_timeout_secs: 1800 # 30 minutes

.evergreen/config/standard.yml.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ buildvariants:
519519
matrix_spec:
520520
ruby: <%= supported_mri_rubies_3_ubuntu %>
521521
os: ubuntu2204
522-
display_name: "Atlas tests ${ruby}"
522+
display_name: "Atlas connectivity tests ${ruby}"
523523
tasks:
524-
- name: testatlas_task_group
524+
- name: test-atlas
525525

526526
- matrix_name: "aws-lambda"
527527
matrix_spec:

.evergreen/run-tests-atlas.sh

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ bundle_install
1414

1515
echo "Running specs"
1616

17-
test_status=0
18-
export ATLAS_URI=$MONGODB_URI
19-
20-
if test -z "$ATLAS_URI"; then
21-
echo "The \$$uri environment variable was not set" 1>&2
22-
test_status=1
23-
fi
17+
export ATLAS_TESTING=1
2418

2519
bundle exec rspec spec/atlas -fd
26-
this_test_status=$?
27-
echo "TEST STATUS"
28-
echo ${this_test_status}
29-
30-
if test $this_test_status != 0; then
31-
test_status=$this_test_status
32-
fi
33-
34-
kill_jruby
35-
36-
exit ${test_status}

lib/mongo/socket/ssl.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Socket
2323
# @since 2.0.0
2424
class SSL < Socket
2525
include OpenSSL
26+
include Loggable
2627

2728
# Initializes a new TLS socket.
2829
#
@@ -455,12 +456,15 @@ def verify_certificate!(socket)
455456
end
456457

457458
def verify_ocsp_endpoint!(socket, timeout = nil)
458-
unless verify_ocsp_endpoint?
459-
return
460-
end
459+
return unless verify_ocsp_endpoint?
461460

462461
cert = socket.peer_cert
463-
ca_cert = socket.peer_cert_chain.last
462+
ca_cert = find_issuer(cert, socket.peer_cert_chain)
463+
464+
unless ca_cert
465+
log_warn("TLS certificate of '#{host_name}' could not be definitively verified via OCSP: issuer certificate not found in the chain.")
466+
return
467+
end
464468

465469
verifier = OcspVerifier.new(@host_name, cert, ca_cert, context.cert_store,
466470
**Utils.shallow_symbolize_keys(options).merge(timeout: timeout))
@@ -503,6 +507,11 @@ def extract_certs(text)
503507
end
504508
end
505509
end
510+
511+
# Find the issuer certificate in the chain.
512+
def find_issuer(cert, cert_chain)
513+
cert_chain.find { |c| c.subject == cert.issuer }
514+
end
506515
end
507516
end
508517
end

spec/atlas/atlas_connectivity_spec.rb

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,86 @@
11
# frozen_string_literal: true
2-
# rubocop:todo all
32

43
require 'lite_spec_helper'
4+
require 'base64'
5+
require 'tempfile'
6+
7+
RSpec.shared_examples 'atlas connectivity test' do
8+
after do
9+
client.close
10+
rescue StandardError
11+
# no-op
12+
end
13+
14+
it 'runs hello successfully' do
15+
expect { client.database.command(ping: 1) }
16+
.not_to raise_error
17+
end
18+
end
519

620
describe 'Atlas connectivity' do
7-
let(:uri) { ENV['ATLAS_URI'] }
8-
let(:client) { Mongo::Client.new(uri) }
21+
before do
22+
skip 'These tests must be run against a live Atlas cluster' unless ENV['ATLAS_TESTING']
23+
end
924

10-
require_atlas
25+
context 'with regular authentication' do
26+
regular_auth_env_vars = %w[
27+
ATLAS_REPLICA_SET_URI
28+
ATLAS_SHARDED_URI
29+
ATLAS_FREE_TIER_URI
30+
ATLAS_TLS11_URI
31+
ATLAS_TLS12_URI
32+
]
1133

12-
describe 'connection to Atlas' do
13-
after do
14-
client.close
15-
end
34+
regular_auth_env_vars.each do |uri_var|
35+
describe "Connecting to #{uri_var}" do
36+
before do
37+
raise "Environment variable #{uri_var} is not set" unless ENV[uri_var]
38+
end
39+
40+
let(:uri) { ENV[uri_var] }
1641

17-
it 'runs ismaster successfully' do
18-
expect { client.database.command(:hello => 1) }
19-
.not_to raise_error
42+
let(:client) { Mongo::Client.new(uri) }
43+
44+
include_examples 'atlas connectivity test'
45+
end
2046
end
47+
end
48+
49+
context 'with X.509 authentication' do
50+
x509_auth_env_vars = [
51+
%w[ATLAS_X509_URI ATLAS_X509_CERT_BASE64],
52+
%w[ATLAS_X509_DEV_URI ATLAS_X509_DEV_CERT_BASE64]
53+
]
54+
55+
x509_auth_env_vars.each do |uri_var, cert_var|
56+
describe "Connecting to #{uri_var} with certificate" do
57+
before do
58+
raise "Environment variable #{uri_var} is not set" unless ENV[uri_var]
59+
end
60+
61+
let(:client_cert) do
62+
decoded = Base64.strict_decode64(ENV[cert_var])
63+
cert_file = Tempfile.new([ 'x509-cert', '.pem' ])
64+
cert_file.write(decoded)
65+
File.chmod(0o600, cert_file.path)
66+
cert_file.close
67+
cert_file
68+
end
69+
70+
let(:uri) do
71+
"#{ENV[uri_var]}&tlsCertificateKeyFile=#{URI::DEFAULT_PARSER.escape(client_cert.path)}"
72+
end
73+
74+
let(:client) do
75+
Mongo::Client.new(uri)
76+
end
77+
78+
after do
79+
client_cert&.unlink
80+
end
2181

22-
it 'runs findOne successfully' do
23-
expect { client.use(:test)['test'].find.to_a }
24-
.not_to raise_error
82+
include_examples 'atlas connectivity test'
83+
end
2584
end
2685
end
2786
end

spec/atlas/operations_spec.rb

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

0 commit comments

Comments
 (0)