Sha256: c06dc1d99867b01f30a896b302d64f478a1054dbc776ccc8150415af01be42cb

Contents?: true

Size: 1.59 KB

Versions: 21

Compression:

Stored size: 1.59 KB

Contents

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require './test/test_helper'
require './test/tools/auth_repl_set_manager'

class AuthTest < Test::Unit::TestCase
  include Mongo

  def setup
    @manager = AuthReplSetManager.new(:start_port => 40000)
    @manager.start_set
  end

  def teardown
    @manager.cleanup_set
  end

  def test_repl_set_auth
    @conn = ReplSetConnection.new([@manager.host, @manager.ports[0]], [@manager.host, @manager.ports[1]],
      [@manager.host, @manager.ports[2]], :name => @manager.name)

    # Add an admin user
    @conn['admin'].add_user("me", "secret")

    # Ensure that insert fails
    assert_raise_error Mongo::OperationFailure, "unauthorized" do
      @conn['foo']['stuff'].insert({:a => 2}, :safe => {:w => 3})
    end

    # Then authenticate
    assert @conn['admin'].authenticate("me", "secret")

    # Insert should succeed now
    assert @conn['foo']['stuff'].insert({:a => 2}, :safe => {:w => 3})

    # So should a query
    assert @conn['foo']['stuff'].find_one

    # But not when we logout
    @conn['admin'].logout

    assert_raise_error Mongo::OperationFailure, "unauthorized" do
      @conn['foo']['stuff'].find_one
    end

    # Same should apply to a random secondary
    @slave1 = Connection.new(@conn.secondary_pools[0].host,
      @conn.secondary_pools[0].port, :slave_ok => true)

    # Find should fail
    assert_raise_error Mongo::OperationFailure, "unauthorized" do
      @slave1['foo']['stuff'].find_one
    end

    # But not when authenticated
    @slave1['admin'].authenticate("me", "secret")
    assert @slave1['foo']['stuff'].find_one
  end
end

Version data entries

21 entries across 21 versions & 5 rubygems

Version Path
mongo-1.5.2 test/auxillary/repl_set_auth_test.rb
mongo-1.5.1 test/auxillary/repl_set_auth_test.rb
mongo-1.5.0 test/auxillary/repl_set_auth_test.rb
mongo-1.5.0.rc0 test/auxillary/repl_set_auth_test.rb
jmongo-1.1.5 test/auxillary/repl_set_auth_test.rb
jmongo-1.1.4 test/auxillary/repl_set_auth_test.rb
jmongo-1.1.3 test/auxillary/repl_set_auth_test.rb
jmongo-1.1.2 test/auxillary/repl_set_auth_test.rb
jmongo-1.1.1 test/auxillary/repl_set_auth_test.rb
jmongo-1.1.0 test/auxillary/repl_set_auth_test.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/mongo-1.3.1/test/auxillary/repl_set_auth_test.rb
mongo-1.4.0 test/auxillary/repl_set_auth_test.rb
jonbell-mongo-1.3.1.2 test/auxillary/repl_set_auth_test.rb
mongo-lyon-1.2.4 test/auxillary/repl_set_auth_test.rb
mongo-1.3.1 test/auxillary/repl_set_auth_test.rb
mongo-1.3.0 test/auxillary/repl_set_auth_test.rb
mongo-1.3.0.rc0 test/auxillary/repl_set_auth_test.rb
mongo-1.2.4 test/auxillary/repl_set_auth_test.rb
mongo-1.2.3 test/auxillary/repl_set_auth_test.rb
mongo-1.2.2 test/auxillary/repl_set_auth_test.rb