serverspec-2.41.5/0000755000004100000410000000000013526734265014031 5ustar www-datawww-dataserverspec-2.41.5/.travis.yml0000644000004100000410000000107313526734265016143 0ustar www-datawww-datalanguage: ruby rvm: - 1.8.7 - 1.9.3 - 2.0.0 - 2.1.1 - 2.2.4 - 2.3.6 - 2.4.3 - 2.5.0 before_install: - travis_retry gem update --system 2.7.8 - travis_retry gem install bundler -v 1.17.3 - travis_retry gem uninstall -i /home/travis/.rvm/gems/ruby-2.3.7@global bundler || echo script: - bundle exec rake spec sudo: false cache: bundler notifications: slack: secure: X1umGErES0zd+LXX1EqZZxrPZv2YOzbCNxiLLiSGmJLlZAEtlSkMPyr+M00Lrs2DFhn4blwKPm+5YCBvU7f9F4K5GthSl0qZYNpNX/lGNn6EGeBnzJ8rFVgwXPUv1rvrJq0NjeSGni3yAK69K/uX6QohGojAI3iI28/EbJ+uYQM= serverspec-2.41.5/README.md0000644000004100000410000000274713526734265015322 0ustar www-datawww-data# Serverspec [![Gem Version](https://badge.fury.io/rb/serverspec.svg)](http://badge.fury.io/rb/serverspec) [![BuildStatus](https://secure.travis-ci.org/mizzy/serverspec.svg)](http://travis-ci.org/mizzy/serverspec) [![wercker status](https://app.wercker.com/status/526d1ff4df6eadaa793dca1affcaed35/s/ "wercker status")](https://app.wercker.com/project/bykey/526d1ff4df6eadaa793dca1affcaed35) RSpec tests for your servers configured by Puppet, Chef or anything else You can see the details of serverspec on [serverspec.org](http://serverspec.org/). ---- ## Running the gem's tests Use ```bundle exec rake``` (Using ```rspec``` alone will not work). ## Maintenance policy of Serverspec/Specinfra * The person who found a bug should fix the bug by themself. * If you find a bug and cannot fix it by yourself, send a pull request and attach test code to reproduce the bug, please. * The person who want a new feature should implement it by themself. * For above reasons, I accept pull requests only and disable issues. * If you'd like to discuss about a new feature before implement it, make an empty commit and send [a WIP pull request](http://ben.straub.cc/2015/04/02/wip-pull-request/). But It is better that the WIP PR has some code than an empty commit. ---- ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request serverspec-2.41.5/bin/0000755000004100000410000000000013526734265014601 5ustar www-datawww-dataserverspec-2.41.5/bin/serverspec-init0000755000004100000410000000020413526734265017645 0ustar www-datawww-data#!/usr/bin/env ruby $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) require 'serverspec' Serverspec::Setup.run serverspec-2.41.5/spec/0000755000004100000410000000000013526734265014763 5ustar www-datawww-dataserverspec-2.41.5/spec/type/0000755000004100000410000000000013526734265015744 5ustar www-datawww-dataserverspec-2.41.5/spec/type/fedora20/0000755000004100000410000000000013526734265017346 5ustar www-datawww-dataserverspec-2.41.5/spec/type/fedora20/service_spec.rb0000644000004100000410000000040613526734265022345 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'fedora', :release => 20 describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end serverspec-2.41.5/spec/type/opensuse/0000755000004100000410000000000013526734265017605 5ustar www-datawww-dataserverspec-2.41.5/spec/type/opensuse/service_spec.rb0000644000004100000410000000037113526734265022605 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'opensuse' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end serverspec-2.41.5/spec/type/ubuntu/0000755000004100000410000000000013526734265017266 5ustar www-datawww-dataserverspec-2.41.5/spec/type/ubuntu/service_spec.rb0000644000004100000410000000016013526734265022262 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'ubuntu' describe service('sshd') do it { should be_running } end serverspec-2.41.5/spec/type/ubuntu/ppa_spec.rb0000644000004100000410000000027113526734265021405 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'ubuntu' describe ppa('username/ppa-name') do it { should exist } end describe ppa('username/ppa-name') do it { should be_enabled } end serverspec-2.41.5/spec/type/linux/0000755000004100000410000000000013526734265017103 5ustar www-datawww-dataserverspec-2.41.5/spec/type/linux/x509_private_key_spec.rb0000644000004100000410000000123413526734265023551 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe x509_private_key('key.pem') do let(:exit_status) { 0 } let(:stdout) { 'RSA key ok' } it { should be_valid } end describe x509_private_key('key.pem') do let(:exit_status) { 1 } let(:stdout) { 'RSA key ok' } it { should_not be_valid } end describe x509_private_key('key.pem') do let(:exit_status) { 0 } it { should be_encrypted } end describe x509_private_key('key.pem') do let(:exit_status) { 1 } it { should_not be_encrypted } end describe x509_private_key('key.pem') do let(:exit_status) { 0 } let(:stdout) { 'SHA1SUM' } it { should have_matching_certificate('cert.pem') } endserverspec-2.41.5/spec/type/linux/interface_spec.rb0000644000004100000410000000207513526734265022406 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe interface('eth0') do let(:stdout) { '1000' } its(:speed) { should eq 1000 } end describe interface('eth0') do let(:stdout) { '1500' } its(:mtu) { should eq 1500 } end describe interface('eth0') do it { should have_ipv4_address('192.168.10.10') } end describe interface('eth0') do it { should have_ipv4_address('192.168.10.10/24') } end describe interface('eth0') do it { should have_ipv6_address('2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') } end describe interface('eth1') do let(:stdout) { "1.2.3.4/1\r\n" } its(:ipv4_address) { should match(/^[\d.]+\/\d+$/) } end describe interface('eth1') do let(:stdout) { "2001:db8::1234/1\r\n" } its(:ipv6_address) { should match(/^[a-f\d:]+\/\d+$/i) } end describe interface('eth0') do let(:stdout) { 'up' } it { should be_up } end describe interface('invalid-interface') do let(:stdout) { '1000' } its(:speed) { should_not eq 100 } end describe interface('invalid-interface') do let(:stdout) { '9001' } its(:mtu) { should_not eq 1500 } end serverspec-2.41.5/spec/type/linux/iptables_spec.rb0000644000004100000410000000035113526734265022244 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe iptables do it { should have_rule '-P INPUT ACCEPT' } end describe iptables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } end serverspec-2.41.5/spec/type/linux/ip6tables_spec.rb0000644000004100000410000000036313526734265022335 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe ip6tables do it { should have_rule '-P INPUT ACCEPT' } end describe ip6tables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } end serverspec-2.41.5/spec/type/linux/kvm_guest_spec.rb0000644000004100000410000000032613526734265022447 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe kvm('ct01') do it { should exist } end describe kvm('ct01') do it { should be_running } end describe kvm('ct01') do it { should be_enabled } end serverspec-2.41.5/spec/type/linux/file_spec.rb0000644000004100000410000000105413526734265021361 0ustar www-datawww-datarequire 'spec_helper' property[:os] = nil set :os, {:family => 'linux'} describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end describe file('/tmp') do it { should be_immutable } end describe file('/tmp') do let(:exit_status) { 0 } let(:stdout) { 'unconfined_u:unconfined_r:unconfined_t:s0' } its(:selinux_label) { should eq 'unconfined_u:unconfined_r:unconfined_t:s0' } end serverspec-2.41.5/spec/type/linux/kernel_module_spec.rb0000644000004100000410000000016213526734265023266 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe kernel_module('lp') do it { should be_loaded } end serverspec-2.41.5/spec/type/linux/linux_kernel_parameter_spec.rb0000644000004100000410000000163413526734265025205 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do let(:stdout) { "1\n" } its(:value) { should eq 1 } end describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do let(:stdout) { "1\n" } its(:value) { should_not eq 2 } end describe linux_kernel_parameter('kernel.osrelease') do let(:stdout) { "2.6.32-131.0.15.el6.x86_64\n" } its(:value) { should eq "2.6.32-131.0.15.el6.x86_64" } end describe linux_kernel_parameter('kernel.osrelease') do let(:stdout) { "2.6.32-131.0.15.el6.x86_64\n" } its(:value) { should_not eq "2.6.32-131.0.15.el6.i386" } end describe linux_kernel_parameter('net.ipv4.tcp_wmem') do let(:stdout) { "4096 16384 4194304\n" } its(:value) { should match /16384/ } end describe linux_kernel_parameter('net.ipv4.tcp_wmem') do let(:stdout) { "4096 16384 4194304\n" } its(:value) { should_not match /123456/ } end serverspec-2.41.5/spec/type/linux/docker_container_pre_1_8_spec.rb0000644000004100000410000000644713526734265025303 0ustar www-datawww-data# -*- coding: utf-8 -*- require 'spec_helper' require 'json' property[:os] = nil set :os, {:family => 'linux'} describe docker_container('c1') do it { should exist } end describe docker_container('c1 pre 1.8') do let(:stdout) { inspect_container } it { should be_running } it { should have_volume('/tmp', '/data') } it { should_not have_volume('/tmp', '/data-bad') } its(:inspection) { should include 'Driver' => 'aufs' } its(['Config.Cmd']) { should include '/bin/sh' } its(['HostConfig.PortBindings.80.[0].HostPort']) { should eq '8080' } end describe docker_container('restarting pre 1.8') do let(:stdout) do attrs = JSON.parse(inspect_container) attrs.first['State']['Restarting'] = true attrs.to_json end it { should_not be_running } end def inspect_container <<'EOS' [{ "Args": [], "Config": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "/bin/sh" ], "CpuShares": 0, "Cpuset": "", "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "65cd2e2d7963", "Image": "busybox", "Memory": 0, "MemorySwap": 0, "NetworkDisabled": false, "OnBuild": null, "OpenStdin": true, "PortSpecs": null, "StdinOnce": false, "Tty": true, "User": "", "Volumes": null, "WorkingDir": "" }, "Created": "2014-09-26T15:08:37.527931773Z", "Driver": "aufs", "ExecDriver": "native-0.2", "HostConfig": { "Binds": [ "/data:/tmp" ], "ContainerIDFile": "", "Dns": null, "DnsSearch": null, "Links": null, "LxcConf": [], "NetworkMode": "bridge", "PortBindings": { "80": [ { "HostIp": "", "HostPort": "8080" } ] }, "Privileged": false, "PublishAllPorts": false, "VolumesFrom": null }, "HostnamePath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hostname", "HostsPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hosts", "Id": "65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545", "Image": "e72ac664f4f0c6a061ac4ef332557a70d69b0c624b6add35f1c181ff7fff2287", "MountLabel": "", "Name": "/c1", "NetworkSettings": { "Bridge": "docker0", "Gateway": "172.17.42.1", "IPAddress": "172.17.0.24", "IPPrefixLen": 16, "PortMapping": null, "Ports": {} }, "Path": "/bin/sh", "ProcessLabel": "", "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/resolv.conf", "State": { "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "Paused": false, "Pid": 4123, "Running": true, "StartedAt": "2014-09-26T15:08:37.737780273Z" }, "Volumes": { "/tmp": "/data" }, "VolumesRW": { "/tmp": true } } ] EOS end serverspec-2.41.5/spec/type/linux/x509_certificate_spec.rb0000644000004100000410000000314013526734265023507 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe x509_certificate('test.pem') do let(:exit_status) { 0 } it { should be_certificate } end describe x509_certificate('test.pem') do let(:exit_status) { 1 } it { should_not be_certificate } end describe x509_certificate('test.pem') do let(:stdout) { sample_subj } its(:subject) { should eq '/O=some/OU=thing' } end describe x509_certificate('test.pem') do let(:stdout) { sample_issuer } its(:issuer) { should eq '/O=some/OU=issuer' } end describe x509_certificate('test.pem') do let(:stdout) { sample_validity } it { should be_valid } its(:validity_in_days) { should be >= 1000 } end describe x509_certificate('test.pem') do let(:stdout) { sample_validity2 } it { should_not be_valid } end describe x509_certificate('test.pem') do let(:stdout) { sample_san } its(:subject_alt_names) { should eq %w[DNS:*.example.com DNS:www.example.net IP:192.0.2.10] } end def sample_subj <<'EOS' subject= /O=some/OU=thing EOS end def sample_issuer <<'EOS' issuer= /O=some/OU=issuer EOS end def sample_validity <<'EOS' notBefore=Jul 1 11:11:00 2000 GMT notAfter=Jul 1 11:11:00 2050 GMT EOS end def sample_validity2 <<'EOS' notBefore=Jul 1 11:11:00 2000 GMT notAfter=Jul 1 11:11:00 2010 GMT EOS end def sample_san <<'EOS' Certificate: Data: Version: 3 (0x2) X509v3 extensions: X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication X509v3 Subject Alternative Name: DNS:*.example.com, DNS:www.example.net, IP:192.0.2.10 EOS end serverspec-2.41.5/spec/type/linux/lxc_container_spec.rb0000644000004100000410000000023713526734265023274 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe lxc('ct01') do it { should exist } end describe lxc('ct01') do it { should be_running } end serverspec-2.41.5/spec/type/linux/fstab_spec.rb0000644000004100000410000000125213526734265021541 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe fstab do let(:stdout) { "/dev/sda1 /mnt ext4 ro,errors=remount-ro,barrier=0 0 2\r\n" } it { should have_entry( :mount_point => '/mnt' ) } end describe fstab do let(:exit_status) { 1 } it { should_not have_entry( :mount_point => '/mnt' ) } end describe fstab do let(:stdout) { "/dev/sda1 /mnt ext4 ro,errors=remount-ro,barrier=0 0 2\r\n" } it do should have_entry( :device => '/dev/sda1', :mount_point => '/mnt', :type => 'ext4', :options => { :ro => true, :errors => 'remount-ro', :barrier => 0 }, :dump => 0, :pass => 2 ) end end serverspec-2.41.5/spec/type/linux/docker_container_spec.rb0000644000004100000410000000702613526734265023760 0ustar www-datawww-data# -*- coding: utf-8 -*- require 'spec_helper' require 'multi_json' property[:os] = nil set :os, {:family => 'linux'} describe docker_container('c1') do it { should exist } end describe docker_container('c1') do let(:stdout) { inspect_container } it { should be_running } it { should have_volume('/tmp', '/data') } it { should_not have_volume('/tmp', '/data-bad') } its(:inspection) { should include 'Driver' => 'aufs' } its(['Config.Cmd']) { should include '/bin/sh' } its(['HostConfig.PortBindings.80.[0].HostPort']) { should eq '8080' } its(['HostConfig.PortBindings.80.[1].HostPort']) { should eq '8081' } end describe docker_container('restarting') do let(:stdout) do attrs = MultiJson.load(inspect_container) attrs.first['State']['Restarting'] = true attrs.to_json end it { should_not be_running } end def inspect_container <<'EOS' [{ "Args": [], "Config": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "/bin/sh" ], "CpuShares": 0, "Cpuset": "", "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "65cd2e2d7963", "Image": "busybox", "Memory": 0, "MemorySwap": 0, "NetworkDisabled": false, "OnBuild": null, "OpenStdin": true, "PortSpecs": null, "StdinOnce": false, "Tty": true, "User": "", "Volumes": null, "WorkingDir": "" }, "Created": "2014-09-26T15:08:37.527931773Z", "Driver": "aufs", "ExecDriver": "native-0.2", "HostConfig": { "Binds": [ "/data:/tmp" ], "ContainerIDFile": "", "Dns": null, "DnsSearch": null, "Links": null, "LxcConf": [], "NetworkMode": "bridge", "PortBindings": { "80": [ { "HostIp": "", "HostPort": "8080" }, { "HostIp": "", "HostPort": "8081" } ] }, "Privileged": false, "PublishAllPorts": false, "VolumesFrom": null }, "HostnamePath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hostname", "HostsPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hosts", "Id": "65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545", "Image": "e72ac664f4f0c6a061ac4ef332557a70d69b0c624b6add35f1c181ff7fff2287", "MountLabel": "", "Name": "/c1", "NetworkSettings": { "Bridge": "docker0", "Gateway": "172.17.42.1", "IPAddress": "172.17.0.24", "IPPrefixLen": 16, "PortMapping": null, "Ports": {} }, "Path": "/bin/sh", "ProcessLabel": "", "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/resolv.conf", "State": { "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "Paused": false, "Pid": 4123, "Running": true, "StartedAt": "2014-09-26T15:08:37.737780273Z" }, "Mounts": [ { "Source": "/data", "Destination": "/tmp", "Mode": "", "RW": true } ] } ] EOS end serverspec-2.41.5/spec/type/linux/selinux_module_spec.rb0000644000004100000410000000045013526734265023475 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe selinux_module('bootloader') do it { should be_installed } end describe selinux_module('bootloader') do it { should be_installed.with_version('1.10') } end describe selinux_module('bootloader') do it { should be_enabled } end serverspec-2.41.5/spec/type/linux/cgroup_spec.rb0000644000004100000410000000037313526734265021744 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should eq 1 } end describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should_not eq 0 } end serverspec-2.41.5/spec/type/linux/bond_spec.rb0000644000004100000410000000030713526734265021364 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe bond('bond0') do it { should exist } end describe bond('bond0') do let(:stdout) { 'eth0' } it { should have_interface 'eth0' } end serverspec-2.41.5/spec/type/linux/linux_audit_system_spec.rb0000644000004100000410000000477613526734265024411 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe linux_audit_system do let(:stdout) { out_auditctl1_1 } it { should be_enabled } end describe linux_audit_system do let(:stdout) { out_auditctl1_2 } it { should_not be_enabled } end describe linux_audit_system do let(:stdout) { out_auditctl1_1 } it { should be_running } end describe linux_audit_system do let(:stdout) { out_auditctl1_3 } it { should_not be_running } end describe linux_audit_system do let(:stdout) { out_auditctl1_4 } it { should_not be_running } end describe linux_audit_system do let(:stdout) { out_auditctl2_1 } it { should be_enabled } end describe linux_audit_system do let(:stdout) { out_auditctl2_2 } it { should_not be_enabled } end describe linux_audit_system do let(:stdout) { out_auditctl2_1 } it { should be_running } end describe linux_audit_system do let(:stdout) { out_auditctl2_3 } it { should_not be_running } end describe linux_audit_system do let(:stdout) { out_auditctl2_4 } it { should_not be_running } end describe linux_audit_system do let(:stdout) { '-a -w /etc/sysconfig -p wa -k test' } its(:rules) { should match %r!-w /etc/sysconfig.*-k test! } end describe linux_audit_system do let(:stdout) { 'test' } its(:rules) { should eq 'test' } its(:rules) { should match /es/ } its(:rules) { should_not match /ab/ } end # variants of auditctl -s output for different versions def out_auditctl1_1 "AUDIT_STATUS: enabled=1 flag=1 pid=881 rate_limit=0 backlog_limit=320 lost=0 backlog=0" end def out_auditctl1_2 "AUDIT_STATUS: enabled=0 flag=1 pid=881 rate_limit=0 backlog_limit=320 lost=0 backlog=0" end def out_auditctl1_3 "AUDIT_STATUS: enabled=1 flag=1 pid=0 rate_limit=0 backlog_limit=320 lost=0 backlog=0" end def out_auditctl1_4 "AUDIT_STATUS: enabled=1 flag=1 pid= rate_limit=0 backlog_limit=320 lost=0 backlog=0" end def out_auditctl2_1 < 'linux' describe bridge('br0') do it { should exist } end describe bridge('br0') do let(:stdout) { 'eth0' } it { should have_interface 'eth0' } end serverspec-2.41.5/spec/type/linux/selinux_spec.rb0000644000004100000410000000055513526734265022136 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe selinux do it { should be_enforcing } end describe selinux do it { should be_enforcing.with_policy('mls') } end describe selinux do it { should be_permissive } end describe selinux do it { should be_permissive.with_policy('targeted') } end describe selinux do it { should be_disabled } end serverspec-2.41.5/spec/type/linux/docker_image_spec.rb0000644000004100000410000000503713526734265023060 0ustar www-datawww-data# -*- coding: utf-8 -*- require 'spec_helper' property[:os] = nil set :os, {:family => 'linux'} describe docker_image('busybox:latest') do it { should exist } end describe docker_image('busybox:latest') do let(:stdout) { inspect_image } its(:inspection) { should include 'Architecture' => 'amd64' } its(['Architecture']) { should eq 'amd64' } its(['Config.Cmd']) { should include '/bin/sh' } end def inspect_image <<'EOS' [{ "Architecture": "amd64", "Author": "Jérôme Petazzoni \u003cjerome@docker.com\u003e", "Comment": "", "Config": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "/bin/sh" ], "CpuShares": 0, "Cpuset": "", "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "88f18f678e5d", "Image": "e433a6c5b276a31aa38bf6eaba9cd1cfd69ea33f706ed72b3f20bafde5cd8644", "Memory": 0, "MemorySwap": 0, "NetworkDisabled": false, "OnBuild": [], "OpenStdin": false, "PortSpecs": null, "StdinOnce": false, "Tty": false, "User": "", "Volumes": null, "WorkingDir": "" }, "Container": "8e73b239682fe73338323d9af83d3c5aa5bb7d22a3fe84cbfcf5f47e756d6636", "ContainerConfig": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "/bin/sh", "-c", "#(nop) CMD [/bin/sh]" ], "CpuShares": 0, "Cpuset": "", "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "88f18f678e5d", "Image": "e433a6c5b276a31aa38bf6eaba9cd1cfd69ea33f706ed72b3f20bafde5cd8644", "Memory": 0, "MemorySwap": 0, "NetworkDisabled": false, "OnBuild": [], "OpenStdin": false, "PortSpecs": null, "StdinOnce": false, "Tty": false, "User": "", "Volumes": null, "WorkingDir": "" }, "Created": "2014-10-01T20:46:08.914288461Z", "DockerVersion": "1.2.0", "Id": "e72ac664f4f0c6a061ac4ef332557a70d69b0c624b6add35f1c181ff7fff2287", "Os": "linux", "Parent": "e433a6c5b276a31aa38bf6eaba9cd1cfd69ea33f706ed72b3f20bafde5cd8644", "Size": 0 } ] EOS end serverspec-2.41.5/spec/type/linux/zfs_spec.rb0000644000004100000410000000045213526734265021245 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'linux' describe zfs('rpool') do it { should exist } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } end serverspec-2.41.5/spec/type/debian/0000755000004100000410000000000013526734265017166 5ustar www-datawww-dataserverspec-2.41.5/spec/type/debian/package_spec.rb0000644000004100000410000000101713526734265022117 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'debian' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('apt').with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end serverspec-2.41.5/spec/type/debian/service_spec.rb0000644000004100000410000000027213526734265022166 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'debian' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end serverspec-2.41.5/spec/type/arch/0000755000004100000410000000000013526734265016661 5ustar www-datawww-dataserverspec-2.41.5/spec/type/arch/file_spec.rb0000644000004100000410000000042213526734265021135 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'arch' describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end serverspec-2.41.5/spec/type/arch/package_spec.rb0000644000004100000410000000064613526734265021621 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'arch' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end serverspec-2.41.5/spec/type/arch/service_spec.rb0000644000004100000410000000021213526734265021653 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'arch' describe service('sshd') do it { should be_enabled } it { should be_running } end serverspec-2.41.5/spec/type/plamo/0000755000004100000410000000000013526734265017054 5ustar www-datawww-dataserverspec-2.41.5/spec/type/plamo/package_spec.rb0000644000004100000410000000016313526734265022006 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'plamo' describe package('httpd') do it { should be_installed } end serverspec-2.41.5/spec/type/plamo/service_spec.rb0000644000004100000410000000016013526734265022050 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'plamo' describe service('sshd') do it { should be_enabled } end serverspec-2.41.5/spec/type/gentoo/0000755000004100000410000000000013526734265017237 5ustar www-datawww-dataserverspec-2.41.5/spec/type/gentoo/package_spec.rb0000644000004100000410000000016313526734265022171 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'gentoo' describe package('httpd') do it { should be_installed } end serverspec-2.41.5/spec/type/gentoo/service_spec.rb0000644000004100000410000000025513526734265022240 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'gentoo' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_running } end serverspec-2.41.5/spec/type/fedora/0000755000004100000410000000000013526734265017204 5ustar www-datawww-dataserverspec-2.41.5/spec/type/fedora/service_spec.rb0000644000004100000410000000036613526734265022210 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'fedora' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end serverspec-2.41.5/spec/type/aix/0000755000004100000410000000000013526734265016525 5ustar www-datawww-dataserverspec-2.41.5/spec/type/aix/file_spec.rb0000644000004100000410000000075013526734265021005 0ustar www-datawww-datarequire 'spec_helper' set :os, {:family => 'aix'} describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end serverspec-2.41.5/spec/type/aix/package_spec.rb0000644000004100000410000000016013526734265021454 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'aix' describe package('httpd') do it { should be_installed } end serverspec-2.41.5/spec/type/aix/group_spec.rb0000644000004100000410000000015313526734265021217 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'aix' describe group('root') do it { should have_gid 0 } end serverspec-2.41.5/spec/type/aix/user_spec.rb0000644000004100000410000000041413526734265021041 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'aix' describe user('root') do it { should belong_to_group 'root' } end describe user('root') do it { should have_login_shell '/bin/bash' } end describe user('root') do it { should have_home_directory '/root' } end serverspec-2.41.5/spec/type/aix/service_spec.rb0000644000004100000410000000027013526734265021523 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'aix' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end serverspec-2.41.5/spec/type/aix/port_spec.rb0000644000004100000410000000046613526734265021056 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'aix' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(53) do it { should be_listening.with('udp') } end serverspec-2.41.5/spec/type/suse/0000755000004100000410000000000013526734265016723 5ustar www-datawww-dataserverspec-2.41.5/spec/type/suse/package_spec.rb0000644000004100000410000000101513526734265021652 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'suse' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('rpm').with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end serverspec-2.41.5/spec/type/suse/service_spec.rb0000644000004100000410000000027013526734265021721 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'suse' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end serverspec-2.41.5/spec/type/smartos/0000755000004100000410000000000013526734265017434 5ustar www-datawww-dataserverspec-2.41.5/spec/type/smartos/package_spec.rb0000644000004100000410000000065113526734265022370 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'smartos' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end serverspec-2.41.5/spec/type/smartos/service_spec.rb0000644000004100000410000000037313526734265022436 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'smartos' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_running } end describe service('sshd') do it { should have_property :foo => 'bar' } end serverspec-2.41.5/spec/type/fedora15/0000755000004100000410000000000013526734265017352 5ustar www-datawww-dataserverspec-2.41.5/spec/type/fedora15/service_spec.rb0000644000004100000410000000040613526734265022351 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'fedora', :release => 15 describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end serverspec-2.41.5/spec/type/redhat5/0000755000004100000410000000000013526734265017300 5ustar www-datawww-dataserverspec-2.41.5/spec/type/redhat5/iptables_spec.rb0000644000004100000410000000037113526734265022443 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'redhat', :release => 5 describe iptables do it { should have_rule '-P INPUT ACCEPT' } end describe iptables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } end serverspec-2.41.5/spec/type/freebsd10/0000755000004100000410000000000013526734265017517 5ustar www-datawww-dataserverspec-2.41.5/spec/type/freebsd10/package_spec.rb0000644000004100000410000000067113526734265022455 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'freebsd', :release => 10 describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end serverspec-2.41.5/spec/type/nixos/0000755000004100000410000000000013526734265017104 5ustar www-datawww-dataserverspec-2.41.5/spec/type/nixos/package_spec.rb0000644000004100000410000000046613526734265022044 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'nixos' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('nix').with_version('2.2.15-28.el6') } end serverspec-2.41.5/spec/type/nixos/service_spec.rb0000644000004100000410000000021313526734265022077 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'nixos' describe service('sshd') do it { should be_enabled } it { should be_running } end serverspec-2.41.5/spec/type/freebsd/0000755000004100000410000000000013526734265017356 5ustar www-datawww-dataserverspec-2.41.5/spec/type/freebsd/file_spec.rb0000644000004100000410000000106713526734265021640 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'freebsd' describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end describe file('/sbin/nologin') do it { should be_linked_to '/usr/sbin/nologin' } end describe file('/etc/passwd') do let(:stdout) { Time.now.to_i.to_s } its(:mtime) { should > DateTime.now - 1 } end describe file('/etc/passwod') do let(:stdout) { 100.to_s } its(:size) { should > 0 } end serverspec-2.41.5/spec/type/freebsd/package_spec.rb0000644000004100000410000000065113526734265022312 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'freebsd' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end serverspec-2.41.5/spec/type/freebsd/service_spec.rb0000644000004100000410000000016213526734265022354 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'freebsd' describe service('sshd') do it { should be_enabled } end serverspec-2.41.5/spec/type/freebsd/port_spec.rb0000644000004100000410000000076413526734265021710 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'freebsd' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it do expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) end end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(53) do it { should be_listening.with('udp') } end serverspec-2.41.5/spec/type/redhat/0000755000004100000410000000000013526734265017213 5ustar www-datawww-dataserverspec-2.41.5/spec/type/redhat/file_spec.rb0000644000004100000410000000051713526734265021474 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'redhat' describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end describe file('/tmp') do it { should be_immutable } end serverspec-2.41.5/spec/type/redhat/package_spec.rb0000644000004100000410000000101713526734265022144 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'redhat' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('rpm').with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end serverspec-2.41.5/spec/type/redhat/yumrepo_spec.rb0000644000004100000410000000024713526734265022255 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'redhat' describe yumrepo('epel') do it { should exist } end describe yumrepo('epel') do it { should be_enabled } end serverspec-2.41.5/spec/type/redhat/service_spec.rb0000644000004100000410000000027213526734265022213 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'redhat' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end serverspec-2.41.5/spec/type/solaris10/0000755000004100000410000000000013526734265017561 5ustar www-datawww-dataserverspec-2.41.5/spec/type/solaris10/file_spec.rb0000644000004100000410000001667713526734265022060 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris', :release => 10 describe file('/etc/ssh/sshd_config') do it { should be_file } end describe file('/etc/ssh') do it { should be_directory } end describe file('/var/run/unicorn.sock') do it { should be_socket } end describe file('/etc/ssh/sshd_config') do it { should contain 'This is the sshd server system-wide configuration file' } end describe file('/etc/ssh/sshd_config') do it { should contain /^This is the sshd server system-wide configuration file/ } end describe file('Gemfile') do it { should contain('rspec').from(/^group :test do/).to(/^end/) } end describe file('Gemfile') do it { should contain('rspec').after(/^group :test do/) } end describe file('Gemfile') do it { should contain('rspec').before(/^end/) } end describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_readable } end describe file('/dev') do let(:stdout) { "333\r\n" } it { should_not be_readable } end describe file('/dev') do let(:stdout) { "400\r\n" } it { should be_readable.by('owner') } end describe file('/dev') do let(:stdout) { "044\r\n" } it { should_not be_readable.by('owner') } end describe file('/dev') do let(:stdout) { "040\r\n" } it { should be_readable.by('group') } end describe file('/dev') do let(:stdout) { "404\r\n" } it { should_not be_readable.by('group') } end describe file('/dev') do let(:stdout) { "044\r\n" } it { should be_readable.by('others') } end describe file('/dev') do let(:stdout) { "443\r\n" } it { should_not be_readable.by('others') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_writable } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable } end describe file('/dev') do let(:stdout) { "200\r\n" } it { should be_writable.by('owner') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('owner') } end describe file('/dev') do let(:stdout) { "030\r\n" } it { should be_writable.by('group') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('group') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should be_writable.by('others') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('others') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_executable } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable } end describe file('/dev') do let(:stdout) { "100\r\n" } it { should be_executable.by('owner') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('owner') } end describe file('/dev') do let(:stdout) { "070\r\n" } it { should be_executable.by('group') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('group') } end describe file('/dev') do let(:stdout) { "001\r\n" } it { should be_executable.by('others') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('others') } end describe file('/') do it { should be_mounted } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :rw => true } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :mode => 620 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :rw => false } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :mode => 600 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_r00t' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, :bind => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_roooooooooot', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/etc/services') do let(:stdout) { "35435ea447c19f0ea5ef971837ab9ced\n" } its(:md5sum) { should eq '35435ea447c19f0ea5ef971837ab9ced' } end describe file('/etc/services') do let(:stdout) {"0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } its(:md5sum) { should eq '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } end describe file('/etc/passwd') do let(:stdout) {< 'solaris', :release => 10 describe package('httpd') do it { should be_installed } end serverspec-2.41.5/spec/type/solaris10/group_spec.rb0000644000004100000410000000017313526734265022255 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris', :release => 10 describe group('root') do it { should exist } end serverspec-2.41.5/spec/type/solaris10/user_spec.rb0000644000004100000410000000023213526734265022073 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris', :release => 10 describe user('root') do it { should have_authorized_key 'XXXXXXXXXXXXXXX' } end serverspec-2.41.5/spec/type/solaris10/host_spec.rb0000644000004100000410000000053413526734265022077 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris', :release => 10 describe host('127.0.0.1') do it { should be_reachable } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'icmp', :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'tcp', :port => 22, :timeout=> 1) } end serverspec-2.41.5/spec/type/solaris/0000755000004100000410000000000013526734265017420 5ustar www-datawww-dataserverspec-2.41.5/spec/type/solaris/ipnat_spec.rb0000644000004100000410000000021613526734265022071 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe ipnat do it { should have_rule 'map net1 192.168.0.0/24 -> 0.0.0.0/32' } end serverspec-2.41.5/spec/type/solaris/file_spec.rb0000644000004100000410000000042513526734265021677 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end serverspec-2.41.5/spec/type/solaris/cron_spec.rb0000644000004100000410000000036213526734265021721 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe cron do it { should have_entry '* * * * * /usr/local/bin/batch.sh' } end describe cron do it { should have_entry('* * * * * /usr/local/bin/batch.sh').with_user('root') } end serverspec-2.41.5/spec/type/solaris/package_spec.rb0000644000004100000410000000016413526734265022353 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe package('httpd') do it { should be_installed } end serverspec-2.41.5/spec/type/solaris/group_spec.rb0000644000004100000410000000015713526734265022116 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe group('root') do it { should have_gid 0 } end serverspec-2.41.5/spec/type/solaris/user_spec.rb0000644000004100000410000000042013526734265021731 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe user('root') do it { should belong_to_group 'root' } end describe user('root') do it { should have_login_shell '/bin/bash' } end describe user('root') do it { should have_home_directory '/root' } end serverspec-2.41.5/spec/type/solaris/service_spec.rb0000644000004100000410000000037313526734265022422 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_running } end describe service('sshd') do it { should have_property :foo => 'bar' } end serverspec-2.41.5/spec/type/solaris/host_spec.rb0000644000004100000410000000067413526734265021743 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe host('127.0.0.1') do it { should be_reachable } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'icmp', :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'tcp', :port => 22, :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'udp', :port => 53, :timeout=> 1) } end serverspec-2.41.5/spec/type/solaris/port_spec.rb0000644000004100000410000000114513526734265021744 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it do expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) end end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(80) do it do expect{ should be_listening.on('') }.to raise_error(ArgumentError) end end describe port(123) do it { should be_listening.with('udp') } end serverspec-2.41.5/spec/type/solaris/ipfilter_spec.rb0000644000004100000410000000020413526734265022571 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe ipfilter do it { should have_rule 'pass in quick on lo0 all' } end serverspec-2.41.5/spec/type/solaris/zfs_spec.rb0000644000004100000410000000045413526734265021564 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'solaris' describe zfs('rpool') do it { should exist } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } end serverspec-2.41.5/spec/type/base/0000755000004100000410000000000013526734265016656 5ustar www-datawww-dataserverspec-2.41.5/spec/type/base/mail_alias_spec.rb0000644000004100000410000000017513526734265022313 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe mail_alias('daemon') do it { should be_aliased_to "root" } end serverspec-2.41.5/spec/type/base/php_extension_spec.rb0000644000004100000410000000036213526734265023101 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe php_extension('tillext') do let(:exit_status) { 1 } it { should_not be_loaded } end describe php_extension('session') do let(:exit_status) { 0 } it { should be_loaded } end serverspec-2.41.5/spec/type/base/default_gateway_spec.rb0000644000004100000410000000050713526734265023364 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe default_gateway do let(:stdout) { "default via 192.168.1.1 dev eth1 \r\n" } its(:ipaddress) { should eq '192.168.1.1' } its(:interface) { should eq 'eth1' } its(:ipaddress) { should_not eq '192.168.1.2' } its(:interface) { should_not eq 'eth0' } end serverspec-2.41.5/spec/type/base/file_spec.rb0000644000004100000410000002324313526734265021140 0ustar www-datawww-datarequire 'spec_helper' set :os, {:family => 'base'} describe file('/etc/ssh/sshd_config') do it { should be_file } end describe file('/etc/ssh') do it { should be_directory } end describe file('/var/run/unicorn.sock') do it { should be_socket } end describe file('/dev/disk0') do it { should be_block_device } end describe file('/dev/ttys0') do it { should be_character_device } end describe file('/var/run/pure-ftpd/pure-ftpd.upload.pipe') do it { should be_pipe } end describe file('/bin/sh') do it { should be_symlink } end describe file('/bin/sh') do it { should exist } end describe file('/etc/ssh/sshd_config') do it { should contain 'This is the sshd server system-wide configuration file' } end describe file('/etc/ssh/sshd_config') do it { should contain /^This is the sshd server system-wide configuration file/ } end describe file('Gemfile') do it { should contain('rspec').from(/^group :test do/).to(/^end/) } end describe file('Gemfile') do it { should contain('rspec').after(/^group :test do/) } end describe file('Gemfile') do it { should contain('rspec').before(/^end/) } end describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_readable } end describe file('/dev') do let(:stdout) { "333\r\n" } it { should_not be_readable } end describe file('/dev') do let(:stdout) { "400\r\n" } it { should be_readable.by('owner') } end describe file('/dev') do let(:stdout) { "044\r\n" } it { should_not be_readable.by('owner') } end describe file('/dev') do let(:stdout) { "040\r\n" } it { should be_readable.by('group') } end describe file('/dev') do let(:stdout) { "404\r\n" } it { should_not be_readable.by('group') } end describe file('/dev') do let(:stdout) { "044\r\n" } it { should be_readable.by('others') } end describe file('/dev') do let(:stdout) { "443\r\n" } it { should_not be_readable.by('others') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_writable } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable } end describe file('/dev') do let(:stdout) { "200\r\n" } it { should be_writable.by('owner') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('owner') } end describe file('/dev') do let(:stdout) { "030\r\n" } it { should be_writable.by('group') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('group') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should be_writable.by('others') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('others') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_executable } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable } end describe file('/dev') do let(:stdout) { "100\r\n" } it { should be_executable.by('owner') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('owner') } end describe file('/dev') do let(:stdout) { "070\r\n" } it { should be_executable.by('group') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('group') } end describe file('/dev') do let(:stdout) { "001\r\n" } it { should be_executable.by('others') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('others') } end describe file('/') do it { should be_mounted } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :rw => true } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :mode => 620 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :rw => false } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :mode => 600 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_r00t' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, :bind => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_roooooooooot', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.only_with( :type => 'ext4' ) } end describe file('/etc/services') do let(:stdout) { "35435ea447c19f0ea5ef971837ab9ced\n" } its(:md5sum) { should eq '35435ea447c19f0ea5ef971837ab9ced' } end describe file('invalid-file') do its(:md5sum) { should_not eq 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do let(:stdout) {"0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } its(:sha256sum) { should eq '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } end describe file('invalid-file') do its(:sha256sum) { should_not eq 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) { "root\r\n" } its(:group) { should eq 'root' } end describe file('/etc/passwd') do let(:stdout) {< include('title' => 'this is a json')) } its(:content_as_json) { should include('json' => include('array' => include('title' => 'array 2'))) } end describe file('example.yml') do let(:stdout) {< include('title' => 'this is a yaml')) } its(:content_as_yaml) { should include('yaml' => include('array' => include('title' => 'array 2'))) } end describe file('/etc/pam.d/system-auth') do let(:stdout) { "/etc/pam.dsystem-auth-ac\r\n" } its(:link_target) { should eq '/etc/pam.dsystem-auth-ac' } end describe file('/etc/passwd') do let(:stdout) { "644\r\n" } its(:mode) { should eq '644' } end describe file('/etc/passwd') do let(:stdout) { Time.now.to_i.to_s } its(:mtime) { should > DateTime.now - 1 } end describe file('/etc/passwd') do let(:stdout) { "root\r\n" } its(:owner) { should eq 'root' } end describe file('/etc/passwod') do let(:stdout) { 100.to_s } its(:size) { should > 0 } end describe file('/etc/passwd') do it 'be_immutable is not implemented in base class' do expect { should be_immutable }.to raise_error(/is not implemented in Specinfra/) end end serverspec-2.41.5/spec/type/base/cron_spec.rb0000644000004100000410000000035713526734265021163 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe cron do it { should have_entry '* * * * * /usr/local/bin/batch.sh' } end describe cron do it { should have_entry('* * * * * /usr/local/bin/batch.sh').with_user('root') } end serverspec-2.41.5/spec/type/base/package_spec.rb0000644000004100000410000000207413526734265021613 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe package('jekyll') do it { should be_installed.by(:gem) } end describe package('jekyll') do it { should be_installed.by(:gem).with_version('1.1.1') } end describe package('ruby') do it { should be_installed.by(:rvm) } end describe package('ruby') do it { should be_installed.by(:rvm).with_version('2.2.0') } end describe package('bower') do it { should be_installed.by(:npm) } end describe package('bower') do it { should be_installed.by(:npm).with_version('0.9.2') } end describe package('mongo') do it { should be_installed.by(:pecl) } end describe package('mongo') do it { should be_installed.by(:pecl).with_version('1.4.1') } end describe package('XML_Util') do it { should be_installed.by(:pear).with_version('1.2.1') } end describe package('supervisor') do it { should be_installed.by(:pip).with_version('3.0') } end describe package('App::Ack') do it { should be_installed.by(:cpan) } end describe package('App::Ack') do it { should be_installed.by(:cpan).with_version('2.04') } end serverspec-2.41.5/spec/type/base/routing_table_spec.rb0000644000004100000410000000266013526734265023057 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } end describe routing_table do let(:exit_status) { 1 } it { should_not have_entry( :destination => '192.168.100.100/24' ) } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it do should have_entry( :destination => '192.168.200.0/24', :gateway => '192.168.200.1' ) end it do should have_entry( :destination => '192.168.200.0/24', :gateway => '192.168.200.1', :interface => 'eth0' ) end end describe routing_table do let(:stdout) { "default via 10.0.2.2 dev eth0 \r\n" } it { should have_entry( :destination => 'default' ) } it do should have_entry( :destination => 'default', :gateway => '10.0.2.2' ) end it do should have_entry( :destination => 'default', :gateway => '10.0.2.2', :interface => 'eth0' ) end end serverspec-2.41.5/spec/type/base/process_spec.rb0000644000004100000410000000137413526734265021700 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } end describe process("memcached") do let(:stdout) { "/usr/bin/memcached -m 14386 -p 11211 -u nobody -l 10.11.1.53 -c 30000\n" } its(:args) { should match /-c 30000\b/ } end describe process("memcached") do let(:stdout) { "nobody\n" } its(:user) { should eq "nobody" } end describe process("memcached") do let(:stdout) { "nobody\n" } its(:group) { should eq "nobody" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } end end serverspec-2.41.5/spec/type/base/group_spec.rb0000644000004100000410000000024113526734265021346 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe group('root') do it { should exist } end describe group('root') do it { should have_gid 0 } end serverspec-2.41.5/spec/type/base/user_spec.rb0000644000004100000410000000236313526734265021177 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe user('root') do it { should exist } end describe user('root') do it { should belong_to_group 'root' } end describe user('root') do it { should belong_to_primary_group 'root' } end describe user('root') do it { should have_uid 0 } end describe user('root') do it { should have_login_shell '/bin/bash' } end describe user('root') do it { should have_home_directory '/root' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } end describe user('root') do let(:stdout) { "$1$T0aTw9NJ$NdMldLUQ8WqhlEEGToNzl/\n" } its(:encrypted_password) { should eq '$1$T0aTw9NJ$NdMldLUQ8WqhlEEGToNzl/' } end describe user('root') do its(:minimum_days_between_password_change) { should == 0 } end describe user('root') do its(:maximum_days_between_password_change) { should == 0 } end serverspec-2.41.5/spec/type/base/php_config_spec.rb0000644000004100000410000000166513526734265022341 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } end describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should_not eq 'text/plain' } end describe php_config('session.cache_expire') do let(:stdout) { '180' } its(:value) { should eq 180 } end describe php_config('session.cache_expire') do let(:stdout) { '180' } its(:value) { should_not eq 360 } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should match /application/ } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end describe php_config('default_mimetype', :ini => '/etc/php5/php.ini') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } end serverspec-2.41.5/spec/type/base/service_spec.rb0000644000004100000410000000224113526734265021654 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe service('sshd') do it { should be_running } end describe service('sshd') do let(:stdout) { "sshd is stopped\r\n" } it { should be_running } end describe service('sshd') do it { should be_running.under(:supervisor) } end describe service('sshd') do it { should be_running.under(:upstart) } end describe service('sshd') do it { should be_running.under(:daemontools) } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(/is not implemented in Specinfra/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by(:monit) } end describe service('tinc') do let(:stdout) { "Process 'tinc-myvpn'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by(:monit).with_name('tinc-myvpn') } end describe service('unicorn') do it { should be_monitored_by(:god) } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(NotImplementedError) } end serverspec-2.41.5/spec/type/base/host_spec.rb0000644000004100000410000000177313526734265021202 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe host('127.0.0.1') do it { should be_resolvable } end describe host('127.0.0.1') do it { should be_resolvable.by('hosts') } end describe host('127.0.0.1') do it { should be_resolvable.by('dns') } end describe host('127.0.0.1') do it { should be_reachable } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "icmp", :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end describe host('example.jp') do let(:stdout) { "1.2.3.4\r\n" } its(:ipaddress) { should eq '1.2.3.4' } end describe host('example.jp') do let(:stdout) { "1.2.3.4\r\n" } its(:ipv4_address) { should match(/^[\d.]+$/) } end describe host('example.jp') do let(:stdout) { "2001:db8::1234\r\n" } its(:ipv6_address) { should match(/^[a-f\d:]+$/i) } end serverspec-2.41.5/spec/type/base/command_spec.rb0000644000004100000410000000553413526734265021642 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } its(:stdout) { should match /nameserver 127.0.0.1/ } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } its(:stdout) { should_not eq 'content-should-be-included' } end end describe 'regexp matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } its(:stdout) { should match /127\.0\.0\.1/ } end end describe command('cat /etc/resolv.conf') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should match /No such file or directory/ } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stderr) { "No such file or directory\r\n" } its(:stdout) { should_not eq 'file' } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should match /file/ } end end describe command('cat /etc/resolv.conf') do its(:exit_status) { should eq 0 } end describe command('ls -al /') do let(:stdout) { < include('version' => '0.26.5')) } its(:stdout_as_json) { should include('transport' => include('keepalives' => include('consumers' => 1))) } its(:stdout_as_json) { should include('transport' => include('connected' => true)) } its(:stdout_as_json) { should include('array' => include('title' => 'array 2')) } end serverspec-2.41.5/spec/type/base/mysql_config_spec.rb0000644000004100000410000000055713526734265022716 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe mysql_config('innodb-buffer-pool-size') do let(:stdout) { 'innodb-buffer-pool-size 134217728' } its(:value) { should eq 134217728 } end describe mysql_config('socket') do let(:stdout) { 'socket /tmp/mysql.sock' } its(:value) { should eq '/tmp/mysql.sock' } end serverspec-2.41.5/spec/type/base/port_spec.rb0000644000004100000410000000115013526734265021176 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'base' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it do expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) end end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(80) do it do expect{ should be_listening.on('') }.to raise_error(ArgumentError) end end describe port(53) do it { should be_listening.with('udp') } end serverspec-2.41.5/spec/type/base/json_file_spec.rb0000644000004100000410000000077513526734265022176 0ustar www-datawww-datarequire 'spec_helper' set :os, {:family => 'base'} describe json_file('example.json') do let(:stdout) {< include('title' => 'this is a json')) } its(:content) { should include('json' => include('array' => include('title' => 'array 2'))) } end serverspec-2.41.5/spec/type/darwin/0000755000004100000410000000000013526734265017230 5ustar www-datawww-dataserverspec-2.41.5/spec/type/darwin/file_spec.rb0000644000004100000410000000172113526734265021507 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'darwin' describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end describe file('/etc/services') do let(:stdout) { "35435ea447c19f0ea5ef971837ab9ced\n" } its(:md5sum) { should eq '35435ea447c19f0ea5ef971837ab9ced' } end describe file('/etc/services') do let(:stdout) {"0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } its(:sha256sum) { should eq '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } end describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end serverspec-2.41.5/spec/type/darwin/package_spec.rb0000644000004100000410000000055313526734265022165 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'darwin' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('homebrew') } end describe package('httpd') do it { should be_installed.by('pkgutil') } end serverspec-2.41.5/spec/type/darwin/service_spec.rb0000644000004100000410000000036713526734265022235 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'darwin' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end serverspec-2.41.5/spec/type/darwin/port_spec.rb0000644000004100000410000000076313526734265021561 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'darwin' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it do expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) end end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(53) do it { should be_listening.with('udp') } end serverspec-2.41.5/spec/type/windows/0000755000004100000410000000000013526734265017436 5ustar www-datawww-dataserverspec-2.41.5/spec/type/windows/registry_key_spec.rb0000644000004100000410000000265113526734265023521 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe windows_registry_key('PATH/TO/THE_KEY') do it { should exist } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_value('Test Value') } end describe 'Key value types' do context 'default type' do describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property('TestProperty') } end end { :type_string => 'String', :type_binary => 'Binary', :type_dword => 'DWord', :type_qword => 'QWord', :type_multistring => 'MultiString', :type_expandstring => 'ExpandString' }.each do |sym, type| context "type #{type}" do describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property('TestProperty', sym) } end end end end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_binary, '12a07b') } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_dword, 'fffffd6c') } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_qword, '1e240') } end describe windows_registry_key('PATH/TO/THE_KEY') do it { value = <<-EOF test line1 test line2 test line3 EOF should have_property_value('TestProperty', :type_multistring, value) } end serverspec-2.41.5/spec/type/windows/iis_webisite_spec.rb0000644000004100000410000000111713526734265023454 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe iis_website('Default Website') do it { should exist } it { should be_enabled } it { should be_running } it { should be_in_app_pool('Default App Pool') } it { should have_physical_path('C:\\inetpub\\www') } it { should have_site_bindings('port').with_protocol('protocol').with_ipaddress('ipaddress').with_host_header('host_header') } it { should have_virtual_dir('vdir').with_path('path') } it { should have_site_application('app').with_pool('pool').with_physical_path('physical_path') } end serverspec-2.41.5/spec/type/windows/file_spec.rb0000644000004100000410000000556713526734265021731 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe file('/some/valid/file') do it { should be_file } end describe file('/some/valid/folder') do it { should be_directory } end describe file('/some/file') do it { should contain 'search text' } end describe file('/some/file') do it { should contain /^search text/ } end describe file('Gemfile') do it { should contain('rspec').from(/^group :test do/).to(/^end/) } end describe file('Gemfile') do it { should contain('rspec').after(/^group :test do/) } end describe file('Gemfile') do it { should contain('rspec').before(/end/) } end describe file('/some/file') do it { should be_readable } end describe file('/some/file') do it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do ['owner', 'group', 'others'].each do |access| expect { should be_readable.by(access) }.to raise_error(RuntimeError) end end end describe file('/some/file') do it { should be_readable.by('test.identity') } end describe file('/some/file') do it { should be_readable.by_user('test.identity') } end describe file('/some/file') do it { should be_writable } end describe file('/some/file') do it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do ['owner', 'group', 'others'].each do |access| expect { should be_writable.by(access) }.to raise_error(RuntimeError) end end end describe file('/some/file') do it { should be_writable.by('test.identity') } end describe file('/some/file') do it { should be_writable.by_user('test.identity') } end describe file('/some/file') do it { should be_executable } end describe file('/some/file') do it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do ['owner', 'group', 'others'].each do |access| expect { should be_executable.by(access) }.to raise_error(RuntimeError) end end end describe file('/some/file') do it { should be_executable.by('test.identity') } end describe file('/some/file') do it { should be_executable.by_user('test.identity') } end describe file('/some/file') do it { should be_version 1 } end describe file('/some/test/file') do it "should raise error if command is not implemented" do { :be_socket => [], :be_mode => 644, :be_grouped_into => 'root', :be_linked_to => '/some/other/file', :be_mounted => [] }.each do |method, args| expect { should self.send(method, *args) }.to raise_error(NotImplementedError) end end it "should raise error if command is not defined" do { :match_md5checksum => '35435ea447c19f0ea5ef971837ab9ced', :match_sha256checksum => '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' }.each do |method, args| expect { should self.send(method, *args) }.to raise_error(NoMethodError) end end end serverspec-2.41.5/spec/type/windows/feature_spec.rb0000644000004100000410000000051313526734265022427 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe windows_feature('Minesweeper') do it{ should be_installed } end describe windows_feature('IIS-Webserver') do it{ should be_installed.by(:dism) } end describe windows_feature('Web-Webserver') do it{ should be_installed.by(:powershell) } end serverspec-2.41.5/spec/type/windows/package_spec.rb0000644000004100000410000000020713526734265022367 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe package('foo') do it { should be_installed } end serverspec-2.41.5/spec/type/windows/scheduled_task_spec.rb0000644000004100000410000000021613526734265023756 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe windows_scheduled_task('foo') do it { should exist } end serverspec-2.41.5/spec/type/windows/group_spec.rb0000644000004100000410000000071213526734265022131 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe group('test.group') do it { should exist } end describe group('test.domain\test.group') do it { should exist } end describe group('test.group') do it "should raise error if command is not supported" do { :have_gid => [nil], }.each do |method, args| expect { should self.send(method, *args) }.to raise_error(NotImplementedError) end end end serverspec-2.41.5/spec/type/windows/user_spec.rb0000644000004100000410000000131613526734265021754 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe user('test.user') do it { should exist } end describe user('test.domain\test.user') do it { should exist } end describe user('test.user') do it { should belong_to_group 'test.group' } end describe user('test.user.domain\test.user') do it { should belong_to_group 'test.group.domain\test.group' } end describe user('test.user') do it "should raise error if command is not supported" do { :have_uid => [nil], :have_login_shell => [nil], :have_authorized_key => [nil], }.each do |method, args| expect { should self.send(method, *args) }.to raise_error(NotImplementedError) end end end serverspec-2.41.5/spec/type/windows/iis_app_pool_spec.rb0000644000004100000410000000073313526734265023455 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe iis_app_pool('Default App Pool') do it { should exist } it { should have_dotnet_version('2.0') } it { should have_32bit_enabled } it { should have_idle_timeout(5) } it { should have_identity_type('foo') } it { should have_periodic_restart(60) } it { should have_user_profile_enabled } it { should have_username('user') } it { should have_managed_pipeline_mode('mode') } end serverspec-2.41.5/spec/type/windows/service_spec.rb0000644000004100000410000000131413526734265022434 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe service('Test Service') do it { should be_enabled } end describe service('Test Service') do it { should be_running } end describe service('service') do it { should be_installed } end describe service('service') do it { should have_start_mode 'mode' } end describe service('Test service') do it "should raise error if trying to check service process controller" do expect { should be_running.under('supervisor') }.to raise_error(NotImplementedError) end it "should raise error if trying to check service monitoring" do expect { should_not be_monitored_by('monit') }.to raise_error(NotImplementedError) end end serverspec-2.41.5/spec/type/windows/hot_fix_spec.rb0000644000004100000410000000071613526734265022441 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe windows_hot_fix('DESCRIPTION-OR-KB-ID') do it { should be_installed } end describe windows_hot_fix('DESCRIPTION') do it { should be_installed.with_version('KB-ID') } end describe windows_hot_fix('DESCRIPTION_WITH_KB123456789_INLINED') do it { should be_installed } end describe windows_hot_fix('DESCRIPTION_WITH_SUFFIX_KB123456789') do it { should be_installed } end serverspec-2.41.5/spec/type/windows/host_spec.rb0000644000004100000410000000125013526734265021750 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe host('127.0.0.1') do it { should be_resolvable } end describe host('127.0.0.1') do it { should be_resolvable.by('hosts') } end describe host('127.0.0.1') do it { should be_resolvable.by('dns') } end describe host('127.0.0.1') do it { should be_reachable } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "icmp", :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-2.41.5/spec/type/windows/command_spec.rb0000644000004100000410000000345113526734265022416 0ustar www-datawww-datarequire 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe command('test_cmd /test/path/file') do let(:stdout) { "test output 1.2.3\r\n" } its(:stdout) { should match /test output 1.2.3/ } end describe 'complete matching of stdout' do context command('test_cmd /test/path/file') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } its(:stdout) { should_not eq 'content-should-be-included' } end end describe 'regexp matching of stdout' do context command('test_cmd /test/path/file') do let(:stdout) { "test output 1.2.3\r\n" } its(:stdout) { should match /1\.2\.3/ } end end describe command('test_cmd /test/path/file') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should match /No such file or directory/ } end describe 'complete matching of stderr' do context command('test_cmd /test/path/file') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should_not eq 'file' } end end describe 'regexp matching of stderr' do context command('test_cmd /test/path/file') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should match /file/ } end end describe command('test_cmd /test/path/file') do its(:exit_status) { should eq 0 } end describe command('dir "c:\"') do let(:stdout) { < 'windows' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with("tcp") } end describe port(123) do it { should be_listening.with("udp") } end describe port(80) do it { expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) } end serverspec-2.41.5/spec/type/redhat7/0000755000004100000410000000000013526734265017302 5ustar www-datawww-dataserverspec-2.41.5/spec/type/redhat7/service_spec.rb0000644000004100000410000000023313526734265022277 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'redhat', :release => 7 describe service('sshd') do it { should be_enabled } it { should be_running } end serverspec-2.41.5/spec/type/openbsd/0000755000004100000410000000000013526734265017376 5ustar www-datawww-dataserverspec-2.41.5/spec/type/openbsd/mail_alias_spec.rb0000644000004100000410000000020013526734265023020 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'openbsd' describe mail_alias('daemon') do it { should be_aliased_to "root" } end serverspec-2.41.5/spec/type/openbsd/interface_spec.rb0000644000004100000410000000126513526734265022701 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'openbsd' describe interface('eth0') do let(:stdout) { '1000' } its(:speed) { should eq 1000 } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10") } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10/24") } end describe interface('eth1') do let(:stdout) { "1.2.3.4/1\r\n" } its(:ipv4_address) { should match(/^[\d.]+\/\d+$/) } end describe interface('eth1') do let(:stdout) { "2001:db8::1234/1\r\n" } its(:ipv6_address) { should match(/^[a-f\d:]+\/\d+$/i) } end describe interface('invalid-interface') do let(:stdout) { '1000' } its(:speed) { should_not eq 100 } end serverspec-2.41.5/spec/type/openbsd/file_spec.rb0000644000004100000410000000732213526734265021660 0ustar www-datawww-datarequire 'spec_helper' set :os, {:family => 'openbsd'} describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } end describe file('/') do it { should be_mounted } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :rw => true } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :mode => 620 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :rw => false } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :mode => 600 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_r00t' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, :bind => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_roooooooooot', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/etc/services') do let(:stdout) { "35435ea447c19f0ea5ef971837ab9ced\n" } its(:md5sum) { should eq '35435ea447c19f0ea5ef971837ab9ced' } end describe file('/etc/services') do let(:stdout) {"0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } its(:sha256sum) { should eq '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } end serverspec-2.41.5/spec/type/openbsd/package_spec.rb0000644000004100000410000000032113526734265022324 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'openbsd' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end serverspec-2.41.5/spec/type/openbsd/user_spec.rb0000644000004100000410000000031313526734265021710 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'openbsd' describe user('root') do it { should have_login_shell '/bin/bash' } end describe user('root') do it { should have_home_directory '/root' } end serverspec-2.41.5/spec/type/openbsd/service_spec.rb0000644000004100000410000000025713526734265022401 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'openbsd' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_running } end serverspec-2.41.5/spec/type/openbsd/port_spec.rb0000644000004100000410000000015413526734265021721 0ustar www-datawww-datarequire 'spec_helper' set :os, :family => 'openbsd' describe port(80) do it { should be_listening } end serverspec-2.41.5/spec/spec_helper.rb0000644000004100000410000000133013526734265017576 0ustar www-datawww-datarequire 'serverspec' set :backend, :exec module Specinfra module Backend class Exec < Base def run_command cmd CommandResult.new({ :stdout => ::Specinfra.configuration.stdout, :stderr => ::Specinfra.configuration.stderr, :exit_status => ::Specinfra.configuration.exit_status, :exit_signal => nil, }) end end class Cmd < Base def run_command cmd CommandResult.new({ :stdout => ::Specinfra.configuration.stdout, :stderr => ::Specinfra.configuration.stderr, :exit_status => ::Specinfra.configuration.exit_status, :exit_signal => nil, }) end end end end serverspec-2.41.5/spec/helper/0000755000004100000410000000000013526734265016242 5ustar www-datawww-dataserverspec-2.41.5/spec/helper/type_spec.rb0000644000004100000410000000015413526734265020562 0ustar www-datawww-datarequire 'spec_helper' describe String do subject { String.new } it { should_not respond_to :host } end serverspec-2.41.5/.gitignore0000644000004100000410000000037513526734265016026 0ustar www-datawww-data*.gem *.rbc *.swp .bundle .rvmrc .versions.conf .config .yardoc .rspec .idea/ Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp Vagrantfile vendor/ .DS_Store Gemfile.local upstream.sh serverspec-2.41.5/wercker.yml0000644000004100000410000000056513526734265016224 0ustar www-datawww-databuild: box: id: mizzy/wercker-serverspec steps: - script: name: initialize git submodules code: git submodule update --init --recursive - script: name: Run walter code: ./$WORKING_DIR/walter -config ./$WORKING_DIR/pipeline.yml -build after-steps: - wantedly/pretty-slack-notify: webhook_url: $SLACK_WEBHOOK_URL serverspec-2.41.5/Rakefile0000644000004100000410000000124013526734265015473 0ustar www-datawww-datarequire "bundler/gem_tasks" begin require "rspec/core/rake_task" require "octorelease" rescue LoadError end if defined?(RSpec) task :default => 'spec:all' task :spec => 'spec:all' namespace :spec do task :all => [ 'spec:type:all', 'spec:helper' ] namespace :type do oses = Dir.glob('spec/type/*').map {|d| File.basename(d)} task :all => oses.map {|os| "spec:type:#{os}" } oses.each do |os| RSpec::Core::RakeTask.new(os.to_sym) do |t| t.pattern = "spec/type/#{os}/*_spec.rb" end end end RSpec::Core::RakeTask.new(:helper) do |t| t.pattern = "spec/helper/*_spec.rb" end end end serverspec-2.41.5/lib/0000755000004100000410000000000013526734265014577 5ustar www-datawww-dataserverspec-2.41.5/lib/serverspec/0000755000004100000410000000000013526734265016760 5ustar www-datawww-dataserverspec-2.41.5/lib/serverspec/version.rb0000644000004100000410000000005313526734265020770 0ustar www-datawww-datamodule Serverspec VERSION = "2.41.5" end serverspec-2.41.5/lib/serverspec/helper.rb0000644000004100000410000000030113526734265020556 0ustar www-datawww-data# Subject type helper require 'serverspec/helper/type' extend Serverspec::Helper::Type class RSpec::Core::ExampleGroup extend Serverspec::Helper::Type include Serverspec::Helper::Type end serverspec-2.41.5/lib/serverspec/power_assert.rb0000644000004100000410000000040413526734265022020 0ustar www-datawww-datarequire 'test/unit' require 'specinfra' require 'serverspec/helper/type' PowerAssert.configure do |c| c.lazy_inspection = true end class Serverspec::TestCase < Test::Unit::TestCase extend Serverspec::Helper::Type include Serverspec::Helper::Type end serverspec-2.41.5/lib/serverspec/type/0000755000004100000410000000000013526734265017741 5ustar www-datawww-dataserverspec-2.41.5/lib/serverspec/type/x509_private_key.rb0000644000004100000410000000152513526734265023400 0ustar www-datawww-datarequire 'time' module Serverspec::Type class X509PrivateKey < Base def valid? runner_res = @runner.run_command("echo | openssl rsa -in #{name} -check -noout -passin #{@options[:passin] || "stdin"}") ( runner_res.exit_status == 0 && runner_res.stdout.chomp == 'RSA key ok' ) && (!@options.has_key?(:passin) || encrypted?) end def encrypted? @runner.run_command("grep -Ewq \"^(Proc-Type.*ENCRYPTED|-----BEGIN ENCRYPTED PRIVATE KEY-----)$\" #{name}").exit_status == 0 end def has_matching_certificate?(cert_file) h1 = @runner.run_command("openssl x509 -noout -modulus -in #{cert_file}") h2 = @runner.run_command("echo | openssl rsa -noout -modulus -in #{name} -passin #{@options[:passin] || "stdin"}") (h1.stdout == h2.stdout) && (h1.exit_status == 0) && (h2.exit_status == 0) end end end serverspec-2.41.5/lib/serverspec/type/docker_base.rb0000644000004100000410000000106013526734265022524 0ustar www-datawww-datarequire 'multi_json' module Serverspec::Type class DockerBase < Base def exist? get_inspection.success? end def [](key) value = inspection key.split('.').each do |k| is_index = k.start_with?('[') && k.end_with?(']') value = value[is_index ? k[1..-2].to_i : k] end value end def inspection @inspection ||= ::MultiJson.load(get_inspection.stdout)[0] end private def get_inspection @get_inspection ||= @runner.run_command("docker inspect #{@name}") end end end serverspec-2.41.5/lib/serverspec/type/iptables.rb0000644000004100000410000000031113526734265022064 0ustar www-datawww-datamodule Serverspec::Type class Iptables < Base def has_rule?(rule, table, chain) @runner.check_iptables_has_rule(rule, table, chain) end def to_s 'iptables' end end end serverspec-2.41.5/lib/serverspec/type/interface.rb0000644000004100000410000000170613526734265022232 0ustar www-datawww-datamodule Serverspec::Type class Interface < Base def exists? @runner.check_interface_exists(@name) end def speed ret = @runner.get_interface_speed_of(@name) val_to_integer(ret) end def mtu ret = @runner.get_interface_mtu_of(@name) val_to_integer(ret) end def has_ipv4_address?(ip_address) @runner.check_interface_has_ipv4_address(@name, ip_address) end def has_ipv6_address?(ip_address) @runner.check_interface_has_ipv6_address(@name, ip_address) end def ipv4_address @runner.get_interface_ipv4_address(@name).stdout.strip end def ipv6_address @runner.get_interface_ipv6_address(@name).stdout.strip end def up? ret = @runner.get_interface_link_state(@name) ret.stdout.strip == 'up' end private def val_to_integer(ret) val = ret.stdout.strip val = val.to_i if val.match(/^\d+$/) val end end end serverspec-2.41.5/lib/serverspec/type/ipfilter.rb0000644000004100000410000000025513526734265022106 0ustar www-datawww-datamodule Serverspec::Type class Ipfilter < Base def has_rule?(rule) @runner.check_ipfilter_has_rule(rule) end def to_s 'ipfilter' end end end serverspec-2.41.5/lib/serverspec/type/cgroup.rb0000644000004100000410000000065713526734265021575 0ustar www-datawww-datamodule Serverspec::Type class Cgroup < Base attr_accessor :subsystem def method_missing(meth) if @subsystem.nil? @subsystem = meth.to_s self else param = "#{@subsystem}.#{meth.to_s}" ret = @runner.run_command("cgget -n -r #{param} #{@name} | awk '{print $2}'") val = ret.stdout.strip val = val.to_i if val.match(/^\d+$/) val end end end end serverspec-2.41.5/lib/serverspec/type/linux_kernel_parameter.rb0000644000004100000410000000035513526734265025030 0ustar www-datawww-datamodule Serverspec::Type class LinuxKernelParameter < Base def value ret = @runner.run_command("/sbin/sysctl -q -n #{@name}") val = ret.stdout.strip val = val.to_i if val.match(/^\d+$/) val end end end serverspec-2.41.5/lib/serverspec/type/kvm.rb0000644000004100000410000000045713526734265021071 0ustar www-datawww-datamodule Serverspec::Type class Kvm < Base def exists? @runner.check_kvm_guest_exists(@name) end def running? @runner.check_kvm_guest_is_running(@name) end def enabled? @runner.check_kvm_guest_is_enabled(@name) end def to_s 'KVM' end end end serverspec-2.41.5/lib/serverspec/type/selinux_module.rb0000644000004100000410000000046113526734265023323 0ustar www-datawww-datamodule Serverspec::Type class SelinuxModule < Base def enabled? @runner.check_selinux_module_is_enabled(@name) end def installed?(version = nil) @runner.check_selinux_module_is_installed(@name, version) end def to_s %(SELinux module "#{@name}") end end end serverspec-2.41.5/lib/serverspec/type/group.rb0000644000004100000410000000030413526734265021417 0ustar www-datawww-datamodule Serverspec::Type class Group < Base def exists? @runner.check_group_exists(@name) end def has_gid?(gid) @runner.check_group_has_gid(@name, gid) end end end serverspec-2.41.5/lib/serverspec/type/windows_registry_key.rb0000644000004100000410000000121113526734265024553 0ustar www-datawww-datamodule Serverspec::Type class WindowsRegistryKey < Base def exists? @runner.check_registry_key_exists(@name) end def has_property?(property_name, property_type = :type_string) @runner.check_registry_key_has_property(@name, {:name => property_name, :type => property_type}) end def has_value?(value) @runner.check_registry_key_has_value(@name, {:name => '', :type => :type_string, :value => value}) end def has_property_value?(property_name, property_type, value) @runner.check_registry_key_has_value(@name, {:name => property_name, :type => property_type, :value => value}) end end end serverspec-2.41.5/lib/serverspec/type/linux_audit_system.rb0000644000004100000410000000212113526734265024213 0ustar www-datawww-datamodule Serverspec::Type class LinuxAuditSystem < Base def initialize(name=nil) @name = 'linux_audit_system' @runner = Specinfra::Runner @rules_content = nil end def enabled? status_of('enabled') == '1' end def running? pid = status_of('pid') (!pid.nil? && pid.size > 0 && pid != '0') end def rules if @rules_content.nil? @rules_content = @runner.run_command('/sbin/auditctl -l').stdout || '' end @rules_content end private def status_of(part) cmd = "/sbin/auditctl -s" status_str = @runner.run_command(cmd).stdout.chomp status_map = parse_status(status_str) status_map[part] || '' end def parse_status(status_str) map = nil if status_str =~ /^AUDIT_STATUS/ then map = status_str.split(' ')[1..-1].inject({}) { |res,elem| a = elem.split('='); res.store(a[0],a[1] || ''); res } else map = status_str.split("\n").inject({}) { |res,elem| a = elem.split(' '); res.store(a[0],a[1] || ''); res } end map end end end serverspec-2.41.5/lib/serverspec/type/yumrepo.rb0000644000004100000410000000030313526734265021762 0ustar www-datawww-datamodule Serverspec::Type class Yumrepo < Base def exists? @runner.check_yumrepo_exists(@name) end def enabled? @runner.check_yumrepo_is_enabled(@name) end end end serverspec-2.41.5/lib/serverspec/type/json_file.rb0000644000004100000410000000020413526734265022232 0ustar www-datawww-datarequire 'multi_json' module Serverspec::Type class JsonFile < File def content MultiJson.load(super) end end end serverspec-2.41.5/lib/serverspec/type/kernel_module.rb0000644000004100000410000000021113526734265023105 0ustar www-datawww-datamodule Serverspec::Type class KernelModule < Base def loaded? @runner.check_kernel_module_is_loaded(@name) end end end serverspec-2.41.5/lib/serverspec/type/user.rb0000644000004100000410000000205013526734265021241 0ustar www-datawww-datamodule Serverspec::Type class User < Base def exists? @runner.check_user_exists(@name) end def belongs_to_group?(group) @runner.check_user_belongs_to_group(@name, group) end def belongs_to_primary_group?(group) @runner.check_user_belongs_to_primary_group(@name, group) end def has_uid?(uid) @runner.check_user_has_uid(@name, uid) end def has_home_directory?(path) @runner.check_user_has_home_directory(@name, path) end def has_login_shell?(shell) @runner.check_user_has_login_shell(@name, shell) end def has_authorized_key?(key) @runner.check_user_has_authorized_key(@name, key) end def minimum_days_between_password_change @runner.get_user_minimum_days_between_password_change(@name).stdout.to_i end def maximum_days_between_password_change @runner.get_user_maximum_days_between_password_change(@name).stdout.to_i end def encrypted_password @runner.get_user_encrypted_password(@name).stdout.strip end end end serverspec-2.41.5/lib/serverspec/type/fstab.rb0000644000004100000410000000025013526734265021362 0ustar www-datawww-datamodule Serverspec::Type class Fstab < Base def has_entry?(entry) @runner.check_fstab_has_entry(entry) end def to_s 'Fstab' end end end serverspec-2.41.5/lib/serverspec/type/docker_image.rb0000644000004100000410000000010313526734265022671 0ustar www-datawww-datamodule Serverspec::Type class DockerImage < DockerBase end end serverspec-2.41.5/lib/serverspec/type/iis_app_pool.rb0000644000004100000410000000207513526734265022747 0ustar www-datawww-datamodule Serverspec::Type class IisAppPool < Base def exists?() @runner.check_iis_app_pool_exists(@name) end def has_dotnet_version?(dotnet) @runner.check_iis_app_pool_has_dotnet_version(@name, dotnet) end def has_32bit_enabled?() @runner.check_iis_app_pool_has_32bit_enabled(@name) end def has_idle_timeout?(minutes) @runner.check_iis_app_pool_has_idle_timeout(@name, minutes) end def has_identity_type?(identity_type) @runner.check_iis_app_pool_has_identity_type(@name, identity_type) end def has_periodic_restart?(minutes) @runner.check_iis_app_pool_has_periodic_restart(@name, minutes) end def has_user_profile_enabled?() @runner.check_iis_app_pool_has_user_profile(@name) end def has_username?(username) @runner.check_iis_app_pool_has_username(@name, username) end def has_managed_pipeline_mode?(mode) @runner.check_iis_app_pool_has_managed_pipeline_mode(@name, mode) end def to_s %Q[IIS Application Pool "#{@name}"] end end end serverspec-2.41.5/lib/serverspec/type/ppa.rb0000644000004100000410000000026713526734265021053 0ustar www-datawww-datamodule Serverspec::Type class Ppa < Base def exists? @runner.check_ppa_exists(@name) end def enabled? @runner.check_ppa_is_enabled(@name) end end end serverspec-2.41.5/lib/serverspec/type/ipnat.rb0000644000004100000410000000024413526734265021401 0ustar www-datawww-datamodule Serverspec::Type class Ipnat < Base def has_rule?(rule) @runner.check_ipnat_has_rule(rule) end def to_s 'ipnat' end end end serverspec-2.41.5/lib/serverspec/type/bridge.rb0000644000004100000410000000034013526734265021517 0ustar www-datawww-datamodule Serverspec::Type class Bridge < Base def exists? @runner.check_bridge_exists(@name) end def has_interface?(interface) @runner.check_bridge_has_interface(@name, interface) end end end serverspec-2.41.5/lib/serverspec/type/base.rb0000644000004100000410000000102413526734265021175 0ustar www-datawww-datamodule Serverspec::Type class Base attr_reader :name def initialize(name=nil, options = {}) @name = name @options = options @runner = Specinfra::Runner end def to_s type = self.class.name.split(':')[-1] type.gsub!(/([a-z\d])([A-Z])/, '\1 \2') type.capitalize! %Q!#{type} "#{@name}"! end def inspect if defined?(PowerAssert) @inspection else to_s end end def to_ary to_s.split(" ") end end end serverspec-2.41.5/lib/serverspec/type/package.rb0000644000004100000410000000324313526734265021663 0ustar www-datawww-datamodule Serverspec::Type class Package < Base def installed?(provider=nil, version=nil) if provider.nil? @inspection = Specinfra.command.get(:check_package_is_installed, @name, version) @runner.check_package_is_installed(@name, version) else check_method = "check_package_is_installed_by_#{provider}".to_sym @runner.send(check_method, @name, version) end end def version ret = @runner.get_package_version(@name).stdout.strip if ret.empty? nil else Version.new(ret) end end class Version include Comparable attr_reader :epoch, :version def initialize(val) matches = val.match(/^(?:(\d+):)?(\d[0-9a-zA-Z.+:~_-]*)$/) if matches.nil? raise ArgumentError, "Malformed version number string #{val}" end @epoch = matches[1].to_i @version = matches[2].to_s end def <=>(other) other = Version.new(other) if other.is_a?(String) rv = @epoch <=> other.epoch return rv if rv != 0 self.ver_array <=> other.ver_array end def ver_array val = @version re = /^(?:(\d+)|(\D+))(.*)$/ res = [] until val.empty? matches = val.match(re) if matches[1].nil? # String matches[2].to_s.each_byte do |b| code_point = defined?("~".ord) ? "~".ord : ?~ res << ((b == code_point) ? -2 : b) end else # Digits res << matches[1].to_i end val = matches[3].to_s end res << -1 end end end end serverspec-2.41.5/lib/serverspec/type/lxc.rb0000644000004100000410000000035513526734265021057 0ustar www-datawww-datamodule Serverspec::Type class Lxc < Base def exists? @runner.check_lxc_container_exists(@name) end def running? @runner.check_lxc_container_is_running(@name) end def to_s 'LXC' end end end serverspec-2.41.5/lib/serverspec/type/zfs.rb0000644000004100000410000000105213526734265021066 0ustar www-datawww-datamodule Serverspec::Type class Zfs < Base def exists? @runner.check_zfs_exists(@name) end def has_property?(property) @runner.check_zfs_has_property(@name, property) end def to_s 'ZFS' end def property get_property if @property.nil? @property end private def get_property @property = Hash.new @runner.get_zfs_property(@name).stdout.split(/\n/).each do |line| property, value = line.split(/\s+/) @property[property] = value end end end end serverspec-2.41.5/lib/serverspec/type/bond.rb0000644000004100000410000000033113526734265021205 0ustar www-datawww-datamodule Serverspec::Type class Bond < Base def exists? @runner.check_bond_exists(@name) end def has_interface?(interface) @runner.check_bond_has_interface(@name, interface) end end end serverspec-2.41.5/lib/serverspec/type/command.rb0000644000004100000410000000065013526734265021705 0ustar www-datawww-datarequire 'multi_json' module Serverspec::Type class Command < Base def stdout command_result.stdout end def stdout_as_json MultiJson.load(command_result.stdout) end def stderr command_result.stderr end def exit_status command_result.exit_status.to_i end private def command_result() @command_result ||= @runner.run_command(@name) end end end serverspec-2.41.5/lib/serverspec/type/windows_hot_fix.rb0000644000004100000410000000024613526734265023502 0ustar www-datawww-datamodule Serverspec::Type class WindowsHotFix < Base def installed?(provider, version) @runner.check_hot_fix_is_installed(@name, version) end end end serverspec-2.41.5/lib/serverspec/type/port.rb0000644000004100000410000000202313526734265021247 0ustar www-datawww-datarequire 'resolv' module Serverspec::Type class Port < Base def protocols %w(udp tcp tcp6 udp6) end def options @options ||= {} end def protocol_matcher(protocol) protocol = protocol.to_s.downcase if protocols.include?(protocol) options[:protocol] = protocol else raise ArgumentError.new("`be_listening` matcher doesn't support #{protocol}") end end def local_address_matcher(local_address) if valid_ip_address?(local_address) options[:local_address] = local_address else raise ArgumentError.new("`be_listening` matcher requires valid IPv4 or IPv6 address") end end def listening?(protocol, local_address) protocol_matcher(protocol) if protocol local_address_matcher(local_address) if local_address @runner.check_port_is_listening(@name, options) end def valid_ip_address?(ip_address) !!(ip_address =~ Resolv::IPv4::Regex) || !!(ip_address =~ Resolv::IPv6::Regex) end end end serverspec-2.41.5/lib/serverspec/type/file.rb0000644000004100000410000000675713526734265021224 0ustar www-datawww-datarequire 'date' require 'multi_json' require 'yaml' module Serverspec::Type class File < Base attr_accessor :content def file? cmd = Specinfra.command.get(:check_file_is_file, @name) @inspection = Specinfra.backend.build_command(cmd.to_s) @runner.check_file_is_file(@name) end def block_device? @runner.check_file_is_block_device(@name) end def character_device? @runner.check_file_is_character_device(@name) end def socket? @runner.check_file_is_socket(@name) end def directory? @runner.check_file_is_directory(@name) end def symlink? @runner.check_file_is_symlink(@name) end def pipe? @runner.check_file_is_pipe(@name) end def contain(pattern, from, to) if pattern.is_a?(Array) @runner.check_file_contains_lines(@name, pattern, from, to) else if (from || to).nil? @runner.check_file_contains(@name, pattern) else @runner.check_file_contains_within(@name, pattern, from, to) end end end def mode?(mode) @runner.check_file_has_mode(@name, mode) end def owned_by?(owner) @runner.check_file_is_owned_by(@name, owner) end def grouped_into?(group) @runner.check_file_is_grouped(@name, group) end def linked_to?(target) @runner.check_file_is_linked_to(@name, target) end def readable?(by_whom, by_user) if by_user != nil @runner.check_file_is_accessible_by_user(@name, by_user, 'r') else @runner.check_file_is_readable(@name, by_whom) end end def writable?(by_whom, by_user) if by_user != nil @runner.check_file_is_accessible_by_user(@name, by_user, 'w') else @runner.check_file_is_writable(@name, by_whom) end end def executable?(by_whom, by_user) if by_user != nil @runner.check_file_is_accessible_by_user(@name, by_user, 'x') else @runner.check_file_is_executable(@name, by_whom) end end def mounted?(attr, only_with) @runner.check_file_is_mounted(@name, attr, only_with) end def immutable? @runner.check_file_is_immutable(@name) end def exists? @runner.check_file_exists(@name) end def md5sum @runner.get_file_md5sum(@name).stdout.strip end def sha256sum @runner.get_file_sha256sum(@name).stdout.strip end def content if @content.nil? @content = @runner.get_file_content(@name).stdout end @content end def content_as_json @content_as_json = MultiJson.load(content) if @content_as_json.nil? @content_as_json end def content_as_yaml @content_as_yaml = YAML.load(content) if @content_as_yaml.nil? @content_as_yaml end def group @runner.get_file_owner_group(@name).stdout.strip end def version?(version) @runner.check_file_has_version(@name, version) end def link_target @runner.get_file_link_target(@name).stdout.strip end def mode @runner.get_file_mode(@name).stdout.strip end def mtime d = @runner.get_file_mtime(@name).stdout.strip DateTime.strptime(d, '%s').new_offset(DateTime.now.offset) end def owner @runner.get_file_owner_user(@name).stdout.strip end def size @runner.get_file_size(@name).stdout.strip.to_i end def selinux_label @runner.get_file_selinuxlabel(@name).stdout.strip end end end serverspec-2.41.5/lib/serverspec/type/service.rb0000644000004100000410000000277113526734265021735 0ustar www-datawww-datamodule Serverspec::Type class Service < Base def enabled?(level, under=nil) under = under ? "_under_#{under.gsub(/^under_/, '')}" : '' check_method = "check_service_is_enabled#{under}" if level @runner.send(check_method.to_sym, @name, level) else @runner.send(check_method.to_sym, @name) end end def installed?(name, version) @runner.check_service_is_installed(@name) end def has_start_mode?(mode) @runner.check_service_has_start_mode(@name, mode) end def running?(under) if under check_method = "check_service_is_running_under_#{under}".to_sym @runner.send(check_method, @name) else @runner.check_service_is_running(@name) end end def monitored_by?(monitor, monitor_name) check_method = "check_service_is_monitored_by_#{monitor}".to_sym # use the with_name value if set instead of the service name monitor_name = (monitor_name ? monitor_name : @name) res = @runner.send(check_method, monitor_name) end def has_property?(property) @runner.check_service_has_property(@name, property) end def property get_property if @property.nil? @property end private def get_property @property = {} props = @runner.get_service_property(@name).stdout props.split(/\n/).each do |line| property, _type, *value = line.split(/\s+/) @property[property] = value.join(' ') end end end end serverspec-2.41.5/lib/serverspec/type/mail_alias.rb0000644000004100000410000000023313526734265022357 0ustar www-datawww-datamodule Serverspec::Type class MailAlias < Base def aliased_to?(target) @runner.check_mail_alias_is_aliased_to(@name, target) end end end serverspec-2.41.5/lib/serverspec/type/windows_firewall.rb0000644000004100000410000000104313526734265023643 0ustar www-datawww-datamodule Serverspec::Type class WindowsFirewall < Base def exists? @runner.check_firewall_exists(@name) end def tcp? @runner.check_firewall_has_protocol(@name, 'TCP') end def has_localport?(port) @runner.check_firewall_has_localport(@name, port) end def inbound? @runner.check_firewall_has_direction(@name, 'Inbound') end def enabled? @runner.check_firewall_is_enabled(@name) end def allowed? @runner.check_firewall_has_action(@name, 'Allow') end end end serverspec-2.41.5/lib/serverspec/type/iis_website.rb0000644000004100000410000000176013526734265022600 0ustar www-datawww-datamodule Serverspec::Type class IisWebsite < Base def exists?() @runner.check_iis_website_is_installed(@name) end def enabled?() @runner.check_iis_website_is_enabled(@name) end def running?() @runner.check_iis_website_is_running(@name) end def in_app_pool?(app_pool) @runner.check_iis_website_is_in_app_pool(@name, app_pool) end def has_physical_path?(path) @runner.check_iis_website_has_physical_path(@name, path) end def has_site_bindings?(port, protocol, ipaddress, host_header) @runner.check_iis_website_has_site_bindings(@name, port, protocol, ipaddress, host_header) end def has_virtual_dir?(vdir, path) @runner.check_iis_website_has_virtual_dir(@name, vdir, path) end def has_site_application?(app, pool, physical_path) @runner.check_iis_website_has_site_application(@name, app, pool, physical_path) end def to_s %Q[IIS Website "#{@name}"] end end end serverspec-2.41.5/lib/serverspec/type/windows_scheduled_task.rb0000644000004100000410000000021713526734265025022 0ustar www-datawww-datamodule Serverspec::Type class WindowsScheduledTask < Base def exists? @runner.check_scheduled_task_exists(@name) end end end serverspec-2.41.5/lib/serverspec/type/php_config.rb0000644000004100000410000000051613526734265022404 0ustar www-datawww-datamodule Serverspec::Type class PhpConfig < Base def value extra = ''; extra = extra + "-c #{@options[:ini]}" if @options.has_key?(:ini) ret = @runner.run_command("php #{extra} -r 'echo get_cfg_var( \"#{@name}\" );'") val = ret.stdout val = val.to_i if val.match(/^\d+$/) val end end end serverspec-2.41.5/lib/serverspec/type/process.rb0000644000004100000410000000111613526734265021743 0ustar www-datawww-datamodule Serverspec::Type class Process < Base def running? pid = @runner.get_process(@name, :format => "pid=").stdout not pid.empty? end def user get_column("user") end def group get_column("group") end def count @runner.count_process(@name).stdout.strip.to_i end def method_missing(meth) get_column(meth.to_s) end def get_column(keyword) ret = @runner.get_process(@name, :format => "#{keyword}=") val = ret.stdout.strip val = val.to_i if val.match(/^\d+$/) val end end end serverspec-2.41.5/lib/serverspec/type/windows_feature.rb0000644000004100000410000000024613526734265023475 0ustar www-datawww-datamodule Serverspec::Type class WindowsFeature < Base def installed?(provider, version) @runner.check_feature_is_enabled(@name, provider) end end end serverspec-2.41.5/lib/serverspec/type/host.rb0000644000004100000410000000077313526734265021252 0ustar www-datawww-datamodule Serverspec::Type class Host < Base def resolvable?(type) @runner.check_host_is_resolvable(@name, type) end def reachable?(port, proto, timeout) @runner.check_host_is_reachable(@name, port, proto, timeout) end def ipaddress @runner.get_host_ipaddress(@name).stdout.strip end def ipv4_address @runner.get_host_ipv4_address(@name).stdout.strip end def ipv6_address @runner.get_host_ipv6_address(@name).stdout.strip end end end serverspec-2.41.5/lib/serverspec/type/default_gateway.rb0000644000004100000410000000037513526734265023440 0ustar www-datawww-datamodule Serverspec::Type class DefaultGateway < Base def ipaddress @runner.get_default_gateway(:gateway) end def interface @runner.get_default_gateway(:interface) end def to_s 'Default Gateway' end end end serverspec-2.41.5/lib/serverspec/type/cron.rb0000644000004100000410000000035413526734265021231 0ustar www-datawww-datamodule Serverspec::Type class Cron < Base def has_entry?(user, entry) @runner.check_cron_has_entry(user, entry) end def table @runner.get_cron_table.stdout end def to_s 'Cron' end end end serverspec-2.41.5/lib/serverspec/type/php_extension.rb0000644000004100000410000000031113526734265023144 0ustar www-datawww-datamodule Serverspec::Type class PhpExtension < Base def loaded? ret = @runner.run_command("php --ri '#{@name}'") return false if ret.exit_status.to_i > 0 true end end end serverspec-2.41.5/lib/serverspec/type/mysql_config.rb0000644000004100000410000000042713526734265022763 0ustar www-datawww-datamodule Serverspec::Type class MysqlConfig < Base def value ret = @runner.run_command("mysqld --verbose --help 2> /dev/null | grep '^#{@name}'") val = ret.stdout.match(/#{@name}\s+(.+)$/)[1] val = val.to_i if val.match(/^\d+$/) val end end end serverspec-2.41.5/lib/serverspec/type/docker_container.rb0000644000004100000410000000130713526734265023600 0ustar www-datawww-datamodule Serverspec::Type class DockerContainer < DockerBase def running? inspection['State']['Running'] && !inspection['State']['Restarting'] end def has_volume?(container_path, host_path) if (inspection['Mounts']) check_volume(container_path, host_path) else check_volume_pre_1_8(container_path, host_path) end end private def check_volume(container_path, host_path) inspection['Mounts'].find {|mount| mount['Destination'] == container_path && mount['Source'] == host_path } end def check_volume_pre_1_8(container_path, host_path) inspection['Volumes'][container_path] == host_path end end end serverspec-2.41.5/lib/serverspec/type/hadoop_config.rb0000644000004100000410000000134313526734265023066 0ustar www-datawww-datamodule Serverspec::Type class HadoopConfig < Base def initialize(name=nil, options={}) super begin require 'nokogiri' rescue LoadError fail "nokogiri is not available. Try installing it." end end def value @runner.run_command("find /etc/hadoop/conf/ -type f -name \"*.xml\" ").stdout.split(/\n/).each do |file| @doc = ::Nokogiri::XML( @runner.get_file_content("#{file}").stdout.strip ) @doc.xpath('/configuration/property').each do |property| case property.xpath('name').text when /#{@name}/ ret = property.xpath('value').text val = ret.to_s return val end end end end end end serverspec-2.41.5/lib/serverspec/type/routing_table.rb0000644000004100000410000000027713526734265023132 0ustar www-datawww-datamodule Serverspec::Type class RoutingTable < Base def has_entry?(entry) @runner.check_routing_table_has_entry(entry) end def to_s 'Routing Table' end end end serverspec-2.41.5/lib/serverspec/type/ip6tables.rb0000644000004100000410000000035213526734265022157 0ustar www-datawww-datamodule Serverspec module Type class Ip6tables < Base def has_rule?(rule, table, chain) @runner.check_ip6tables_has_rule(rule, table, chain) end def to_s 'ip6tables' end end end end serverspec-2.41.5/lib/serverspec/type/x509_certificate.rb0000644000004100000410000000467213526734265023346 0ustar www-datawww-datarequire 'time' module Serverspec::Type class X509Certificate < Base def certificate? (run_openssl_command_with("-noout").exit_status == 0) end def subject run_openssl_command_with("-subject -noout").stdout.chomp.gsub(/^subject= */,'') end def issuer run_openssl_command_with("-issuer -noout").stdout.chomp.gsub(/^issuer= */,'') end def email run_openssl_command_with("-email -noout").stdout.chomp end def fingerprint run_openssl_command_with("-fingerprint -noout").stdout.chomp end def alias run_openssl_command_with("-alias -noout").stdout.chomp end # Modern openssl use following output format for key length: # Public-Key: (4096 bit) # while ancient (0.9.8 for example) use # RSA Public Key: (2048 bit) def keylength len_str = run_openssl_command_with("-text -noout | grep -E 'Public(-| )Key: \\([[:digit:]]+ bit\\)'").stdout.chomp len_str.gsub(/^.*\(/,'').gsub(/ bit\)$/,'').to_i end def has_purpose?(p) grep_str = "#{p} : Yes" ( run_openssl_command_with("-purpose -noout | grep -wq \"#{grep_str}\""). exit_status == 0 ) end def valid? runner_res = run_openssl_command_with("-startdate -enddate -noout") return false if runner_res.exit_status != 0 date_map = parse_dates_str_to_map(runner_res.stdout) now = Time.now ( now >= date_map[:notBefore] && now <= date_map[:notAfter]) end def validity_in_days runner_res = run_openssl_command_with("-enddate -noout") return 0 if runner_res.exit_status != 0 date_map = parse_dates_str_to_map(runner_res.stdout) diff = date_map[:notAfter] - Time.now ( diff/(60*60*24) ) end def subject_alt_names text = run_openssl_command_with('-text -noout').stdout # X509v3 Subject Alternative Name: # DNS:*.example.com, DNS:www.example.net, IP:192.0.2.10 if text =~ /^ *X509v3 Subject Alternative Name:.*\n *(.*)$/ $1.split(/, +/) end end private def run_openssl_command_with(param_str) @runner.run_command("openssl x509 -in #{name} #{param_str}") end def parse_dates_str_to_map(dates_str) dates_str.split("\n").inject({}) do |res,line| kv_arr = line.split '=' time = Time.strptime(kv_arr[1],'%b %e %T %Y %Z') rescue Time.parse(kv_arr[1] || '') res.merge({ kv_arr[0].to_sym => time }) end end end end serverspec-2.41.5/lib/serverspec/type/selinux.rb0000644000004100000410000000057413526734265021763 0ustar www-datawww-datamodule Serverspec::Type class Selinux < Base def disabled? @runner.check_selinux_has_mode('disabled') end def enforcing?(with_policy) @runner.check_selinux_has_mode('enforcing', with_policy) end def permissive?(with_policy) @runner.check_selinux_has_mode('permissive', with_policy) end def to_s 'SELinux' end end end serverspec-2.41.5/lib/serverspec/matcher/0000755000004100000410000000000013526734265020403 5ustar www-datawww-dataserverspec-2.41.5/lib/serverspec/matcher/belong_to_primary_group.rb0000644000004100000410000000020113526734265025650 0ustar www-datawww-dataRSpec::Matchers.define :belong_to_primary_group do |group| match do |user| user.belongs_to_primary_group?(group) end end serverspec-2.41.5/lib/serverspec/matcher/be_executable.rb0000644000004100000410000000034113526734265023515 0ustar www-datawww-dataRSpec::Matchers.define :be_executable do match do |file| file.executable?(@by_whom, @by_user) end chain :by do |by_whom| @by_whom = by_whom end chain :by_user do |by_user| @by_user = by_user end end serverspec-2.41.5/lib/serverspec/matcher/be_listening.rb0000644000004100000410000000061213526734265023371 0ustar www-datawww-dataRSpec::Matchers.define :be_listening do match do |port| port.listening? @with, @local_address end description do message = 'be listening' message << " on #{@local_address}" if @local_address message << " with #{@with}" if @with message end chain :with do |with| @with = with end chain :on do |local_address| @local_address = local_address end end serverspec-2.41.5/lib/serverspec/matcher/belong_to_group.rb0000644000004100000410000000016113526734265024112 0ustar www-datawww-dataRSpec::Matchers.define :belong_to_group do |group| match do |user| user.belongs_to_group?(group) end end serverspec-2.41.5/lib/serverspec/matcher/be_monitored_by.rb0000644000004100000410000000056613526734265024077 0ustar www-datawww-dataRSpec::Matchers.define :be_monitored_by do |monitor| match do |service| service.monitored_by?(monitor, @monitor_name) end description do if @monitor_name "be monitored by #{monitor} with name #{@monitor_name}" else "be monitored by #{monitor}" end end chain :with_name do |name| @monitor_name = (name ? name : nil) end end serverspec-2.41.5/lib/serverspec/matcher/be_installed.rb0000644000004100000410000000102013526734265023346 0ustar www-datawww-dataRSpec::Matchers.define :be_installed do match do |subject| if subject.class.name == 'Serverspec::Type::SelinuxModule' subject.installed?(@version) else subject.installed?(@provider, @version) end end description do message = 'be installed' message << %( by "#{@provider}") if @provider message << %( with version "#{@version}") if @version message end chain :by do |provider| @provider = provider end chain :with_version do |version| @version = version end end serverspec-2.41.5/lib/serverspec/matcher/have_virtual_dir.rb0000644000004100000410000000052413526734265024260 0ustar www-datawww-dataRSpec::Matchers.define :have_virtual_dir do |vdir| match do |subject| if subject.class.name == 'Serverspec::Type::IisWebsite' subject.has_virtual_dir?(vdir, @path) else className = subject.class.name raise "not supported class #{className}" end end chain :with_path do |path| @path = path end end serverspec-2.41.5/lib/serverspec/matcher/have_entry.rb0000644000004100000410000000050413526734265023073 0ustar www-datawww-dataRSpec::Matchers.define :have_entry do |entry| match do |subject| if subject.class.name == 'Serverspec::Type::Cron' subject.has_entry?(@user, entry) elsif subject.respond_to?(:has_entry?) subject.has_entry?(entry) end end # For cron type chain :with_user do |user| @user = user end end serverspec-2.41.5/lib/serverspec/matcher/be_running.rb0000644000004100000410000000054413526734265023061 0ustar www-datawww-dataRSpec::Matchers.define :be_running do match do |subject| if subject.class.name == 'Serverspec::Type::Service' subject.running?(@under) else subject.running? end end description do message = 'be running' message << " under #{@under}" if @under message end chain :under do |under| @under = under end end serverspec-2.41.5/lib/serverspec/matcher/be_readable.rb0000644000004100000410000000033513526734265023136 0ustar www-datawww-dataRSpec::Matchers.define :be_readable do match do |file| file.readable?(@by_whom, @by_user) end chain :by do |by_whom| @by_whom = by_whom end chain :by_user do |by_user| @by_user = by_user end end serverspec-2.41.5/lib/serverspec/matcher/have_site_bindings.rb0000644000004100000410000000104013526734265024547 0ustar www-datawww-dataRSpec::Matchers.define :have_site_bindings do |port| match do |subject| if subject.class.name == 'Serverspec::Type::IisWebsite' subject.has_site_bindings?(port, @protocol, @ipaddress, @host_header) else className = subject.class.name raise "not supported class #{className}" end end chain :with_protocol do |protocol| @protocol = protocol end chain :with_ipaddress do |ipaddress| @ipaddress = ipaddress end chain :with_host_header do |host_header| @host_header = host_header end end serverspec-2.41.5/lib/serverspec/matcher/be_resolvable.rb0000644000004100000410000000021713526734265023534 0ustar www-datawww-dataRSpec::Matchers.define :be_resolvable do match do |name| name.resolvable?(@type) end chain :by do |type| @type = type end end serverspec-2.41.5/lib/serverspec/matcher/have_site_application.rb0000644000004100000410000000070713526734265025266 0ustar www-datawww-dataRSpec::Matchers.define :have_site_application do |app| match do |subject| if subject.class.name == 'Serverspec::Type::IisWebsite' subject.has_site_application?(app, @pool, @physical_path) else className = subject.class.name raise "not supported class #{className}" end end chain :with_pool do |pool| @pool = pool end chain :with_physical_path do |physical_path| @physical_path = physical_path end end serverspec-2.41.5/lib/serverspec/matcher/be_reachable.rb0000644000004100000410000000053213526734265023304 0ustar www-datawww-dataRSpec::Matchers.define :be_reachable do match do |host| proto = 'tcp' timeout = 5 if @attr port = @attr[:port] proto = @attr[:proto] if @attr[:proto] timeout = @attr[:timeout] if @attr[:timeout] end host.reachable?(port, proto, timeout) end chain :with do |attr| @attr = attr end end serverspec-2.41.5/lib/serverspec/matcher/be_permissive.rb0000644000004100000410000000027313526734265023566 0ustar www-datawww-dataRSpec::Matchers.define :be_permissive do match do |selinux| selinux.permissive?(@with_policy) end chain :with_policy do |with_policy| @with_policy = with_policy end end serverspec-2.41.5/lib/serverspec/matcher/be_enforcing.rb0000644000004100000410000000027113526734265023350 0ustar www-datawww-dataRSpec::Matchers.define :be_enforcing do match do |selinux| selinux.enforcing?(@with_policy) end chain :with_policy do |with_policy| @with_policy = with_policy end end serverspec-2.41.5/lib/serverspec/matcher/be_writable.rb0000644000004100000410000000033513526734265023210 0ustar www-datawww-dataRSpec::Matchers.define :be_writable do match do |file| file.writable?(@by_whom, @by_user) end chain :by do |by_whom| @by_whom = by_whom end chain :by_user do |by_user| @by_user = by_user end end serverspec-2.41.5/lib/serverspec/matcher/be_mounted.rb0000644000004100000410000000040313526734265023046 0ustar www-datawww-dataRSpec::Matchers.define :be_mounted do match do |path| path.mounted?(@attr, @only_with) end chain :with do |attr| @attr = attr @only_with = false end chain :only_with do |attr| @attr = attr @only_with = true end end serverspec-2.41.5/lib/serverspec/matcher/have_rule.rb0000644000004100000410000000114113526734265022677 0ustar www-datawww-dataRSpec::Matchers.define :have_rule do |rule| match do |subject| if subject.class.name == 'Serverspec::Type::Iptables' || subject.class.name == 'Serverspec::Type::Ip6tables' subject.has_rule?(rule, @table, @chain) else subject.has_rule?(rule) end end description do message = %Q{have rule "#{rule}"} message << " with table #{@table}" if @table message << ' and' if @table && @chain message << " with chain #{@chain}" if @chain message end chain :with_table do |table| @table = table end chain :with_chain do |chain| @chain = chain end end serverspec-2.41.5/lib/serverspec/matcher/contain.rb0000644000004100000410000000122313526734265022361 0ustar www-datawww-dataRSpec::Matchers.define :contain do |pattern| match do |resource| if resource.is_a?(String) resource.match(Regexp.new([@from, pattern, @to].compact.join.gsub('/', '.*'), Regexp::MULTILINE)) else resource.contain(pattern, @from, @to) end end # for contain(pattern).from(/A/).to(/B/) chain :from do |from| @from = Regexp.new(from).inspect end chain :to do |to| @to = Regexp.new(to).inspect end # for contain(pattern).after(/A/) chain :after do |after| @from = Regexp.new(after).inspect end # for contain(pattern).before(/B/) chain :before do |before| @to = Regexp.new(before).inspect end end serverspec-2.41.5/lib/serverspec/matcher/be_enabled.rb0000644000004100000410000000072613526734265022775 0ustar www-datawww-dataRSpec::Matchers.define :be_enabled do match do |subject| if subject.class.name == 'Serverspec::Type::Service' subject.enabled?(@level, @under) else subject.enabled? end end description do message = 'be enabled' message << " under #{@under}" if @under message << " with level #{@level}" if @level message end chain :with_level do |level| @level = level end chain :under do |under| @under = under end end serverspec-2.41.5/lib/serverspec/subject.rb0000644000004100000410000000023513526734265020744 0ustar www-datawww-datamodule Serverspec class Subject def value(v=nil) if v.nil? @value else @value = v self end end end end serverspec-2.41.5/lib/serverspec/matcher.rb0000644000004100000410000000203313526734265020726 0ustar www-datawww-data# file require 'serverspec/matcher/be_mounted' require 'serverspec/matcher/contain' require 'serverspec/matcher/be_readable' require 'serverspec/matcher/be_writable' require 'serverspec/matcher/be_executable' # port require 'serverspec/matcher/be_listening' # host require 'serverspec/matcher/be_resolvable' require 'serverspec/matcher/be_reachable' # package require 'serverspec/matcher/be_installed' # selinux require 'serverspec/matcher/be_enforcing' require 'serverspec/matcher/be_permissive' # service require 'serverspec/matcher/be_enabled' require 'serverspec/matcher/be_running' require 'serverspec/matcher/be_monitored_by' # user require 'serverspec/matcher/belong_to_group' require 'serverspec/matcher/belong_to_primary_group' # ipfiter, ipnat, iptables, ip6tables require 'serverspec/matcher/have_rule' # cron, fstab, routing_table require 'serverspec/matcher/have_entry' # iis_website require 'serverspec/matcher/have_site_application' require 'serverspec/matcher/have_site_bindings' require 'serverspec/matcher/have_virtual_dir' serverspec-2.41.5/lib/serverspec/setup.rb0000644000004100000410000002044613526734265020453 0ustar www-datawww-datarequire 'pathname' require 'fileutils' require 'erb' module Serverspec class Setup def self.run ask_os_type if @os_type == 'UN*X' ask_unix_backend else ask_windows_backend end if @backend_type == 'ssh' print 'Vagrant instance y/n: ' @vagrant = $stdin.gets.chomp if @vagrant =~ (/(true|t|yes|y|1)$/i) @vagrant = true print 'Auto-configure Vagrant from Vagrantfile? y/n: ' auto_config = $stdin.gets.chomp if auto_config =~ (/(true|t|yes|y|1)$/i) auto_vagrant_configuration else print('Input vagrant instance name: ') @hostname = $stdin.gets.chomp end else @vagrant = false print('Input target host name: ') @hostname = $stdin.gets.chomp end elsif @backend_type == 'winrm' print('Input target host name: ') @hostname = $stdin.gets.chomp else @hostname = 'localhost' end ['spec', "spec/#{@hostname}"].each { |dir| safe_mkdir(dir) } safe_create_spec safe_create_spec_helper safe_create_rakefile safe_create_dotrspec end def self.ask_os_type prompt = <<-EOF Select OS type: 1) UN*X 2) Windows Select number: EOF print prompt.chop num = $stdin.gets.to_i - 1 puts @os_type = ['UN*X', 'Windows'][num] || 'UN*X' end def self.ask_unix_backend prompt = <<-EOF Select a backend type: 1) SSH 2) Exec (local) Select number: EOF print prompt.chop num = $stdin.gets.to_i - 1 puts @backend_type = ['ssh', 'exec'][num] || 'exec' end def self.ask_windows_backend prompt = <<-EOF Select a backend type: 1) WinRM 2) Cmd (local) Select number: EOF print prompt.chop num = $stdin.gets.to_i - 1 puts @backend_type = ['winrm', 'cmd'][num] || 'exec' end def self.safe_create_spec content = <<-EOF require 'spec_helper' describe package('httpd'), :if => os[:family] == 'redhat' do it { should be_installed } end describe package('apache2'), :if => os[:family] == 'ubuntu' do it { should be_installed } end describe service('httpd'), :if => os[:family] == 'redhat' do it { should be_enabled } it { should be_running } end describe service('apache2'), :if => os[:family] == 'ubuntu' do it { should be_enabled } it { should be_running } end describe service('org.apache.httpd'), :if => os[:family] == 'darwin' do it { should be_enabled } it { should be_running } end describe port(80) do it { should be_listening } end EOF if File.exists? "spec/#{@hostname}/sample_spec.rb" old_content = File.read("spec/#{@hostname}/sample_spec.rb") if old_content != content $stderr.puts "!! spec/#{@hostname}/sample_spec.rb already exists and differs from template" end else File.open("spec/#{@hostname}/sample_spec.rb", 'w') do |f| f.puts content end puts " + spec/#{@hostname}/sample_spec.rb" end end def self.safe_mkdir(dir) if File.exists? dir unless File.directory? dir $stderr.puts "!! #{dir} already exists and is not a directory" end else FileUtils.mkdir dir puts " + #{dir}/" end end def self.safe_create_spec_helper content = ERB.new(spec_helper_template, nil, '-').result(binding) if File.exists? 'spec/spec_helper.rb' old_content = File.read('spec/spec_helper.rb') if old_content != content $stderr.puts "!! spec/spec_helper.rb already exists and differs from template" end else File.open('spec/spec_helper.rb', 'w') do |f| f.puts content end puts ' + spec/spec_helper.rb' end end def self.safe_create_rakefile content = <<-'EOF' require 'rake' require 'rspec/core/rake_task' task :spec => 'spec:all' task :default => :spec namespace :spec do targets = [] Dir.glob('./spec/*').each do |dir| next unless File.directory?(dir) target = File.basename(dir) target = "_#{target}" if target == "default" targets << target end task :all => targets task :default => :all targets.each do |target| original_target = target == "_default" ? target[1..-1] : target desc "Run serverspec tests to #{original_target}" RSpec::Core::RakeTask.new(target.to_sym) do |t| ENV['TARGET_HOST'] = original_target t.pattern = "spec/#{original_target}/*_spec.rb" end end end EOF if File.exists? 'Rakefile' old_content = File.read('Rakefile') if old_content != content $stderr.puts '!! Rakefile already exists and differs from template' end else File.open('Rakefile', 'w') do |f| f.puts content end puts ' + Rakefile' end end def self.find_vagrantfile Pathname.new(Dir.pwd).ascend do |dir| path = File.expand_path('Vagrantfile', dir) return path if File.exists?(path) end nil end def self.auto_vagrant_configuration if find_vagrantfile vagrant_list = `vagrant status` list_of_vms = [] if vagrant_list != '' vagrant_list.each_line do |line| if match = /([\w-]+[\s]+)(created|aborted|not created|poweroff|running|saved)[\s](\(virtualbox\)|\(vmware\)|\(vmware_fusion\)|\(libvirt\))/.match(line) list_of_vms << match[1].strip! end end if list_of_vms.length == 1 @hostname = list_of_vms[0] else list_of_vms.each_with_index { |vm, index | puts "#{index}) #{vm}\n" } print 'Choose a VM from the Vagrantfile: ' chosen_vm = $stdin.gets.chomp @hostname = list_of_vms[chosen_vm.to_i] end else $stderr.puts 'Vagrant status error - Check your Vagrantfile or .vagrant' exit 1 end else $stderr.puts 'Vagrantfile not found in directory!' exit 1 end end def self.spec_helper_template template = <<-'EOF' require 'serverspec' <% if @backend_type == 'ssh' -%> require 'net/ssh' <% end -%> <%- if @vagrant -%> require 'tempfile' <% end -%> <% if @backend_type == 'winrm' -%> require 'winrm' <% end -%> set :backend, :<%= @backend_type %> <% if @os_type == 'UN*X' && @backend_type == 'ssh' -%> if ENV['ASK_SUDO_PASSWORD'] begin require 'highline/import' rescue LoadError fail "highline is not available. Try installing it." end set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false } else set :sudo_password, ENV['SUDO_PASSWORD'] end <%- if @backend_type == 'ssh' -%> host = ENV['TARGET_HOST'] <%- if @vagrant -%> `vagrant up #{host}` config = Tempfile.new('', Dir.tmpdir) config.write(`vagrant ssh-config #{host}`) config.close options = Net::SSH::Config.for(host, [config.path]) <%- else -%> options = Net::SSH::Config.for(host) <%- end -%> options[:user] ||= Etc.getlogin set :host, options[:host_name] || host set :ssh_options, options # Disable sudo # set :disable_sudo, true <%- end -%> # Set environment variables # set :env, :LANG => 'C', :LC_MESSAGES => 'C' # Set PATH # set :path, '/sbin:/usr/local/sbin:$PATH' <%- end -%> <% if @backend_type == 'winrm'-%> user = pass = endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" if Gem::Version.new(WinRM::VERSION) < Gem::Version.new('2') winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true) winrm.set_timeout 300 # 5 minutes max timeout for any operation else opts = { user: user, password: pass, endpoint: endpoint, operation_timeout: 300, no_ssl_peer_verification: false, } winrm = ::WinRM::Connection.new(opts) end Specinfra.configuration.winrm = winrm <% end -%> EOF template end def self.safe_create_dotrspec content = <<-'EOF' --color --format documentation EOF if File.exists? '.rspec' old_content = File.read('.rspec') if old_content != content $stderr.puts '!! .rspec already exists and differs from template' end else File.open('.rspec', 'w') do |f| f.puts content end puts ' + .rspec' end end end end serverspec-2.41.5/lib/serverspec/helper/0000755000004100000410000000000013526734265020237 5ustar www-datawww-dataserverspec-2.41.5/lib/serverspec/helper/type.rb0000644000004100000410000000163113526734265021546 0ustar www-datawww-datamodule Serverspec module Helper module Type types = %w( base bridge bond cgroup command cron default_gateway file fstab group host iis_website iis_app_pool interface ipfilter ipnat iptables ip6tables json_file kernel_module kvm linux_kernel_parameter lxc mail_alias mysql_config package php_config port ppa process routing_table selinux selinux_module service user yumrepo windows_feature windows_hot_fix windows_registry_key windows_scheduled_task zfs docker_base docker_image docker_container x509_certificate x509_private_key linux_audit_system hadoop_config php_extension windows_firewall ) types.each {|type| require "serverspec/type/#{type}" } types.each do |type| define_method type do |*args| eval "Serverspec::Type::#{type.to_camel_case}.new(*args)" end end end end end serverspec-2.41.5/lib/serverspec/commands/0000755000004100000410000000000013526734265020561 5ustar www-datawww-dataserverspec-2.41.5/lib/serverspec/commands/base.rb0000644000004100000410000000014113526734265022014 0ustar www-datawww-datamodule Serverspec module Commands class Base < Specinfra::Command::Base end end end serverspec-2.41.5/lib/serverspec.rb0000644000004100000410000000431413526734265017307 0ustar www-datawww-datarequire 'rubygems' require 'rspec' require 'rspec/its' require 'specinfra' require 'serverspec/version' require 'serverspec/matcher' require 'serverspec/helper' require 'serverspec/setup' require 'serverspec/subject' require 'serverspec/commands/base' require 'rspec/core/formatters/base_formatter' require 'specinfra/helper/set' include Specinfra::Helper::Set module RSpec::Core::Notifications class FailedExampleNotification < ExampleNotification def failure_lines host = ENV['TARGET_HOST'] || Specinfra.configuration.host @failure_lines ||= begin lines = [] lines << "On host `#{host}'" if host lines << "Failure/Error: #{read_failed_line.strip}" lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/ exception.message.to_s.split("\n").each do |line| lines << " #{line}" if exception.message end lines << " #{example.metadata[:command]}" lines << " #{example.metadata[:stdout]}" if example.metadata[:stdout] lines << " #{example.metadata[:stderr]}" if example.metadata[:stderr] lines end end end end # For RSpec 3.3.x if defined?(RSpec::Core::Formatters::ExceptionPresenter) class RSpec::Core::Formatters::ExceptionPresenter def failure_lines host = ENV['TARGET_HOST'] || Specinfra.configuration.host @failure_lines ||= begin lines = [] lines << "On host `#{host}'" if host error_lines = [] error_lines = [failure_slash_error_line] if defined?(failure_slash_error_line) error_lines = failure_slash_error_lines if defined?(failure_slash_error_lines) lines += error_lines unless (description == error_lines.join('')) lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/ encoded_string(exception.message.to_s).split("\n").each do |line| lines << " #{line}" end lines << " #{example.metadata[:command]}" lines << " #{example.metadata[:stdout]}" if example.metadata[:stdout] lines << " #{example.metadata[:stderr]}" if example.metadata[:stderr] lines end end end end serverspec-2.41.5/Guardfile0000644000004100000410000000014213526734265015653 0ustar www-datawww-dataguard :rspec do watch(%r{^spec/.+/.+_spec\.rb$}) watch('spec/spec_helper.rb') { "spec" } end serverspec-2.41.5/serverspec.gemspec0000644000004100000410000000224213526734265017557 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'serverspec/version' Gem::Specification.new do |spec| spec.name = "serverspec" spec.version = Serverspec::VERSION spec.authors = ["Gosuke Miyashita"] spec.email = ["gosukenator@gmail.com"] spec.description = %q{RSpec tests for your servers configured by Puppet, Chef, Itamae or anything else} spec.summary = %q{RSpec tests for your servers configured by Puppet, Chef, Itamae or anything else} spec.homepage = "http://serverspec.org/" spec.license = "MIT" spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_runtime_dependency "rspec", "~> 3.0" spec.add_runtime_dependency "rspec-its" spec.add_runtime_dependency "multi_json" spec.add_runtime_dependency "specinfra", "~> 2.72" spec.add_development_dependency("json", "~> 1.8") if RUBY_VERSION < "1.9" spec.add_development_dependency "rake", "~> 10.1.1" end serverspec-2.41.5/Gemfile0000644000004100000410000000036213526734265015325 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in serverspec.gemspec gemspec if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') # net-ssh 3.x dropped Ruby 1.8 and 1.9 support. gem 'net-ssh', '~> 2.7' end serverspec-2.41.5/.gitmodules0000644000004100000410000000017513526734265016211 0ustar www-datawww-data[submodule "integration-test"] path = integration-test url = https://github.com/serverspec/serverspec-integration-test.git serverspec-2.41.5/appveyor.yml0000644000004100000410000000440213526734265016421 0ustar www-datawww-dataversion: "{build}" image: Previous Visual Studio 2015 platform: - x64 environment: bundle_gemfile: integration-test/Gemfile.winrm bundler_url: https://rubygems.org/downloads/bundler-1.9.9.gem matrix: - ruby_version: "193" - ruby_version: "200" - ruby_version: "21" - ruby_version: "22" - ruby_version: "23" - ruby_version: "24" - ruby_version: "25" - ruby_version: "26" matrix: allow_failures: - ruby_version: "193" clone_depth: 5 cache: - C:\Ruby193\lib\ruby\gems\1.9.1 -> appveyor.yml - C:\Ruby193\bin -> appveyor.yml - C:\Ruby200\lib\ruby\gems\2.0.0 -> appveyor.yml - C:\Ruby200\bin -> appveyor.yml - C:\Ruby21\lib\ruby\gems\2.1.0 -> appveyor.yml - C:\Ruby21\bin -> appveyor.yml - C:\Ruby22\lib\ruby\gems\2.2.0 -> appveyor.yml - C:\Ruby22\bin -> appveyor.yml - C:\Ruby23\lib\ruby\gems\2.2.0 -> appveyor.yml - C:\Ruby23\bin -> appveyor.yml - C:\Ruby24\lib\ruby\gems\2.4.0 -> appveyor.yml - C:\Ruby24\bin -> appveyor.yml - C:\Ruby25\lib\ruby\gems\2.5.0 -> appveyor.yml - C:\Ruby25\bin -> appveyor.yml - C:\Ruby26\lib\ruby\gems\2.6.0 -> appveyor.yml - C:\Ruby26\bin install: - git submodule update --init --recursive - ps: Enable-PSRemoting -Force - winrm quickconfig -q - winrm set winrm/config/client @{TrustedHosts="*"} - winrm set winrm/config/client/auth @{Basic="true"} - winrm set winrm/config/service/auth @{Basic="true"} - winrm set winrm/config/service @{AllowUnencrypted="true"} - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - echo %PATH% - ruby --version - gem --version - appveyor DownloadFile -Url %bundler_url% -FileName bundler.gem - gem install --local bundler.gem --no-document --force ## appveyor often stops `gem install bundler`..? - ps: $PSVersionTable build_script: - ruby -rfileutils -e 'FileUtils.rm_r(File.join(Gem.dir, "cache", "bundler")) if Dir.exists?(File.join(Gem.dir, "cache", "bundler"))' - bundle install --jobs 3 --retry 3 - net user - net localgroup test_script: - net user appveyor %WINDOWS_PASSWORD% # set by webui - bundle exec rspec -fd --backtrace -r .\integration-test\winrm\spec_helper.rb .\integration-test\winrm serverspec-2.41.5/WINDOWS_SUPPORT.md0000644000004100000410000001023613526734265016743 0ustar www-datawww-data## Windows support Serverspec is now providing a limited support for Microsoft Windows. If you want to test Windows based machines you need to set the target host's OS explicitly in your `spec/spec_helper.rb` For local testing (equivalent to the Exec option in Linux/Unix systems) simply do: ```ruby require 'serverspec' set :backend, :cmd set :os, :family => 'windows' ``` For remote testing you have to configure Windows Remote Management in order to communicate to the target host: ```ruby require 'serverspec' require 'winrm' set :backend, :winrm set :os, :family => 'windows' user = pass = endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" if Gem::Version.new(WinRM::VERSION) < Gem::Version.new('2') winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true) winrm.set_timeout 300 # 5 minutes max timeout for any operation else opts = { user: user, password: pass, endpoint: endpoint, operation_timeout: 300, no_ssl_peer_verification: false, } winrm = ::WinRM::Connection.new(opts) end Specinfra.configuration.winrm = winrm ``` For how to configure the guest to accept WinRM connections and the different authentication mechanisms check the Microsoft WinRM documentation and verify the ones that are supported by [WinRb/WinRM](https://github.com/WinRb/WinRM). ###RSpec Examples for windows target hosts ```ruby describe file('c:/windows') do it { should be_directory } it { should be_readable } it { should_not be_writable.by('Everyone') } end describe file('c:/temp/test.txt') do it { should be_file } it { should contain "some text" } end describe package('Adobe AIR') do it { should be_installed} end describe service('DNS Client') do it { should be_installed } it { should be_enabled } it { should be_running } it { should have_start_mode("Manual") } end describe port(139) do it { should be_listening } end describe user('some.admin') do it { should exist } it { should belong_to_group('Administrators')} end describe group('Guests') do it { should exist } end describe group('MYDOMAIN\Domain Users') do it { should exist } end describe command('& "ipconfig"') do its(:stdout) { should match /IPv4 Address(\.| )*: 192\.168\.1\.100/ } end describe windows_registry_key('HKEY_USERS\S-1-5-21-1319311448-2088773778-316617838-32407\Test MyKey') do it { should exist } it { should have_property('string value') } it { should have_property('binary value', :type_binary) } it { should have_property('dword value', :type_dword) } it { should have_value('test default data') } it { should have_property_value('multistring value', :type_multistring, "test\nmulti\nstring\ndata") } it { should have_property_value('qword value', :type_qword, 'adff32') } it { should have_property_value('binary value', :type_binary, 'dfa0f066') } end describe windows_feature('Minesweeper') do it{ should be_installed } it{ should be_installed.by("dism") } it{ should be_installed.by("powershell") } end describe iis_website("Default Website") do it { should exist } it { should be_enabled } it { should be_running } it { should be_in_app_pool "DefaultAppPool" } it { should have_physical_path "c:/inetpub/wwwroot" } end describe iis_app_pool("DefaultAppPool") do it { should exist } it { should have_dotnet_version "2.0" } end ``` ###Notes: * Not all the matchers you are used to in Linux-like OS are supported in Windows, some because of differences between the operating systems (e.g. users and permissions model), some because they haven't been yet implemented. * All commands in the windows backend are run via powershell, so the output in case of stderr is a pretty ugly xml-like thing. Still it should contain some information to help troubleshooting. * The *command* type is executed again through powershell, so bear that in mind if you mean to run old CMD windows batch or programs. (i.e run the command using the **Invoke-Expression** Cmdlet, or the **&** Call Operator) * You may have to change Exectution Policy on the machine at both, machine and user level in order for tests to run: Get-ExecutionPolicy -list|%{set-executionpolicy bypass -scope $_.scope} serverspec-2.41.5/.github/0000755000004100000410000000000013526734265015371 5ustar www-datawww-dataserverspec-2.41.5/.github/stale.yml0000644000004100000410000000125513526734265017227 0ustar www-datawww-data# Number of days of inactivity before an issue becomes stale daysUntilStale: 60 # Number of days of inactivity before a stale issue is closed daysUntilClose: 7 # Issues with these labels will never be considered stale exemptLabels: - pinned - security # Label to use when marking an issue as stale staleLabel: wontfix # Comment to post when marking an issue as stale. Set to `false` to disable markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. # Comment to post when closing a stale issue. Set to `false` to disable closeComment: false serverspec-2.41.5/LICENSE.txt0000644000004100000410000000206113526734265015653 0ustar www-datawww-dataCopyright (c) 2013 Gosuke Miyashita MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.