Sha256: 94955f6553b98a4f934961bf2dfc2d0fd356e184b7052b811a5711fc53055cb9

Contents?: true

Size: 1.98 KB

Versions: 47

Compression:

Stored size: 1.98 KB

Contents

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

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

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

  def teardown
    #@rs.cleanup_set
  end

  def test_repl_set_auth
    @conn = ReplSetConnection.new(build_seeds(3), :name => @rs.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
    assert @slave1['admin'].authenticate("me", "secret")
    assert @slave1['foo']['stuff'].find_one

    # Same should apply when using :secondary_only
    @second_only = ReplSetConnection.new(build_seeds(3), 
      :require_primary => false, :read => :secondary_only)

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

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

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.7.4 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.7.3 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.7.2 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.7.1 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.7.0 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.9 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.8 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.7 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.6 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.5 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.4 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.3 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.2 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.1 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.6.0 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.5.17 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.5.16 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.5.15 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb
classiccms-0.5.14 vendor/bundle/gems/mongo-1.6.2/test/auxillary/repl_set_auth_test.rb