serverspec 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe group('root') do
8
+ it { should exist }
9
+ its(:command) { should eq "getent group | grep -wq -- root" }
10
+ end
11
+
12
+ describe group('invalid-group') do
13
+ it { should_not exist }
14
+ end
15
+
16
+ describe group('root') do
17
+ it { should have_gid 0 }
18
+ its(:command) { should eq "getent group | grep -w -- \\^root | cut -f 3 -d ':' | grep -w -- 0" }
19
+ end
20
+
21
+ describe group('root') do
22
+ it { should_not have_gid 'invalid-gid' }
23
+ end
24
+
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe host('127.0.0.1') do
8
+ it { should be_resolvable }
9
+ its(:command) { should eq "getent hosts 127.0.0.1" }
10
+ end
11
+
12
+ describe host('invalid-name') do
13
+ it { should_not be_resolvable }
14
+ end
15
+
16
+ describe host('127.0.0.1') do
17
+ it { should be_resolvable.by('hosts') }
18
+ its(:command) { should eq "grep -w -- 127.0.0.1 /etc/hosts" }
19
+ end
20
+
21
+ describe host('invalid-name') do
22
+ it { should_not be_resolvable.by('hosts') }
23
+ end
24
+
25
+ describe host('127.0.0.1') do
26
+ it { should be_resolvable.by('dns') }
27
+ its(:command) { should eq "nslookup -timeout=1 127.0.0.1" }
28
+ end
29
+
30
+ describe host('invalid-name') do
31
+ it { should_not be_resolvable.by('dns') }
32
+ end
33
+
34
+ describe host('127.0.0.1') do
35
+ it { should be_reachable }
36
+ its(:command) { should eq "ping -n 127.0.0.1 -w 5 -c 2" }
37
+ end
38
+
39
+ describe host('invalid-host') do
40
+ it { should_not be_reachable }
41
+ end
42
+
43
+ describe host('127.0.0.1') do
44
+ it { should be_reachable.with(:proto => "icmp", :timeout=> 1) }
45
+ its(:command) { should eq "ping -n 127.0.0.1 -w 1 -c 2" }
46
+ end
47
+
48
+ describe host('127.0.0.1') do
49
+ it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) }
50
+ its(:command) { should eq "nc -vvvvzt 127.0.0.1 22 -w 1" }
51
+ end
52
+
53
+ describe host('127.0.0.1') do
54
+ it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) }
55
+ its(:command) { should eq "nc -vvvvzu 127.0.0.1 53 -w 1" }
56
+ end
57
+
58
+ describe host('invalid-host') do
59
+ it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) }
60
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe interface('eth0') do
8
+ let(:stdout) { '1000' }
9
+ its(:speed) { should eq 1000 }
10
+ its(:command) { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" }
11
+ end
12
+
13
+ describe interface('eth0') do
14
+ it { should have_ipv4_address("192.168.10.10") }
15
+ its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/'" }
16
+ end
17
+
18
+ describe interface('eth0') do
19
+ it { should have_ipv4_address("192.168.10.10/24") }
20
+ its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/24 '" }
21
+ end
22
+
23
+ describe interface('invalid-interface') do
24
+ let(:stdout) { '1000' }
25
+ its(:speed) { should_not eq 100 }
26
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe iptables do
8
+ it { should have_rule '-P INPUT ACCEPT' }
9
+ its(:command) { should eq "iptables -S | grep -- -P\\ INPUT\\ ACCEPT" }
10
+ end
11
+
12
+ describe iptables do
13
+ it { should_not have_rule 'invalid-rule' }
14
+ end
15
+
16
+ describe iptables do
17
+ it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') }
18
+ its(:command) { should eq "iptables -t mangle -S INPUT | grep -- -P\\ INPUT\\ ACCEPT" }
19
+ end
20
+
21
+ describe iptables do
22
+ it { should_not have_rule('invalid-rule').with_table('mangle').with_chain('INPUT') }
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe kernel_module('lp') do
8
+ it { should be_loaded }
9
+ its(:command) { should eq "lsmod | grep ^lp" }
10
+ end
11
+
12
+ describe kernel_module('invalid-module') do
13
+ it { should_not be_loaded }
14
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do
8
+ let(:stdout) { "1\n" }
9
+ its(:value) { should eq 1 }
10
+ its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_syncookies" }
11
+ end
12
+
13
+ describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do
14
+ let(:stdout) { "1\n" }
15
+ its(:value) { should_not eq 2 }
16
+ end
17
+
18
+ describe linux_kernel_parameter('kernel.osrelease') do
19
+ let(:stdout) { "2.6.32-131.0.15.el6.x86_64\n" }
20
+ its(:value) { should eq "2.6.32-131.0.15.el6.x86_64" }
21
+ its(:command) { should eq "/sbin/sysctl -q -n kernel.osrelease" }
22
+ end
23
+
24
+ describe linux_kernel_parameter('kernel.osrelease') do
25
+ let(:stdout) { "2.6.32-131.0.15.el6.x86_64\n" }
26
+ its(:value) { should_not eq "2.6.32-131.0.15.el6.i386" }
27
+ end
28
+
29
+ describe linux_kernel_parameter('net.ipv4.tcp_wmem') do
30
+ let(:stdout) { "4096 16384 4194304\n" }
31
+ its(:value) { should match /16384/ }
32
+ its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_wmem" }
33
+ end
34
+
35
+ describe linux_kernel_parameter('net.ipv4.tcp_wmem') do
36
+ let(:stdout) { "4096 16384 4194304\n" }
37
+ its(:value) { should_not match /123456/ }
38
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe mail_alias('daemon') do
8
+ it { should be_aliased_to "root" }
9
+ its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" }
10
+ end
11
+
12
+ describe mail_alias('invalid-recipient') do
13
+ it { should_not be_aliased_to "foo" }
14
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe package('httpd') do
8
+ it { should be_installed }
9
+ its(:command) { should eq "ls /var/log/packages/httpd" }
10
+ end
11
+
12
+ describe package('invalid-package') do
13
+ it { should_not be_installed }
14
+ end
15
+
16
+ describe package('httpd') do
17
+ it { should be_installed.with_version('1.1.1') }
18
+ its(:command) { should eq "ls /var/log/packages/httpd && grep -E \"PACKAGE NAME:.+httpd-1.1.1\" /var/log/packages/httpd" }
19
+ end
20
+
21
+ describe package('invalid-package') do
22
+ it { should_not be_installed.with_version('invalid-version') }
23
+ end
24
+
25
+ describe package('jekyll') do
26
+ it { should be_installed.by('gem') }
27
+ its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" }
28
+ end
29
+
30
+ describe package('invalid-gem') do
31
+ it { should_not be_installed.by('gem') }
32
+ end
33
+
34
+ describe package('jekyll') do
35
+ it { should be_installed.by('gem').with_version('1.1.1') }
36
+ its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" }
37
+ end
38
+
39
+ describe package('jekyll') do
40
+ it { should_not be_installed.by('gem').with_version('invalid-version') }
41
+ end
42
+
43
+ describe package('bower') do
44
+ it { should be_installed.by('npm') }
45
+ its(:command) { should eq "npm ls bower -g" }
46
+ end
47
+
48
+ describe package('invalid-npm-package') do
49
+ it { should_not be_installed.by('npm') }
50
+ end
51
+
52
+ describe package('bower') do
53
+ it { should be_installed.by('npm').with_version('0.9.2') }
54
+ its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" }
55
+ end
56
+
57
+ describe package('bower') do
58
+ it { should_not be_installed.by('npm').with_version('invalid-version') }
59
+ end
60
+
61
+
62
+ describe package('mongo') do
63
+ it { should be_installed.by('pecl') }
64
+ its(:command) { should eq "pecl list | grep -w -- \\^mongo" }
65
+ end
66
+
67
+ describe package('invalid-pecl') do
68
+ it { should_not be_installed.by('pecl') }
69
+ end
70
+
71
+ describe package('mongo') do
72
+ it { should be_installed.by('pecl').with_version('1.4.1') }
73
+ its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" }
74
+ end
75
+
76
+ describe package('mongo') do
77
+ it { should_not be_installed.by('pecl').with_version('invalid-version') }
78
+ end
79
+
80
+ describe package('XML_Util') do
81
+ it { should be_installed.by('pear').with_version('1.2.1') }
82
+ its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" }
83
+ end
84
+
85
+ describe package('supervisor') do
86
+ it { should be_installed.by('pip').with_version('3.0') }
87
+ its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" }
88
+ end
89
+
90
+ describe package('invalid-pip') do
91
+ it { should_not be_installed.by('pip').with_version('invalid-version') }
92
+ end
93
+
94
+ describe package('App::Ack') do
95
+ it { should be_installed.by('cpan') }
96
+ its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" }
97
+ end
98
+
99
+ describe package('App::Ack') do
100
+ it { should be_installed.by('cpan').with_version('2.04') }
101
+ its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" }
102
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe php_config('default_mimetype') do
8
+ let(:stdout) { 'text/html' }
9
+ its(:value) { should eq 'text/html' }
10
+ its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" }
11
+ end
12
+
13
+ describe php_config('default_mimetype') do
14
+ let(:stdout) { 'text/html' }
15
+ its(:value) { should_not eq 'text/plain' }
16
+ end
17
+
18
+ describe php_config('session.cache_expire') do
19
+ let(:stdout) { '180' }
20
+ its(:value) { should eq 180 }
21
+ its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" }
22
+ end
23
+
24
+ describe php_config('session.cache_expire') do
25
+ let(:stdout) { '180' }
26
+ its(:value) { should_not eq 360 }
27
+ end
28
+
29
+ describe php_config('mbstring.http_output_conv_mimetypes') do
30
+ let(:stdout) { 'application' }
31
+ its(:value) { should match /application/ }
32
+ its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" }
33
+ end
34
+
35
+ describe php_config('mbstring.http_output_conv_mimetypes') do
36
+ let(:stdout) { 'application' }
37
+ its(:value) { should_not match /html/ }
38
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe port(80) do
8
+ it { should be_listening }
9
+ its(:command) { should eq 'netstat -tunl | grep -- :80\\ ' }
10
+ end
11
+
12
+ describe port('invalid') do
13
+ it { should_not be_listening }
14
+ end
15
+
16
+ describe port(80) do
17
+ it { should be_listening.with("tcp") }
18
+ its(:command) { should eq 'netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ ' }
19
+ end
20
+
21
+ describe port(123) do
22
+ it { should be_listening.with("udp") }
23
+ its(:command) { should eq 'netstat -tunl | grep -- \\^udp\\ .\\*:123\\ ' }
24
+ end
25
+
26
+ describe port(80) do
27
+ it {
28
+ expect {
29
+ should be_listening.with('not implemented')
30
+ }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/)
31
+ }
32
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.configure do |c|
4
+ c.os = 'Plamo'
5
+ end
6
+
7
+ describe routing_table do
8
+ let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
9
+ it { should have_entry( :destination => '192.168.100.0/24' ) }
10
+ its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" }
11
+ end
12
+
13
+ describe routing_table do
14
+ let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
15
+ it { should_not have_entry( :destination => '192.168.100.100/24' ) }
16
+ its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" }
17
+ end
18
+
19
+ describe routing_table do
20
+ let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
21
+ it do
22
+ should have_entry(
23
+ :destination => '192.168.100.0/24',
24
+ :gateway => '192.168.100.1'
25
+ )
26
+ end
27
+
28
+ it do
29
+ should have_entry(
30
+ :destination => '192.168.100.0/24',
31
+ :gateway => '192.168.100.1',
32
+ :interface => 'eth1'
33
+ )
34
+ end
35
+
36
+ it do
37
+ should_not have_entry(
38
+ :gateway => '192.168.100.1',
39
+ :interface => 'eth1'
40
+ )
41
+ end
42
+
43
+ it do
44
+ should_not have_entry(
45
+ :destination => '192.168.100.0/32',
46
+ :gateway => '192.168.100.1',
47
+ :interface => 'eth1'
48
+ )
49
+ end
50
+ end
51
+
52
+ describe routing_table do
53
+ let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" }
54
+ it { should have_entry( :destination => '192.168.200.0/24' ) }
55
+ it { should_not have_entry( :destination => '192.168.200.200/24' ) }
56
+
57
+ it do
58
+ should have_entry(
59
+ :destination => '192.168.200.0/24',
60
+ :gateway => '192.168.200.1'
61
+ )
62
+ end
63
+
64
+ it do
65
+ should have_entry(
66
+ :destination => '192.168.200.0/24',
67
+ :gateway => '192.168.200.1',
68
+ :interface => 'eth0'
69
+ )
70
+ end
71
+
72
+ it do
73
+ should_not have_entry(
74
+ :gateway => '192.168.200.1',
75
+ :interface => 'eth0'
76
+ )
77
+ end
78
+
79
+ it do
80
+ should_not have_entry(
81
+ :destination => '192.168.200.0/32',
82
+ :gateway => '192.168.200.1',
83
+ :interface => 'eth0'
84
+ )
85
+ end
86
+ end
87
+
88
+ describe routing_table do
89
+ let(:stdout) { "default via 10.0.2.2 dev eth0 \r\n" }
90
+ it { should have_entry( :destination => 'default' ) }
91
+ it { should_not have_entry( :destination => 'defaulth' ) }
92
+
93
+ it do
94
+ should have_entry(
95
+ :destination => 'default',
96
+ :gateway => '10.0.2.2'
97
+ )
98
+ end
99
+
100
+ it do
101
+ should have_entry(
102
+ :destination => 'default',
103
+ :gateway => '10.0.2.2',
104
+ :interface => 'eth0'
105
+ )
106
+ end
107
+
108
+ it do
109
+ should_not have_entry(
110
+ :gateway => '10.0.2.2',
111
+ :interface => 'eth0'
112
+ )
113
+ end
114
+
115
+ it do
116
+ should_not have_entry(
117
+ :destination => 'default',
118
+ :gateway => '10.0.2.1',
119
+ :interface => 'eth0'
120
+ )
121
+ end
122
+ end