mongo 1.10.2 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +43 -9
  5. data/VERSION +1 -1
  6. data/lib/mongo.rb +1 -0
  7. data/lib/mongo/collection.rb +36 -21
  8. data/lib/mongo/connection/pool.rb +14 -22
  9. data/lib/mongo/cursor.rb +13 -0
  10. data/lib/mongo/db.rb +18 -13
  11. data/lib/mongo/functional.rb +0 -2
  12. data/lib/mongo/functional/authentication.rb +35 -25
  13. data/lib/mongo/legacy.rb +4 -4
  14. data/mongo.gemspec +0 -5
  15. data/test/functional/authentication_test.rb +3 -2
  16. data/test/functional/bulk_write_collection_view_test.rb +9 -14
  17. data/test/functional/client_test.rb +42 -43
  18. data/test/functional/collection_test.rb +1073 -995
  19. data/test/functional/collection_writer_test.rb +1 -1
  20. data/test/functional/cursor_fail_test.rb +3 -9
  21. data/test/functional/cursor_message_test.rb +14 -15
  22. data/test/functional/cursor_test.rb +224 -166
  23. data/test/functional/db_api_test.rb +262 -261
  24. data/test/functional/db_connection_test.rb +1 -3
  25. data/test/functional/db_test.rb +116 -115
  26. data/test/functional/grid_file_system_test.rb +108 -108
  27. data/test/functional/pool_test.rb +73 -0
  28. data/test/functional/timeout_test.rb +2 -0
  29. data/test/helpers/test_unit.rb +146 -11
  30. data/test/replica_set/authentication_test.rb +4 -2
  31. data/test/replica_set/basic_test.rb +5 -13
  32. data/test/replica_set/client_test.rb +8 -6
  33. data/test/replica_set/complex_connect_test.rb +3 -0
  34. data/test/replica_set/count_test.rb +2 -0
  35. data/test/replica_set/cursor_test.rb +5 -0
  36. data/test/replica_set/insert_test.rb +1 -1
  37. data/test/replica_set/max_values_test.rb +1 -1
  38. data/test/replica_set/pinning_test.rb +1 -1
  39. data/test/replica_set/query_test.rb +1 -1
  40. data/test/replica_set/read_preference_test.rb +7 -1
  41. data/test/replica_set/refresh_test.rb +11 -8
  42. data/test/replica_set/replication_ack_test.rb +2 -1
  43. data/test/sharded_cluster/basic_test.rb +17 -11
  44. data/test/shared/authentication/basic_auth_shared.rb +59 -98
  45. data/test/shared/authentication/bulk_api_auth_shared.rb +11 -21
  46. data/test/shared/authentication/gssapi_shared.rb +28 -21
  47. data/test/test_helper.rb +5 -0
  48. data/test/tools/mongo_config.rb +96 -11
  49. metadata +4 -5
  50. metadata.gz.sig +0 -0
  51. data/lib/mongo/functional/sasl_java.rb +0 -48
@@ -17,19 +17,12 @@ module BulkAPIAuthTests
17
17
  include Mongo
18
18
 
19
19
  def init_auth_bulk
20
- # enable authentication
21
- @admin = @client["admin"]
22
- @admin.add_user('admin', 'password', nil, :roles => ['readWriteAnyDatabase',
23
- 'userAdminAnyDatabase',
24
- 'dbAdminAnyDatabase'])
25
- @admin.authenticate('admin', 'password')
26
-
27
20
  # Set up the test db
28
21
  @collection = @db["bulk-api-auth-tests"]
29
22
 
30
23
  # db user can insert but not remove
31
24
  res = BSON::OrderedHash.new
32
- res[:db] = TEST_DB
25
+ res[:db] = @db.name
33
26
  res[:collection] = ""
34
27
 
35
28
  cmd = BSON::OrderedHash.new
@@ -47,31 +40,28 @@ module BulkAPIAuthTests
47
40
  @db.command(cmd)
48
41
  @db.add_user('insertAndRemove', 'password', nil, :roles => ['insertAndRemove'])
49
42
 
50
- # for 2.4 cleanup etc.
51
- @db.add_user('admin', 'password', nil, :roles => ['readWrite',
52
- 'userAdmin',
53
- 'dbAdmin'])
54
43
  @admin.logout
55
44
  end
56
45
 
57
- def teardown_bulk
58
- remove_all_users_and_roles(@db, 'admin', 'password')
59
- remove_all_users_and_roles(@admin, 'admin', 'password')
60
- end
61
-
62
46
  def clear_collection(collection)
63
- @admin.authenticate('admin', 'password')
47
+ @admin.authenticate(TEST_USER, TEST_USER_PWD)
64
48
  collection.remove
65
49
  @admin.logout
66
50
  end
67
51
 
68
- def remove_all_users_and_roles(database, username, password)
69
- @admin.authenticate('admin', 'password')
52
+ def teardown_bulk
53
+ remove_all_users_and_roles(@db)
54
+ remove_all_users_and_roles(@admin)
55
+ end
56
+
57
+ def remove_all_users_and_roles(database)
58
+ @admin.authenticate(TEST_USER, TEST_USER_PWD)
70
59
  if @version < '2.5.3'
71
60
  database['system.users'].remove
72
61
  else
73
62
  database.command({:dropAllRolesFromDatabase => 1})
74
- database.command({:dropAllUsersFromDatabase => 1})
63
+ # Don't delete the TEST_USER from the TEST_DB, it is needed for future tests
64
+ database.command({:dropAllUsersFromDatabase => 1}) unless database.name == TEST_DB
75
65
  end
76
66
  @admin.logout
77
67
  end
@@ -28,7 +28,8 @@ module GSSAPITests
28
28
  # export MONGODB_GSSAPI_REALM='applicationuser@example.com'
29
29
  # export MONGODB_GSSAPI_KDC='SERVER.DOMAIN.COM'
30
30
  #
31
- # You must either use kinit or provide a config file that references a keytab file:
31
+ # You must use kinit when on MRI.
32
+ # You have the option of providing a config file that references a keytab file on JRuby:
32
33
  #
33
34
  # export JAAS_LOGIN_CONFIG_FILE='file:///path/to/config/file'
34
35
  #
@@ -37,10 +38,12 @@ module GSSAPITests
37
38
  MONGODB_GSSAPI_REALM = ENV['MONGODB_GSSAPI_REALM']
38
39
  MONGODB_GSSAPI_KDC = ENV['MONGODB_GSSAPI_KDC']
39
40
  MONGODB_GSSAPI_PORT = ENV['MONGODB_GSSAPI_PORT'] || '27017'
40
- JAAS_LOGIN_CONFIG_FILE = ENV['JAAS_LOGIN_CONFIG_FILE']
41
+ MONGODB_GSSAPI_DB = ENV['MONGODB_GSSAPI_DB']
42
+ JAAS_LOGIN_CONFIG_FILE = ENV['JAAS_LOGIN_CONFIG_FILE'] # only JRuby
41
43
 
42
44
  if ENV.key?('MONGODB_GSSAPI_HOST') && ENV.key?('MONGODB_GSSAPI_USER') &&
43
- ENV.key?('MONGODB_GSSAPI_REALM') && ENV.key?('MONGODB_GSSAPI_KDC') && RUBY_PLATFORM =~ /java/
45
+ ENV.key?('MONGODB_GSSAPI_REALM') && ENV.key?('MONGODB_GSSAPI_KDC') &&
46
+ ENV.key?('MONGODB_GSSAPI_DB')
44
47
  def test_gssapi_authenticate
45
48
  client = Mongo::MongoClient.new(MONGODB_GSSAPI_HOST, MONGODB_GSSAPI_PORT)
46
49
  if client['admin'].command(:isMaster => 1)['setName']
@@ -48,7 +51,7 @@ module GSSAPITests
48
51
  end
49
52
 
50
53
  set_system_properties
51
- db = client['kerberos']
54
+ db = client[MONGODB_GSSAPI_DB]
52
55
  db.authenticate(MONGODB_GSSAPI_USER, nil, nil, nil, 'GSSAPI')
53
56
  assert db.command(:dbstats => 1)
54
57
 
@@ -68,7 +71,7 @@ module GSSAPITests
68
71
  uri = "mongodb://#{username}@#{ENV['MONGODB_GSSAPI_HOST']}:#{ENV['MONGODB_GSSAPI_PORT']}/?" +
69
72
  "authMechanism=GSSAPI"
70
73
  client = @client.class.from_uri(uri)
71
- assert client['kerberos'].command(:dbstats => 1)
74
+ assert client[MONGODB_GSSAPI_DB].command(:dbstats => 1)
72
75
  end
73
76
 
74
77
  def test_wrong_service_name_fails
@@ -79,8 +82,8 @@ module GSSAPITests
79
82
  end
80
83
 
81
84
  set_system_properties
82
- assert_raise_error Java::OrgMongodbSasl::MongoSecurityException do
83
- client['kerberos'].authenticate(MONGODB_GSSAPI_USER, nil, nil, nil, 'GSSAPI', extra_opts)
85
+ assert_raise_error Mongo::AuthenticationError do
86
+ client[MONGODB_GSSAPI_DB].authenticate(MONGODB_GSSAPI_USER, nil, nil, nil, 'GSSAPI', extra_opts)
84
87
  end
85
88
  end
86
89
 
@@ -92,8 +95,8 @@ module GSSAPITests
92
95
  uri = "mongodb://#{username}@#{ENV['MONGODB_GSSAPI_HOST']}:#{ENV['MONGODB_GSSAPI_PORT']}/?" +
93
96
  "authMechanism=GSSAPI&gssapiServiceName=example"
94
97
  client = @client.class.from_uri(uri)
95
- assert_raise_error Java::OrgMongodbSasl::MongoSecurityException do
96
- client['kerberos'].command(:dbstats => 1)
98
+ assert_raise_error Mongo::AuthenticationError do
99
+ client[MONGODB_GSSAPI_DB].command(:dbstats => 1)
97
100
  end
98
101
  end
99
102
 
@@ -103,10 +106,11 @@ module GSSAPITests
103
106
  set_system_properties
104
107
 
105
108
  Mongo::Sasl::GSSAPI.expects(:authenticate).with do |username, client, socket, opts|
106
- opts[:gssapi_service_name] == extra_opts[:gssapi_service_name]
107
- opts[:canonicalize_host_name] == extra_opts[:canonicalize_host_name]
109
+ assert_equal opts[:gssapi_service_name], extra_opts[:gssapi_service_name]
110
+ assert_equal opts[:canonicalize_host_name], extra_opts[:canonicalize_host_name]
111
+ [ username, client, socket, opts ]
108
112
  end.returns('ok' => true )
109
- client['kerberos'].authenticate(MONGODB_GSSAPI_USER, nil, nil, nil, 'GSSAPI', extra_opts)
113
+ client[MONGODB_GSSAPI_DB].authenticate(MONGODB_GSSAPI_USER, nil, nil, nil, 'GSSAPI', extra_opts)
110
114
  end
111
115
 
112
116
  def test_extra_opts_uri
@@ -114,8 +118,9 @@ module GSSAPITests
114
118
  set_system_properties
115
119
 
116
120
  Mongo::Sasl::GSSAPI.expects(:authenticate).with do |username, client, socket, opts|
117
- opts[:gssapi_service_name] == extra_opts[:gssapi_service_name]
118
- opts[:canonicalize_host_name] == extra_opts[:canonicalize_host_name]
121
+ assert_equal opts[:gssapi_service_name], extra_opts[:gssapi_service_name]
122
+ assert_equal opts[:canonicalize_host_name], extra_opts[:canonicalize_host_name]
123
+ [ username, client, socket, opts ]
119
124
  end.returns('ok' => true)
120
125
 
121
126
  require 'cgi'
@@ -124,7 +129,7 @@ module GSSAPITests
124
129
  "authMechanism=GSSAPI&gssapiServiceName=example&canonicalizeHostName=true"
125
130
  client = @client.class.from_uri(uri)
126
131
  client.expects(:receive_message).returns([[{ 'ok' => 1 }], 1, 1])
127
- client['kerberos'].command(:dbstats => 1)
132
+ client[MONGODB_GSSAPI_DB].command(:dbstats => 1)
128
133
  end
129
134
 
130
135
  # In order to run this test, you must set the following environment variable:
@@ -137,7 +142,7 @@ module GSSAPITests
137
142
  set_system_properties
138
143
  client = Mongo::MongoClient.new(ENV['MONGODB_GSSAPI_HOST_IP'], MONGODB_GSSAPI_PORT)
139
144
 
140
- db = client['kerberos']
145
+ db = client[MONGODB_GSSAPI_DB]
141
146
  db.authenticate(MONGODB_GSSAPI_USER, nil, nil, nil, 'GSSAPI', extra_opts)
142
147
  assert db.command(:dbstats => 1)
143
148
  end
@@ -148,16 +153,18 @@ module GSSAPITests
148
153
  client = Mongo::MongoClient.new(MONGODB_GSSAPI_HOST)
149
154
 
150
155
  assert_raise Mongo::MongoArgumentError do
151
- client['kerberos'].authenticate(MONGODB_GSSAPI_USER, nil, nil, nil, 'GSSAPI', extra_opts)
156
+ client[MONGODB_GSSAPI_DB].authenticate(MONGODB_GSSAPI_USER, nil, nil, nil, 'GSSAPI', extra_opts)
152
157
  end
153
158
  end
154
159
 
155
160
  private
156
161
  def set_system_properties
157
- java.lang.System.set_property 'javax.security.auth.useSubjectCredsOnly', 'false'
158
- java.lang.System.set_property "java.security.krb5.realm", MONGODB_GSSAPI_REALM
159
- java.lang.System.set_property "java.security.krb5.kdc", MONGODB_GSSAPI_KDC
160
- java.lang.System.set_property "java.security.auth.login.config", JAAS_LOGIN_CONFIG_FILE if JAAS_LOGIN_CONFIG_FILE
162
+ if RUBY_PLATFORM =~ /java/
163
+ java.lang.System.set_property 'javax.security.auth.useSubjectCredsOnly', 'false'
164
+ java.lang.System.set_property "java.security.krb5.realm", MONGODB_GSSAPI_REALM
165
+ java.lang.System.set_property "java.security.krb5.kdc", MONGODB_GSSAPI_KDC
166
+ java.lang.System.set_property "java.security.auth.login.config", JAAS_LOGIN_CONFIG_FILE if JAAS_LOGIN_CONFIG_FILE
167
+ end
161
168
  end
162
169
  end
163
170
 
@@ -43,6 +43,11 @@ require 'mocha/setup'
43
43
  # cluster manager
44
44
  require 'tools/mongo_config'
45
45
 
46
+ # For kerberos testing.
47
+ begin
48
+ require 'mongo_kerberos'
49
+ rescue LoadError; end
50
+
46
51
  # test helpers
47
52
  require 'helpers/general'
48
53
  require 'helpers/test_unit'
@@ -83,9 +83,11 @@ module Mongo
83
83
  make_config(opts)
84
84
  when :routers
85
85
  make_router(config, opts)
86
+ when :shards
87
+ make_standalone_shard(kind, opts)
86
88
  else
87
89
  make_mongod(kind, opts)
88
- end
90
+ end
89
91
 
90
92
  replica_count += 1 if [:replicas, :arbiters].member?(kind)
91
93
  node
@@ -130,25 +132,37 @@ module Mongo
130
132
  :ipv6 => ipv6)
131
133
  end
132
134
 
135
+ def self.key_file(opts)
136
+ keyFile = opts[:key_file] || '/test/fixtures/auth/keyfile'
137
+ keyFile = Dir.pwd << keyFile
138
+ system "chmod 600 #{keyFile}"
139
+ keyFile
140
+ end
141
+
142
+ # A regular mongod minus --auth and plus --keyFile.
143
+ def self.make_standalone_shard(kind, opts)
144
+ params = make_mongod(kind, opts)
145
+ params.delete(:auth)
146
+ params.merge(:keyFile => key_file(opts))
147
+ end
148
+
133
149
  def self.make_replica(opts, id)
134
150
  params = make_mongod('replicas', opts)
135
151
 
136
152
  replSet = opts[:replSet] || 'ruby-driver-test'
137
153
  oplogSize = opts[:oplog_size] || 5
138
- keyFile = opts[:key_file] || '/test/fixtures/auth/keyfile'
139
-
140
- keyFile = Dir.pwd << keyFile
141
- system "chmod 600 #{keyFile}"
142
154
 
143
155
  params.merge(:_id => id,
144
156
  :replSet => replSet,
145
157
  :oplogSize => oplogSize,
146
- :keyFile => keyFile)
158
+ :keyFile => key_file(opts))
147
159
  end
148
160
 
149
161
  def self.make_config(opts)
150
162
  params = make_mongod('configs', opts)
151
- params.merge(:configsvr => nil)
163
+ params.delete(:auth)
164
+ params.merge(:configsvr => true,
165
+ :keyFile => key_file(opts))
152
166
  end
153
167
 
154
168
  def self.make_router(config, opts)
@@ -156,8 +170,9 @@ module Mongo
156
170
  mongos = ENV['MONGOS'] || 'mongos'
157
171
 
158
172
  params.merge(
159
- :command => mongos,
160
- :configdb => self.configdb(config)
173
+ :command => mongos,
174
+ :configdb => self.configdb(config),
175
+ :keyFile => key_file(opts)
161
176
  )
162
177
  end
163
178
 
@@ -339,6 +354,35 @@ module Mongo
339
354
  @servers.collect{|k,v| (!key || key == k) ? v : nil}.flatten.compact
340
355
  end
341
356
 
357
+ def ensure_authenticated(client)
358
+ begin
359
+ client[TEST_DB].authenticate(TEST_USER, TEST_USER_PWD)
360
+ rescue Mongo::MongoArgumentError => ex
361
+ # client is already authenticated
362
+ raise ex unless ex.message =~ /already authenticated/
363
+ rescue Mongo::AuthenticationError => ex
364
+ # 1) The creds are wrong
365
+ # 2) Or the user doesn't exist
366
+ roles = [ 'dbAdminAnyDatabase',
367
+ 'userAdminAnyDatabase',
368
+ 'readWriteAnyDatabase',
369
+ 'clusterAdmin' ]
370
+ begin
371
+ # Try to add the user for case (2)
372
+ client[TEST_DB].add_user(TEST_USER, TEST_USER_PWD, nil, :roles => roles)
373
+ client[TEST_DB].authenticate(TEST_USER, TEST_USER_PWD)
374
+ rescue Mongo::ConnectionFailure, Mongo::OperationFailure => ex
375
+ # Maybe not master, so try to authenticate
376
+ # 2.2 throws an OperationFailure if add_user fails
377
+ begin
378
+ client[TEST_DB].authenticate(TEST_USER, TEST_USER_PWD)
379
+ rescue => ex
380
+ # Maybe creds are wrong, nothing we can do
381
+ end
382
+ end
383
+ end
384
+ end
385
+
342
386
  def command( cmd_servers, db_name, cmd, opts = {} )
343
387
  ret = []
344
388
  cmd = cmd.class == Array ? cmd : [ cmd ]
@@ -348,6 +392,7 @@ module Mongo
348
392
  debug 3, cmd_server.inspect
349
393
  cmd_server = cmd_server.config if cmd_server.is_a?(DbServer)
350
394
  client = Mongo::MongoClient.new(cmd_server[:host], cmd_server[:port])
395
+ ensure_authenticated(client)
351
396
  cmd.each do |c|
352
397
  debug 3, "ClusterManager.command c:#{c.inspect}"
353
398
  response = client[db_name].command( c, opts )
@@ -361,6 +406,10 @@ module Mongo
361
406
  ret.size == 1 ? ret.first : ret
362
407
  end
363
408
 
409
+ def replica_set?
410
+ !!config[:replicas]
411
+ end
412
+
364
413
  def repl_set_get_status
365
414
  command( @config[:replicas], 'admin', { :replSetGetStatus => 1 }, {:check_response => false } )
366
415
  end
@@ -368,6 +417,7 @@ module Mongo
368
417
  def repl_set_get_config
369
418
  host, port = primary_name.split(":")
370
419
  client = Mongo::MongoClient.new(host, port)
420
+ ensure_authenticated(client)
371
421
  client['local']['system.replset'].find_one
372
422
  end
373
423
 
@@ -389,7 +439,7 @@ module Mongo
389
439
  states = nil
390
440
  healthy = false
391
441
 
392
- 60.times do
442
+ 80.times do
393
443
  # enter the thunderdome...
394
444
  states = repl_set_get_status.zip(repl_set_is_master)
395
445
  healthy = states.all? do |status, is_master|
@@ -442,6 +492,11 @@ module Mongo
442
492
  repl_set_seeds.join(',')
443
493
  end
444
494
 
495
+ def members_uri
496
+ members = @config[:replicas] || @config[:routers]
497
+ members.collect{|node| "#{node[:host]}:#{node[:port]}"}.join(',')
498
+ end
499
+
445
500
  def repl_set_name
446
501
  @config[:replicas].first[:replSet]
447
502
  end
@@ -553,7 +608,15 @@ module Mongo
553
608
  end
554
609
 
555
610
  def addshards(shards = @config[:shards])
556
- command( @config[:routers].first, 'admin', Array(shards).collect{|s| { :addshard => "#{s[:host]}:#{s[:port]}" } } )
611
+ begin
612
+ command( @config[:routers].first, 'admin', Array(shards).collect{|s| { :addshard => "#{s[:host]}:#{s[:port]}" } } )
613
+ rescue Mongo::OperationFailure => ex
614
+ # Because we cannot run the listshards command under the localhost
615
+ # exception in > 2.7.1, we run the risk of attempting to add the same shard twice.
616
+ # Our tests may add a local db to a shard, if the cluster is still up,
617
+ # then we can ignore this.
618
+ raise ex unless ex.message =~ /host already used/
619
+ end
557
620
  end
558
621
 
559
622
  def listshards
@@ -593,7 +656,29 @@ module Mongo
593
656
  end
594
657
  alias :restart :start
595
658
 
659
+ def delete_users
660
+ cmd_servers = replica_set? ? [ primary ] : routers
661
+
662
+ cmd_servers.each do |cmd_server|
663
+ begin
664
+ client = Mongo::MongoClient.new(cmd_server.config[:host],
665
+ cmd_server.config[:port])
666
+ ensure_authenticated(client)
667
+ db = client[TEST_DB]
668
+
669
+ if client.server_version < '2.5'
670
+ db['system.users'].remove
671
+ else
672
+ db.command(:dropAllUsersFromDatabase => 1)
673
+ end
674
+ break
675
+ rescue Mongo::ConnectionFailure
676
+ end
677
+ end
678
+ end
679
+
596
680
  def stop
681
+ delete_users
597
682
  servers.each{|server| server.stop}
598
683
  self
599
684
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.2
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emily Stolfo
@@ -34,7 +34,7 @@ cert_chain:
34
34
  JrZM8w8wGbIOeLtoQqa7HB/jOYbTahH7KMNh2LHAbOR93hNIJxVRa4iwxiMQ75tN
35
35
  9WUIAJ4AEtjwRg1Bz0OwDo3aucPCBpx77+/FWhv7JYY=
36
36
  -----END CERTIFICATE-----
37
- date: 2014-06-16 00:00:00.000000000 Z
37
+ date: 2014-09-15 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: bson
@@ -42,14 +42,14 @@ dependencies:
42
42
  requirements:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.10.2
45
+ version: 1.11.1
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
49
49
  requirements:
50
50
  - - '='
51
51
  - !ruby/object:Gem::Version
52
- version: 1.10.2
52
+ version: 1.11.1
53
53
  description: A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.
54
54
  email: mongodb-dev@googlegroups.com
55
55
  executables:
@@ -83,7 +83,6 @@ files:
83
83
  - lib/mongo/functional/authentication.rb
84
84
  - lib/mongo/functional/logging.rb
85
85
  - lib/mongo/functional/read_preference.rb
86
- - lib/mongo/functional/sasl_java.rb
87
86
  - lib/mongo/functional/uri_parser.rb
88
87
  - lib/mongo/functional/write_concern.rb
89
88
  - lib/mongo/gridfs.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,48 +0,0 @@
1
- # Copyright (C) 2009-2013 MongoDB, 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
-
15
- require 'jruby'
16
-
17
- include Java
18
-
19
- jar_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../../ext/jsasl'))
20
- require File.join(jar_dir, 'target/jsasl.jar')
21
-
22
- module Mongo
23
- module Sasl
24
-
25
- module GSSAPI
26
-
27
- def self.authenticate(username, client, socket, opts={})
28
- db = client.db('$external')
29
- hostname = socket.pool.host
30
- servicename = opts[:gssapi_service_name] || 'mongodb'
31
- canonicalize = opts[:canonicalize_host_name] ? opts[:canonicalize_host_name] : false
32
-
33
- authenticator = org.mongodb.sasl.GSSAPIAuthenticator.new(JRuby.runtime, username, hostname, servicename, canonicalize)
34
- token = BSON::Binary.new(authenticator.initialize_challenge)
35
- cmd = BSON::OrderedHash['saslStart', 1, 'mechanism', 'GSSAPI', 'payload', token, 'autoAuthorize', 1]
36
- response = db.command(cmd, :check_response => false, :socket => socket)
37
-
38
- until response['done'] do
39
- token = BSON::Binary.new(authenticator.evaluate_challenge(response['payload'].to_s))
40
- cmd = BSON::OrderedHash['saslContinue', 1, 'conversationId', response['conversationId'], 'payload', token]
41
- response = db.command(cmd, :check_response => false, :socket => socket)
42
- end
43
- response
44
- end
45
- end
46
-
47
- end
48
- end