File: auth_spec.rb

package info (click to toggle)
ruby-mongo 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,332 kB
  • sloc: ruby: 45,579; makefile: 5
file content (65 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'spec_helper'

describe Mongo::Auth do

  describe '#get' do

    context 'when a mongodb_cr user is provided' do

      let(:user) do
        Mongo::Auth::User.new(auth_mech: :mongodb_cr)
      end

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

      it 'returns CR' do
        expect(cr).to be_a(Mongo::Auth::CR)
      end
    end

    context 'when a mongodb_x509 user is provided' do

      let(:user) do
        Mongo::Auth::User.new(auth_mech: :mongodb_x509)
      end

      let(:x509) do
        described_class.get(user)
      end

      it 'returns X509' do
        expect(x509).to be_a(Mongo::Auth::X509)
      end
    end

    context 'when a plain user is provided' do

      let(:user) do
        Mongo::Auth::User.new(auth_mech: :plain)
      end

      let(:ldap) do
        described_class.get(user)
      end

      it 'returns LDAP' do
        expect(ldap).to be_a(Mongo::Auth::LDAP)
      end
    end

    context 'when an invalid mechanism is provided' do

      let(:user) do
        Mongo::Auth::User.new(auth_mech: :nothing)
      end

      it 'raises an error' do
        expect {
          described_class.get(user)
        }.to raise_error(Mongo::Auth::InvalidMechanism)
      end
    end
  end
end