serverspec 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -103,6 +103,49 @@ module Serverspec
103
103
  def check_zfs(zfs, property)
104
104
  check_zero(:check_zfs, zfs, property)
105
105
  end
106
+
107
+ def check_readable(file, by_whom)
108
+ mode = sprintf('%04s',do_check(commands.get_mode(file))[:stdout].strip)
109
+ mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
110
+ if by_whom.nil?
111
+ mode_octal & 0444 != 0
112
+ elsif by_whom == 'owner'
113
+ mode_octal & 0400 != 0
114
+ elsif by_whom == 'group'
115
+ mode_octal & 0040 != 0
116
+ elsif by_whom == 'others'
117
+ mode_octal & 0004 != 0
118
+ end
119
+ end
120
+
121
+ def check_writable(file, by_whom)
122
+ mode = sprintf('%04s',do_check(commands.get_mode(file))[:stdout].strip)
123
+ mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
124
+ if by_whom.nil?
125
+ mode_octal & 0222 != 0
126
+ elsif by_whom == 'owner'
127
+ mode_octal & 0200 != 0
128
+ elsif by_whom == 'group'
129
+ mode_octal & 0020 != 0
130
+ elsif by_whom == 'others'
131
+ mode_octal & 0002 != 0
132
+ end
133
+ end
134
+
135
+ def check_executable(file, by_whom)
136
+ mode = sprintf('%04s',do_check(commands.get_mode(file))[:stdout].strip)
137
+ mode_octal = mode[0].to_i * 512 + mode[1].to_i * 64 + mode[2].to_i * 8 + mode[3].to_i * 1
138
+ if by_whom.nil?
139
+ mode_octal & 0111 != 0
140
+ elsif by_whom == 'owner'
141
+ mode_octal & 0100 != 0
142
+ elsif by_whom == 'group'
143
+ mode_octal & 0010 != 0
144
+ elsif by_whom == 'others'
145
+ mode_octal & 0001 != 0
146
+ end
147
+ end
148
+
106
149
  end
107
150
  end
108
151
  end
@@ -96,6 +96,11 @@ module Serverspec
96
96
  def check_zfs zfs, property=nil, value=nil
97
97
  raise NotImplementedError.new
98
98
  end
99
+
100
+ def get_mode(file)
101
+ "stat -c %a #{file}"
102
+ end
103
+
99
104
  end
100
105
  end
101
106
  end
@@ -17,3 +17,6 @@ require 'serverspec/matchers/belong_to_group'
17
17
  require 'serverspec/matchers/have_iptables_rule'
18
18
  require 'serverspec/matchers/get_stdout'
19
19
  require 'serverspec/matchers/be_zfs'
20
+ require 'serverspec/matchers/be_readable'
21
+ require 'serverspec/matchers/be_writable'
22
+ require 'serverspec/matchers/be_executable'
@@ -0,0 +1,8 @@
1
+ RSpec::Matchers.define :be_executable do
2
+ match do |file|
3
+ backend.check_executable(file, @by_whom)
4
+ end
5
+ chain :by do |by_whom|
6
+ @by_whom = by_whom
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ RSpec::Matchers.define :be_readable do
2
+ match do |file|
3
+ backend.check_readable(file, @by_whom)
4
+ end
5
+ chain :by do |by_whom|
6
+ @by_whom = by_whom
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ RSpec::Matchers.define :be_writable do
2
+ match do |file|
3
+ backend.check_writable(file, @by_whom)
4
+ end
5
+ chain :by do |by_whom|
6
+ @by_whom = by_whom
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -97,3 +97,7 @@ end
97
97
  describe commands.check_iptables_rule('-P INPUT ACCEPT', 'mangle', 'INPUT') do
98
98
  it { should eq "iptables -t mangle -S INPUT | grep '\\-P INPUT ACCEPT'" }
99
99
  end
100
+
101
+ describe commands.get_mode('/dev') do
102
+ it { should eq 'stat -c %a /dev' }
103
+ end
@@ -36,4 +36,19 @@ describe 'Serverspec matchers of Debian family', :os => :debian do
36
36
  it_behaves_like 'support have_iptables_rule.with_table.with_chain matcher', '-P INPUT ACCEPT', 'mangle', 'INPUT'
37
37
 
38
38
  it_behaves_like 'support get_stdout matcher', 'whoami', 'root'
39
+
40
+ it_behaves_like 'support be_readable matcher', '/dev'
41
+ it_behaves_like 'support be_readable_by_owner matcher', '/dev'
42
+ it_behaves_like 'support be_readable_by_group matcher', '/dev'
43
+ it_behaves_like 'support be_readable_by_others matcher', '/dev'
44
+
45
+ it_behaves_like 'support be_writable matcher', '/dev'
46
+ it_behaves_like 'support be_writable_by_owner matcher', '/dev'
47
+ it_behaves_like 'support be_writable_by_group matcher', '/dev'
48
+ it_behaves_like 'support be_writable_by_others matcher', '/dev'
49
+
50
+ it_behaves_like 'support be_executable matcher', '/dev'
51
+ it_behaves_like 'support be_executable_by_owner matcher', '/dev'
52
+ it_behaves_like 'support be_executable_by_group matcher', '/dev'
53
+ it_behaves_like 'support be_executable_by_others matcher', '/dev'
39
54
  end
@@ -97,3 +97,7 @@ end
97
97
  describe commands.check_iptables_rule('-P INPUT ACCEPT', 'mangle', 'INPUT') do
98
98
  it { should eq "iptables -t mangle -S INPUT | grep '\\-P INPUT ACCEPT'" }
99
99
  end
100
+
101
+ describe commands.get_mode('/dev') do
102
+ it { should eq 'stat -c %a /dev' }
103
+ end
@@ -37,4 +37,19 @@ describe 'Serverspec matchers of Gentoo family', :os => :gentoo do
37
37
  it_behaves_like 'support have_iptables_rule.with_table.with_chain matcher', '-P INPUT ACCEPT', 'mangle', 'INPUT'
38
38
 
39
39
  it_behaves_like 'support get_stdout matcher', 'whoami', 'root'
40
+
41
+ it_behaves_like 'support be_readable matcher', '/dev'
42
+ it_behaves_like 'support be_readable_by_owner matcher', '/dev'
43
+ it_behaves_like 'support be_readable_by_group matcher', '/dev'
44
+ it_behaves_like 'support be_readable_by_others matcher', '/dev'
45
+
46
+ it_behaves_like 'support be_writable matcher', '/dev'
47
+ it_behaves_like 'support be_writable_by_owner matcher', '/dev'
48
+ it_behaves_like 'support be_writable_by_group matcher', '/dev'
49
+ it_behaves_like 'support be_writable_by_others matcher', '/dev'
50
+
51
+ it_behaves_like 'support be_executable matcher', '/dev'
52
+ it_behaves_like 'support be_executable_by_owner matcher', '/dev'
53
+ it_behaves_like 'support be_executable_by_group matcher', '/dev'
54
+ it_behaves_like 'support be_executable_by_others matcher', '/dev'
40
55
  end
@@ -97,3 +97,7 @@ end
97
97
  describe commands.check_iptables_rule('-P INPUT ACCEPT', 'mangle', 'INPUT') do
98
98
  it { should eq "iptables -t mangle -S INPUT | grep '\\-P INPUT ACCEPT'" }
99
99
  end
100
+
101
+ describe commands.get_mode('/dev') do
102
+ it { should eq 'stat -c %a /dev' }
103
+ end
@@ -38,4 +38,19 @@ describe 'Serverspec matchers of Red Hat family', :os => :redhat do
38
38
  it_behaves_like 'support have_iptables_rule.with_table.with_chain matcher', '-P INPUT ACCEPT', 'mangle', 'INPUT'
39
39
 
40
40
  it_behaves_like 'support get_stdout matcher', 'whoami', 'root'
41
+
42
+ it_behaves_like 'support be_readable matcher', '/dev'
43
+ it_behaves_like 'support be_readable_by_owner matcher', '/dev'
44
+ it_behaves_like 'support be_readable_by_group matcher', '/dev'
45
+ it_behaves_like 'support be_readable_by_others matcher', '/dev'
46
+
47
+ it_behaves_like 'support be_writable matcher', '/dev'
48
+ it_behaves_like 'support be_writable_by_owner matcher', '/dev'
49
+ it_behaves_like 'support be_writable_by_group matcher', '/dev'
50
+ it_behaves_like 'support be_writable_by_others matcher', '/dev'
51
+
52
+ it_behaves_like 'support be_executable matcher', '/dev'
53
+ it_behaves_like 'support be_executable_by_owner matcher', '/dev'
54
+ it_behaves_like 'support be_executable_by_group matcher', '/dev'
55
+ it_behaves_like 'support be_executable_by_others matcher', '/dev'
41
56
  end
@@ -110,3 +110,7 @@ check_zfs_with_multiple_properties = commands.check_zfs('rpool', {
110
110
  describe check_zfs_with_multiple_properties do
111
111
  it { should eq "/sbin/zfs list -H -o compression rpool | grep ^off$ && /sbin/zfs list -H -o mountpoint rpool | grep ^/rpool$" }
112
112
  end
113
+
114
+ describe commands.get_mode('/dev') do
115
+ it { should eq 'stat -c %a /dev' }
116
+ end
@@ -36,4 +36,19 @@ describe 'Serverspec matchers of Solaris family', :os => :solaris do
36
36
  it_behaves_like 'support get_stdout matcher', 'whoami', 'root'
37
37
  it_behaves_like 'support be_zfs matcher', 'rpool'
38
38
  it_behaves_like 'support be_zfs.property matcher', 'rpool', { 'mountpoint' => '/rpool' }
39
+
40
+ it_behaves_like 'support be_readable matcher', '/dev'
41
+ it_behaves_like 'support be_readable_by_owner matcher', '/dev'
42
+ it_behaves_like 'support be_readable_by_group matcher', '/dev'
43
+ it_behaves_like 'support be_readable_by_others matcher', '/dev'
44
+
45
+ it_behaves_like 'support be_writable matcher', '/dev'
46
+ it_behaves_like 'support be_writable_by_owner matcher', '/dev'
47
+ it_behaves_like 'support be_writable_by_group matcher', '/dev'
48
+ it_behaves_like 'support be_writable_by_others matcher', '/dev'
49
+
50
+ it_behaves_like 'support be_executable matcher', '/dev'
51
+ it_behaves_like 'support be_executable_by_owner matcher', '/dev'
52
+ it_behaves_like 'support be_executable_by_group matcher', '/dev'
53
+ it_behaves_like 'support be_executable_by_others matcher', '/dev'
39
54
  end
@@ -77,7 +77,7 @@ shared_examples_for 'support be_running.under("not implemented") matcher' do |va
77
77
  it {
78
78
  expect {
79
79
  should be_running.under('not implemented')
80
- }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn't support/)
80
+ }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/)
81
81
  }
82
82
  end
83
83
  end
@@ -367,3 +367,267 @@ shared_examples_for 'support be_zfs.property matcher' do |zfs, property|
367
367
  end
368
368
  end
369
369
  end
370
+
371
+ shared_examples_for 'support be_readable matcher' do |file|
372
+ describe 'be_readable' do
373
+ describe file do
374
+ before :all do
375
+ RSpec.configure do |c|
376
+ c.stdout = "755\r\n"
377
+ end
378
+ end
379
+ it { should be_readable }
380
+ end
381
+
382
+ describe file do
383
+ before :all do
384
+ RSpec.configure do |c|
385
+ c.stdout = "333\r\n"
386
+ end
387
+ end
388
+ it { should_not be_readable }
389
+ end
390
+ end
391
+ end
392
+
393
+ shared_examples_for 'support be_readable_by_owner matcher' do |file|
394
+ describe 'be_readable_by_owner' do
395
+ describe file do
396
+ before :all do
397
+ RSpec.configure do |c|
398
+ c.stdout = "400\r\n"
399
+ end
400
+ end
401
+ it { should be_readable.by('owner') }
402
+ end
403
+
404
+ describe file do
405
+ before :all do
406
+ RSpec.configure do |c|
407
+ c.stdout = "044\r\n"
408
+ end
409
+ end
410
+ it { should_not be_readable.by('owner') }
411
+ end
412
+ end
413
+ end
414
+
415
+ shared_examples_for 'support be_readable_by_group matcher' do |file|
416
+ describe 'be_readable_by_group' do
417
+ describe file do
418
+ before :all do
419
+ RSpec.configure do |c|
420
+ c.stdout = "040\r\n"
421
+ end
422
+ end
423
+ it { should be_readable.by('group') }
424
+ end
425
+
426
+ describe file do
427
+ before :all do
428
+ RSpec.configure do |c|
429
+ c.stdout = "404\r\n"
430
+ end
431
+ end
432
+ it { should_not be_readable.by('group') }
433
+ end
434
+ end
435
+ end
436
+
437
+ shared_examples_for 'support be_readable_by_others matcher' do |file|
438
+ describe 'be_readable_by_others' do
439
+ describe file do
440
+ before :all do
441
+ RSpec.configure do |c|
442
+ c.stdout = "044\r\n"
443
+ end
444
+ end
445
+ it { should be_readable.by('others') }
446
+ end
447
+
448
+ describe file do
449
+ before :all do
450
+ RSpec.configure do |c|
451
+ c.stdout = "443\r\n"
452
+ end
453
+ end
454
+ it { should_not be_readable.by('others') }
455
+ end
456
+ end
457
+ end
458
+
459
+ shared_examples_for 'support be_writable matcher' do |file|
460
+ describe 'be_writable' do
461
+ describe file do
462
+ before :all do
463
+ RSpec.configure do |c|
464
+ c.stdout = "755\r\n"
465
+ end
466
+ end
467
+ it { should be_writable }
468
+ end
469
+
470
+ describe file do
471
+ before :all do
472
+ RSpec.configure do |c|
473
+ c.stdout = "555\r\n"
474
+ end
475
+ end
476
+ it { should_not be_writable }
477
+ end
478
+ end
479
+ end
480
+
481
+ shared_examples_for 'support be_writable_by_owner matcher' do |file|
482
+ describe 'be_writable_by_owner' do
483
+ describe file do
484
+ before :all do
485
+ RSpec.configure do |c|
486
+ c.stdout = "200\r\n"
487
+ end
488
+ end
489
+ it { should be_writable.by('owner') }
490
+ end
491
+
492
+ describe file do
493
+ before :all do
494
+ RSpec.configure do |c|
495
+ c.stdout = "555\r\n"
496
+ end
497
+ end
498
+ it { should_not be_writable.by('owner') }
499
+ end
500
+ end
501
+ end
502
+
503
+ shared_examples_for 'support be_writable_by_group matcher' do |file|
504
+ describe 'be_writable_by_group' do
505
+ describe file do
506
+ before :all do
507
+ RSpec.configure do |c|
508
+ c.stdout = "030\r\n"
509
+ end
510
+ end
511
+ it { should be_writable.by('group') }
512
+ end
513
+
514
+ describe file do
515
+ before :all do
516
+ RSpec.configure do |c|
517
+ c.stdout = "555\r\n"
518
+ end
519
+ end
520
+ it { should_not be_writable.by('group') }
521
+ end
522
+ end
523
+ end
524
+
525
+ shared_examples_for 'support be_writable_by_others matcher' do |file|
526
+ describe 'be_writable_by_others' do
527
+ describe file do
528
+ before :all do
529
+ RSpec.configure do |c|
530
+ c.stdout = "666\r\n"
531
+ end
532
+ end
533
+ it { should be_writable.by('others') }
534
+ end
535
+
536
+ describe file do
537
+ before :all do
538
+ RSpec.configure do |c|
539
+ c.stdout = "555\r\n"
540
+ end
541
+ end
542
+ it { should_not be_writable.by('others') }
543
+ end
544
+ end
545
+ end
546
+
547
+ shared_examples_for 'support be_executable matcher' do |file|
548
+ describe 'be_executable' do
549
+ describe file do
550
+ before :all do
551
+ RSpec.configure do |c|
552
+ c.stdout = "755\r\n"
553
+ end
554
+ end
555
+ it { should be_executable }
556
+ end
557
+
558
+ describe file do
559
+ before :all do
560
+ RSpec.configure do |c|
561
+ c.stdout = "666\r\n"
562
+ end
563
+ end
564
+ it { should_not be_executable }
565
+ end
566
+ end
567
+ end
568
+
569
+ shared_examples_for 'support be_executable_by_owner matcher' do |file|
570
+ describe 'be_executable_by_owner' do
571
+ describe file do
572
+ before :all do
573
+ RSpec.configure do |c|
574
+ c.stdout = "100\r\n"
575
+ end
576
+ end
577
+ it { should be_executable.by('owner') }
578
+ end
579
+
580
+ describe file do
581
+ before :all do
582
+ RSpec.configure do |c|
583
+ c.stdout = "666\r\n"
584
+ end
585
+ end
586
+ it { should_not be_executable.by('owner') }
587
+ end
588
+ end
589
+ end
590
+
591
+ shared_examples_for 'support be_executable_by_group matcher' do |file|
592
+ describe 'be_executable_by_group' do
593
+ describe file do
594
+ before :all do
595
+ RSpec.configure do |c|
596
+ c.stdout = "070\r\n"
597
+ end
598
+ end
599
+ it { should be_executable.by('group') }
600
+ end
601
+
602
+ describe file do
603
+ before :all do
604
+ RSpec.configure do |c|
605
+ c.stdout = "666\r\n"
606
+ end
607
+ end
608
+ it { should_not be_executable.by('group') }
609
+ end
610
+ end
611
+ end
612
+
613
+ shared_examples_for 'support be_executable_by_others matcher' do |file|
614
+ describe 'be_executable_by_others' do
615
+ describe file do
616
+ before :all do
617
+ RSpec.configure do |c|
618
+ c.stdout = "001\r\n"
619
+ end
620
+ end
621
+ it { should be_executable.by('others') }
622
+ end
623
+
624
+ describe file do
625
+ before :all do
626
+ RSpec.configure do |c|
627
+ c.stdout = "666\r\n"
628
+ end
629
+ end
630
+ it { should_not be_executable.by('others') }
631
+ end
632
+ end
633
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -113,6 +113,7 @@ files:
113
113
  - lib/serverspec/matchers.rb
114
114
  - lib/serverspec/matchers/be_directory.rb
115
115
  - lib/serverspec/matchers/be_enabled.rb
116
+ - lib/serverspec/matchers/be_executable.rb
116
117
  - lib/serverspec/matchers/be_file.rb
117
118
  - lib/serverspec/matchers/be_group.rb
118
119
  - lib/serverspec/matchers/be_grouped_into.rb
@@ -122,8 +123,10 @@ files:
122
123
  - lib/serverspec/matchers/be_listening.rb
123
124
  - lib/serverspec/matchers/be_mode.rb
124
125
  - lib/serverspec/matchers/be_owned_by.rb
126
+ - lib/serverspec/matchers/be_readable.rb
125
127
  - lib/serverspec/matchers/be_running.rb
126
128
  - lib/serverspec/matchers/be_user.rb
129
+ - lib/serverspec/matchers/be_writable.rb
127
130
  - lib/serverspec/matchers/be_zfs.rb
128
131
  - lib/serverspec/matchers/belong_to_group.rb
129
132
  - lib/serverspec/matchers/contain.rb
@@ -139,7 +142,7 @@ files:
139
142
  - spec/gentoo/matchers_spec.rb
140
143
  - spec/redhat/commands_spec.rb
141
144
  - spec/redhat/matchers_spec.rb
142
- - spec/solaris/commads_spec.rb
145
+ - spec/solaris/commands_spec.rb
143
146
  - spec/solaris/matchers_spec.rb
144
147
  - spec/spec_helper.rb
145
148
  - spec/support/shared_matcher_examples.rb
@@ -164,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
167
  version: '0'
165
168
  requirements: []
166
169
  rubyforge_project:
167
- rubygems_version: 1.8.23
170
+ rubygems_version: 1.8.25
168
171
  signing_key:
169
172
  specification_version: 3
170
173
  summary: RSpec tests for your servers provisioned by Puppet, Chef or anything else
@@ -175,7 +178,7 @@ test_files:
175
178
  - spec/gentoo/matchers_spec.rb
176
179
  - spec/redhat/commands_spec.rb
177
180
  - spec/redhat/matchers_spec.rb
178
- - spec/solaris/commads_spec.rb
181
+ - spec/solaris/commands_spec.rb
179
182
  - spec/solaris/matchers_spec.rb
180
183
  - spec/spec_helper.rb
181
184
  - spec/support/shared_matcher_examples.rb