mongo 1.8.6 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +13 -1
  5. data/VERSION +1 -1
  6. data/bin/mongo_console +15 -0
  7. data/lib/mongo.rb +14 -0
  8. data/lib/mongo/collection.rb +80 -42
  9. data/lib/mongo/cursor.rb +15 -1
  10. data/lib/mongo/db.rb +56 -19
  11. data/lib/mongo/exceptions.rb +14 -0
  12. data/lib/mongo/gridfs/grid.rb +16 -3
  13. data/lib/mongo/gridfs/grid_ext.rb +14 -0
  14. data/lib/mongo/gridfs/grid_file_system.rb +16 -3
  15. data/lib/mongo/gridfs/grid_io.rb +17 -3
  16. data/lib/mongo/legacy.rb +14 -0
  17. data/lib/mongo/mongo_client.rb +93 -40
  18. data/lib/mongo/mongo_replica_set_client.rb +21 -0
  19. data/lib/mongo/mongo_sharded_client.rb +15 -1
  20. data/lib/mongo/networking.rb +14 -0
  21. data/lib/mongo/util/conversions.rb +16 -2
  22. data/lib/mongo/util/core_ext.rb +14 -31
  23. data/lib/mongo/util/logging.rb +23 -7
  24. data/lib/mongo/util/node.rb +17 -2
  25. data/lib/mongo/util/pool.rb +17 -1
  26. data/lib/mongo/util/pool_manager.rb +15 -2
  27. data/lib/mongo/util/read_preference.rb +14 -0
  28. data/lib/mongo/util/server_version.rb +15 -0
  29. data/lib/mongo/util/sharding_pool_manager.rb +13 -0
  30. data/lib/mongo/util/socket_util.rb +14 -0
  31. data/lib/mongo/util/ssl_socket.rb +48 -7
  32. data/lib/mongo/util/support.rb +14 -0
  33. data/lib/mongo/util/tcp_socket.rb +18 -4
  34. data/lib/mongo/util/thread_local_variable_manager.rb +14 -0
  35. data/lib/mongo/util/unix_socket.rb +20 -6
  36. data/lib/mongo/util/uri_parser.rb +16 -8
  37. data/lib/mongo/util/write_concern.rb +16 -2
  38. data/test/functional/authentication_test.rb +26 -1
  39. data/test/functional/collection_test.rb +140 -41
  40. data/test/functional/connection_test.rb +19 -6
  41. data/test/functional/conversions_test.rb +14 -0
  42. data/test/functional/cursor_fail_test.rb +14 -0
  43. data/test/functional/cursor_message_test.rb +14 -0
  44. data/test/functional/cursor_test.rb +15 -1
  45. data/test/functional/db_api_test.rb +15 -1
  46. data/test/functional/db_connection_test.rb +14 -0
  47. data/test/functional/db_test.rb +14 -0
  48. data/test/functional/grid_file_system_test.rb +16 -4
  49. data/test/functional/grid_io_test.rb +14 -0
  50. data/test/functional/grid_test.rb +14 -0
  51. data/test/functional/pool_test.rb +22 -6
  52. data/test/functional/safe_test.rb +14 -0
  53. data/test/functional/ssl_test.rb +109 -0
  54. data/test/functional/support_test.rb +14 -0
  55. data/test/functional/threading_test.rb +22 -8
  56. data/test/functional/timeout_test.rb +20 -6
  57. data/test/functional/uri_test.rb +14 -14
  58. data/test/functional/write_concern_test.rb +14 -0
  59. data/test/replica_set/authentication_test.rb +28 -2
  60. data/test/replica_set/basic_test.rb +14 -0
  61. data/test/replica_set/client_test.rb +14 -0
  62. data/test/replica_set/complex_connect_test.rb +14 -0
  63. data/test/replica_set/connection_test.rb +14 -0
  64. data/test/replica_set/count_test.rb +14 -0
  65. data/test/replica_set/cursor_test.rb +14 -0
  66. data/test/replica_set/insert_test.rb +14 -0
  67. data/test/replica_set/max_values_test.rb +14 -0
  68. data/test/replica_set/pinning_test.rb +14 -0
  69. data/test/replica_set/query_test.rb +14 -0
  70. data/test/replica_set/read_preference_test.rb +14 -0
  71. data/test/replica_set/refresh_test.rb +14 -0
  72. data/test/replica_set/replication_ack_test.rb +14 -0
  73. data/test/replica_set/ssl_test.rb +114 -0
  74. data/test/sharded_cluster/basic_test.rb +14 -0
  75. data/test/shared/authentication.rb +55 -0
  76. data/test/test_helper.rb +15 -1
  77. data/test/threading/basic_test.rb +14 -0
  78. data/test/tools/mongo_config.rb +16 -1
  79. data/test/tools/mongo_config_test.rb +15 -1
  80. data/test/unit/client_test.rb +14 -0
  81. data/test/unit/collection_test.rb +14 -0
  82. data/test/unit/connection_test.rb +14 -0
  83. data/test/unit/cursor_test.rb +14 -0
  84. data/test/unit/db_test.rb +15 -1
  85. data/test/unit/grid_test.rb +14 -0
  86. data/test/unit/mongo_sharded_client_test.rb +14 -0
  87. data/test/unit/node_test.rb +15 -0
  88. data/test/unit/pool_manager_test.rb +15 -0
  89. data/test/unit/pool_test.rb +14 -0
  90. data/test/unit/read_pref_test.rb +14 -0
  91. data/test/unit/read_test.rb +14 -0
  92. data/test/unit/safe_test.rb +14 -0
  93. data/test/unit/sharding_pool_manager_test.rb +15 -0
  94. data/test/unit/util_test.rb +14 -0
  95. data/test/unit/write_concern_test.rb +15 -1
  96. metadata +8 -4
  97. metadata.gz.sig +0 -0
@@ -1,17 +1,31 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class TestTimeout < Test::Unit::TestCase
4
18
  def test_op_timeout
5
- connection = standard_connection(:op_timeout => 1)
19
+ connection = standard_connection(:op_timeout => 0.5)
6
20
 
7
21
  admin = connection.db('admin')
8
22
 
9
- command = {:eval => "sleep(500)"}
23
+ command = {:eval => "sleep(100)"}
10
24
  # Should not timeout
11
25
  assert admin.command(command)
12
26
 
13
27
  # Should timeout
14
- command = {:eval => "sleep(1500)"}
28
+ command = {:eval => "sleep(1000)"}
15
29
  assert_raise Mongo::OperationTimeout do
16
30
  admin.command(command)
17
31
  end
@@ -28,10 +42,10 @@ class TestTimeout < Test::Unit::TestCase
28
42
 
29
43
  # use external timeout to mangle socket
30
44
  begin
31
- Timeout::timeout(1) do
32
- db.command({:eval => "sleep(1500)"})
45
+ Timeout::timeout(0.5) do
46
+ db.command({:eval => "sleep(1000)"})
33
47
  end
34
- rescue Timeout::Error => ex
48
+ rescue Timeout::Error
35
49
  #puts "Thread timed out and has now mangled the socket"
36
50
  end
37
51
 
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class URITest < Test::Unit::TestCase
@@ -45,20 +59,6 @@ class URITest < Test::Unit::TestCase
45
59
  end
46
60
  end
47
61
 
48
- def test_multiple_uris_with_auths
49
- parser = Mongo::URIParser.new('mongodb://bob:secret@a.example.com:27018,b.example.com/test')
50
- assert_equal 2, parser.nodes.length
51
- assert_equal ['a.example.com', 27018], parser.nodes[0]
52
- assert_equal ['b.example.com', 27017], parser.nodes[1]
53
- assert_equal 2, parser.auths.length
54
- assert_equal "bob", parser.auths[0][:username]
55
- assert_equal "secret", parser.auths[0][:password]
56
- assert_equal "test", parser.auths[0][:db_name]
57
- assert_equal "bob", parser.auths[1][:username]
58
- assert_equal "secret", parser.auths[1][:password]
59
- assert_equal "test", parser.auths[1][:db_name]
60
- end
61
-
62
62
  def test_opts_with_semincolon_separator
63
63
  parser = Mongo::URIParser.new('mongodb://localhost:27018?connect=direct;slaveok=true;safe=true')
64
64
  assert_equal 'direct', parser.connect
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
  include Mongo
3
17
 
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
  require 'shared/authentication'
3
17
 
@@ -14,7 +28,19 @@ class ReplicaSetAuthenticationTest < Test::Unit::TestCase
14
28
 
15
29
  def test_authenticate_with_connection_uri
16
30
  @db.add_user('eunice', 'uritest')
17
- assert MongoReplicaSetClient.from_uri(
18
- "mongodb://eunice:uritest@#{@rs.repl_set_seeds.join(',')}/#{@db.name}?replicaSet=#{@rs.repl_set_name}")
31
+
32
+ client =
33
+ MongoReplicaSetClient.from_uri(
34
+ "mongodb://eunice:uritest@#{@rs.repl_set_seeds.join(',')}/#{@db.name}" +
35
+ "?replicaSet=#{@rs.repl_set_name}")
36
+
37
+ assert client
38
+ assert_equal client.auths.size, 1
39
+ assert client[MONGO_TEST_DB]['auth_test'].count
40
+
41
+ auth = client.auths.first
42
+ assert_equal @db.name, auth[:db_name]
43
+ assert_equal 'eunice', auth[:username]
44
+ assert_equal 'uritest', auth[:password]
19
45
  end
20
46
  end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class BasicTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ClientTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ComplexConnectTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ConnectionTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ReplicaSetCountTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ReplicaSetCursorTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ReplicaSetInsertTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class MaxValuesTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ReplicaSetPinningTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ReplicaSetQueryTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ReadPreferenceTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ReplicaSetRefreshTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'test_helper'
2
16
 
3
17
  class ReplicaSetAckTest < Test::Unit::TestCase
@@ -0,0 +1,114 @@
1
+ require 'test_helper'
2
+
3
+ # Note: For testing with MongoReplicaSetClient you *MUST* use the
4
+ # hostname 'server' for all members of the replica set.
5
+
6
+ class ReplicaSetSSLCertValidationTest < Test::Unit::TestCase
7
+ include Mongo
8
+
9
+ CERT_PATH = "#{Dir.pwd}/test/fixtures/certificates/"
10
+ CLIENT_CERT = "#{CERT_PATH}client.pem"
11
+ CA_CERT = "#{CERT_PATH}ca.pem"
12
+ SEEDS = ['server:3000','server:3001','server:3002']
13
+ BAD_SEEDS = ['localhost:3000','localhost:3001','localhost:3002']
14
+
15
+ # This test doesn't connect, no server config required
16
+ def test_ssl_configuration
17
+ # raises when ssl=false and ssl opts specified
18
+ assert_raise MongoArgumentError do
19
+ MongoReplicaSetClient.new(SEEDS, :connect => false,
20
+ :ssl => false,
21
+ :ssl_cert => CLIENT_CERT)
22
+ end
23
+
24
+ # raises when ssl=nil and ssl opts specified
25
+ assert_raise MongoArgumentError do
26
+ MongoReplicaSetClient.new(SEEDS, :connect => false,
27
+ :ssl_key => CLIENT_CERT)
28
+ end
29
+
30
+ # raises when verify=true and no ca_cert
31
+ assert_raise MongoArgumentError do
32
+ MongoReplicaSetClient.new(SEEDS, :connect => false,
33
+ :ssl => true,
34
+ :ssl_key => CLIENT_CERT,
35
+ :ssl_cert => CLIENT_CERT,
36
+ :ssl_verify => true)
37
+ end
38
+ end
39
+
40
+ # Requires MongoDB built with SSL and the follow options:
41
+ #
42
+ # mongod --dbpath /path/to/data/directory --sslOnNormalPorts \
43
+ # --sslPEMKeyFile /path/to/server.pem \
44
+ # --sslCAFile /path/to/ca.pem \
45
+ # --sslCRLFile /path/to/crl.pem \
46
+ # --sslWeakCertificateValidation
47
+ #
48
+ # Make sure you have 'server' as an alias for localhost in /etc/hosts
49
+ #
50
+ def test_ssl_basic
51
+ client = MongoReplicaSetClient.new(SEEDS, :connect => false,
52
+ :ssl => true)
53
+ assert client.connect
54
+ end
55
+
56
+ # Requires MongoDB built with SSL and the follow options:
57
+ #
58
+ # mongod --dbpath /path/to/data/directory --sslOnNormalPorts \
59
+ # --sslPEMKeyFile /path/to/server.pem \
60
+ # --sslCAFile /path/to/ca.pem \
61
+ # --sslCRLFile /path/to/crl.pem
62
+ #
63
+ # Make sure you have 'server' as an alias for localhost in /etc/hosts
64
+ #
65
+ def test_ssl_with_cert
66
+ client = MongoReplicaSetClient.new(SEEDS, :connect => false,
67
+ :ssl => true,
68
+ :ssl_cert => CLIENT_CERT,
69
+ :ssl_key => CLIENT_CERT)
70
+ assert client.connect
71
+ end
72
+
73
+ def test_ssl_with_peer_cert_validation
74
+ client = MongoReplicaSetClient.new(SEEDS, :connect => false,
75
+ :ssl => true,
76
+ :ssl_key => CLIENT_CERT,
77
+ :ssl_cert => CLIENT_CERT,
78
+ :ssl_verify => true,
79
+ :ssl_ca_cert => CA_CERT)
80
+ assert client.connect
81
+ end
82
+
83
+ def test_ssl_peer_cert_validation_hostname_fail
84
+ client = MongoReplicaSetClient.new(BAD_SEEDS, :connect => false,
85
+ :ssl => true,
86
+ :ssl_key => CLIENT_CERT,
87
+ :ssl_cert => CLIENT_CERT,
88
+ :ssl_verify => true,
89
+ :ssl_ca_cert => CA_CERT)
90
+ assert_raise ConnectionFailure do
91
+ client.connect
92
+ end
93
+ end
94
+
95
+ # Requires mongod built with SSL and the follow options:
96
+ #
97
+ # mongod --dbpath /path/to/data/directory --sslOnNormalPorts \
98
+ # --sslPEMKeyFile /path/to/server.pem \
99
+ # --sslCAFile /path/to/ca.pem \
100
+ # --sslCRLFile /path/to/crl_client_revoked.pem
101
+ #
102
+ # Make sure you have 'server' as an alias for localhost in /etc/hosts
103
+ #
104
+ def test_ssl_with_invalid_cert
105
+ assert_raise ConnectionFailure do
106
+ MongoReplicaSetClient.new(SEEDS, :ssl => true,
107
+ :ssl_key => CLIENT_CERT,
108
+ :ssl_cert => CLIENT_CERT,
109
+ :ssl_verify => true,
110
+ :ssl_ca_cert => CA_CERT)
111
+ end
112
+ end
113
+
114
+ end