Sha256: 2c6a1009c98e9adef09275be55c7e5e876a698b14699f0e3e533f7ea79db009f

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'

describe Mongo::Auth::CR do

  let(:address) do
    Mongo::Address.new(DEFAULT_ADDRESS)
  end

  let(:server) do
    Mongo::Server.new(address, Mongo::Event::Listeners.new, TEST_OPTIONS)
  end

  let(:connection) do
    Mongo::Server::Connection.new(server, TEST_OPTIONS)
  end

  describe '#login' do

    context 'when the user is not authorized' do

      let(:user) do
        Mongo::Auth::User.new(
          database: 'driver',
          user: 'notauser',
          password: 'password'
        )
      end

      let(:cr) do
        described_class.new(user)
      end

      let(:login) do
        cr.login(connection).documents[0]
      end

      it 'raises an exception' do
        expect {
          cr.login(connection)
        }.to raise_error(Mongo::Auth::Unauthorized)
      end
    end
  end

  context 'when the user is authorized for the database' do

    let(:cr) do
      described_class.new(root_user)
    end

    let(:login) do
      cr.login(connection).documents[0]
    end

    it 'logs the user into the connection', unless: scram_sha_1_enabled? do
      expect(cr.login(connection).documents[0]['ok']).to eq(1)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongo-2.0.5 spec/mongo/auth/cr_spec.rb
mongo-2.0.4 spec/mongo/auth/cr_spec.rb
mongo-2.0.3 spec/mongo/auth/cr_spec.rb