ldap_spec.rb 3.6 KB
Newer Older
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require 'spec_helper'

describe 'freeradius::module::ldap' do
  include_context 'redhat_common_dependencies'

  let(:title) { 'test' }

  let(:params) do
    {
      identity: 'cn=root,dc=example,dc=com',
      password: 'test password',
      basedn: 'dc=example,dc=com',
      server: ['localhost'],
    }
  end

  let(:facts) do
    {
      freeradius_version: '3.0.21',
    }
  end

  let(:node_params) do
    {
      'freeradius::fr_3_1' => false,
    }
  end

  it do
    is_expected.to contain_file('/etc/raddb/mods-available/test')
      .with_content(%r{^ldap test \{\n})
      .with_content(%r{^\s+server = 'localhost'\n})
      .with_content(%r{^\s+identity = 'cn=root,dc=example,dc=com'\n})
      .with_content(%r{^\s+password = 'test password'\n})
      .with_content(%r{^\s+base_dn = 'dc=example,dc=com'\n})
      .without_content(%r{^\s+connect_timeout = .*})
      .with_ensure('present')
      .with_group('radiusd')
      .with_mode('0640')
      .with_owner('root')
      .that_notifies('Service[radiusd]')
      .that_requires('Package[freeradius]')
      .that_requires('Group[radiusd]')
  end

  it do
    is_expected.to contain_file('/etc/raddb/mods-enabled/test')
      .with_ensure('link')
      .with_target('../mods-available/test')
  end

  context 'when freeradius::fr_3_1 is true' do
    let(:facts) do
      super().merge(
        'freeradius_version' => '3.1.1',
      )
    end

    let(:node_params) do
      {
        'freeradius::fr_3_1' => true,
      }
    end

    it do
      is_expected.to contain_file('/etc/raddb/mods-available/test')
      .with_content(%r{^\s+connect_timeout = 3.0})
      .with_content(%r{^\s+use_referral_credentials = no})
      .without_content(%r{^\s+session_tracking = .*})
    end

    context 'with connect_timeout, session_tracking, and use_referral_credentials specified' do
      let(:params) do
        super().merge(
          connect_timeout: 5.0,
          session_tracking: 'yes',
          use_referral_credentials: 'yes',
        )
      end

      it do
        is_expected.to contain_file('/etc/raddb/mods-available/test')
        .with_content(%r{^\s+connect_timeout = 5.0})
        .with_content(%r{^\s+use_referral_credentials = yes})
        .with_content(%r{^\s+session_tracking = yes})
      end

      # it do
      #   is_expected.to create_notify('warning_test').with_message(%r{^The `connect_timeout` parameter requires FreeRADIUS 3.1.x})
      # end

      # it do
      #   is_expected.to create_notify('warning_test').with_message(%r{^The `use_referral_credentials` parameter requires FreeRADIUS 3.1.x})
      # end

      # it do
      #   is_expected.to create_notify('warning_test').with_message(%r{^The `session_tracking` parameter requires FreeRADIUS 3.1.x})
      # end
    end
  end

  # context 'with connect_timeout specified' do
  #   let(:params) do
  #     super().merge(
  #       connect_timeout: 5.0,
  #     )
  #   end

  #   it do
  #     is_expected.to compile.and_raise_error(%r{^The \`connect_timeout` parameter requires FreeRADIUS 3\.1\.x})
  #   end
  # end

  # context 'with session_tracking specified' do
  #   let(:params) do
  #     super().merge(
  #       session_tracking: 'yes',
  #     )
  #   end

  #   it do
  #     is_expected.to compile.and_raise_error(%r{^The `session_tracking` parameter requires FreeRADIUS 3.1.x})
  #   end
  # end

  # context 'with use_referral_credentials specified' do
  #   let(:params) do
  #     super().merge(
  #       use_referral_credentials: 'yes',
  #     )
  #   end

  #   it do
  #     is_expected.to compile.and_raise_error(%r{^The `use_referral_credentials` parameter requires FreeRADIUS 3.1.x})
  #   end
  # end
end