mongo 1.9.2 → 1.10.0.rc0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +1 -1
- data/README.md +94 -334
- data/Rakefile +6 -4
- data/VERSION +1 -1
- data/bin/mongo_console +13 -6
- data/lib/mongo.rb +22 -27
- data/lib/mongo/bulk_write_collection_view.rb +352 -0
- data/lib/mongo/collection.rb +128 -188
- data/lib/mongo/collection_writer.rb +348 -0
- data/lib/mongo/connection.rb +19 -0
- data/lib/mongo/{util → connection}/node.rb +15 -1
- data/lib/mongo/{util → connection}/pool.rb +34 -19
- data/lib/mongo/{util → connection}/pool_manager.rb +8 -2
- data/lib/mongo/{util → connection}/sharding_pool_manager.rb +1 -1
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/{util → connection/socket}/socket_util.rb +5 -2
- data/lib/mongo/{util → connection/socket}/ssl_socket.rb +3 -4
- data/lib/mongo/{util → connection/socket}/tcp_socket.rb +25 -15
- data/lib/mongo/{util → connection/socket}/unix_socket.rb +6 -4
- data/lib/mongo/cursor.rb +113 -47
- data/lib/mongo/db.rb +203 -131
- data/lib/mongo/{exceptions.rb → exception.rb} +7 -1
- data/lib/mongo/functional.rb +19 -0
- data/lib/mongo/functional/authentication.rb +303 -0
- data/lib/mongo/{util → functional}/logging.rb +1 -1
- data/lib/mongo/{util → functional}/read_preference.rb +49 -1
- data/lib/mongo/{util → functional}/uri_parser.rb +81 -69
- data/lib/mongo/{util → functional}/write_concern.rb +2 -1
- data/{test/unit/pool_test.rb → lib/mongo/gridfs.rb} +5 -10
- data/lib/mongo/gridfs/grid.rb +1 -3
- data/lib/mongo/gridfs/grid_ext.rb +1 -1
- data/lib/mongo/gridfs/grid_file_system.rb +1 -1
- data/lib/mongo/gridfs/grid_io.rb +1 -1
- data/lib/mongo/legacy.rb +63 -8
- data/lib/mongo/mongo_client.rb +128 -154
- data/lib/mongo/mongo_replica_set_client.rb +17 -11
- data/lib/mongo/mongo_sharded_client.rb +2 -1
- data/lib/mongo/networking.rb +19 -10
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo/{util → utils}/conversions.rb +1 -1
- data/lib/mongo/{util → utils}/core_ext.rb +1 -1
- data/lib/mongo/{util → utils}/server_version.rb +1 -1
- data/lib/mongo/{util → utils}/support.rb +10 -57
- data/lib/mongo/{util → utils}/thread_local_variable_manager.rb +1 -1
- data/test/functional/authentication_test.rb +8 -21
- data/test/functional/bulk_write_collection_view_test.rb +782 -0
- data/test/functional/{connection_test.rb → client_test.rb} +153 -78
- data/test/functional/collection_test.rb +343 -97
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/functional/conversions_test.rb +1 -3
- data/test/functional/cursor_fail_test.rb +3 -3
- data/test/functional/cursor_message_test.rb +3 -3
- data/test/functional/cursor_test.rb +38 -3
- data/test/functional/db_api_test.rb +5 -5
- data/test/functional/db_connection_test.rb +2 -2
- data/test/functional/db_test.rb +35 -11
- data/test/functional/grid_file_system_test.rb +2 -2
- data/test/functional/grid_io_test.rb +2 -2
- data/test/functional/grid_test.rb +2 -2
- data/test/functional/pool_test.rb +2 -3
- data/test/functional/safe_test.rb +5 -5
- data/test/functional/ssl_test.rb +22 -102
- data/test/functional/support_test.rb +1 -1
- data/test/functional/timeout_test.rb +6 -22
- data/test/functional/uri_test.rb +113 -12
- data/test/functional/write_concern_test.rb +6 -6
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +309 -0
- data/test/replica_set/authentication_test.rb +8 -23
- data/test/replica_set/basic_test.rb +41 -14
- data/test/replica_set/client_test.rb +179 -117
- data/test/replica_set/complex_connect_test.rb +6 -7
- data/test/replica_set/connection_test.rb +46 -38
- data/test/replica_set/count_test.rb +2 -2
- data/test/replica_set/cursor_test.rb +8 -8
- data/test/replica_set/insert_test.rb +64 -2
- data/test/replica_set/max_values_test.rb +59 -10
- data/test/replica_set/pinning_test.rb +2 -2
- data/test/replica_set/query_test.rb +2 -2
- data/test/replica_set/read_preference_test.rb +6 -6
- data/test/replica_set/refresh_test.rb +7 -7
- data/test/replica_set/replication_ack_test.rb +5 -5
- data/test/replica_set/ssl_test.rb +24 -106
- data/test/sharded_cluster/basic_test.rb +43 -15
- data/test/shared/authentication/basic_auth_shared.rb +215 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/ssl_shared.rb +173 -0
- data/test/test_helper.rb +31 -199
- data/test/threading/basic_test.rb +29 -3
- data/test/tools/mongo_config.rb +45 -20
- data/test/tools/mongo_config_test.rb +1 -1
- data/test/unit/client_test.rb +136 -57
- data/test/unit/collection_test.rb +31 -55
- data/test/unit/connection_test.rb +135 -72
- data/test/unit/cursor_test.rb +2 -2
- data/test/unit/db_test.rb +19 -15
- data/test/unit/grid_test.rb +2 -2
- data/test/unit/mongo_sharded_client_test.rb +17 -15
- data/test/unit/node_test.rb +2 -2
- data/test/unit/pool_manager_test.rb +7 -5
- data/test/unit/read_pref_test.rb +82 -2
- data/test/unit/read_test.rb +14 -14
- data/test/unit/safe_test.rb +9 -9
- data/test/unit/sharding_pool_manager_test.rb +11 -5
- data/test/unit/write_concern_test.rb +9 -9
- metadata +71 -56
- metadata.gz.sig +0 -0
- data/test/functional/threading_test.rb +0 -109
- data/test/shared/authentication.rb +0 -121
- data/test/unit/util_test.rb +0 -69
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,43 +14,45 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
|
17
|
+
module Mongo
|
18
|
+
class Collection
|
19
|
+
attr_reader :operation_writer,
|
20
|
+
:command_writer
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class CollectionUnitTest < Test::Unit::TestCase
|
18
25
|
|
19
26
|
context "Basic operations: " do
|
20
27
|
setup do
|
21
28
|
@logger = mock()
|
22
29
|
@logger.stubs(:level => 0)
|
23
30
|
@logger.expects(:debug)
|
31
|
+
|
32
|
+
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
33
|
+
@db = @client[TEST_DB]
|
34
|
+
@coll = @db.collection('collection-unit-test')
|
24
35
|
end
|
25
36
|
|
26
37
|
should "send update message" do
|
27
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
28
|
-
@db = @client['testing']
|
29
|
-
@coll = @db.collection('books')
|
30
38
|
@client.expects(:send_message_with_gle).with do |op, msg, log|
|
31
39
|
op == 2001
|
32
40
|
end
|
33
|
-
@coll.stubs(:log_operation)
|
41
|
+
@coll.operation_writer.stubs(:log_operation)
|
34
42
|
@coll.update({}, {:title => 'Moby Dick'})
|
35
43
|
end
|
36
44
|
|
37
45
|
should "send insert message" do
|
38
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
39
|
-
@db = @client['testing']
|
40
|
-
@coll = @db.collection('books')
|
41
46
|
@client.expects(:send_message_with_gle).with do |op, msg, log|
|
42
47
|
op == 2002
|
43
48
|
end
|
44
|
-
@coll.expects(:log_operation).with do |name, payload|
|
45
|
-
(name == :insert) && payload[:documents][
|
49
|
+
@coll.operation_writer.expects(:log_operation).with do |name, payload|
|
50
|
+
(name == :insert) && payload[:documents][:title].include?('Moby')
|
46
51
|
end
|
47
52
|
@coll.insert({:title => 'Moby Dick'})
|
48
53
|
end
|
49
54
|
|
50
55
|
should "send sort data" do
|
51
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
52
|
-
@db = @client['testing']
|
53
|
-
@coll = @db.collection('books')
|
54
56
|
@client.expects(:checkout_reader).returns(new_mock_socket)
|
55
57
|
@client.expects(:receive_message).with do |op, msg, log, sock|
|
56
58
|
op == 2004
|
@@ -60,60 +62,48 @@ class CollectionTest < Test::Unit::TestCase
|
|
60
62
|
end
|
61
63
|
|
62
64
|
should "not log binary data" do
|
63
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
64
|
-
@db = @client['testing']
|
65
|
-
@coll = @db.collection('books')
|
66
65
|
data = BSON::Binary.new(("BINARY " * 1000).unpack("c*"))
|
67
66
|
@client.expects(:send_message_with_gle).with do |op, msg, log|
|
68
67
|
op == 2002
|
69
68
|
end
|
70
|
-
@coll.expects(:log_operation).with do |name, payload|
|
71
|
-
(name == :insert) && payload[:documents][
|
69
|
+
@coll.operation_writer.expects(:log_operation).with do |name, payload|
|
70
|
+
(name == :insert) && payload[:documents][:data].inspect.include?('Binary')
|
72
71
|
end
|
73
72
|
@coll.insert({:data => data})
|
74
73
|
end
|
75
74
|
|
76
75
|
should "send safe update message" do
|
77
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
78
|
-
@db = @client['testing']
|
79
|
-
@coll = @db.collection('books')
|
80
76
|
@client.expects(:send_message_with_gle).with do |op, msg, db_name, log|
|
81
77
|
op == 2001
|
82
78
|
end
|
83
|
-
@coll.expects(:log_operation).with do |name, payload|
|
84
|
-
(name == :update) && payload[:
|
79
|
+
@coll.operation_writer.expects(:log_operation).with do |name, payload|
|
80
|
+
(name == :update) && payload[:documents][:title].include?('Moby')
|
85
81
|
end
|
86
82
|
@coll.update({}, {:title => 'Moby Dick'})
|
87
83
|
end
|
88
84
|
|
89
85
|
should "send safe update message with legacy" do
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
86
|
+
connection = Connection.new('localhost', 27017, :safe => true, :connect => false)
|
87
|
+
db = connection[TEST_DB]
|
88
|
+
coll = db.collection('collection-unit-test')
|
89
|
+
connection.expects(:send_message_with_gle).with do |op, msg, db_name, log|
|
94
90
|
op == 2001
|
95
91
|
end
|
96
|
-
|
97
|
-
(name == :update) && payload[:
|
92
|
+
coll.operation_writer.expects(:log_operation).with do |name, payload|
|
93
|
+
(name == :update) && payload[:documents][:title].include?('Moby')
|
98
94
|
end
|
99
|
-
|
95
|
+
coll.update({}, {:title => 'Moby Dick'})
|
100
96
|
end
|
101
97
|
|
102
98
|
should "send safe insert message" do
|
103
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
104
|
-
@db = @client['testing']
|
105
|
-
@coll = @db.collection('books')
|
106
99
|
@client.expects(:send_message_with_gle).with do |op, msg, db_name, log|
|
107
100
|
op == 2001
|
108
101
|
end
|
109
|
-
@coll.stubs(:log_operation)
|
102
|
+
@coll.operation_writer.stubs(:log_operation)
|
110
103
|
@coll.update({}, {:title => 'Moby Dick'})
|
111
104
|
end
|
112
105
|
|
113
106
|
should "not call insert for each ensure_index call" do
|
114
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
115
|
-
@db = @client['testing']
|
116
|
-
@coll = @db.collection('books')
|
117
107
|
@coll.expects(:generate_indexes).once
|
118
108
|
|
119
109
|
@coll.ensure_index [["x", Mongo::DESCENDING]]
|
@@ -121,21 +111,15 @@ class CollectionTest < Test::Unit::TestCase
|
|
121
111
|
end
|
122
112
|
|
123
113
|
should "call generate_indexes for a new type on the same field for ensure_index" do
|
124
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
125
|
-
@db = @client['testing']
|
126
|
-
@coll = @db.collection('books')
|
127
114
|
@coll.expects(:generate_indexes).twice
|
128
115
|
|
129
116
|
@coll.ensure_index [["x", Mongo::DESCENDING]]
|
130
117
|
@coll.ensure_index [["x", Mongo::ASCENDING]]
|
131
|
-
|
132
118
|
end
|
133
119
|
|
134
120
|
should "call generate_indexes twice because the cache time is 0 seconds" do
|
135
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
136
|
-
@db = @client['testing']
|
137
121
|
@db.cache_time = 0
|
138
|
-
@coll = @db.collection('
|
122
|
+
@coll = @db.collection('collection-unit-test')
|
139
123
|
@coll.expects(:generate_indexes).twice
|
140
124
|
|
141
125
|
@coll.ensure_index [["x", Mongo::DESCENDING]]
|
@@ -143,10 +127,8 @@ class CollectionTest < Test::Unit::TestCase
|
|
143
127
|
end
|
144
128
|
|
145
129
|
should "call generate_indexes for each key when calling ensure_indexes" do
|
146
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
147
|
-
@db = @client['testing']
|
148
130
|
@db.cache_time = 300
|
149
|
-
@coll = @db.collection('
|
131
|
+
@coll = @db.collection('collection-unit-test')
|
150
132
|
@coll.expects(:generate_indexes).once.with do |a, b, c|
|
151
133
|
a == {"x"=>-1, "y"=>-1}
|
152
134
|
end
|
@@ -155,10 +137,8 @@ class CollectionTest < Test::Unit::TestCase
|
|
155
137
|
end
|
156
138
|
|
157
139
|
should "call generate_indexes for each key when calling ensure_indexes with a hash" do
|
158
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
159
|
-
@db = @client['testing']
|
160
140
|
@db.cache_time = 300
|
161
|
-
@coll = @db.collection('
|
141
|
+
@coll = @db.collection('collection-unit-test')
|
162
142
|
oh = BSON::OrderedHash.new
|
163
143
|
oh['x'] = Mongo::DESCENDING
|
164
144
|
oh['y'] = Mongo::DESCENDING
|
@@ -176,11 +156,7 @@ class CollectionTest < Test::Unit::TestCase
|
|
176
156
|
end
|
177
157
|
end
|
178
158
|
|
179
|
-
|
180
159
|
should "use the connection's logger" do
|
181
|
-
@client = MongoClient.new('localhost', 27017, :logger => @logger, :connect => false)
|
182
|
-
@db = @client['testing']
|
183
|
-
@coll = @db.collection('books')
|
184
160
|
@logger.expects(:warn).with do |msg|
|
185
161
|
msg == "MONGODB [WARNING] test warning"
|
186
162
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
require 'test_helper'
|
16
16
|
|
17
|
-
class
|
17
|
+
class ConnectionUnitTest < Test::Unit::TestCase
|
18
18
|
context "Mongo::MongoClient initialization " do
|
19
19
|
context "given a single node" do
|
20
20
|
setup do
|
@@ -66,22 +66,6 @@ class ConnectionTest < Test::Unit::TestCase
|
|
66
66
|
connection.send(:initialize, *args)
|
67
67
|
end
|
68
68
|
|
69
|
-
context "given a replica set" do
|
70
|
-
|
71
|
-
# should "warn if invalid options are specified" do
|
72
|
-
# connection = Mongo::ReplSetConnection.allocate
|
73
|
-
# opts = {:connect => false}
|
74
|
-
|
75
|
-
# # Mongo::Connection::CLIENT_ONLY_OPTS.each do |opt|
|
76
|
-
# connection.expects(:warn).with("#{:slave_ok} is not a valid option for #{connection.class}")
|
77
|
-
# opts[:slave_ok] = true
|
78
|
-
# # end
|
79
|
-
|
80
|
-
# args = [['localhost:27017'], opts]
|
81
|
-
# connection.send(:initialize, *args)
|
82
|
-
# end
|
83
|
-
|
84
|
-
end
|
85
69
|
end
|
86
70
|
|
87
71
|
context "initializing with a unix socket" do
|
@@ -100,11 +84,19 @@ class ConnectionTest < Test::Unit::TestCase
|
|
100
84
|
assert_equal ['localhost', 27017], @connection.host_port
|
101
85
|
end
|
102
86
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
87
|
+
should "set auth source" do
|
88
|
+
@connection = Mongo::Connection.from_uri("mongodb://user:pass@localhost?authSource=foo", :connect => false)
|
89
|
+
assert_equal 'foo', @connection.auths.first[:source]
|
90
|
+
end
|
91
|
+
|
92
|
+
should "set auth mechanism" do
|
93
|
+
@connection = Mongo::Connection.from_uri("mongodb://user@localhost?authMechanism=MONGODB-X509", :connect => false)
|
94
|
+
assert_equal 'MONGODB-X509', @connection.auths.first[:mechanism]
|
95
|
+
|
96
|
+
assert_raise MongoArgumentError do
|
97
|
+
Mongo::Connection.from_uri("mongodb://localhost?authMechanism=INVALID", :connect => false)
|
98
|
+
end
|
99
|
+
end
|
108
100
|
|
109
101
|
should "allow a complex host names" do
|
110
102
|
host_name = "foo.bar-12345.org"
|
@@ -136,8 +128,15 @@ class ConnectionTest < Test::Unit::TestCase
|
|
136
128
|
should "parse a uri with a hyphen & underscore in the username or password" do
|
137
129
|
@connection = Mongo::Connection.from_uri("mongodb://hyphen-user_name:p-s_s@localhost:27017/db", :connect => false)
|
138
130
|
assert_equal ['localhost', 27017], @connection.host_port
|
139
|
-
|
140
|
-
|
131
|
+
|
132
|
+
auth_hash = {
|
133
|
+
:db_name => 'db',
|
134
|
+
:username => 'hyphen-user_name',
|
135
|
+
:password => 'p-s_s',
|
136
|
+
:source => 'db',
|
137
|
+
:mechanism => Authentication::DEFAULT_MECHANISM
|
138
|
+
}
|
139
|
+
assert_equal auth_hash, @connection.auths.first
|
141
140
|
end
|
142
141
|
|
143
142
|
should "attempt to connect" do
|
@@ -160,99 +159,163 @@ class ConnectionTest < Test::Unit::TestCase
|
|
160
159
|
end
|
161
160
|
end
|
162
161
|
|
163
|
-
should "require
|
162
|
+
should "require password if using legacy auth and username present" do
|
164
163
|
assert Mongo::Connection.from_uri("mongodb://kyle:jones@localhost/db", :connect => false)
|
165
164
|
|
166
165
|
assert_raise MongoArgumentError do
|
167
|
-
Mongo::Connection.from_uri("mongodb://kyle
|
166
|
+
Mongo::Connection.from_uri("mongodb://kyle:@localhost", :connect => false)
|
167
|
+
end
|
168
|
+
|
169
|
+
assert_raise MongoArgumentError do
|
170
|
+
Mongo::Connection.from_uri("mongodb://kyle@localhost", :connect => false)
|
168
171
|
end
|
169
172
|
end
|
170
173
|
end
|
171
174
|
|
172
175
|
context "initializing with ENV['MONGODB_URI']" do
|
173
|
-
|
174
|
-
|
176
|
+
should "parse a simple uri" do
|
177
|
+
uri = "mongodb://localhost?connect=false"
|
178
|
+
with_preserved_env_uri(uri) do
|
179
|
+
@connection = Mongo::Connection.new
|
180
|
+
assert_equal ['localhost', 27017], @connection.host_port
|
181
|
+
end
|
175
182
|
end
|
176
183
|
|
177
|
-
|
178
|
-
|
184
|
+
should "set auth source" do
|
185
|
+
uri = "mongodb://user:pass@localhost?authSource=foo&connect=false"
|
186
|
+
with_preserved_env_uri(uri) do
|
187
|
+
@connection = Mongo::Connection.new
|
188
|
+
assert_equal 'foo', @connection.auths.first[:source]
|
189
|
+
end
|
179
190
|
end
|
180
191
|
|
181
|
-
should "
|
182
|
-
|
183
|
-
|
184
|
-
|
192
|
+
should "set auth mechanism" do
|
193
|
+
uri = "mongodb://user@localhost?authMechanism=MONGODB-X509&connect=false"
|
194
|
+
with_preserved_env_uri(uri) do
|
195
|
+
@connection = Mongo::Connection.new
|
196
|
+
assert_equal 'MONGODB-X509', @connection.auths.first[:mechanism]
|
197
|
+
|
198
|
+
ENV['MONGODB_URI'] = "mongodb://user@localhost?authMechanism=INVALID&connect=false"
|
199
|
+
assert_raise MongoArgumentError do
|
200
|
+
Mongo::Connection.new
|
201
|
+
end
|
202
|
+
end
|
185
203
|
end
|
186
204
|
|
187
205
|
should "allow a complex host names" do
|
188
206
|
host_name = "foo.bar-12345.org"
|
189
|
-
|
190
|
-
|
191
|
-
|
207
|
+
uri = "mongodb://#{host_name}?connect=false"
|
208
|
+
with_preserved_env_uri(uri) do
|
209
|
+
@connection = Mongo::Connection.new
|
210
|
+
assert_equal [host_name, 27017], @connection.host_port
|
211
|
+
end
|
192
212
|
end
|
193
213
|
|
194
214
|
should "allow db without username and password" do
|
195
215
|
host_name = "foo.bar-12345.org"
|
196
|
-
|
197
|
-
|
198
|
-
|
216
|
+
uri = "mongodb://#{host_name}/foo?connect=false"
|
217
|
+
with_preserved_env_uri(uri) do
|
218
|
+
@connection = Mongo::Connection.new
|
219
|
+
assert_equal [host_name, 27017], @connection.host_port
|
220
|
+
end
|
199
221
|
end
|
200
222
|
|
201
223
|
should "set safe options on connection" do
|
202
224
|
host_name = "localhost"
|
203
225
|
opts = "safe=true&w=2&wtimeoutMS=1000&fsync=true&journal=true&connect=false"
|
204
|
-
|
205
|
-
|
206
|
-
|
226
|
+
uri = "mongodb://#{host_name}/foo?#{opts}"
|
227
|
+
with_preserved_env_uri(uri) do
|
228
|
+
@connection = Mongo::Connection.new
|
229
|
+
assert_equal({:w => 2, :wtimeout => 1000, :fsync => true, :j => true}, @connection.safe)
|
230
|
+
end
|
207
231
|
end
|
208
232
|
|
209
233
|
should "set timeout options on connection" do
|
210
234
|
host_name = "localhost"
|
211
235
|
opts = "connectTimeoutMS=1000&socketTimeoutMS=5000&connect=false"
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
236
|
+
uri = "mongodb://#{host_name}/foo?#{opts}"
|
237
|
+
with_preserved_env_uri(uri) do
|
238
|
+
@connection = Mongo::Connection.new
|
239
|
+
assert_equal 1, @connection.connect_timeout
|
240
|
+
assert_equal 5, @connection.op_timeout
|
241
|
+
end
|
216
242
|
end
|
217
243
|
|
218
244
|
should "parse a uri with a hyphen & underscore in the username or password" do
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
245
|
+
uri = "mongodb://hyphen-user_name:p-s_s@localhost:27017/db?connect=false"
|
246
|
+
with_preserved_env_uri(uri) do
|
247
|
+
@connection = Mongo::Connection.new
|
248
|
+
assert_equal ['localhost', 27017], @connection.host_port
|
249
|
+
|
250
|
+
auth_hash = {
|
251
|
+
:db_name => 'db',
|
252
|
+
:username => 'hyphen-user_name',
|
253
|
+
:password => 'p-s_s',
|
254
|
+
:source => 'db',
|
255
|
+
:mechanism => Authentication::DEFAULT_MECHANISM
|
256
|
+
}
|
257
|
+
assert_equal auth_hash, @connection.auths.first
|
258
|
+
end
|
224
259
|
end
|
225
260
|
|
226
261
|
should "attempt to connect" do
|
227
262
|
TCPSocket.stubs(:new).returns(new_mock_socket)
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
263
|
+
uri = "mongodb://localhost?connect=false"
|
264
|
+
with_preserved_env_uri(uri) do
|
265
|
+
@connection = Mongo::Connection.new
|
266
|
+
|
267
|
+
admin_db = new_mock_db
|
268
|
+
admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
|
269
|
+
@connection.expects(:[]).with('admin').returns(admin_db)
|
270
|
+
@connection.connect
|
271
|
+
end
|
235
272
|
end
|
236
273
|
|
237
274
|
should "raise an error on invalid uris" do
|
238
|
-
|
239
|
-
|
240
|
-
|
275
|
+
uri = "mongo://localhost"
|
276
|
+
with_preserved_env_uri(uri) do
|
277
|
+
assert_raise MongoArgumentError do
|
278
|
+
Mongo::Connection.new
|
279
|
+
end
|
280
|
+
|
281
|
+
ENV['MONGODB_URI'] = "mongodb://localhost:abc"
|
282
|
+
assert_raise MongoArgumentError do
|
283
|
+
Mongo::Connection.new
|
284
|
+
end
|
241
285
|
end
|
286
|
+
end
|
242
287
|
|
243
|
-
|
244
|
-
|
245
|
-
|
288
|
+
should "require password if using legacy auth and username present" do
|
289
|
+
uri = "mongodb://kyle:jones@localhost/db?connect=false"
|
290
|
+
with_preserved_env_uri(uri) do
|
291
|
+
assert Mongo::Connection.new
|
292
|
+
|
293
|
+
ENV['MONGODB_URI'] = "mongodb://kyle:@localhost?connect=false"
|
294
|
+
assert_raise MongoArgumentError do
|
295
|
+
Mongo::Connection.new
|
296
|
+
end
|
297
|
+
|
298
|
+
ENV['MONGODB_URI'] = "mongodb://kyle@localhost?connect=false"
|
299
|
+
assert_raise MongoArgumentError do
|
300
|
+
Mongo::Connection.new
|
301
|
+
end
|
246
302
|
end
|
247
303
|
end
|
248
304
|
|
249
|
-
should "require
|
250
|
-
|
251
|
-
|
305
|
+
should "require password if using PLAIN auth and username present" do
|
306
|
+
uri = "mongodb://kyle:jones@localhost/db?connect=false&authMechanism=PLAIN"
|
307
|
+
with_preserved_env_uri(uri) do
|
308
|
+
assert Mongo::Connection.new
|
252
309
|
|
253
|
-
|
254
|
-
|
255
|
-
|
310
|
+
ENV['MONGODB_URI'] = "mongodb://kyle:@localhost?connect=false&authMechanism=PLAIN"
|
311
|
+
assert_raise MongoArgumentError do
|
312
|
+
Mongo::Connection.new
|
313
|
+
end
|
314
|
+
|
315
|
+
ENV['MONGODB_URI'] = "mongodb://kyle@localhost?connect=false&authMechanism=PLAIN"
|
316
|
+
assert_raise MongoArgumentError do
|
317
|
+
Mongo::Connection.new
|
318
|
+
end
|
256
319
|
end
|
257
320
|
end
|
258
321
|
end
|