Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 56e37c1

Browse files
RUBY-3361 Test x509 authentication on Atlas (#2948)
1 parent 8043444 commit 56e37c1

File tree

6 files changed

+106
-161
lines changed

6 files changed

+106
-161
lines changed

‎.evergreen/config.yml‎

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ functions:
122122
export ATLAS_TLS12_URI="${atlas_tls12_uri}"
123123
export ATLAS_SERVERLESS_URI="${atlas_serverless_uri}"
124124
export ATLAS_SERVERLESS_LB_URI="${atlas_serverless_lb_uri}"
125+
export ATLAS_X509_CERT_BASE64="${atlas_x509_cert_base64}"
126+
export ATLAS_X509_URI="${atlas_x509}"
127+
export ATLAS_X509_DEV_CERT_BASE64="${atlas_x509_dev_cert_base64}"
128+
export ATLAS_X509_DEV_URI="${atlas_x509_dev}"
125129
export RVM_RUBY="${RVM_RUBY}"
126130
127131
export SERVERLESS_DRIVERS_GROUP="${SERVERLESS_DRIVERS_GROUP}"
@@ -456,7 +460,16 @@ functions:
456460
working_dir: "src"
457461
script: |
458462
${PREPARE_SHELL}
459-
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests-atlas.sh
463+
AUTH=${AUTH} SSL=${SSL} TOPOLOGY=${TOPOLOGY} RVM_RUBY="${RVM_RUBY}" \
464+
ATLAS_REPLICA_SET_URI=${atlas_replica_set_uri} ATLAS_SHARDED_URI=${atlas_sharded_uri} \
465+
ATLAS_FREE_TIER_URI=${atlas_free_tier_uri} ATLAS_TLS11_URI=${atlas_tls11_uri} \
466+
ATLAS_TLS12_URI=${atlas_tls12_uri} ATLAS_SERVERLESS_URI=${atlas_serverless_uri} \
467+
ATLAS_SERVERLESS_LB_URI=${atlas_serverless_lb_uri} \
468+
ATLAS_X509_CERT_BASE64="${atlas_x509_cert_base64}" \
469+
ATLAS_X509_URI="${atlas_x509}" \
470+
ATLAS_X509_DEV_CERT_BASE64="${atlas_x509_dev_cert_base64}" \
471+
ATLAS_X509_DEV_URI="${atlas_x509_dev}" \
472+
.evergreen/run-tests-atlas.sh
460473
461474
"run serverless tests":
462475
- command: shell.exec
@@ -518,56 +531,6 @@ task_groups:
518531
tasks:
519532
- "test-serverless"
520533

521-
- name: testatlas_task_group
522-
setup_group_can_fail_task: true
523-
setup_group_timeout_secs: 1800 # 30 minutes
524-
setup_group:
525-
- func: fetch source
526-
- func: create expansions
527-
- command: shell.exec
528-
params:
529-
shell: "bash"
530-
working_dir: "src"
531-
script: |
532-
${PREPARE_SHELL}
533-
534-
echo "Setting up Atlas cluster"
535-
536-
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
537-
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
538-
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
539-
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
540-
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
541-
DRIVERS_ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL}" \
542-
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
543-
MONGODB_VERSION="7.0" \
544-
task_id="${task_id}" \
545-
execution="${execution}" \
546-
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
547-
548-
echo "MONGODB_URI=${MONGODB_URI}"
549-
- command: expansions.update
550-
params:
551-
file: src/atlas-expansion.yml
552-
teardown_group:
553-
- command: shell.exec
554-
params:
555-
shell: "bash"
556-
working_dir: "src"
557-
script: |
558-
${PREPARE_SHELL}
559-
560-
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
561-
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
562-
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
563-
DRIVERS_ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL}" \
564-
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
565-
task_id="${task_id}" \
566-
execution="${execution}" \
567-
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
568-
tasks:
569-
- test-atlas
570-
571534
- name: testatlas_full_task_group
572535
setup_group_can_fail_task: true
573536
setup_group_timeout_secs: 1800 # 30 minutes
@@ -1946,9 +1909,9 @@ buildvariants:
19461909
matrix_spec:
19471910
ruby: ["ruby-3.3", "ruby-3.2", "ruby-3.1"]
19481911
os: ubuntu2204
1949-
display_name: "Atlas tests ${ruby}"
1912+
display_name: "Atlas connectivity tests ${ruby}"
19501913
tasks:
1951-
- name: testatlas_task_group
1914+
- name: test-atlas
19521915

19531916
- matrix_name: "aws-lambda"
19541917
matrix_spec:

‎.evergreen/config/common.yml.erb‎

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ functions:
119119
export ATLAS_TLS12_URI="${atlas_tls12_uri}"
120120
export ATLAS_SERVERLESS_URI="${atlas_serverless_uri}"
121121
export ATLAS_SERVERLESS_LB_URI="${atlas_serverless_lb_uri}"
122+
export ATLAS_X509_CERT_BASE64="${atlas_x509_cert_base64}"
123+
export ATLAS_X509_URI="${atlas_x509}"
124+
export ATLAS_X509_DEV_CERT_BASE64="${atlas_x509_dev_cert_base64}"
125+
export ATLAS_X509_DEV_URI="${atlas_x509_dev}"
122126
export RVM_RUBY="${RVM_RUBY}"
123127

124128
export SERVERLESS_DRIVERS_GROUP="${SERVERLESS_DRIVERS_GROUP}"
@@ -453,7 +457,16 @@ functions:
453457
working_dir: "src"
454458
script: |
455459
${PREPARE_SHELL}
456-
MONGODB_URI="${MONGODB_URI}" .evergreen/run-tests-atlas.sh
460+
AUTH=${AUTH} SSL=${SSL} TOPOLOGY=${TOPOLOGY} RVM_RUBY="${RVM_RUBY}" \
461+
ATLAS_REPLICA_SET_URI=${atlas_replica_set_uri} ATLAS_SHARDED_URI=${atlas_sharded_uri} \
462+
ATLAS_FREE_TIER_URI=${atlas_free_tier_uri} ATLAS_TLS11_URI=${atlas_tls11_uri} \
463+
ATLAS_TLS12_URI=${atlas_tls12_uri} ATLAS_SERVERLESS_URI=${atlas_serverless_uri} \
464+
ATLAS_SERVERLESS_LB_URI=${atlas_serverless_lb_uri} \
465+
ATLAS_X509_CERT_BASE64="${atlas_x509_cert_base64}" \
466+
ATLAS_X509_URI="${atlas_x509}" \
467+
ATLAS_X509_DEV_CERT_BASE64="${atlas_x509_dev_cert_base64}" \
468+
ATLAS_X509_DEV_URI="${atlas_x509_dev}" \
469+
.evergreen/run-tests-atlas.sh
457470

458471
"run serverless tests":
459472
- command: shell.exec
@@ -515,56 +528,6 @@ task_groups:
515528
tasks:
516529
- "test-serverless"
517530

518-
- name: testatlas_task_group
519-
setup_group_can_fail_task: true
520-
setup_group_timeout_secs: 1800 # 30 minutes
521-
setup_group:
522-
- func: fetch source
523-
- func: create expansions
524-
- command: shell.exec
525-
params:
526-
shell: "bash"
527-
working_dir: "src"
528-
script: |
529-
${PREPARE_SHELL}
530-
531-
echo "Setting up Atlas cluster"
532-
533-
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
534-
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
535-
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
536-
DRIVERS_ATLAS_LAMBDA_USER="${DRIVERS_ATLAS_LAMBDA_USER}" \
537-
DRIVERS_ATLAS_LAMBDA_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}" \
538-
DRIVERS_ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL}" \
539-
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
540-
MONGODB_VERSION="7.0" \
541-
task_id="${task_id}" \
542-
execution="${execution}" \
543-
$DRIVERS_TOOLS/.evergreen/atlas/setup-atlas-cluster.sh
544-
545-
echo "MONGODB_URI=${MONGODB_URI}"
546-
- command: expansions.update
547-
params:
548-
file: src/atlas-expansion.yml
549-
teardown_group:
550-
- command: shell.exec
551-
params:
552-
shell: "bash"
553-
working_dir: "src"
554-
script: |
555-
${PREPARE_SHELL}
556-
557-
DRIVERS_ATLAS_PUBLIC_API_KEY="${DRIVERS_ATLAS_PUBLIC_API_KEY}" \
558-
DRIVERS_ATLAS_PRIVATE_API_KEY="${DRIVERS_ATLAS_PRIVATE_API_KEY}" \
559-
DRIVERS_ATLAS_GROUP_ID="${DRIVERS_ATLAS_GROUP_ID}" \
560-
DRIVERS_ATLAS_BASE_URL="${DRIVERS_ATLAS_BASE_URL}" \
561-
LAMBDA_STACK_NAME="dbx-ruby-lambda" \
562-
task_id="${task_id}" \
563-
execution="${execution}" \
564-
$DRIVERS_TOOLS/.evergreen/atlas/teardown-atlas-cluster.sh
565-
tasks:
566-
- test-atlas
567-
568531
- name: testatlas_full_task_group
569532
setup_group_can_fail_task: true
570533
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}
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)

AltStyle によって変換されたページ (->オリジナル) /