aboutsummaryrefslogtreecommitdiff
path: root/spec/defines/samba__server__share_spec.rb
blob: b4182f0f6f247a2461ecb5e5730eaf34727b0528 (plain)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
require 'spec_helper'

shared_examples "default share" do
  let(:title) { "test_share" }
  let(:params) {{ :ensure => 'present' }}
  let(:default_changes) do
    set = Augeas::TargetedChangeSet.new(title)
    set.with("available")
    set.with("browsable")
    set.with("comment")
    set.with("copy")
    set.with("create mask")
    set.with("directory mask")
    set.with("force create mask")
    set.with("force directory mode")
    set.with("force group")
    set.with("force user")
    set.with("guest ok")
    set.with("guest only")
    set.with("hide unreadable")
    set.with("path", nil, nil)
    set.with("read only")
    set.with("public")
    set.with("writable")
    set.with("printable")
    set.with("follow symlinks")
    set.with("wide links")
    set.with("acl group control")
    set.with("map acl inherit")
    set.with("profile acls")
    set.with("store dos attributes")
    set.with("strict allocate")
    set.with("valid users")
    set.with("oplocks")
    set.with("level2 oplocks")
    set.with("veto oplock files")
    set.with("read list")
    set.with("write list")
    set.with("hide dot files")
    set.with("root preexec")
    set.with("inherit permissions")
    set.with("inherit acls")
  end
  let(:change_set) { default_changes }
  let(:changes) { change_set.to_a }

  it { is_expected.to contain_samba__server__share(title) }
  it { is_expected.to contain_augeas("#{title}-section").with(
    :incl    => '/etc/samba/smb.conf',
    :lens    => 'Samba.lns',
    :context => '/files/etc/samba/smb.conf',
    :changes => ["set target[. = '#{title}'] '#{title}'"],
    :require => 'Class[Samba::Server::Config]',
    :notify  => 'Class[Samba::Server::Service]')
  }
  it { is_expected.to contain_augeas("#{title}-changes").with(
    :incl    => '/etc/samba/smb.conf',
    :lens    => 'Samba.lns',
    :context => '/files/etc/samba/smb.conf',
    :changes => changes,
    :require => 'Augeas[test_share-section]',
    :notify  => 'Class[Samba::Server::Service]')
  }
end

describe 'samba::server::share', :type => :define do
  let(:pre_condition){ 'class{"samba::server":}'}
  on_supported_os({
      :hardwaremodels => ['x86_64'],
      :supported_os   => [
        {
          "operatingsystem" => "Ubuntu",
          "operatingsystemrelease" => [
            "14.04"
          ]
        },
        {
          "operatingsystem" => "CentOS",
          "operatingsystemrelease" => [
            "7"
          ]
        }
      ],
    }).each do |os, facts|
    context "for #{os}" do
      let(:facts) do
        facts.merge({
          :concat_basedir => '/tmp',
          :domain => 'domain.com'
        })
      end

      context 'with base options' do
        let(:title) { 'test_share' }
        let(:params) {{
          :ensure => 'present'
        }}

        it { is_expected.to contain_samba__server__share('test_share') }
        it { is_expected.to contain_augeas('test_share-section').with(
          :incl    => '/etc/samba/smb.conf',
          :lens    => 'Samba.lns',
          :context => '/files/etc/samba/smb.conf',
          :changes => ["set target[. = 'test_share'] 'test_share'"],
          :require => 'Class[Samba::Server::Config]',
          :notify  => 'Class[Samba::Server::Service]')
        }
        it { is_expected.to contain_augeas('test_share-changes').with(
          :incl     => '/etc/samba/smb.conf',
          :lens     => 'Samba.lns',
          :context  => '/files/etc/samba/smb.conf',
          :require  => 'Augeas[test_share-section]',
          :notify   => 'Class[Samba::Server::Service]')
        }
      end

      context 'with ensure set to absent' do
        let(:title) { 'test_share' }
        let(:params) {{
          :ensure => 'absent'
        }}

        it { is_expected.to contain_augeas('test_share-section').with(
          :incl    => '/etc/samba/smb.conf',
          :lens    => 'Samba.lns',
          :context => '/files/etc/samba/smb.conf',
          :changes => ["rm target[. = 'test_share'] 'test_share'"],
          :require => 'Class[Samba::Server::Config]',
          :notify  => 'Class[Samba::Server::Service]')
        }
      end

      context 'with available set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :available => true,
        }}
        let(:change_set) { default_changes.with("available", "yes") }
      end

      context 'with available set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :available => false,
        }}
        let(:change_set) { default_changes.with("available", "no") }
      end

      context 'with browsable set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :browsable => true,
        }}
        let(:change_set) { default_changes.with("browsable", "yes") }
      end

      context 'with browsable set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :browsable => false,
        }}
        let(:change_set) { default_changes.with("browsable", "no") }
      end

      context 'with root_preexec set to /bin/true' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :root_preexec => '/bin/true',
        }}
        let(:change_set) { default_changes.with("root preexec", "'/bin/true'") }
      end

      context 'with comment set to "testing testing"' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :comment => 'testing testing',
        }}
        let(:change_set) { default_changes.with("comment", "'testing testing'") }
      end

      context 'with copy set to "testing testing"' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :copy => 'testing testing',
        }}
        let(:change_set) { default_changes.with("copy", "'testing testing'") }
      end

      context 'with create_mask set to "755"' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :create_mask => '755',
        }}
        let(:change_set) { default_changes.with("create mask", "'755'") }
      end

      context 'with directory_mask set to "755"' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :directory_mask => '755',
        }}
        let(:change_set) { default_changes.with("directory mask", "'755'") }
      end

      context 'with force_create_mask set to "755"' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :force_create_mask => '755',
        }}
        let(:change_set) { default_changes.with("force create mask", "'755'") }
      end

      context 'with force_directory_mode set to "755"' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :force_directory_mode => '755',
        }}
        let(:change_set) { default_changes.with("force directory mode", "'755'") }
      end

      context 'with force_group set to "nogroup"' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :force_group => 'nogroup',
        }}
        let(:change_set) { default_changes.with("force group", "'nogroup'") }
      end

      context 'with force_user set to "nobody"' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :force_user => 'nobody',
        }}
        let(:change_set) { default_changes.with("force user", "'nobody'") }
      end

      context 'with guest_ok set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure   => 'present',
          :guest_ok => true,
        }}
        let(:change_set) { default_changes.with("guest ok", "yes") }
      end

      context 'with guest_ok set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure   => 'present',
          :guest_ok => false,
        }}
        let(:change_set) { default_changes.with("guest ok", "no") }
      end

      context 'with guest_only set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure     => 'present',
          :guest_only => true,
        }}
        let(:change_set) { default_changes.with("guest only", "yes") }
      end

      context 'with guest_only set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure     => 'present',
          :guest_only => false,
        }}
        let(:change_set) { default_changes.with("guest only", "no") }
      end

      context 'with hide_unreadable set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :hide_unreadable => true,
        }}
        let(:change_set) { default_changes.with("hide unreadable", "yes") }
      end

      context 'with hide_unreadable set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :hide_unreadable => false,
        }}
        let(:change_set) { default_changes.with("hide unreadable", "no") }
      end

      context 'with path set to /tmp' do
        include_examples "default share"
        let(:params) {{
          :ensure => 'present',
          :path   => '/tmp',
        }}
        let(:change_set) { default_changes.with("path", "'/tmp'", nil) }
      end

      context 'with read_only set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :read_only => true,
        }}
        let(:change_set) { default_changes.with("read only", "yes") }
      end

      context 'with read_only set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :read_only => false,
        }}
        let(:change_set) { default_changes.with("read only", "no") }
      end

      context 'with public set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure => 'present',
          :public => true,
        }}
        let(:change_set) { default_changes.with("public", "yes") }
      end

      context 'with public set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure => 'present',
          :public => false,
        }}
        let(:change_set) { default_changes.with("public", "no") }
      end

      context 'with writable set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure   => 'present',
          :writable => true,
        }}
        let(:change_set) { default_changes.with("writable", "yes") }
      end

      context 'with writable set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure   => 'present',
          :writable => false,
        }}
        let(:change_set) { default_changes.with("writable", "no") }
      end

      context 'with printable set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :printable => true,
        }}
        let(:change_set) { default_changes.with("printable", "yes") }
      end

      context 'with printable set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure    => 'present',
          :printable => false,
        }}
        let(:change_set) { default_changes.with("printable", "no") }
      end

      context 'with follow_symlinks set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :follow_symlinks => true,
        }}
        let(:change_set) { default_changes.with("follow symlinks", "yes") }
      end

      context 'with follow_symlinks set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :follow_symlinks => false,
        }}
        let(:change_set) { default_changes.with("follow symlinks", "no") }
      end

      context 'with wide_links set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure     => 'present',
          :wide_links => true,
        }}
        let(:change_set) { default_changes.with("wide links", "yes") }
      end

      context 'with wide_links set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure     => 'present',
          :wide_links => false,
        }}
        let(:change_set) { default_changes.with("wide links", "no") }
      end

      context 'with acl_group_control set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :acl_group_control => true,
        }}
        let(:change_set) { default_changes.with("acl group control", "yes") }
      end

      context 'with acl_group_control set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :acl_group_control => false,
        }}
        let(:change_set) { default_changes.with("acl group control", "no") }
      end

      context 'with map_acl_inherit set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :map_acl_inherit => true,
        }}
        let(:change_set) { default_changes.with("map acl inherit", "yes") }
      end

      context 'with map_acl_inherit set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :map_acl_inherit => false,
        }}
        let(:change_set) { default_changes.with("map acl inherit", "no") }
      end

      context 'with profile_acls set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :profile_acls    => true,
        }}
        let(:change_set) { default_changes.with("profile acls", "yes") }
      end

      context 'with profile_acls set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :profile_acls    => false,
        }}
        let(:change_set) { default_changes.with("profile acls", "no") }
      end

      context 'with store_dos_attributes set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure               => 'present',
          :store_dos_attributes => true,
        }}
        let(:change_set) { default_changes.with("store dos attributes", "yes") }
      end

      context 'with store_dos_attributes set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure               => 'present',
          :store_dos_attributes => false,
        }}
        let(:change_set) { default_changes.with("store dos attributes", "no") }
      end

      context 'with strict_allocate set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :strict_allocate => true,
        }}
        let(:change_set) { default_changes.with("strict allocate", "yes") }
      end

      context 'with strict_allocate set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure          => 'present',
          :strict_allocate => false,
        }}
        let(:change_set) { default_changes.with("strict allocate", "no") }
      end

      context 'with valid_users set to "bill,ben"' do
        include_examples "default share"
        let(:params) {{
          :ensure      => 'present',
          :valid_users => 'bill,ben',
        }}
        let(:change_set) { default_changes.with("valid users", "'bill,ben'") }
      end

      context 'with op_locks set to "testing"' do
        include_examples "default share"
        let(:params) {{
          :ensure   => 'present',
          :op_locks => 'testing',
        }}
        let(:change_set) { default_changes.with("oplocks", "'testing'") }
      end

      context 'with level2_oplocks set to "testing"' do
        include_examples "default share"
        let(:params) {{
          :ensure         => 'present',
          :level2_oplocks => 'testing',
        }}
        let(:change_set) { default_changes.with("level2 oplocks", "'testing'") }
      end

      context 'with veto_oplock_files set to "testing"' do
        include_examples "default share"
        let(:params) {{
          :ensure            => 'present',
          :veto_oplock_files => 'testing',
        }}
        let(:change_set) { default_changes.with("veto oplock files", "'testing'") }
      end

      context 'with read_list set to "bill,ben"' do
        include_examples "default share"
        let(:params) {{
          :ensure     => 'present',
          :read_list => 'bill,ben',
        }}
        let(:change_set) { default_changes.with("read list", "'bill,ben'") }
      end

      context 'with write_list set to "bill,ben"' do
        include_examples "default share"
        let(:params) {{
          :ensure     => 'present',
          :write_list => 'bill,ben',
        }}
        let(:change_set) { default_changes.with("write list", "'bill,ben'") }
      end

      context 'with hide_dot_files set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure         => 'present',
          :hide_dot_files => true,
        }}
        let(:change_set) { default_changes.with("hide dot files", "yes") }
      end

      context 'with hide_dot_files set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure         => 'present',
          :hide_dot_files => false,
        }}
        let(:change_set) { default_changes.with("hide dot files", "no") }
      end

      context 'with root_preexec set to "/bin/test"' do
        include_examples "default share"
        let(:params) {{
          :ensure       => 'present',
          :root_preexec => '/bin/test',
        }}
        let(:change_set) { default_changes.with("root preexec", "'/bin/test'") }
      end

      context 'with inherit_permissions set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure         => 'present',
          :inherit_permissions => true,
        }}
        let(:change_set) { default_changes.with("inherit permissions", "yes") }
      end

      context 'with inherit_permissions set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure         => 'present',
          :inherit_permissions => false,
        }}
        let(:change_set) { default_changes.with("inherit permissions", "no") }
      end

      context 'with inherit_acls set to true' do
        include_examples "default share"
        let(:params) {{
          :ensure         => 'present',
          :inherit_acls => true,
        }}
        let(:change_set) { default_changes.with("inherit acls", "yes") }
      end

      context 'with inherit_acls set to false' do
        include_examples "default share"
        let(:params) {{
          :ensure         => 'present',
          :inherit_acls => false,
        }}
        let(:change_set) { default_changes.with("inherit acls", "no") }
      end
    end
  end
end