Skip to content

Commit ee1931c

Browse files
committed
Ability to run test suite on ssl
1 parent 2f38db3 commit ee1931c

File tree

10 files changed

+57
-44
lines changed

10 files changed

+57
-44
lines changed

spec/mongo/auth/cr_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
end
88

99
let(:server) do
10-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
10+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
1111
end
1212

1313
let(:connection) do
14-
Mongo::Server::Connection.new(server)
14+
Mongo::Server::Connection.new(server, TEST_OPTIONS)
1515
end
1616

1717
describe '#login' do

spec/mongo/auth/ldap_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
end
88

99
let(:server) do
10-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
10+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
1111
end
1212

1313
let(:connection) do
14-
Mongo::Server::Connection.new(server)
14+
Mongo::Server::Connection.new(server, TEST_OPTIONS)
1515
end
1616

1717
let(:user) do

spec/mongo/auth/scram_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
end
88

99
let(:server) do
10-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
10+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
1111
end
1212

1313
let(:connection) do
14-
Mongo::Server::Connection.new(server)
14+
Mongo::Server::Connection.new(server, TEST_OPTIONS)
1515
end
1616

1717
describe '#login' do

spec/mongo/auth/x509_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
end
88

99
let(:server) do
10-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
10+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
1111
end
1212

1313
let(:connection) do
14-
Mongo::Server::Connection.new(server)
14+
Mongo::Server::Connection.new(server, TEST_OPTIONS)
1515
end
1616

1717
let(:user) do

spec/mongo/cluster_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
describe Mongo::Cluster do
44

55
let(:cluster) do
6-
described_class.new(ADDRESSES)
6+
described_class.new(ADDRESSES, TEST_OPTIONS)
77
end
88

9+
910
describe '#==' do
1011

1112
context 'when the other is a cluster' do
@@ -15,7 +16,7 @@
1516
context 'when the options are the same' do
1617

1718
let(:other) do
18-
described_class.new([ '127.0.0.1:27017' ])
19+
described_class.new(ADDRESSES, TEST_OPTIONS)
1920
end
2021

2122
it 'returns true' do
@@ -26,7 +27,7 @@
2627
context 'when the options are not the same' do
2728

2829
let(:other) do
29-
described_class.new([ '127.0.0.1:27017' ], :replica_set => 'test')
30+
described_class.new([ '127.0.0.1:27017' ], TEST_OPTIONS.merge(:replica_set => 'test'))
3031
end
3132

3233
it 'returns false' do
@@ -80,7 +81,7 @@
8081
context 'when the option is provided' do
8182

8283
let(:cluster) do
83-
described_class.new(ADDRESSES, :replica_set => 'testing')
84+
described_class.new(ADDRESSES, TEST_OPTIONS.merge(:replica_set => 'testing'))
8485
end
8586

8687
it 'returns the name' do
@@ -91,7 +92,7 @@
9192
context 'when the option is not provided' do
9293

9394
let(:cluster) do
94-
described_class.new(ADDRESSES)
95+
described_class.new(ADDRESSES, TEST_OPTIONS)
9596
end
9697

9798
it 'returns nil' do

spec/mongo/server/connection_spec.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
end
88

99
let(:server) do
10-
Mongo::Server.new(address, Mongo::Event::Listeners.new)
10+
Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
1111
end
1212

1313
describe '#connect!' do
@@ -66,9 +66,10 @@
6666
let(:connection) do
6767
described_class.new(
6868
server,
69-
:user => 'notauser',
70-
:password => 'password',
71-
:database => TEST_DB
69+
TEST_OPTIONS.merge(
70+
:user => 'notauser',
71+
:password => 'password',
72+
:database => TEST_DB )
7273
)
7374
end
7475

@@ -84,9 +85,10 @@
8485
let(:connection) do
8586
described_class.new(
8687
server,
87-
:user => TEST_USER.name,
88-
:password => TEST_USER.password,
89-
:database => TEST_DB
88+
TEST_OPTIONS.merge(
89+
:user => TEST_USER.name,
90+
:password => TEST_USER.password,
91+
:database => TEST_DB )
9092
)
9193
end
9294

@@ -136,9 +138,10 @@
136138
let!(:connection) do
137139
described_class.new(
138140
server,
139-
:user => TEST_USER.name,
140-
:password => TEST_USER.password,
141-
:database => TEST_DB
141+
TEST_OPTIONS.merge(
142+
:user => TEST_USER.name,
143+
:password => TEST_USER.password,
144+
:database => TEST_DB )
142145
)
143146
end
144147

spec/mongo/server/monitor_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
context 'when calling multiple times in succession' do
1616

1717
let(:monitor) do
18-
described_class.new(address, listeners)
18+
described_class.new(address, listeners, TEST_OPTIONS)
1919
end
2020

2121
it 'throttles the scans to minimum 500ms' do
@@ -29,7 +29,7 @@
2929
context 'when the ismaster command succeeds' do
3030

3131
let(:monitor) do
32-
described_class.new(address, listeners)
32+
described_class.new(address, listeners, TEST_OPTIONS)
3333
end
3434

3535
before do

spec/mongo/socket/ssl_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
describe '#connect!', if: running_ssl? do
66

77
let(:socket) do
8-
described_class.new('localhost', 27017, 5, Socket::PF_INET, options)
8+
described_class.new(*DEFAULT_ADDRESS.split(":"), 5, Socket::PF_INET, options)
99
end
1010

1111
context 'when a certificate is provided' do

spec/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def list_command_enabled?
147147
end
148148

149149
def running_ssl?
150-
!!ENV['SSL']
150+
SSL
151151
end
152152

153153
alias :scram_sha_1_enabled? :list_command_enabled?
@@ -165,7 +165,7 @@ def failing_delete_doc
165165
#
166166
# @since 2.0.0
167167
def initialize_scanned_client!
168-
Mongo::Client.new(ADDRESSES, database: TEST_DB, connect: CONNECT)
168+
Mongo::Client.new(ADDRESSES, TEST_OPTIONS.merge(database: TEST_DB))
169169
end
170170

171171
# require all shared examples

spec/support/authorization.rb

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@
4040
ENV['SHARDED_ENABLED'] == 'true' ? :sharded.freeze :
4141
:direct.freeze
4242

43+
# The write concern to use in the tests.
44+
#
45+
# @since 2.0.0
46+
WRITE_CONCERN = (CONNECT == :replica_set) ? { w: ADDRESSES.size } : { w: 1 }
47+
48+
# Whether to use SSL.
49+
#
50+
# @since 2.0.3
51+
SSL = ENV['SSL_ENABLED'] == 'true'
52+
53+
# Options for test suite clients.
54+
#
55+
# @since 2.0.3
56+
TEST_OPTIONS = { max_pool_size: 1,
57+
write: WRITE_CONCERN,
58+
ssl: SSL }
59+
4360
# The root user name.
4461
#
4562
# @since 2.0.0
@@ -93,32 +110,25 @@
93110
roles: [ Mongo::Auth::Roles::READ_WRITE, Mongo::Auth::Roles::DATABASE_ADMIN ]
94111
)
95112

96-
# The write concern to use in the tests.
97-
#
98-
# @since 2.0.0
99-
WRITE_CONCERN = (CONNECT == :replica_set) ? { w: ADDRESSES.size } : { w: 1 }
100-
101113
# Provides an authorized mongo client on the default test database for the
102114
# default test user.
103115
#
104116
# @since 2.0.0
105117
AUTHORIZED_CLIENT = Mongo::Client.new(
106118
ADDRESSES,
107-
database: TEST_DB,
108-
user: TEST_USER.name,
109-
password: TEST_USER.password,
110-
max_pool_size: 1,
111-
write: WRITE_CONCERN
119+
TEST_OPTIONS.merge(
120+
database: TEST_DB,
121+
user: TEST_USER.name,
122+
password: TEST_USER.password)
112123
)
113124

114125
# Provides an unauthorized mongo client on the default test database.
115126
#
116127
# @since 2.0.0
117128
UNAUTHORIZED_CLIENT = Mongo::Client.new(
118129
ADDRESSES,
119-
database: TEST_DB,
120-
max_pool_size: 1,
121-
write: WRITE_CONCERN
130+
TEST_OPTIONS.merge(
131+
database: TEST_DB)
122132
)
123133

124134
# Provides an unauthorized mongo client on the admin database, for use in
@@ -127,9 +137,8 @@
127137
# @since 2.0.0
128138
ADMIN_UNAUTHORIZED_CLIENT = Mongo::Client.new(
129139
ADDRESSES,
130-
database: Mongo::Database::ADMIN,
131-
max_pool_size: 1,
132-
write: WRITE_CONCERN
140+
TEST_OPTIONS.merge(
141+
database: Mongo::Database::ADMIN)
133142
)
134143

135144
# Get an authorized client on the test database logged in as the admin

0 commit comments

Comments
 (0)