Sha256: 70530cb1d7d5ec7ebd5be0a3afb07b15b437a0a4598b867ed399e6c9f8e278db

Contents?: true

Size: 1.34 KB

Versions: 9

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true
# rubocop:todo all

require 'spec_helper'

describe Mongo::Auth::X509::Conversation do

  let(:user) do
    Mongo::Auth::User.new(
      database: '$external',
      user: 'user',
    )
  end

  let(:conversation) do
    described_class.new(user, double('connection'))
  end

  describe '#start' do

    let(:query) do
      conversation.start(nil)
    end

    let(:selector) do
      query.selector
    end

    it 'sets username' do
      expect(selector[:user]).to eq('user')
    end

    it 'sets the mechanism' do
      expect(selector[:mechanism]).to eq('MONGODB-X509')
    end

    context 'when a username is not provided' do

      let(:user) do
        Mongo::Auth::User.new(
          database: '$external',
        )
      end

      it 'does not set the username' do
        expect(selector[:user]).to be_nil
      end

      it 'sets the mechanism' do
        expect(selector[:mechanism]).to eq('MONGODB-X509')
      end
    end

    context 'when the username is nil' do

      let(:user) do
        Mongo::Auth::User.new(
          database: '$external',
          user: nil
        )
      end

      it 'does not set the username' do
        expect(selector.has_key?(:user)).to be(false)
      end

      it 'sets the mechanism' do
        expect(selector[:mechanism]).to eq('MONGODB-X509')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mongo-2.21.0 spec/mongo/auth/x509/conversation_spec.rb
mongo-2.20.1 spec/mongo/auth/x509/conversation_spec.rb
mogno-2.20.0 spec/mongo/auth/x509/conversation_spec.rb
mogno-1.0.0 spec/mongo/auth/x509/conversation_spec.rb
mongo-2.20.0 spec/mongo/auth/x509/conversation_spec.rb
mongo-2.19.3 spec/mongo/auth/x509/conversation_spec.rb
mongo-2.19.2 spec/mongo/auth/x509/conversation_spec.rb
mongo-2.19.1 spec/mongo/auth/x509/conversation_spec.rb
mongo-2.19.0 spec/mongo/auth/x509/conversation_spec.rb