mongodb-mongo 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongo/db.rb +9 -3
- data/mongo-ruby-driver.gemspec +1 -1
- data/tests/test_db.rb +20 -34
- metadata +1 -1
data/lib/mongo/db.rb
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# ++
|
16
16
|
|
17
17
|
require 'socket'
|
18
|
-
require 'md5'
|
18
|
+
require 'digest/md5'
|
19
19
|
require 'mutex_m'
|
20
20
|
require 'mongo/collection'
|
21
21
|
require 'mongo/message'
|
@@ -144,10 +144,16 @@ module XGen
|
|
144
144
|
auth['authenticate'] = 1
|
145
145
|
auth['user'] = username
|
146
146
|
auth['nonce'] = nonce
|
147
|
-
auth['key'] = MD5.
|
147
|
+
auth['key'] = Digest::MD5.hexdigest("#{nonce}#{username}#{hash_password(password)}")
|
148
148
|
ok?(db_command(auth))
|
149
149
|
end
|
150
150
|
|
151
|
+
# Deauthorizes use for this database for this connection.
|
152
|
+
def logout
|
153
|
+
doc = db_command(:logout => 1)
|
154
|
+
raise "error logging out: #{doc.inspect}" unless ok?(doc)
|
155
|
+
end
|
156
|
+
|
151
157
|
# Returns an array of collection names. Each name is of the form
|
152
158
|
# "database_name.collection_name".
|
153
159
|
def collection_names
|
@@ -425,7 +431,7 @@ module XGen
|
|
425
431
|
private
|
426
432
|
|
427
433
|
def hash_password(plaintext)
|
428
|
-
MD5.
|
434
|
+
Digest::MD5.hexdigest("mongo#{plaintext}")
|
429
435
|
end
|
430
436
|
|
431
437
|
end
|
data/mongo-ruby-driver.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mongo'
|
3
|
-
s.version = '0.2.
|
3
|
+
s.version = '0.2.1'
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
|
6
6
|
s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
|
data/tests/test_db.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
-
require 'md5'
|
2
|
+
require 'digest/md5'
|
3
3
|
require 'mongo'
|
4
4
|
require 'test/unit'
|
5
5
|
|
@@ -19,12 +19,17 @@ class DBTest < Test::Unit::TestCase
|
|
19
19
|
@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
20
20
|
@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
|
21
21
|
@db = Mongo.new(@host, @port).db('ruby-mongo-test')
|
22
|
+
|
22
23
|
@spongebob = 'spongebob'
|
23
24
|
@spongebob_password = 'squarepants'
|
25
|
+
@users = @db.collection('system.users')
|
26
|
+
@users.clear
|
27
|
+
@db.add_user(@spongebob, @spongebob_password)
|
24
28
|
end
|
25
29
|
|
26
30
|
def teardown
|
27
31
|
if @db.connected?
|
32
|
+
@users.clear if @users
|
28
33
|
@db.close
|
29
34
|
end
|
30
35
|
end
|
@@ -54,6 +59,7 @@ class DBTest < Test::Unit::TestCase
|
|
54
59
|
|
55
60
|
def test_array
|
56
61
|
@db.close
|
62
|
+
@users = nil
|
57
63
|
@db = Mongo.new([["nosuch.example.com"], [@host, @port]]).db('ruby-mongo-test')
|
58
64
|
assert @db.connected?
|
59
65
|
end
|
@@ -86,45 +92,25 @@ class DBTest < Test::Unit::TestCase
|
|
86
92
|
end
|
87
93
|
|
88
94
|
def test_add_user
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
@db.add_user(@spongebob, @spongebob_password)
|
94
|
-
assert_equal 1, coll.count
|
95
|
-
doc = coll.find({}, :limit => 1).next_object
|
96
|
-
assert_equal @spongebob, doc['user']
|
97
|
-
assert_equal MD5.new("mongo#{@spongebob_password}").to_s, doc['pwd']
|
98
|
-
ensure
|
99
|
-
coll.clear
|
100
|
-
end
|
95
|
+
assert_equal 1, @users.count
|
96
|
+
doc = @users.find({}, :limit => 1).next_object
|
97
|
+
assert_equal @spongebob, doc['user']
|
98
|
+
assert_equal Digest::MD5.hexdigest("mongo#{@spongebob_password}"), doc['pwd']
|
101
99
|
end
|
102
100
|
|
103
101
|
def test_delete_user
|
104
|
-
|
105
|
-
|
106
|
-
begin
|
107
|
-
assert_equal 0, coll.count
|
108
|
-
@db.add_user(@spongebob, @spongebob_password)
|
109
|
-
assert_equal 1, coll.count
|
110
|
-
@db.delete_user(@spongebob)
|
111
|
-
assert_equal 0, coll.count
|
112
|
-
ensure
|
113
|
-
coll.clear
|
114
|
-
end
|
102
|
+
@db.delete_user(@spongebob)
|
103
|
+
assert_equal 0, @users.count
|
115
104
|
end
|
116
105
|
|
117
106
|
def test_authenticate
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
ensure
|
126
|
-
coll.clear
|
127
|
-
end
|
107
|
+
assert !@db.authenticate('nobody', 'nopassword')
|
108
|
+
assert !@db.authenticate(@spongebob, 'squareliederhosen')
|
109
|
+
assert @db.authenticate(@spongebob, @spongebob_password)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_logout
|
113
|
+
@db.logout # only testing that we don't throw exception
|
128
114
|
end
|
129
115
|
|
130
116
|
end
|