-
Notifications
You must be signed in to change notification settings - Fork 533
RUBY-3361 Test x509 authentication on Atlas #2948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8130061
RUBY-3361 Test x509 authentication on Atlas
comandeo-mongo 2a296d7
Update spec/atlas/atlas_connectivity_spec.rb
comandeo-mongo fca394b
Update spec/atlas/atlas_connectivity_spec.rb
comandeo-mongo f5a2a9c
Update spec/atlas/atlas_connectivity_spec.rb
comandeo-mongo 8d80379
Cleanup
comandeo-mongo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,86 @@ | ||
| # frozen_string_literal: true | ||
| # rubocop:todo all | ||
|
|
||
| require 'lite_spec_helper' | ||
| require 'base64' | ||
| require 'tempfile' | ||
|
|
||
| RSpec.shared_examples 'atlas connectivity test' do | ||
| after do | ||
| client.close | ||
| rescue StandardError | ||
| # no-op | ||
| end | ||
|
|
||
| it 'runs hello successfully' do | ||
| expect { client.database.command(ping: 1) } | ||
| .not_to raise_error | ||
| end | ||
| end | ||
|
|
||
| describe 'Atlas connectivity' do | ||
| let(:uri) { ENV['ATLAS_URI'] } | ||
| let(:client) { Mongo::Client.new(uri) } | ||
| before do | ||
| skip 'These tests must be run against a live Atlas cluster' unless ENV['ATLAS_TESTING'] | ||
| end | ||
|
|
||
| require_atlas | ||
| context 'with regular authentication' do | ||
| regular_auth_env_vars = %w[ | ||
| ATLAS_REPLICA_SET_URI | ||
| ATLAS_SHARDED_URI | ||
| ATLAS_FREE_TIER_URI | ||
| ATLAS_TLS11_URI | ||
| ATLAS_TLS12_URI | ||
| ] | ||
|
|
||
| describe 'connection to Atlas' do | ||
| after do | ||
| client.close | ||
| end | ||
| regular_auth_env_vars.each do |uri_var| | ||
| describe "Connecting to #{uri_var}" do | ||
| before do | ||
| raise "Environment variable #{uri_var} is not set" unless ENV[uri_var] | ||
| end | ||
|
|
||
| let(:uri) { ENV[uri_var] } | ||
|
|
||
| it 'runs ismaster successfully' do | ||
| expect { client.database.command(:hello => 1) } | ||
| .not_to raise_error | ||
| let(:client) { Mongo::Client.new(uri) } | ||
|
|
||
| include_examples 'atlas connectivity test' | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'with X.509 authentication' do | ||
| x509_auth_env_vars = [ | ||
| %w[ATLAS_X509_URI ATLAS_X509_CERT_BASE64], | ||
| %w[ATLAS_X509_DEV_URI ATLAS_X509_DEV_CERT_BASE64] | ||
| ] | ||
|
|
||
| x509_auth_env_vars.each do |uri_var, cert_var| | ||
| describe "Connecting to #{uri_var} with certificate" do | ||
| before do | ||
| raise "Environment variable #{uri_var} is not set" unless ENV[uri_var] | ||
| end | ||
|
|
||
| let(:client_cert) do | ||
| decoded = Base64.strict_decode64(ENV[cert_var]) | ||
| cert_file = Tempfile.new([ 'x509-cert', '.pem' ]) | ||
| cert_file.write(decoded) | ||
| File.chmod(0o600, cert_file.path) | ||
| cert_file.close | ||
| cert_file | ||
| end | ||
|
|
||
| let(:uri) do | ||
| "#{ENV[uri_var]}&tlsCertificateKeyFile=#{URI::DEFAULT_PARSER.escape(client_cert.path)}" | ||
| end | ||
|
|
||
| let(:client) do | ||
| Mongo::Client.new(uri) | ||
| end | ||
|
|
||
| after do | ||
| client_cert&.unlink | ||
| end | ||
|
|
||
| it 'runs findOne successfully' do | ||
| expect { client.use(:test)['test'].find.to_a } | ||
| .not_to raise_error | ||
| include_examples 'atlas connectivity test' | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.