pax_global_header00006660000000000000000000000064122574235260014522gustar00rootroot0000000000000052 comment=2d43a3187accbce9894383bf5ec5e880d1eeb557 serverspec-0.14.2/000077500000000000000000000000001225742352600137675ustar00rootroot00000000000000serverspec-0.14.2/.gitignore000066400000000000000000000003601225742352600157560ustar00rootroot00000000000000*.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 serverspec-0.14.2/.travis.yml000066400000000000000000000002531225742352600161000ustar00rootroot00000000000000language: ruby rvm: - 1.8.7 - 1.9.3 - 2.0.0 before_install: - gem update bundler script: - bundle exec rake spec matrix: allow_failures: - rvm: 2.0.0 serverspec-0.14.2/Gemfile000066400000000000000000000003411225742352600152600ustar00rootroot00000000000000source 'https://rubygems.org' # Specify your gem's dependencies in serverspec.gemspec gemspec # Put Gemfile.local to use arbitrary gems for your use case. path = Pathname.new("Gemfile.local") eval(path.read) if path.exist? serverspec-0.14.2/Guardfile000066400000000000000000000001421225742352600156110ustar00rootroot00000000000000guard :rspec do watch(%r{^spec/.+/.+_spec\.rb$}) watch('spec/spec_helper.rb') { "spec" } end serverspec-0.14.2/LICENSE.txt000066400000000000000000000020611225742352600156110ustar00rootroot00000000000000Copyright (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. serverspec-0.14.2/README.md000066400000000000000000000070431225742352600152520ustar00rootroot00000000000000# Serverspec [![Gem Version](https://badge.fury.io/rb/serverspec.png)](http://badge.fury.io/rb/serverspec) [![BuildStatus](https://secure.travis-ci.org/serverspec/serverspec.png)](http://travis-ci.org/serverspec/serverspec) [![Code Climate](https://codeclimate.com/github/serverspec/serverspec.png)](https://codeclimate.com/github/serverspec/serverspec) 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/). ---- ## Installation Add this line to your application's Gemfile: gem 'serverspec' And then execute: $ bundle Or install it yourself as: $ gem install serverspec ---- ## Usage ``` $ serverspec-init Select a backend type: 1) SSH 2) Exec (local) Select number: 1 Input target host name: www.example.jp + spec/ + spec/www.example.jp/ + spec/www.example.jp/httpd_spec.rb + spec/spec_helper.rb + Rakefile ``` spec/www.example.jp/httpd_spec.rb is a sample spec file and its content is like this. ```ruby require 'spec_helper' describe package('httpd') do it { should be_installed } end describe service('httpd') do it { should be_enabled } it { should be_running } end describe port(80) do it { should be_listening } end describe file('/etc/httpd/conf/httpd.conf') do it { should be_file } it { should contain "ServerName www.example.jp" } end ``` You can write spec for testing servers like this. Serverspec with SSH backend logs in to target servers as a user configured in ``~/.ssh/config`` or a current user.If you'd lile to change the user, please edit the below line in ``spec/spec_helper.rb``. ```ruby user = options[:user] || Etc.getlogin ``` Run tests. ``` $ rake spec /usr/bin/ruby -S rspec spec/www.example.jp/httpd_spec.rb ...... Finished in 0.99715 seconds 6 examples, 0 failures ``` ---- ## Multi OS support Serverspec is supporting Darwin based OS, Red Hat based OS, Debian based OS, Gentoo and Solaris. Serverspec can detect target host's OS automatically. If you'd like to set target host's OS explicitly, you should include `Serverspec::Helper::OSName` in `spec/spec_helper.rb` like this. ```ruby require 'serverspec' require 'pathname' require 'net/ssh' include Serverspec::Helper::Ssh include Serverspec::Helper::Debian RSpec.configure do |c| # Add SSH before hook in case you use the SSH backend # (not required for the Exec backend) c.before do host = File.basename(Pathname.new(example.metadata[:location]).dirname) if c.host != host c.ssh.close if c.ssh c.host = host options = Net::SSH::Config.for(c.host) user = options[:user] || Etc.getlogin c.ssh = Net::SSH.start(c.host, user, options) end end end ``` You can select **Serverspec::Helper::RedHat**, **Serverspec::Helper::Debian**, **Serverspec::Helper::Gentoo** , **Serverspec::Helper::Solaris** or **Serverspec::Helper::Darwin**. ## Vagrant support Serverspec now has Vagrant support, and can be automatically configured from a Vagrantfile ``` $ serverspec-init Select a backend type: 1) SSH 2) Exec (local) Select number:1 Vagrant instance y/n: y Auto-configure Vagrant from Vagrantfile? y/n: y 0) web 1) db 1 + spec/db/ + spec/db/httpd_spec.rb + spec/spec_helper.rb + Rakefile ``` See details on [serverspec.org](http://serverspec.org) ---- ## 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-0.14.2/Rakefile000066400000000000000000000013141225742352600154330ustar00rootroot00000000000000require "bundler/gem_tasks" require 'rspec/core/rake_task' task :spec => 'spec:all' namespace :spec do oses = %w( darwin debian gentoo plamo redhat aix solaris solaris10 solaris11 smartos windows freebsd) task :all => [ oses.map {|os| "spec:#{os}" }, :exec, :ssh, :cmd, :winrm, :powershell, :helper ].flatten oses.each do |os| RSpec::Core::RakeTask.new(os.to_sym) do |t| t.pattern = "spec/#{os}/*_spec.rb" end end [:exec, :ssh, :cmd, :winrm, :powershell].each do |backend| RSpec::Core::RakeTask.new(backend) do |t| t.pattern = "spec/backend/#{backend.to_s}/*_spec.rb" end end RSpec::Core::RakeTask.new(:helper) do |t| t.pattern = "spec/helper/*_spec.rb" end end serverspec-0.14.2/WINDOWS_SUPPORT.md000066400000000000000000000066031225742352600167040ustar00rootroot00000000000000## 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' include Serverspec::Helper::Cmd include Serverspec::Helper::Windows ``` For remote testing you have to configure Windows Remote Management in order to communicate to the target host: ```ruby require 'serverspec' require 'winrm' include Serverspec::Helper::WinRM include Serverspec::Helper::Windows RSpec.configure do |c| user = pass = endpoint = "http://:5985/wsman" c.winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true) c.winrm.set_timeout 300 # 5 minutes max timeout for any operation end ``` 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_enabled } it { should be_running } 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 it { should return_stdout(/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 ``` ###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-0.14.2/bin/000077500000000000000000000000001225742352600145375ustar00rootroot00000000000000serverspec-0.14.2/bin/serverspec-init000077500000000000000000000002041225742352600176030ustar00rootroot00000000000000#!/usr/bin/env ruby $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) require 'serverspec' Serverspec::Setup.run serverspec-0.14.2/lib/000077500000000000000000000000001225742352600145355ustar00rootroot00000000000000serverspec-0.14.2/lib/serverspec.rb000066400000000000000000000045221225742352600172460ustar00rootroot00000000000000require 'rubygems' require 'rspec' require 'specinfra' require 'serverspec/version' require 'serverspec/matchers' require 'serverspec/helper' require 'serverspec/setup' require 'serverspec/subject' require 'serverspec/commands/base' require 'rspec/core/formatters/base_formatter' module RSpec module Core module Formatters class BaseTextFormatter < BaseFormatter def dump_failure_info(example) exception = example.execution_result[:exception] exception_class_name = exception_class_name_for(exception) output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}" output.puts "#{long_padding}#{failure_color(exception_class_name)}: #{failure_color(exception.message)}" unless exception_class_name =~ /RSpec/ output.puts "#{long_padding} #{failure_color(example.metadata[:command])}" if example.metadata[:command] output.puts "#{long_padding} #{failure_color(example.metadata[:stdout])}" if example.metadata[:stdout] != '' exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message if shared_group = find_shared_group(example) dump_shared_failure_info(shared_group) end end end class ProgressFormatter < BaseTextFormatter def dump_failure_info(example) exception = example.execution_result[:exception] exception_class_name = exception_class_name_for(exception) output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}" output.puts "#{long_padding}#{failure_color(exception_class_name)}: #{failure_color(exception.message)}" unless exception_class_name =~ /RSpec/ output.puts "#{long_padding} #{failure_color(example.metadata[:command])}" if example.metadata[:command] output.puts "#{long_padding} #{failure_color(example.metadata[:stdout])}" if example.metadata[:stdout] != '' exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message if shared_group = find_shared_group(example) dump_shared_failure_info(shared_group) end end end end end end serverspec-0.14.2/lib/serverspec/000077500000000000000000000000001225742352600167165ustar00rootroot00000000000000serverspec-0.14.2/lib/serverspec/commands/000077500000000000000000000000001225742352600205175ustar00rootroot00000000000000serverspec-0.14.2/lib/serverspec/commands/base.rb000066400000000000000000000001411225742352600217520ustar00rootroot00000000000000module Serverspec module Commands class Base < SpecInfra::Command::Base end end end serverspec-0.14.2/lib/serverspec/helper.rb000066400000000000000000000003051225742352600205200ustar00rootroot00000000000000require 'serverspec/helper/os' require 'serverspec/helper/backend' # Subject type helper require 'serverspec/helper/type' include Serverspec::Helper::Type require 'serverspec/helper/properties' serverspec-0.14.2/lib/serverspec/helper/000077500000000000000000000000001225742352600201755ustar00rootroot00000000000000serverspec-0.14.2/lib/serverspec/helper/backend.rb000066400000000000000000000004141225742352600221100ustar00rootroot00000000000000module Serverspec module Helper ['Exec', 'Ssh', 'Cmd', 'WinRM'].each do |backend| eval <<-EOF module #{backend} include self.class.const_get('SpecInfra').const_get('Helper').const_get('#{backend}') end EOF end end end serverspec-0.14.2/lib/serverspec/helper/os.rb000066400000000000000000000006601225742352600211450ustar00rootroot00000000000000module Serverspec module Helper [ 'DetectOS', 'AIX', 'Darwin', 'Debian', 'FreeBSD', 'Gentoo', 'Plamo', 'RedHat', 'SmartOS', 'Solaris', 'Solaris10', 'Solaris11', 'Windows', ].each do |os| eval <<-EOF module #{os} include self.class.const_get('SpecInfra').const_get('Helper').const_get('#{os}') end EOF end end end serverspec-0.14.2/lib/serverspec/helper/properties.rb000066400000000000000000000002261225742352600227160ustar00rootroot00000000000000require 'specinfra/properties' module Serverspec module Helper module Properties include SpecInfra::Helper::Properties end end end serverspec-0.14.2/lib/serverspec/helper/type.rb000066400000000000000000000013511225742352600215030ustar00rootroot00000000000000module Serverspec module Helper module Type types = %w( base cgroup command cron default_gateway file group host interface ipfilter ipnat iptables kernel_module linux_kernel_parameter lxc mail_alias package php_config port process routing_table selinux service user yumrepo windows_registry_key zfs ) types.each {|type| require "serverspec/type/#{type}" } types.each do |type| define_method type do |*args| name = args.first self.class.const_get('Serverspec').const_get('Type').const_get(camelize(type)).new(name) end end def camelize(string) string.split("_").each {|s| s.capitalize! }.join("") end end end end serverspec-0.14.2/lib/serverspec/matchers.rb000066400000000000000000000016421225742352600210540ustar00rootroot00000000000000# file require 'serverspec/matchers/be_mounted' require 'serverspec/matchers/contain' require 'serverspec/matchers/be_readable' require 'serverspec/matchers/be_writable' require 'serverspec/matchers/be_executable' require 'serverspec/matchers/match_md5checksum' require 'serverspec/matchers/match_sha256checksum' # port require 'serverspec/matchers/be_listening' # host require 'serverspec/matchers/be_resolvable' require 'serverspec/matchers/be_reachable' # package require 'serverspec/matchers/be_installed' # service require 'serverspec/matchers/be_enabled' require 'serverspec/matchers/be_running' # user require 'serverspec/matchers/belong_to_group' require 'serverspec/matchers/return_exit_status' require 'serverspec/matchers/return_stdout' require 'serverspec/matchers/return_stderr' # ipfiter, ipnat, iptables require 'serverspec/matchers/have_rule' # cron, routing_table require 'serverspec/matchers/have_entry' serverspec-0.14.2/lib/serverspec/matchers/000077500000000000000000000000001225742352600205245ustar00rootroot00000000000000serverspec-0.14.2/lib/serverspec/matchers/be_enabled.rb000066400000000000000000000004031225742352600231060ustar00rootroot00000000000000RSpec::Matchers.define :be_enabled do match do |subject| if subject.class.name == 'Serverspec::Type::Service' subject.enabled?(@level || 3) else subject.enabled? end end chain :with_level do |level| @level = level end end serverspec-0.14.2/lib/serverspec/matchers/be_executable.rb000066400000000000000000000003371225742352600236430ustar00rootroot00000000000000RSpec::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-0.14.2/lib/serverspec/matchers/be_installed.rb000066400000000000000000000003511225742352600234750ustar00rootroot00000000000000RSpec::Matchers.define :be_installed do match do |name| name.installed?(@provider, @version) end chain :by do |provider| @provider = provider end chain :with_version do |version| @version = version end end serverspec-0.14.2/lib/serverspec/matchers/be_listening.rb000066400000000000000000000002201225742352600235050ustar00rootroot00000000000000RSpec::Matchers.define :be_listening do match do |port| port.listening?(@with) end chain :with do |with| @with = with end end serverspec-0.14.2/lib/serverspec/matchers/be_mounted.rb000066400000000000000000000004011225742352600231650ustar00rootroot00000000000000RSpec::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-0.14.2/lib/serverspec/matchers/be_reachable.rb000066400000000000000000000005331225742352600234260ustar00rootroot00000000000000RSpec::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-0.14.2/lib/serverspec/matchers/be_readable.rb000066400000000000000000000003331225742352600232550ustar00rootroot00000000000000RSpec::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-0.14.2/lib/serverspec/matchers/be_resolvable.rb000066400000000000000000000002171225742352600236550ustar00rootroot00000000000000RSpec::Matchers.define :be_resolvable do match do |name| name.resolvable?(@type) end chain :by do |type| @type = type end end serverspec-0.14.2/lib/serverspec/matchers/be_running.rb000066400000000000000000000003711225742352600232000ustar00rootroot00000000000000RSpec::Matchers.define :be_running do match do |process| if subject.class.name == 'Serverspec::Type::Service' process.running?(@under) else process.running? end end chain :under do |under| @under = under end end serverspec-0.14.2/lib/serverspec/matchers/be_writable.rb000066400000000000000000000003331225742352600233270ustar00rootroot00000000000000RSpec::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-0.14.2/lib/serverspec/matchers/belong_to_group.rb000066400000000000000000000001621225742352600242340ustar00rootroot00000000000000RSpec::Matchers.define :belong_to_group do |group| match do |user| user.belongs_to_group?(group) end end serverspec-0.14.2/lib/serverspec/matchers/contain.rb000066400000000000000000000007561225742352600225140ustar00rootroot00000000000000RSpec::Matchers.define :contain do |pattern| match do |file| file.contain(pattern, @from, @to) 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-0.14.2/lib/serverspec/matchers/have_entry.rb000066400000000000000000000005041225742352600232140ustar00rootroot00000000000000RSpec::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-0.14.2/lib/serverspec/matchers/have_rule.rb000066400000000000000000000005221225742352600230220ustar00rootroot00000000000000RSpec::Matchers.define :have_rule do |rule| match do |subject| if subject.class.name == 'Serverspec::Type::Iptables' subject.has_rule?(rule, @table, @chain) else subject.has_rule?(rule) end end chain :with_table do |table| @table = table end chain :with_chain do |chain| @chain = chain end end serverspec-0.14.2/lib/serverspec/matchers/match_md5checksum.rb000066400000000000000000000001671225742352600244410ustar00rootroot00000000000000RSpec::Matchers.define :match_md5checksum do |pattern| match do |file| file.match_md5checksum(pattern) end end serverspec-0.14.2/lib/serverspec/matchers/match_sha256checksum.rb000066400000000000000000000001751225742352600247630ustar00rootroot00000000000000RSpec::Matchers.define :match_sha256checksum do |pattern| match do |file| file.match_sha256checksum(pattern) end end serverspec-0.14.2/lib/serverspec/matchers/return_exit_status.rb000066400000000000000000000001761225742352600250300ustar00rootroot00000000000000RSpec::Matchers.define :return_exit_status do |status| match do |command| command.return_exit_status?(status) end end serverspec-0.14.2/lib/serverspec/matchers/return_stderr.rb000066400000000000000000000001661225742352600237560ustar00rootroot00000000000000RSpec::Matchers.define :return_stderr do |content| match do |command| command.return_stderr?(content) end end serverspec-0.14.2/lib/serverspec/matchers/return_stdout.rb000066400000000000000000000001661225742352600237750ustar00rootroot00000000000000RSpec::Matchers.define :return_stdout do |content| match do |command| command.return_stdout?(content) end end serverspec-0.14.2/lib/serverspec/setup.rb000066400000000000000000000163311225742352600204070ustar00rootroot00000000000000require '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 else @hostname = 'localhost' end [ 'spec', "spec/#{@hostname}" ].each { |dir| safe_mkdir(dir) } safe_create_spec safe_create_spec_helper safe_create_rakefile 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') do it { should be_installed } end describe service('httpd') do it { should be_enabled } it { should be_running } end describe port(80) do it { should be_listening } end describe file('/etc/httpd/conf/httpd.conf') do it { should be_file } it { should contain "ServerName #{@hostname}" } end EOF if File.exists? "spec/#{@hostname}/httpd_spec.rb" old_content = File.read("spec/#{@hostname}/httpd_spec.rb") if old_content != content $stderr.puts "!! spec/#{@hostname}/httpd_spec.rb already exists and differs from template" end else File.open("spec/#{@hostname}/httpd_spec.rb", 'w') do |f| f.puts content end puts " + spec/#{@hostname}/httpd_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 requirements = [] 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' RSpec::Core::RakeTask.new(:spec) do |t| t.pattern = 'spec/*/*_spec.rb' 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 = /([a-z_-]+[\s]+)(created|not created|poweroff|running|saved)[\s](\(virtualbox\)|\(vmware\))/.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 @os_type == 'UN*X' && @backend_type == 'Ssh' -%> require 'pathname' <% end -%> <% if @backend_type == 'Ssh' -%> require 'net/ssh' <% end -%> <% if @backend_type == 'WinRM' -%> require 'winrm' <% end -%> include SpecInfra::Helper::<%= @backend_type %> <% if @os_type == 'UN*X' -%> include SpecInfra::Helper::DetectOS <% else -%> include SpecInfra::Helper::Windows <% end -%> <% if @os_type == 'UN*X' -%> RSpec.configure do |c| if ENV['ASK_SUDO_PASSWORD'] require 'highline/import' c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false } else c.sudo_password = ENV['SUDO_PASSWORD'] end <%- if @backend_type == 'Ssh' -%> c.before :all do block = self.class.metadata[:example_group_block] if RUBY_VERSION.start_with?('1.8') file = block.to_s.match(/.*@(.*):[0-9]+>/)[1] else file = block.source_location.first end host = File.basename(Pathname.new(file).dirname) if c.host != host c.ssh.close if c.ssh c.host = host options = Net::SSH::Config.for(c.host) user = options[:user] || Etc.getlogin <%- if @vagrant -%> vagrant_up = `vagrant up #{@hostname}` config = `vagrant ssh-config #{@hostname}` if config != '' config.each_line do |line| if match = /HostName (.*)/.match(line) host = match[1] elsif match = /User (.*)/.match(line) user = match[1] elsif match = /IdentityFile (.*)/.match(line) options[:keys] = [match[1].gsub(/\"/,'')] elsif match = /Port (.*)/.match(line) options[:port] = match[1] end end end <%- end -%> c.ssh = Net::SSH.start(host, user, options) end end <%- end -%> end <% end -%> <% if @backend_type == 'WinRM'-%> RSpec.configure do |c| user = pass = endpoint = "http://:5985/wsman" c.winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true) c.winrm.set_timeout 300 # 5 minutes max timeout for any operation end <% end -%> EOF template end end end serverspec-0.14.2/lib/serverspec/subject.rb000066400000000000000000000002351225742352600207020ustar00rootroot00000000000000module Serverspec class Subject def value(v=nil) if v.nil? @value else @value = v self end end end end serverspec-0.14.2/lib/serverspec/type/000077500000000000000000000000001225742352600176775ustar00rootroot00000000000000serverspec-0.14.2/lib/serverspec/type/base.rb000066400000000000000000000006071225742352600211410ustar00rootroot00000000000000module Serverspec module Type class Base def initialize(name=nil) @name = name 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 alias_method :inspect, :to_s def to_ary to_s.split(" ") end end end end serverspec-0.14.2/lib/serverspec/type/cgroup.rb000066400000000000000000000007441225742352600215300ustar00rootroot00000000000000module Serverspec module Type class Cgroup < Base attr_accessor :subsystem def method_missing(meth) if @subsystem.nil? @subsystem = meth.to_s return self else param = "#{@subsystem}.#{meth.to_s}" ret = backend.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 end serverspec-0.14.2/lib/serverspec/type/command.rb000066400000000000000000000024151225742352600216440ustar00rootroot00000000000000module Serverspec module Type class Command < Base attr_accessor :result def return_stdout?(content) ret = backend.run_command(@name) if content.instance_of?(Regexp) ret[:stdout] =~ content else ret[:stdout].strip == content end end def return_stderr?(content) ret = backend.run_command(@name) # In ssh access with pty, stderr is merged to stdout # See http://stackoverflow.com/questions/7937651/receiving-extended-data-with-ssh-using-twisted-conch-as-client # So I use stdout instead of stderr if content.instance_of?(Regexp) ret[:stdout] =~ content else ret[:stdout].strip == content end end def return_exit_status?(status) ret = backend.run_command(@name) ret[:exit_status].to_i == status end def stdout if @result.nil? @result = backend.run_command(@name)[:stdout] end @result end # In ssh access with pty, stderr is merged to stdout # See http://stackoverflow.com/questions/7937651/receiving-extended-data-with-ssh-using-twisted-conch-as-client # So I use stdout instead of stderr alias :stderr :stdout end end end serverspec-0.14.2/lib/serverspec/type/cron.rb000066400000000000000000000003121225742352600211610ustar00rootroot00000000000000module Serverspec module Type class Cron < Base def has_entry?(user, entry) backend.check_cron_entry(user, entry) end def to_s 'Cron' end end end end serverspec-0.14.2/lib/serverspec/type/default_gateway.rb000066400000000000000000000010571225742352600233740ustar00rootroot00000000000000module Serverspec module Type class DefaultGateway < Base def ipaddress ret = backend.run_command(commands.check_routing_table('default')) ret[:stdout] =~ /^(\S+)(?: via (\S+))? dev (\S+).+(?:\r)?\n(?:default via (\S+))?/ $2 ? $2 : $4 end def interface ret = backend.run_command(commands.check_routing_table('default')) ret[:stdout] =~ /^(\S+)(?: via (\S+))? dev (\S+).+(?:\r)?\n(?:default via (\S+))?/ $3 end def to_s 'Default Gateway' end end end end serverspec-0.14.2/lib/serverspec/type/file.rb000066400000000000000000000036611225742352600211510ustar00rootroot00000000000000module Serverspec module Type class File < Base attr_accessor :content def file? backend.check_file(@name) end def socket? backend.check_socket(@name) end def directory? backend.check_directory(@name) end def contain(pattern, from, to) if (from || to).nil? cmd = backend.check_file_contain(@name, pattern) else cmd = backend.check_file_contain_within(@name, pattern, from, to) end end def mode?(mode) backend.check_mode(@name, mode) end def owned_by?(owner) backend.check_owner(@name, owner) end def grouped_into?(group) backend.check_grouped(@name, group) end def linked_to?(target) backend.check_link(@name, target) end def readable?(by_whom, by_user) if by_user != nil backend.check_access_by_user(@name, by_user, 'r') else backend.check_readable(@name, by_whom) end end def writable?(by_whom, by_user) if by_user != nil backend.check_access_by_user(@name, by_user, 'w') else backend.check_writable(@name, by_whom) end end def executable?(by_whom, by_user) if by_user != nil backend.check_access_by_user(@name, by_user, 'x') else backend.check_executable(@name, by_whom) end end def mounted?(attr, only_with) backend.check_mounted(@name, attr, only_with) end def match_md5checksum(md5sum) backend.check_file_md5checksum(@name, md5sum) end def match_sha256checksum(sha256sum) backend.check_file_sha256checksum(@name, sha256sum) end def content if @content.nil? @content = backend.run_command(commands.get_file_content(@name))[:stdout] end @content end end end end serverspec-0.14.2/lib/serverspec/type/group.rb000066400000000000000000000003211225742352600213540ustar00rootroot00000000000000module Serverspec module Type class Group < Base def exists? backend.check_group(@name) end def has_gid?(gid) backend.check_gid(@name, gid) end end end end serverspec-0.14.2/lib/serverspec/type/host.rb000066400000000000000000000004171225742352600212030ustar00rootroot00000000000000module Serverspec module Type class Host < Base def resolvable?(type) backend.check_resolvable(@name, type) end def reachable?(port, proto, timeout) backend.check_reachable(@name, port, proto, timeout) end end end end serverspec-0.14.2/lib/serverspec/type/interface.rb000066400000000000000000000005641225742352600221710ustar00rootroot00000000000000module Serverspec module Type class Interface < Base def speed ret = backend.run_command(commands.get_interface_speed_of(@name)) val = ret[:stdout].strip val = val.to_i if val.match(/^\d+$/) val end def has_ipv4_address?(ip_address) backend.check_ipv4_address(@name, ip_address) end end end end serverspec-0.14.2/lib/serverspec/type/ipfilter.rb000066400000000000000000000003071225742352600220420ustar00rootroot00000000000000module Serverspec module Type class Ipfilter < Base def has_rule?(rule) backend.check_ipfilter_rule(rule) end def to_s 'ipfilter' end end end end serverspec-0.14.2/lib/serverspec/type/ipnat.rb000066400000000000000000000002761225742352600213440ustar00rootroot00000000000000module Serverspec module Type class Ipnat < Base def has_rule?(rule) backend.check_ipnat_rule(rule) end def to_s 'ipnat' end end end end serverspec-0.14.2/lib/serverspec/type/iptables.rb000066400000000000000000000003421225742352600220260ustar00rootroot00000000000000module Serverspec module Type class Iptables < Base def has_rule?(rule, table, chain) backend.check_iptables_rule(rule, table, chain) end def to_s 'iptables' end end end end serverspec-0.14.2/lib/serverspec/type/kernel_module.rb000066400000000000000000000002361225742352600230520ustar00rootroot00000000000000module Serverspec module Type class KernelModule < Base def loaded? backend.check_kernel_module_loaded(@name) end end end end serverspec-0.14.2/lib/serverspec/type/linux_kernel_parameter.rb000066400000000000000000000004151225742352600247630ustar00rootroot00000000000000module Serverspec module Type class LinuxKernelParameter < Base def value ret = backend.run_command("/sbin/sysctl -q -n #{@name}") val = ret[:stdout].strip val = val.to_i if val.match(/^\d+$/) val end end end end serverspec-0.14.2/lib/serverspec/type/lxc.rb000066400000000000000000000003771225742352600210210ustar00rootroot00000000000000module Serverspec module Type class Lxc < Base def exists? backend.check_container(@name) end def running? backend.check_container_running(@name) end def to_s 'LXC' end end end end serverspec-0.14.2/lib/serverspec/type/mail_alias.rb000066400000000000000000000002451225742352600223200ustar00rootroot00000000000000module Serverspec module Type class MailAlias < Base def aliased_to?(target) backend.check_mail_alias(@name, target) end end end end serverspec-0.14.2/lib/serverspec/type/package.rb000066400000000000000000000036241225742352600216240ustar00rootroot00000000000000module Serverspec module Type class Package < Base def installed?(provider, version) if provider.nil? backend.check_installed(@name, version) else check_method = "check_installed_by_#{provider}".to_sym unless backend.respond_to?(check_method) || commands.respond_to?(check_method) raise ArgumentError.new("`be_installed` matcher doesn't support #{provider}") end backend.send(check_method, @name, version) end end def version ret = backend.run_command(commands.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 = [] while !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 return res end end end end end serverspec-0.14.2/lib/serverspec/type/php_config.rb000066400000000000000000000004131225742352600223360ustar00rootroot00000000000000module Serverspec module Type class PhpConfig < Base def value ret = backend.run_command("php -r 'echo get_cfg_var( \"#{@name}\" );'") val = ret[:stdout] val = val.to_i if val.match(/^\d+$/) val end end end end serverspec-0.14.2/lib/serverspec/type/port.rb000066400000000000000000000007401225742352600212110ustar00rootroot00000000000000module Serverspec module Type class Port < Base def listening?(protocol) if protocol protocol = protocol.to_s.downcase unless ["udp", "tcp", "tcp6", "udp6"].include?(protocol) raise ArgumentError.new("`be_listening` matcher doesn't support #{protocol}") end backend.check_listening_with_protocol(@name, protocol) else backend.check_listening(@name) end end end end end serverspec-0.14.2/lib/serverspec/type/process.rb000066400000000000000000000006731225742352600217100ustar00rootroot00000000000000module Serverspec module Type class Process < Base def running? pid = backend.run_command(commands.get_process(@name, :format => "pid="))[:stdout] not pid.empty? end def method_missing(meth) ret = backend.run_command(commands.get_process(@name, :format => "#{meth.to_s}=")) val = ret[:stdout].strip val = val.to_i if val.match(/^\d+$/) val end end end end serverspec-0.14.2/lib/serverspec/type/routing_table.rb000066400000000000000000000003231225742352600230600ustar00rootroot00000000000000module Serverspec module Type class RoutingTable < Base def has_entry?(entry) backend.check_routing_table(entry) end def to_s 'Routing Table' end end end end serverspec-0.14.2/lib/serverspec/type/selinux.rb000066400000000000000000000005271225742352600217170ustar00rootroot00000000000000module Serverspec module Type class Selinux < Base def disabled? backend.check_selinux('disabled') end def enforcing? backend.check_selinux('enforcing') end def permissive? backend.check_selinux('permissive') end def to_s 'SELinux' end end end end serverspec-0.14.2/lib/serverspec/type/service.rb000066400000000000000000000016601225742352600216670ustar00rootroot00000000000000module Serverspec module Type class Service < Base def enabled?(level=3) backend.check_enabled(@name, level) end def running?(under=nil) if under check_method = "check_running_under_#{under}".to_sym unless commands.respond_to?(check_method) raise ArgumentError.new("`be_running` matcher doesn't support #{under}") end backend.send(check_method, @name) else backend.check_running(@name) end end def monitored_by?(monitor) check_method = "check_monitored_by_#{monitor}".to_sym unless monitor && commands.respond_to?(check_method) raise ArgumentError.new("`be_monitored_by` matcher doesn't support #{monitor}") end backend.send(check_method, @name) end def has_property?(property) backend.check_svcprops(@name, property) end end end end serverspec-0.14.2/lib/serverspec/type/user.rb000066400000000000000000000011161225742352600212010ustar00rootroot00000000000000module Serverspec module Type class User < Base def exists? backend.check_user(@name) end def belongs_to_group?(group) backend.check_belonging_group(@name, group) end def has_uid?(uid) backend.check_uid(@name, uid) end def has_home_directory?(path) backend.check_home_directory(@name, path) end def has_login_shell?(shell) backend.check_login_shell(@name, shell) end def has_authorized_key?(key) backend.check_authorized_key(@name, key) end end end end serverspec-0.14.2/lib/serverspec/type/windows_registry_key.rb000066400000000000000000000012131225742352600245130ustar00rootroot00000000000000module Serverspec module Type class WindowsRegistryKey < Base def exists? backend.check_registry_key(@name) end def has_property?(property_name, property_type = :type_string) backend.check_registry_key(@name, {:name => property_name, :type => property_type}) end def has_value?(value) backend.check_registry_key(@name, {:name => '', :type => :type_string, :value => value}) end def has_property_value?(property_name, property_type, value) backend.check_registry_key(@name, {:name => property_name, :type => property_type, :value => value}) end end end end serverspec-0.14.2/lib/serverspec/type/yumrepo.rb000066400000000000000000000003271225742352600217260ustar00rootroot00000000000000module Serverspec module Type class Yumrepo < Base def exists? backend.check_yumrepo(@name) end def enabled? backend.check_yumrepo_enabled(@name) end end end end serverspec-0.14.2/lib/serverspec/type/zfs.rb000066400000000000000000000004041225742352600210240ustar00rootroot00000000000000module Serverspec module Type class Zfs < Base def exists? backend.check_zfs(@name) end def has_property?(property) backend.check_zfs(@name, property) end def to_s 'ZFS' end end end end serverspec-0.14.2/lib/serverspec/version.rb000066400000000000000000000000531225742352600207260ustar00rootroot00000000000000module Serverspec VERSION = "0.14.2" end serverspec-0.14.2/serverspec.gemspec000066400000000000000000000021571225742352600175220ustar00rootroot00000000000000# 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 or anything else} spec.summary = %q{RSpec tests for your servers configured by Puppet, Chef 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 "net-ssh" spec.add_runtime_dependency "rspec", ">= 2.13.0" spec.add_runtime_dependency "highline" spec.add_runtime_dependency "specinfra", ">= 0.1.0" spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake" end serverspec-0.14.2/spec/000077500000000000000000000000001225742352600147215ustar00rootroot00000000000000serverspec-0.14.2/spec/aix/000077500000000000000000000000001225742352600155025ustar00rootroot00000000000000serverspec-0.14.2/spec/aix/command_spec.rb000066400000000000000000000036161225742352600204650ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::AIX describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "md5sum /etc/services | grep -iw -- \\^35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 -w 1 -c 2" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt 127.0.0.1 22 -w 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu 127.0.0.1 53 -w 1" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/aix/package_spec.rb000066400000000000000000000055651225742352600204470ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::AIX describe package('httpd') do it { should be_installed } its(:command) { should eq "lslpp -L httpd" } end describe package('invalid-package') do it { should_not be_installed } end package('invalid-package') do it { should_not be_installed.by('rpm') } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } its(:command) { should eq "lslpp -L httpd | awk '{print $2}' | grep -w -- 2.2.15-28.el6" } end describe package('httpd') do it { should_not be_installed.with_version('invalid-version') } end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } end serverspec-0.14.2/spec/aix/php_config_spec.rb000066400000000000000000000020661225742352600211610ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::AIX describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/aix/port_spec.rb000066400000000000000000000013371225742352600200310ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::AIX describe port(80) do it { should be_listening } its(:command) { should eq "netstat -an -f inet | awk '{print $4}' | grep -- *.80 " } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq 'netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ ' } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq 'netstat -tunl | grep -- \\^udp\\ .\\*:123\\ ' } 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-0.14.2/spec/aix/process_spec.rb000066400000000000000000000014721225742352600205230ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::AIX describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } its(:command) { should eq "ps -C memcached -o pid= | head -1" } 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/ } its(:command) { should eq "ps -C memcached -o args= | head -1" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end end serverspec-0.14.2/spec/aix/routing_table_spec.rb000066400000000000000000000056101225742352600217010ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::AIX describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/aix/service_spec.rb000066400000000000000000000044211225742352600205020ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::AIX describe service('sshd') do it { should be_enabled } its(:command) { should eq "lssrc -s sshd | grep active" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } its(:command) { should eq "lssrc -s sshd | grep active" } end describe service('invalid-service') do it { should_not be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } its(:command) { should eq "ps -ef | grep -v grep | grep sshd" } end describe service('invalid-daemon') do it { should_not 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/aix/user_spec.rb000066400000000000000000000042271225742352600200240ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::AIX describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "lsuser -a groups root | awk -F'=' '{print $2}'| sed -e 's/,/ /g' |grep -w -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "lsuser -a shell root |awk -F'=' '{print $2}' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "lsuser -a home root | awk -F'=' '{print $2}' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/backend/000077500000000000000000000000001225742352600163105ustar00rootroot00000000000000serverspec-0.14.2/spec/backend/cmd/000077500000000000000000000000001225742352600170535ustar00rootroot00000000000000serverspec-0.14.2/spec/backend/cmd/configuration_spec.rb000066400000000000000000000003141225742352600232570ustar00rootroot00000000000000require 'spec_helper' require 'support/powershell_command_runner' include SpecInfra::Helper::Cmd include SpecInfra::Helper::Windows describe "Cmd" do it_behaves_like "a powershell command runner" end serverspec-0.14.2/spec/backend/exec/000077500000000000000000000000001225742352600172345ustar00rootroot00000000000000serverspec-0.14.2/spec/backend/exec/build_command_spec.rb000066400000000000000000000022621225742352600233720ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Exec describe 'build command with path' do before :each do RSpec.configure do |c| c.path = '/sbin:/usr/sbin' end end context 'command pattern 1' do subject { backend.build_command('test -f /etc/passwd') } it { should eq 'env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' } end context 'command pattern 2' do subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') } it { should eq 'env PATH=/sbin:/usr/sbin:$PATH test ! -f /etc/selinux/config || (env PATH=/sbin:/usr/sbin:$PATH getenforce | grep -i -- disabled && env PATH=/sbin:/usr/sbin:$PATH grep -i -- ^SELINUX=disabled$ /etc/selinux/config)' } end context 'command pattern 3' do subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") } it { should eq "env PATH=/sbin:/usr/sbin:$PATH dpkg -s apache2 && ! env PATH=/sbin:/usr/sbin:$PATH dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" } end after :each do RSpec.configure do |c| c.path = nil end end end serverspec-0.14.2/spec/backend/exec/configuration_spec.rb000066400000000000000000000040021225742352600234360ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat include SpecInfra::Helper::Exec describe 'configurations are not set' do context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'test -f /etc/passwd' } end end describe 'path is set' do let(:path) { '/sbin:/usr/sbin' } context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' } end end describe 'path is reset to nil' do context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'test -f /etc/passwd' } end end describe 'pre_command is set' do let(:pre_command) { 'source ~/.zshrc' } context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'source ~/.zshrc && test -f /etc/passwd' } end end describe 'path and pre_command are set' do let(:path) { '/sbin:/usr/sbin' } let(:pre_command) { 'source ~/.zshrc' } context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'env PATH=/sbin:/usr/sbin:$PATH source ~/.zshrc && env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' } end end describe 'path is set for check_selinux' do let(:path) { '/sbin:/usr/sbin' } context selinux do it { should be_disabled } its(:command) { should eq "env PATH=/sbin:/usr/sbin:$PATH test ! -f /etc/selinux/config || (env PATH=/sbin:/usr/sbin:$PATH getenforce | grep -i -- disabled && env PATH=/sbin:/usr/sbin:$PATH grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" } end context selinux do it { should be_enforcing } its(:command) { should eq "env PATH=/sbin:/usr/sbin:$PATH getenforce | grep -i -- enforcing && env PATH=/sbin:/usr/sbin:$PATH grep -i -- ^SELINUX=enforcing$ /etc/selinux/config" } end context selinux do it { should be_permissive } its(:command) { should eq "env PATH=/sbin:/usr/sbin:$PATH getenforce | grep -i -- permissive && env PATH=/sbin:/usr/sbin:$PATH grep -i -- ^SELINUX=permissive$ /etc/selinux/config" } end end serverspec-0.14.2/spec/backend/powershell/000077500000000000000000000000001225742352600204745ustar00rootroot00000000000000serverspec-0.14.2/spec/backend/powershell/script_helper_spec.rb000066400000000000000000000043261225742352600247030ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Backend::PowerShell::ScriptHelper describe 'build command with path' do before :each do RSpec.configure do |c| c.path = 'c:/test/path/bin' end end it "should prefix the command with the path instruction" do cmd = build_command('run_script -f param') cmd.should eq <<-eof $env:path = "c:/test/path/bin;$env:path" run_script -f param eof end after :each do RSpec.configure do |c| c.path = nil end end end describe 'add pre-command' do before :each do SpecInfra.configuration.pre_command = 'test_pre_command' end it "should add the test for pre_command before the command" do cmd = add_pre_command('run_script -f param') cmd.should eq <<-eof if (test_pre_command) { run_script -f param } eof end context "with path" do before :each do RSpec.configure do |c| c.path = 'c:/test/path/bin' end end it "should add the path instruction and the test for pre_command before the command" do cmd = add_pre_command('run_script -f param') cmd.should eq <<-eof $env:path = "c:/test/path/bin;$env:path" if (test_pre_command) { run_script -f param } eof end after :each do RSpec.configure do |c| c.path = nil end end end after :each do SpecInfra.configuration.pre_command = nil end end describe "script encoding" do it "should encode the given script" do script = encode_script("test_powershell_script") script.should == "dABlAHMAdABfAHAAbwB3AGUAcgBzAGgAZQBsAGwAXwBzAGMAcgBpAHAAdAA=" end end describe 'script creation' do context "powershell command" do File.should_receive(:read).with(/test_function1.ps1/).and_return 'function test1' command = Backend::PowerShell::Command.new do using 'test_function1.ps1' exec 'test command' end script = create_script command script.should == <<-eof $exitCode = 1 try { function test1 $success = (test command) if ($success -is [Boolean] -and $success) { $exitCode = 0 } } catch { Write-Output $_.Exception.Message } Write-Output "Exiting with code: $exitCode" exit $exitCode eof end context 'simple command' do create_script('test command').should == 'test command' end end serverspec-0.14.2/spec/backend/ssh/000077500000000000000000000000001225742352600171055ustar00rootroot00000000000000serverspec-0.14.2/spec/backend/ssh/configuration_spec.rb000066400000000000000000000120331225742352600233120ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat include SpecInfra::Helper::Ssh ssh = double describe 'configurations are not set' do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'root' } } c.ssh = ssh end end context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'test -f /etc/passwd' } end end describe 'path is set' do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'root' } } c.ssh = ssh end end let(:path) { '/sbin:/usr/sbin' } context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' } end end describe 'pre_command is set and user is root' do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'root' } } c.ssh = ssh end end let(:pre_command) { 'source ~/.zshrc' } context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'source ~/.zshrc && test -f /etc/passwd' } end end describe 'pre_command is set and user is non-root' do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end let(:pre_command) { 'source ~/.zshrc' } context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'sudo source ~/.zshrc && sudo test -f /etc/passwd' } end end describe 'pre_command is not set and user is non-root' do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'sudo test -f /etc/passwd' } end end describe 'path pre_command and set and user is non-root' do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end let(:path) { '/sbin:/usr/sbin' } let(:pre_command) { 'source ~/.zshrc' } context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'sudo env PATH=/sbin:/usr/sbin:$PATH source ~/.zshrc && sudo env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' } end end describe 'path pre_command and set and user is non-root' do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'root' } } c.ssh = ssh end end let(:path) { '/sbin:/usr/sbin' } let(:pre_command) { 'source ~/.zshrc' } context file('/etc/passwd') do it { should be_file } its(:command) { should eq 'env PATH=/sbin:/usr/sbin:$PATH source ~/.zshrc && env PATH=/sbin:/usr/sbin:$PATH test -f /etc/passwd' } end end describe 'user is non-root for check_selinux' do context selinux do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end it { should be_disabled } its(:command) { should eq "sudo test ! -f /etc/selinux/config || (sudo getenforce | grep -i -- disabled && sudo grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" } end context selinux do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end it { should be_enforcing } its(:command) { should eq "sudo getenforce | grep -i -- enforcing && sudo grep -i -- ^SELINUX=enforcing$ /etc/selinux/config" } end context selinux do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end it { should be_permissive } its(:command) { should eq "sudo getenforce | grep -i -- permissive && sudo grep -i -- ^SELINUX=permissive$ /etc/selinux/config" } end end describe 'path is set and user is non-root for check_selinux' do let(:path) { "/sbin:/usr/sbin" } context selinux do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end it { should be_disabled } its(:command) { should eq "sudo env PATH=/sbin:/usr/sbin:$PATH test ! -f /etc/selinux/config || (sudo env PATH=/sbin:/usr/sbin:$PATH getenforce | grep -i -- disabled && sudo env PATH=/sbin:/usr/sbin:$PATH grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" } end context selinux do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end it { should be_enforcing } its(:command) { should eq "sudo env PATH=/sbin:/usr/sbin:$PATH getenforce | grep -i -- enforcing && sudo env PATH=/sbin:/usr/sbin:$PATH grep -i -- ^SELINUX=enforcing$ /etc/selinux/config" } end context selinux do before :all do RSpec.configure do |c| ssh.stub(:options) { { :user => 'foo' } } c.ssh = ssh end end it { should be_permissive } its(:command) { should eq "sudo env PATH=/sbin:/usr/sbin:$PATH getenforce | grep -i -- permissive && sudo env PATH=/sbin:/usr/sbin:$PATH grep -i -- ^SELINUX=permissive$ /etc/selinux/config" } end end serverspec-0.14.2/spec/backend/winrm/000077500000000000000000000000001225742352600174445ustar00rootroot00000000000000serverspec-0.14.2/spec/backend/winrm/configuration_spec.rb000066400000000000000000000003201225742352600236450ustar00rootroot00000000000000require 'spec_helper' require 'support/powershell_command_runner' include SpecInfra::Helper::WinRM include SpecInfra::Helper::Windows describe "WinRM" do it_behaves_like "a powershell command runner" end serverspec-0.14.2/spec/darwin/000077500000000000000000000000001225742352600162055ustar00rootroot00000000000000serverspec-0.14.2/spec/darwin/command_spec.rb000066400000000000000000000036211225742352600211640ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "openssl md5 /etc/services | cut -d'=' -f2 | cut -c 2- | grep -E ^35435ea447c19f0ea5ef971837ab9ced$" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "openssl sha256 /etc/services | cut -d'=' -f2 | cut -c 2- | grep -E ^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a$" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 -w 1 -c 2" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt 127.0.0.1 22 -w 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu 127.0.0.1 53 -w 1" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/darwin/mail_alias_spec.rb000066400000000000000000000004661225742352600216450ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/darwin/package_spec.rb000066400000000000000000000045211225742352600211410ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } end serverspec-0.14.2/spec/darwin/php_config_spec.rb000066400000000000000000000020711225742352600216600ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/darwin/port_spec.rb000066400000000000000000000013111225742352600205240ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin describe port(80) do it { should be_listening } its(:command) { should eq 'netstat -tunl | grep -- :80\\ ' } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq 'netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ ' } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq 'netstat -tunl | grep -- \\^udp\\ .\\*:123\\ ' } 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-0.14.2/spec/darwin/process_spec.rb000066400000000000000000000014751225742352600212310ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } its(:command) { should eq "ps -C memcached -o pid= | head -1" } 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/ } its(:command) { should eq "ps -C memcached -o args= | head -1" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end end serverspec-0.14.2/spec/darwin/routing_table_spec.rb000066400000000000000000000056131225742352600224070ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/darwin/service_spec.rb000066400000000000000000000042321225742352600212050ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin #describe service('sshd') do # it { should be_enabled } #end #describe service('invalid-service') do # it { should_not be_enabled } #end #describe service('sshd') do # it { should be_enabled.with_level(3) } #end #describe service('invalid-service') do # it { should_not be_enabled.with_level(3) } #end describe service('sshd') do it { should be_running } its(:command) { should eq "service sshd status" } end describe service('invalid-daemon') do it { should_not 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/darwin/user_spec.rb000066400000000000000000000041411225742352600205220ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Darwin describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id root | awk '{print $3}' | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/debian/000077500000000000000000000000001225742352600161435ustar00rootroot00000000000000serverspec-0.14.2/spec/debian/cgroup_spec.rb000066400000000000000000000005231225742352600210010ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should eq 1 } its(:command) { should eq "cgget -n -r cpuset.cpus group1 | awk '{print $2}'" } end describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should_not eq 0 } end serverspec-0.14.2/spec/debian/command_spec.rb000066400000000000000000000036211225742352600211220ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "md5sum /etc/services | grep -iw -- \\^35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 -w 1 -c 2" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt 127.0.0.1 22 -w 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu 127.0.0.1 53 -w 1" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/debian/interface_spec.rb000066400000000000000000000013331225742352600214420ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe interface('eth0') do let(:stdout) { '1000' } its(:speed) { should eq 1000 } its(:command) { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10") } its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/'" } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10/24") } its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/24 '" } end describe interface('invalid-interface') do let(:stdout) { '1000' } its(:speed) { should_not eq 100 } end serverspec-0.14.2/spec/debian/iptables_spec.rb000066400000000000000000000011141225742352600213020ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe iptables do it { should have_rule '-P INPUT ACCEPT' } its(:command) { should eq "iptables -S | grep -- -P\\ INPUT\\ ACCEPT" } end describe iptables do it { should_not have_rule 'invalid-rule' } end describe iptables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } its(:command) { should eq "iptables -t mangle -S INPUT | grep -- -P\\ INPUT\\ ACCEPT" } end describe iptables do it { should_not have_rule('invalid-rule').with_table('mangle').with_chain('INPUT') } end serverspec-0.14.2/spec/debian/kernel_module_spec.rb000066400000000000000000000003701225742352600223270ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe kernel_module('lp') do it { should be_loaded } its(:command) { should eq "lsmod | grep ^lp" } end describe kernel_module('invalid-module') do it { should_not be_loaded } end serverspec-0.14.2/spec/debian/linux_kernel_parameter_spec.rb000066400000000000000000000021661225742352600242460ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do let(:stdout) { "1\n" } its(:value) { should eq 1 } its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_syncookies" } 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" } its(:command) { should eq "/sbin/sysctl -q -n kernel.osrelease" } 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/ } its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_wmem" } end describe linux_kernel_parameter('net.ipv4.tcp_wmem') do let(:stdout) { "4096 16384 4194304\n" } its(:value) { should_not match /123456/ } end serverspec-0.14.2/spec/debian/lxc_spec.rb000066400000000000000000000006301225742352600202670ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe lxc('ct01') do it { should exist } its(:command) { should eq "lxc-ls -1 | grep -w ct01" } end describe lxc('invalid-ct') do it { should_not exist } end describe lxc('ct01') do it { should be_running } its(:command) { should eq "lxc-info -n ct01 -t RUNNING"} end describe lxc('invalid-ct') do it { should_not be_running } end serverspec-0.14.2/spec/debian/mail_alias_spec.rb000066400000000000000000000004661225742352600216030ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/debian/package_spec.rb000066400000000000000000000076161225742352600211070ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe package('apache2') do it { should be_installed } its(:command) { should eq "dpkg-query -f '${Status}' -W apache2 | grep '^install ok installed$'" } end describe package('invalid-package') do it { should_not be_installed } end describe package('apache2') do it { should be_installed.with_version('1.1.1') } its(:command) { should eq "dpkg-query -f '${Status} ${Version}' -W apache2 | grep -E '^install ok installed 1.1.1$'" } end describe package('invalid-package') do it { should_not be_installed.with_version('invalid-version') } end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } 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(:command) { should eq "dpkg-query -f '${Status} ${Version}' -W httpd | sed -n 's/^install ok installed //p'" } end # Debian-style versions describe package('httpd') do let(:stdout) { "2.2.15-3\n" } its(:version) { should eq '2.2.15-3' } its(:version) { should > '2.2.15' } its(:version) { should < '2.2.16' } its(:version) { should < '2.2.15-4' } its(:version) { should > '2.2.15-3~bpo70+1' } end # With some epoch describe package('httpd') do let(:stdout) { "3:2.2.15-3~git20120918+ae4569bc\n" } its(:version) { should eq '3:2.2.15-3~git20120918+ae4569bc' } its(:version) { should > '3:2.2.15-3~git20120912+ae4569bc' } its(:version) { should < '3:2.2.15-3' } its(:version) { should < '3:2.2.15-3+feature1' } its(:version) { should < '4:1.2.15' } its(:version) { should > '2:4.2.15' } its(:version) { should > '14.2.15' } end serverspec-0.14.2/spec/debian/php_config_spec.rb000066400000000000000000000020711225742352600216160ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/debian/port_spec.rb000066400000000000000000000017561225742352600204770ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe port(80) do it { should be_listening } its(:command) { should eq 'netstat -tunl | grep -- :80\\ ' } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq 'netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ ' } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq 'netstat -tunl | grep -- \\^udp\\ .\\*:123\\ ' } end describe port(81) do it { should be_listening.with("tcp6") } its(:command) { should eq 'netstat -tunl | grep -- \\^tcp6\\ .\\*:81\\ ' } end describe port(1234) do it { should be_listening.with("udp6") } its(:command) { should eq 'netstat -tunl | grep -- \\^udp6\\ .\\*:1234\\ ' } 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-0.14.2/spec/debian/process_spec.rb000066400000000000000000000014751225742352600211670ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } its(:command) { should eq "ps -C memcached -o pid= | head -1" } 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/ } its(:command) { should eq "ps -C memcached -o args= | head -1" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end end serverspec-0.14.2/spec/debian/routing_table_spec.rb000066400000000000000000000056131225742352600223450ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/debian/selinux_spec.rb000066400000000000000000000011461225742352600211730ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe selinux do it { should be_enforcing } its(:command) { should eq "getenforce | grep -i -- enforcing && grep -i -- ^SELINUX=enforcing$ /etc/selinux/config" } end describe selinux do it { should be_permissive } its(:command) { should eq "getenforce | grep -i -- permissive && grep -i -- ^SELINUX=permissive$ /etc/selinux/config" } end describe selinux do it { should be_disabled } its(:command) { should eq "test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" } end serverspec-0.14.2/spec/debian/service_spec.rb000066400000000000000000000045441225742352600211510ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe service('sshd') do it { should be_enabled } its(:command) { should eq "ls /etc/rc3.d/ | grep -- '^S..sshd' || grep 'start on' /etc/init/sshd.conf" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } its(:command) { should eq "ls /etc/rc4.d/ | grep -- '^S..sshd' || grep 'start on' /etc/init/sshd.conf" } end describe service('invalid-service') do it { should_not be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } its(:command) { should eq "service sshd status" } end describe service('invalid-daemon') do it { should_not 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/debian/user_spec.rb000066400000000000000000000041411225742352600204600ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id root | awk '{print $3}' | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/debian/zfs_spec.rb000066400000000000000000000011101225742352600202750ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Debian describe zfs('rpool') do it { should exist } its(:command) { should eq "zfs list -H rpool" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } its(:command) { should eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } its(:command) { should eq "zfs list -H -o compression rpool | grep -- \\^off\\$ && zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end serverspec-0.14.2/spec/freebsd/000077500000000000000000000000001225742352600163335ustar00rootroot00000000000000serverspec-0.14.2/spec/freebsd/command_spec.rb000066400000000000000000000036221225742352600213130ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::FreeBSD describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "md5sum /etc/services | grep -iw -- \\^35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 -w 1 -c 2" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt 127.0.0.1 22 -w 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu 127.0.0.1 53 -w 1" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/freebsd/package_spec.rb000066400000000000000000000052401225742352600212660ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::FreeBSD describe package('httpd') do it { should be_installed } its(:command) { should eq "pkg_info -Ix httpd" } end describe package('invalid-package') do it { should_not be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } its(:command) { should eq "pkg_info -Ix httpd"} end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } end serverspec-0.14.2/spec/freebsd/php_config_spec.rb000066400000000000000000000020721225742352600220070ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::FreeBSD describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/freebsd/port_spec.rb000066400000000000000000000013201225742352600206520ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::FreeBSD describe port(80) do it { should be_listening } its(:command) { should eq 'sockstat -46l -p 80 | grep -- :80\\ ' } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq 'netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ ' } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq 'netstat -tunl | grep -- \\^udp\\ .\\*:123\\ ' } 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-0.14.2/spec/freebsd/process_spec.rb000066400000000000000000000014761225742352600213600ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::FreeBSD describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } its(:command) { should eq "ps -C memcached -o pid= | head -1" } 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/ } its(:command) { should eq "ps -C memcached -o args= | head -1" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end end serverspec-0.14.2/spec/freebsd/routing_table_spec.rb000066400000000000000000000056141225742352600225360ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::FreeBSD describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/freebsd/service_spec.rb000066400000000000000000000044031225742352600213330ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::FreeBSD describe service('sshd') do it { should be_enabled } its(:command) { should eq "service -e | grep -- sshd" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } its(:command) { should eq "service -e | grep -- sshd" } end describe service('invalid-service') do it { should_not be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } its(:command) { should eq "service sshd status" } end describe service('invalid-daemon') do it { should_not 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/freebsd/user_spec.rb000066400000000000000000000041421225742352600206510ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::FreeBSD describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id root | awk '{print $3}' | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/gentoo/000077500000000000000000000000001225742352600162145ustar00rootroot00000000000000serverspec-0.14.2/spec/gentoo/cgroup_spec.rb000066400000000000000000000005231225742352600210520ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should eq 1 } its(:command) { should eq "cgget -n -r cpuset.cpus group1 | awk '{print $2}'" } end describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should_not eq 0 } end serverspec-0.14.2/spec/gentoo/command_spec.rb000066400000000000000000000036211225742352600211730ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "md5sum /etc/services | grep -iw -- \\^35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 -w 1 -c 2" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt 127.0.0.1 22 -w 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu 127.0.0.1 53 -w 1" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/gentoo/interface_spec.rb000066400000000000000000000013331225742352600215130ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe interface('eth0') do let(:stdout) { '1000' } its(:speed) { should eq 1000 } its(:command) { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10") } its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/'" } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10/24") } its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/24 '" } end describe interface('invalid-interface') do let(:stdout) { '1000' } its(:speed) { should_not eq 100 } end serverspec-0.14.2/spec/gentoo/iptables_spec.rb000066400000000000000000000011141225742352600213530ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe iptables do it { should have_rule '-P INPUT ACCEPT' } its(:command) { should eq "iptables -S | grep -- -P\\ INPUT\\ ACCEPT" } end describe iptables do it { should_not have_rule 'invalid-rule' } end describe iptables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } its(:command) { should eq "iptables -t mangle -S INPUT | grep -- -P\\ INPUT\\ ACCEPT" } end describe iptables do it { should_not have_rule('invalid-rule').with_table('mangle').with_chain('INPUT') } end serverspec-0.14.2/spec/gentoo/kernel_module_spec.rb000066400000000000000000000003701225742352600224000ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe kernel_module('lp') do it { should be_loaded } its(:command) { should eq "lsmod | grep ^lp" } end describe kernel_module('invalid-module') do it { should_not be_loaded } end serverspec-0.14.2/spec/gentoo/linux_kernel_parameter_spec.rb000066400000000000000000000021661225742352600243170ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do let(:stdout) { "1\n" } its(:value) { should eq 1 } its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_syncookies" } 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" } its(:command) { should eq "/sbin/sysctl -q -n kernel.osrelease" } 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/ } its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_wmem" } end describe linux_kernel_parameter('net.ipv4.tcp_wmem') do let(:stdout) { "4096 16384 4194304\n" } its(:value) { should_not match /123456/ } end serverspec-0.14.2/spec/gentoo/lxc_spec.rb000066400000000000000000000006301225742352600203400ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe lxc('ct01') do it { should exist } its(:command) { should eq "lxc-ls -1 | grep -w ct01" } end describe lxc('invalid-ct') do it { should_not exist } end describe lxc('ct01') do it { should be_running } its(:command) { should eq "lxc-info -n ct01 -t RUNNING"} end describe lxc('invalid-ct') do it { should_not be_running } end serverspec-0.14.2/spec/gentoo/mail_alias_spec.rb000066400000000000000000000004661225742352600216540ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/gentoo/package_spec.rb000066400000000000000000000050251225742352600211500ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe package('apache') do it { should be_installed } its(:command) { should eq "eix apache --installed" } end describe package('invalid-package') do it { should_not be_installed } end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } end serverspec-0.14.2/spec/gentoo/php_config_spec.rb000066400000000000000000000020711225742352600216670ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/gentoo/port_spec.rb000066400000000000000000000013111225742352600205330ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe port(80) do it { should be_listening } its(:command) { should eq 'netstat -tunl | grep -- :80\\ ' } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq 'netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ ' } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq 'netstat -tunl | grep -- \\^udp\\ .\\*:123\\ ' } 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-0.14.2/spec/gentoo/process_spec.rb000066400000000000000000000014751225742352600212400ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } its(:command) { should eq "ps -C memcached -o pid= | head -1" } 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/ } its(:command) { should eq "ps -C memcached -o args= | head -1" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end end serverspec-0.14.2/spec/gentoo/routing_table_spec.rb000066400000000000000000000056131225742352600224160ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/gentoo/selinux_spec.rb000066400000000000000000000011461225742352600212440ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe selinux do it { should be_enforcing } its(:command) { should eq "getenforce | grep -i -- enforcing && grep -i -- ^SELINUX=enforcing$ /etc/selinux/config" } end describe selinux do it { should be_permissive } its(:command) { should eq "getenforce | grep -i -- permissive && grep -i -- ^SELINUX=permissive$ /etc/selinux/config" } end describe selinux do it { should be_disabled } its(:command) { should eq "test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" } end serverspec-0.14.2/spec/gentoo/service_spec.rb000066400000000000000000000046121225742352600212160ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe service('sshd') do it { should be_enabled } its(:command) { should eq "rc-update show | grep -- \\^\\\\s\\*sshd\\\\s\\*\\|\\\\s\\*\\\\\\(boot\\\\\\|default\\\\\\)" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } its(:command) { should eq "rc-update show | grep -- \\^\\\\s\\*sshd\\\\s\\*\\|\\\\s\\*\\\\\\(boot\\\\\\|default\\\\\\)" } end describe service('invalid-service') do it { should_not be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } its(:command) { should eq "/etc/init.d/sshd status" } end describe service('invalid-daemon') do it { should_not 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/gentoo/user_spec.rb000066400000000000000000000041411225742352600205310ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id root | awk '{print $3}' | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/gentoo/zfs_spec.rb000066400000000000000000000011101225742352600203460ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Gentoo describe zfs('rpool') do it { should exist } its(:command) { should eq "zfs list -H rpool" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } its(:command) { should eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } its(:command) { should eq "zfs list -H -o compression rpool | grep -- \\^off\\$ && zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end serverspec-0.14.2/spec/helper/000077500000000000000000000000001225742352600162005ustar00rootroot00000000000000serverspec-0.14.2/spec/helper/properties_spec.rb000066400000000000000000000003341225742352600217330ustar00rootroot00000000000000require 'spec_helper' include Serverspec::Helper::Properties describe 'Properties Helper' do before :all do set_property :role => 'proxy' end subject { property } it { should include :role => 'proxy' } end serverspec-0.14.2/spec/plamo/000077500000000000000000000000001225742352600160315ustar00rootroot00000000000000serverspec-0.14.2/spec/plamo/cgroup_spec.rb000066400000000000000000000005221225742352600206660ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should eq 1 } its(:command) { should eq "cgget -n -r cpuset.cpus group1 | awk '{print $2}'" } end describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should_not eq 0 } end serverspec-0.14.2/spec/plamo/command_spec.rb000066400000000000000000000036201225742352600210070ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "md5sum /etc/services | grep -iw -- \\^35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 -w 1 -c 2" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt 127.0.0.1 22 -w 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu 127.0.0.1 53 -w 1" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/plamo/interface_spec.rb000066400000000000000000000013321225742352600213270ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe interface('eth0') do let(:stdout) { '1000' } its(:speed) { should eq 1000 } its(:command) { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10") } its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/'" } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10/24") } its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/24 '" } end describe interface('invalid-interface') do let(:stdout) { '1000' } its(:speed) { should_not eq 100 } end serverspec-0.14.2/spec/plamo/iptables_spec.rb000066400000000000000000000011131225742352600211670ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe iptables do it { should have_rule '-P INPUT ACCEPT' } its(:command) { should eq "iptables -S | grep -- -P\\ INPUT\\ ACCEPT" } end describe iptables do it { should_not have_rule 'invalid-rule' } end describe iptables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } its(:command) { should eq "iptables -t mangle -S INPUT | grep -- -P\\ INPUT\\ ACCEPT" } end describe iptables do it { should_not have_rule('invalid-rule').with_table('mangle').with_chain('INPUT') } end serverspec-0.14.2/spec/plamo/kernel_module_spec.rb000066400000000000000000000003671225742352600222230ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe kernel_module('lp') do it { should be_loaded } its(:command) { should eq "lsmod | grep ^lp" } end describe kernel_module('invalid-module') do it { should_not be_loaded } end serverspec-0.14.2/spec/plamo/linux_kernel_parameter_spec.rb000066400000000000000000000021651225742352600241330ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do let(:stdout) { "1\n" } its(:value) { should eq 1 } its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_syncookies" } 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" } its(:command) { should eq "/sbin/sysctl -q -n kernel.osrelease" } 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/ } its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_wmem" } end describe linux_kernel_parameter('net.ipv4.tcp_wmem') do let(:stdout) { "4096 16384 4194304\n" } its(:value) { should_not match /123456/ } end serverspec-0.14.2/spec/plamo/lxc_spec.rb000066400000000000000000000006271225742352600201630ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe lxc('ct01') do it { should exist } its(:command) { should eq "lxc-ls -1 | grep -w ct01" } end describe lxc('invalid-ct') do it { should_not exist } end describe lxc('ct01') do it { should be_running } its(:command) { should eq "lxc-info -n ct01 -t RUNNING"} end describe lxc('invalid-ct') do it { should_not be_running } end serverspec-0.14.2/spec/plamo/mail_alias_spec.rb000066400000000000000000000004651225742352600214700ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/plamo/package_spec.rb000066400000000000000000000055261225742352600207730ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe package('httpd') do it { should be_installed } its(:command) { should eq "ls /var/log/packages/httpd" } end describe package('invalid-package') do it { should_not be_installed } end describe package('httpd') do it { should be_installed.with_version('1.1.1') } its(:command) { should eq "ls /var/log/packages/httpd && grep -E \"PACKAGE NAME:.+httpd-1.1.1\" /var/log/packages/httpd" } end describe package('invalid-package') do it { should_not be_installed.with_version('invalid-version') } end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } end serverspec-0.14.2/spec/plamo/php_config_spec.rb000066400000000000000000000020701225742352600215030ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/plamo/port_spec.rb000066400000000000000000000013101225742352600203470ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe port(80) do it { should be_listening } its(:command) { should eq 'netstat -tunl | grep -- :80\\ ' } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq 'netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ ' } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq 'netstat -tunl | grep -- \\^udp\\ .\\*:123\\ ' } 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-0.14.2/spec/plamo/routing_table_spec.rb000066400000000000000000000056121225742352600222320ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/plamo/selinux_spec.rb000066400000000000000000000011451225742352600210600ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe selinux do it { should be_enforcing } its(:command) { should eq "getenforce | grep -i -- enforcing && grep -i -- ^SELINUX=enforcing$ /etc/selinux/config" } end describe selinux do it { should be_permissive } its(:command) { should eq "getenforce | grep -i -- permissive && grep -i -- ^SELINUX=permissive$ /etc/selinux/config" } end describe selinux do it { should be_disabled } its(:command) { should eq "test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" } end serverspec-0.14.2/spec/plamo/service_spec.rb000066400000000000000000000041171225742352600210330ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe service('sshd') do it { should be_enabled } its(:command) { should eq "test -x /etc/rc.d/init.d/sshd" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } its(:command) { should eq "test -x /etc/rc.d/init.d/sshd" } end describe service('invalid-service') do it { should_not be_enabled.with_level(4) } 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/plamo/user_spec.rb000066400000000000000000000041401225742352600203450ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id root | awk '{print $3}' | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/plamo/zfs_spec.rb000066400000000000000000000011071225742352600201710ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Plamo describe zfs('rpool') do it { should exist } its(:command) { should eq "zfs list -H rpool" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } its(:command) { should eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } its(:command) { should eq "zfs list -H -o compression rpool | grep -- \\^off\\$ && zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end serverspec-0.14.2/spec/redhat/000077500000000000000000000000001225742352600161705ustar00rootroot00000000000000serverspec-0.14.2/spec/redhat/cgroup_spec.rb000066400000000000000000000005231225742352600210260ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should eq 1 } its(:command) { should eq "cgget -n -r cpuset.cpus group1 | awk '{print $2}'" } end describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should_not eq 0 } end serverspec-0.14.2/spec/redhat/command_spec.rb000066400000000000000000000036351225742352600211540ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat =begin describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end =end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "md5sum /etc/services | grep -iw -- \\^35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 -w 1 -c 2" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt 127.0.0.1 22 -w 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu 127.0.0.1 53 -w 1" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/redhat/interface_spec.rb000066400000000000000000000013331225742352600214670ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe interface('eth0') do let(:stdout) { '1000' } its(:speed) { should eq 1000 } its(:command) { should eq "ethtool eth0 | grep Speed | gawk '{print gensub(/Speed: ([0-9]+)Mb\\/s/,\"\\\\1\",\"\")}'" } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10") } its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/'" } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10/24") } its(:command) { should eq "ip addr show eth0 | grep 'inet 192\\.168\\.10\\.10/24 '" } end describe interface('invalid-interface') do let(:stdout) { '1000' } its(:speed) { should_not eq 100 } end serverspec-0.14.2/spec/redhat/iptables_spec.rb000066400000000000000000000011141225742352600213270ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe iptables do it { should have_rule '-P INPUT ACCEPT' } its(:command) { should eq "iptables -S | grep -- -P\\ INPUT\\ ACCEPT" } end describe iptables do it { should_not have_rule 'invalid-rule' } end describe iptables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } its(:command) { should eq "iptables -t mangle -S INPUT | grep -- -P\\ INPUT\\ ACCEPT" } end describe iptables do it { should_not have_rule('invalid-rule').with_table('mangle').with_chain('INPUT') } end serverspec-0.14.2/spec/redhat/kernel_module_spec.rb000066400000000000000000000003701225742352600223540ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe kernel_module('lp') do it { should be_loaded } its(:command) { should eq "lsmod | grep ^lp" } end describe kernel_module('invalid-module') do it { should_not be_loaded } end serverspec-0.14.2/spec/redhat/linux_kernel_parameter_spec.rb000066400000000000000000000021661225742352600242730ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do let(:stdout) { "1\n" } its(:value) { should eq 1 } its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_syncookies" } 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" } its(:command) { should eq "/sbin/sysctl -q -n kernel.osrelease" } 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/ } its(:command) { should eq "/sbin/sysctl -q -n net.ipv4.tcp_wmem" } end describe linux_kernel_parameter('net.ipv4.tcp_wmem') do let(:stdout) { "4096 16384 4194304\n" } its(:value) { should_not match /123456/ } end serverspec-0.14.2/spec/redhat/lxc_spec.rb000066400000000000000000000006301225742352600203140ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe lxc('ct01') do it { should exist } its(:command) { should eq "lxc-ls -1 | grep -w ct01" } end describe lxc('invalid-ct') do it { should_not exist } end describe lxc('ct01') do it { should be_running } its(:command) { should eq "lxc-info -n ct01 -t RUNNING"} end describe lxc('invalid-ct') do it { should_not be_running } end serverspec-0.14.2/spec/redhat/mail_alias_spec.rb000066400000000000000000000004661225742352600216300ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/redhat/package_spec.rb000066400000000000000000000064671225742352600211370ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe package('httpd') do it { should be_installed } its(:command) { should eq "rpm -q httpd" } end describe package('invalid-package') do it { should_not be_installed } end package('invalid-package') do it { should_not be_installed.by('rpm') } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } its(:command) { should eq "rpm -q httpd | grep -w -- 2.2.15-28.el6" } end describe package('httpd') do it { should be_installed.by('rpm').with_version('2.2.15-28.el6') } its(:command) { should eq "rpm -q httpd | grep -w -- 2.2.15-28.el6" } end describe package('httpd') do it { should_not be_installed.with_version('invalid-version') } end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } 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' } its(:command) { should eq "rpm -qi httpd | grep Version | awk '{print $3}'" } end serverspec-0.14.2/spec/redhat/php_config_spec.rb000066400000000000000000000020711225742352600216430ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/redhat/port_spec.rb000066400000000000000000000013111225742352600205070ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe port(80) do it { should be_listening } its(:command) { should eq 'netstat -tunl | grep -- :80\\ ' } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq 'netstat -tunl | grep -- \\^tcp\\ .\\*:80\\ ' } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq 'netstat -tunl | grep -- \\^udp\\ .\\*:123\\ ' } 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-0.14.2/spec/redhat/process_spec.rb000066400000000000000000000014751225742352600212140ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } its(:command) { should eq "ps -C memcached -o pid= | head -1" } 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/ } its(:command) { should eq "ps -C memcached -o args= | head -1" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end end serverspec-0.14.2/spec/redhat/routing_table_spec.rb000066400000000000000000000056131225742352600223720ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/redhat/selinux_spec.rb000066400000000000000000000011461225742352600212200ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe selinux do it { should be_enforcing } its(:command) { should eq "getenforce | grep -i -- enforcing && grep -i -- ^SELINUX=enforcing$ /etc/selinux/config" } end describe selinux do it { should be_permissive } its(:command) { should eq "getenforce | grep -i -- permissive && grep -i -- ^SELINUX=permissive$ /etc/selinux/config" } end describe selinux do it { should be_disabled } its(:command) { should eq "test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" } end serverspec-0.14.2/spec/redhat/service_spec.rb000066400000000000000000000044221225742352600211710ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe service('sshd') do it { should be_enabled } its(:command) { should eq "chkconfig --list sshd | grep 3:on" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } its(:command) { should eq "chkconfig --list sshd | grep 4:on" } end describe service('invalid-service') do it { should_not be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } its(:command) { should eq "service sshd status" } end describe service('invalid-daemon') do it { should_not 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/redhat/user_spec.rb000066400000000000000000000041411225742352600205050ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id root | awk '{print $3}' | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/redhat/yumrepo_spec.rb000066400000000000000000000007601225742352600212320ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe 'Serverspec yumrepo matchers of Red Hat family' do describe 'exist' do describe yumrepo('epel') do it { should exist } end describe yumrepo('invalid-repository') do it { should_not exist } end end describe 'be_enabled' do describe yumrepo('epel') do it { should be_enabled } end describe yumrepo('invalid-repository') do it { should_not be_enabled } end end end serverspec-0.14.2/spec/redhat/zfs_spec.rb000066400000000000000000000011101225742352600203220ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::RedHat describe zfs('rpool') do it { should exist } its(:command) { should eq "zfs list -H rpool" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } its(:command) { should eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } its(:command) { should eq "zfs list -H -o compression rpool | grep -- \\^off\\$ && zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end serverspec-0.14.2/spec/smartos/000077500000000000000000000000001225742352600164115ustar00rootroot00000000000000serverspec-0.14.2/spec/smartos/mail_alias_spec.rb000066400000000000000000000004671225742352600220520ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::SmartOS describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/smartos/process_spec.rb000066400000000000000000000014761225742352600214360ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::SmartOS describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } its(:command) { should eq "ps -C memcached -o pid= | head -1" } 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/ } its(:command) { should eq "ps -C memcached -o args= | head -1" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end end serverspec-0.14.2/spec/solaris/000077500000000000000000000000001225742352600163755ustar00rootroot00000000000000serverspec-0.14.2/spec/solaris/command_spec.rb000066400000000000000000000036221225742352600213550ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "md5sum /etc/services | grep -iw -- \\^35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt -w 1 127.0.0.1 22" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu -w 1 127.0.0.1 53" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/solaris/ipfilter_spec.rb000066400000000000000000000003571225742352600215570ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe ipfilter do it { should have_rule 'pass in quick on lo0 all' } its(:command) { should eq "ipfstat -io 2> /dev/null | grep -- pass\\ in\\ quick\\ on\\ lo0\\ all" } end serverspec-0.14.2/spec/solaris/ipnat_spec.rb000066400000000000000000000004111225742352600210430ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe ipnat do it { should have_rule 'map net1 192.168.0.0/24 -> 0.0.0.0/32' } its(:command) { should eq "ipnat -l 2> /dev/null | grep -- \\^map\\ net1\\ 192.168.0.0/24\\ -\\>\\ 0.0.0.0/32\\$" } end serverspec-0.14.2/spec/solaris/mail_alias_spec.rb000066400000000000000000000004671225742352600220360ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/solaris/package_spec.rb000066400000000000000000000054441225742352600213360ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe package('httpd') do it { should be_installed } its(:command) { should eq "pkg list -H httpd 2> /dev/null" } end describe package('invalid-package') do it { should_not be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2') } its(:command) { should eq "pkg list -H httpd 2> /dev/null | grep -qw -- 2.2" } end describe package('httpd') do it { should_not be_installed.with_version('invalid-version') } end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } end serverspec-0.14.2/spec/solaris/php_config_spec.rb000066400000000000000000000020721225742352600220510ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/solaris/port_spec.rb000066400000000000000000000014541225742352600207240ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe port(80) do it { should be_listening } its(:command) { should eq %q!netstat -an 2> /dev/null | grep -- LISTEN | grep -- \\\\.80\\ ! } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq %q!netstat -an -P tcp 2> /dev/null | grep -- LISTEN | grep -- .\\*\\\\.80\\ ! } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq %q!netstat -an -P udp 2> /dev/null | grep -- LISTEN | grep -- .\\*\\\\.123\\ ! } 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-0.14.2/spec/solaris/process_spec.rb000066400000000000000000000014761225742352600214220ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } its(:command) { should eq "ps -C memcached -o pid= | head -1" } 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/ } its(:command) { should eq "ps -C memcached -o args= | head -1" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } its(:command) { should eq "ps -C memcached -o pid= | head -1" } end end serverspec-0.14.2/spec/solaris/routing_table_spec.rb000066400000000000000000000056141225742352600226000ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/solaris/service_spec.rb000066400000000000000000000045361225742352600214040ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe service('sshd') do it { should be_enabled } its(:command) { should eq "svcs -l sshd 2> /dev/null | egrep '^enabled *true$'" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } its(:command) { should eq "svcs -l sshd 2> /dev/null | egrep '^enabled *true$'" } end describe service('invalid-service') do it { should_not be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } its(:command) { should eq "svcs -l sshd status 2> /dev/null | egrep '^state *online$'" } end describe service('invalid-daemon') do it { should_not 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/solaris/svcprop_spec.rb000066400000000000000000000011621225742352600214300ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe service('svc:/network/http:apache22') do it { should have_property 'httpd/enable_64bit' => false } its(:command) { should eq "svcprop -p httpd/enable_64bit svc:/network/http:apache22 | grep -- \\^false\\$" } end describe service('svc:/network/http:apache22') do it { should have_property 'httpd/enable_64bit' => false, 'httpd/server_type' => 'worker' } its(:command) { should eq "svcprop -p httpd/enable_64bit svc:/network/http:apache22 | grep -- \\^false\\$ && svcprop -p httpd/server_type svc:/network/http:apache22 | grep -- \\^worker\\$" } end serverspec-0.14.2/spec/solaris/user_spec.rb000066400000000000000000000041231225742352600207120ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id -Gn root | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/solaris/zfs_spec.rb000066400000000000000000000011111225742352600205300ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris describe zfs('rpool') do it { should exist } its(:command) { should eq "zfs list -H rpool" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } its(:command) { should eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } its(:command) { should eq "zfs list -H -o compression rpool | grep -- \\^off\\$ && zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end serverspec-0.14.2/spec/solaris10/000077500000000000000000000000001225742352600165365ustar00rootroot00000000000000serverspec-0.14.2/spec/solaris10/file_spec.rb000077500000000000000000000255601225742352600210270ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris10 describe file('/etc/ssh/sshd_config') do it { should be_file } its(:command) { should eq "test -f /etc/ssh/sshd_config" } end describe file('/etc/invalid_file') do it { should_not be_file } end describe file('/etc/ssh') do it { should be_directory } its(:command) { should eq "test -d /etc/ssh" } end describe file('/etc/invalid_directory') do it { should_not be_directory } end describe file('/var/run/unicorn.sock') do it { should be_socket } its(:command) { should eq "test -S /var/run/unicorn.sock" } end describe file('/etc/invalid_socket') do it { should_not be_socket } end describe file('/etc/ssh/sshd_config') do it { should contain 'This is the sshd server system-wide configuration file' } its(:command) { should eq "grep -- This\\ is\\ the\\ sshd\\ server\\ system-wide\\ configuration\\ file /etc/ssh/sshd_config" } end describe file('/etc/ssh/sshd_config') do it { should contain /^This is the sshd server system-wide configuration file/ } its(:command) { should eq "grep -- \\^This\\ is\\ the\\ sshd\\ server\\ system-wide\\ configuration\\ file /etc/ssh/sshd_config" } end describe file('/etc/ssh/sshd_config') do it { should_not contain 'This is invalid text!!' } end describe file('Gemfile') do it { should contain('rspec').from(/^group :test do/).to(/^end/) } its(:command) { should eq "sed -n /\\^group\\ :test\\ do/,/\\^end/p Gemfile | grep -q -- rspec /dev/stdin || sed -n /\\^group\\ :test\\ do/,/\\^end/p Gemfile | grep -qF -- rspec /dev/stdin" } end describe file('/etc/ssh/sshd_config') do it { should_not contain('This is invalid text!!').from(/^group :test do/).to(/^end/) } end describe file('Gemfile') do it { should contain('rspec').after(/^group :test do/) } its(:command) { should eq "sed -n /\\^group\\ :test\\ do/,\\$p Gemfile | grep -q -- rspec /dev/stdin || sed -n /\\^group\\ :test\\ do/,\\$p Gemfile | grep -qF -- rspec /dev/stdin" } end describe file('/etc/ssh/sshd_config') do it { should_not contain('This is invalid text!!').after(/^group :test do/) } end describe file('Gemfile') do it { should contain('rspec').before(/^end/) } its(:command) { should eq "sed -n 1,/\\^end/p Gemfile | grep -q -- rspec /dev/stdin || sed -n 1,/\\^end/p Gemfile | grep -qF -- rspec /dev/stdin" } end describe file('/etc/ssh/sshd_config') do it { should_not contain('This is invalid text!!').before(/^end/) } end describe file('/etc/passwd') do it { should be_mode 644 } its(:command) { should eq "perl -e 'printf \"%o\", (stat shift)[2]&07777' /etc/passwd | grep -- \\^644\\$" } end describe file('/etc/passwd') do it { should_not be_mode 'invalid' } end describe file('/etc/passwd') do it { should be_owned_by 'root' } its(:command) { should eq "perl -e 'printf \"%s\", getpwuid((stat(\"/etc/passwd\"))[4])' | grep -- \\^root\\$" } end describe file('/etc/passwd') do it { should_not be_owned_by 'invalid-owner' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } its(:command) { should eq "perl -e 'printf \"%s\", getgrgid((stat(\"/etc/passwd\"))[5])' | grep -- \\^root\\$" } end describe file('/etc/passwd') do it { should_not be_grouped_into 'invalid-group' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } its(:command) { should eq "perl -e 'printf \"%s\", readlink(\"/etc/pam.d/system-auth\")' | grep -- \\^/etc/pam.d/system-auth-ac\\$" } end describe file('dummy-link') do it { should_not be_linked_to '/invalid/target' } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_readable } its(:command) { should eq "perl -e 'printf \"%o\", (stat shift)[2]&07777' /dev" } 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('/tmp') do it { should be_readable.by_user('mail') } its(:command) { should eq "su mail -c \"test -r /tmp\"" } end describe file('/tmp') do it { should_not be_readable.by_user('invalid-user') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_writable } its(:command) { should eq "perl -e 'printf \"%o\", (stat shift)[2]&07777' /dev" } 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('/tmp') do it { should be_writable.by_user('mail') } its(:command) { should eq "su mail -c \"test -w /tmp\"" } end describe file('/tmp') do it { should_not be_writable.by_user('invalid-user') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_executable } its(:command) { should eq "perl -e 'printf \"%o\", (stat shift)[2]&07777' /dev" } 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('/tmp') do it { should be_executable.by_user('mail') } its(:command) { should eq "su mail -c \"test -x /tmp\"" } end describe file('/tmp') do it { should_not be_executable.by_user('invalid-user') } end describe file('/') do it { should be_mounted } its(:command) { should eq "mount | grep -w -- on\\ /" } end describe file('/etc/invalid-mount') do it { should_not 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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "digest -a md5 -v /etc/services | grep -iw -- 35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end serverspec-0.14.2/spec/solaris10/group_spec.rb000077500000000000000000000007271225742352600212420ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris10 describe group('root') do it { should exist } its(:command) { should eq "getent group | grep -w -- root" } end describe group('invalid-group') do it { should_not exist } end describe group('root') do it { should have_gid 0 } its(:command) { should eq "getent group | grep -- \\^root: | cut -f 3 -d ':' | grep -w -- 0" } end describe group('root') do it { should_not have_gid 'invalid-gid' } end serverspec-0.14.2/spec/solaris10/mail_alias_spec.rb000066400000000000000000000004711225742352600221720ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris10 describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/solaris10/package_spec.rb000077500000000000000000000044141225742352600214760ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris10 describe package('httpd') do it { should be_installed } its(:command) { should eq "pkginfo -q httpd" } end describe package('invalid-package') do it { should_not be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2') } its(:command) { should eq "pkginfo -q httpd | grep -- 2.2" } end describe package('httpd') do it { should_not be_installed.with_version('invalid-version') } end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end serverspec-0.14.2/spec/solaris10/php_config_spec.rb000066400000000000000000000020741225742352600222140ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris10 describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/solaris10/user_spec.rb000077500000000000000000000041221225742352600210550ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris10 describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id -ap root | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/solaris11/000077500000000000000000000000001225742352600165375ustar00rootroot00000000000000serverspec-0.14.2/spec/solaris11/command_spec.rb000066400000000000000000000036241225742352600215210ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } it { should return_stdout("nameserver 127.0.0.1") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/127\.0\.0\.1/) } end end describe command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'cat /etc/resolv.conf' } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('cat /etc/resolv.conf') do it { should return_exit_status 0 } its(:command) { should eq 'cat /etc/resolv.conf' } end describe command('ls -al /') do let(:stdout) { < '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('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not 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 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 it { should match_md5checksum '35435ea447c19f0ea5ef971837ab9ced' } its(:command) { should eq "md5sum /etc/services | grep -iw -- \\^35435ea447c19f0ea5ef971837ab9ced" } end describe file('invalid-file') do it { should_not match_md5checksum 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do it { should match_sha256checksum '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } its(:command) { should eq "sha256sum /etc/services | grep -iw -- \\^0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } end describe file('invalid-file') do it { should_not match_sha256checksum 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) {< "icmp", :timeout=> 1) } its(:command) { should eq "ping -n 127.0.0.1 1" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } its(:command) { should eq "nc -vvvvzt -w 1 127.0.0.1 22" } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } its(:command) { should eq "nc -vvvvzu -w 1 127.0.0.1 53" } end describe host('invalid-host') do it { should_not be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end serverspec-0.14.2/spec/solaris11/ipfilter_spec.rb000066400000000000000000000003611225742352600217140ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe ipfilter do it { should have_rule 'pass in quick on lo0 all' } its(:command) { should eq "ipfstat -io 2> /dev/null | grep -- pass\\ in\\ quick\\ on\\ lo0\\ all" } end serverspec-0.14.2/spec/solaris11/ipnat_spec.rb000066400000000000000000000004131225742352600212070ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe ipnat do it { should have_rule 'map net1 192.168.0.0/24 -> 0.0.0.0/32' } its(:command) { should eq "ipnat -l 2> /dev/null | grep -- \\^map\\ net1\\ 192.168.0.0/24\\ -\\>\\ 0.0.0.0/32\\$" } end serverspec-0.14.2/spec/solaris11/mail_alias_spec.rb000066400000000000000000000004711225742352600221730ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe mail_alias('daemon') do it { should be_aliased_to "root" } its(:command) { should eq "getent aliases daemon | grep -- \\[\\[:space:\\]\\]root$" } end describe mail_alias('invalid-recipient') do it { should_not be_aliased_to "foo" } end serverspec-0.14.2/spec/solaris11/package_spec.rb000066400000000000000000000054461225742352600215020ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe package('httpd') do it { should be_installed } its(:command) { should eq "pkg list -H httpd 2> /dev/null" } end describe package('invalid-package') do it { should_not be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2') } its(:command) { should eq "pkg list -H httpd 2> /dev/null | grep -qw -- 2.2" } end describe package('httpd') do it { should_not be_installed.with_version('invalid-version') } end describe package('jekyll') do it { should be_installed.by('gem') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll" } end describe package('invalid-gem') do it { should_not be_installed.by('gem') } end describe package('jekyll') do it { should be_installed.by('gem').with_version('1.1.1') } its(:command) { should eq "gem list --local | grep -w -- \\^jekyll | grep -w -- 1.1.1" } end describe package('jekyll') do it { should_not be_installed.by('gem').with_version('invalid-version') } end describe package('bower') do it { should be_installed.by('npm') } its(:command) { should eq "npm ls bower -g" } end describe package('invalid-npm-package') do it { should_not be_installed.by('npm') } end describe package('bower') do it { should be_installed.by('npm').with_version('0.9.2') } its(:command) { should eq "npm ls bower -g | grep -w -- 0.9.2" } end describe package('bower') do it { should_not be_installed.by('npm').with_version('invalid-version') } end describe package('mongo') do it { should be_installed.by('pecl') } its(:command) { should eq "pecl list | grep -w -- \\^mongo" } end describe package('invalid-pecl') do it { should_not be_installed.by('pecl') } end describe package('mongo') do it { should be_installed.by('pecl').with_version('1.4.1') } its(:command) { should eq "pecl list | grep -w -- \\^mongo | grep -w -- 1.4.1" } end describe package('mongo') do it { should_not be_installed.by('pecl').with_version('invalid-version') } end describe package('XML_Util') do it { should be_installed.by('pear').with_version('1.2.1') } its(:command) { should eq "pear list | grep -w -- \\^XML_Util | grep -w -- 1.2.1" } end describe package('supervisor') do it { should be_installed.by('pip').with_version('3.0') } its(:command) { should eq "pip list | grep -w -- \\^supervisor | grep -w -- 3.0" } end describe package('invalid-pip') do it { should_not be_installed.by('pip').with_version('invalid-version') } end describe package('App::Ack') do it { should be_installed.by('cpan') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack" } end describe package('App::Ack') do it { should be_installed.by('cpan').with_version('2.04') } its(:command) { should eq "cpan -l | grep -w -- \\^App::Ack | grep -w -- 2.04" } end serverspec-0.14.2/spec/solaris11/php_config_spec.rb000066400000000000000000000020741225742352600222150ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } its(:command) { should eq "php -r 'echo get_cfg_var( \"default_mimetype\" );'" } 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 } its(:command) { should eq "php -r 'echo get_cfg_var( \"session.cache_expire\" );'" } 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/ } its(:command) { should eq "php -r 'echo get_cfg_var( \"mbstring.http_output_conv_mimetypes\" );'" } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end serverspec-0.14.2/spec/solaris11/port_spec.rb000066400000000000000000000004261225742352600210640ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe port(80) do it { should be_listening } its(:command) { should eq %q!netstat -an 2> /dev/null | grep -- LISTEN | grep -- \\\\.80\\ ! } end describe port('invalid') do it { should_not be_listening } end serverspec-0.14.2/spec/solaris11/routing_table_spec.rb000066400000000000000000000056161225742352600227440ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should_not have_entry( :destination => '192.168.100.100/24' ) } its(:command) { should eq "ip route | grep -E '^192.168.100.100/24 |^default '" } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1' ) end it do should have_entry( :destination => '192.168.100.0/24', :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :gateway => '192.168.100.1', :interface => 'eth1' ) end it do should_not have_entry( :destination => '192.168.100.0/32', :gateway => '192.168.100.1', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\ndefault via 192.168.100.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it { should_not have_entry( :destination => '192.168.200.200/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 it do should_not have_entry( :gateway => '192.168.200.1', :interface => 'eth0' ) end it do should_not have_entry( :destination => '192.168.200.0/32', :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 { should_not have_entry( :destination => 'defaulth' ) } 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 it do should_not have_entry( :gateway => '10.0.2.2', :interface => 'eth0' ) end it do should_not have_entry( :destination => 'default', :gateway => '10.0.2.1', :interface => 'eth0' ) end end serverspec-0.14.2/spec/solaris11/service_spec.rb000066400000000000000000000045401225742352600215410ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe service('sshd') do it { should be_enabled } its(:command) { should eq "svcs -l sshd 2> /dev/null | egrep '^enabled *true$'" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } its(:command) { should eq "svcs -l sshd 2> /dev/null | egrep '^enabled *true$'" } end describe service('invalid-service') do it { should_not be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } its(:command) { should eq "svcs -l sshd status 2> /dev/null | egrep '^state *online$'" } end describe service('invalid-daemon') do it { should_not 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') } its(:command) { should eq "supervisorctl status sshd | grep RUNNING" } end describe service('invalid-daemon') do it { should_not be_running.under('supervisor') } end describe service('sshd') do it { should be_running.under('upstart') } its(:command) { should eq "initctl status sshd | grep running" } end describe service('invalid-daemon') do it { should_not be_running.under('upstart') } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by('monit') } its(:command) { should eq "monit status" } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status not monitored\r\n monitoring status not monitored" } it { should_not be_monitored_by('monit') } end describe service('invalid-daemon') do it { should_not be_monitored_by('monit') } end describe service('unicorn') do it { should be_monitored_by('god') } its(:command) { should eq "god status unicorn" } end describe service('invalid-daemon') do it { should_not be_monitored_by('god') } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(ArgumentError, %r/\A`be_monitored_by` matcher doesn\'t support/) } end serverspec-0.14.2/spec/solaris11/svcprop_spec.rb000066400000000000000000000011641225742352600215740ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe service('svc:/network/http:apache22') do it { should have_property 'httpd/enable_64bit' => false } its(:command) { should eq "svcprop -p httpd/enable_64bit svc:/network/http:apache22 | grep -- \\^false\\$" } end describe service('svc:/network/http:apache22') do it { should have_property 'httpd/enable_64bit' => false, 'httpd/server_type' => 'worker' } its(:command) { should eq "svcprop -p httpd/enable_64bit svc:/network/http:apache22 | grep -- \\^false\\$ && svcprop -p httpd/server_type svc:/network/http:apache22 | grep -- \\^worker\\$" } end serverspec-0.14.2/spec/solaris11/user_spec.rb000066400000000000000000000041251225742352600210560ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe user('root') do it { should exist } its(:command) { should eq "id root" } end describe user('invalid-user') do it { should_not exist } end describe user('root') do it { should belong_to_group 'root' } its(:command) { should eq "id -Gn root | grep -- root" } end describe user('root') do it { should_not belong_to_group 'invalid-group' } end describe user('root') do it { should have_uid 0 } its(:command) { should eq "id root | grep -- \\^uid\\=0\\(" } end describe user('root') do it { should_not have_uid 'invalid-uid' } end describe user('root') do it { should have_login_shell '/bin/bash' } its(:command) { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" } end describe user('root') do it { should_not have_login_shell 'invalid-login-shell' } end describe user('root') do it { should have_home_directory '/root' } its(:command) { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" } end describe user('root') do it { should_not have_home_directory 'invalid-home-directory' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } its(:command) { should eq "grep -w -- ssh-rsa\\ ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH ~root/.ssh/authorized_keys" } end describe user('root') do it { should_not have_authorized_key 'invalid-key' } end serverspec-0.14.2/spec/solaris11/zfs_spec.rb000066400000000000000000000011131225742352600206740ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Solaris11 describe zfs('rpool') do it { should exist } its(:command) { should eq "zfs list -H rpool" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } its(:command) { should eq "zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } its(:command) { should eq "zfs list -H -o compression rpool | grep -- \\^off\\$ && zfs list -H -o mountpoint rpool | grep -- \\^/rpool\\$" } end serverspec-0.14.2/spec/spec_helper.rb000066400000000000000000000025331225742352600175420ustar00rootroot00000000000000require 'serverspec' require 'pathname' require 'rspec/mocks/standalone' include SpecInfra::Helper::Exec PROJECT_ROOT = (Pathname.new(File.dirname(__FILE__)) + '..').expand_path Dir[PROJECT_ROOT.join("spec/support/**/*.rb")].each { |file| require(file) } module SpecInfra module Backend module TestCommandRunner def do_run cmd if @example @example.metadata[:subject].set_command(cmd) end if cmd =~ /invalid/ { :stdout => ::SpecInfra.configuration.stdout, :stderr => ::SpecInfra.configuration.stderr, :exit_status => 1, :exit_signal => nil } else { :stdout => ::SpecInfra.configuration.stdout, :stderr => ::SpecInfra.configuration.stderr, :exit_status => 0, :exit_signal => nil } end end end [Exec, Ssh, Cmd, WinRM].each do |clz| clz.class_eval do include TestCommandRunner def run_command(cmd) cmd = build_command(cmd.to_s) cmd = add_pre_command(cmd) do_run cmd end end end end end module Serverspec module Type class Base def set_command(command) @command = command end def command @command end end end end serverspec-0.14.2/spec/support/000077500000000000000000000000001225742352600164355ustar00rootroot00000000000000serverspec-0.14.2/spec/support/powershell_command_runner.rb000066400000000000000000000025741225742352600242450ustar00rootroot00000000000000shared_examples "a powershell command runner" do describe 'configurations are not set' do context file('/some/file') do it { should be_file } its(:command) { should == "((Get-Item -Path '/some/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive'" } end end describe 'path is set' do let(:path) { 'c:/path/bin' } context file('/some/file') do it { should be_file } its(:command) { should == <<-eof $env:path = "c:/path/bin;$env:path" ((Get-Item -Path '/some/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive' eof } end end describe 'pre_command is set' do let(:pre_command) { 'some_other_command' } context file('/some/file') do it { should be_file } its(:command) { should == <<-eof if (some_other_command) { ((Get-Item -Path '/some/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive' } eof } end end describe 'path and pre_command are set' do let(:path) { 'c:/path/bin' } let(:pre_command) { 'some_other_command' } context file('/some/file') do it { should be_file } its(:command) { should == <<-eof $env:path = "c:/path/bin;$env:path" if (some_other_command) { $env:path = "c:/path/bin;$env:path" ((Get-Item -Path '/some/file' -Force).attributes.ToString() -Split ', ') -contains 'Archive' } eof } end end endserverspec-0.14.2/spec/windows/000077500000000000000000000000001225742352600164135ustar00rootroot00000000000000serverspec-0.14.2/spec/windows/command_spec.rb000066400000000000000000000040271225742352600213730ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Cmd include SpecInfra::Helper::Windows describe command('test_cmd /test/path/file') do let(:stdout) { "test output 1.2.3\r\n" } it { should return_stdout("test output 1.2.3") } its(:command) { should eq 'test_cmd /test/path/file' } end describe 'complete matching of stdout' do context command('test_cmd /test/path/file') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } it { should_not return_stdout('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" } it { should return_stdout(/1\.2\.3/) } end end describe command('test_cmd /test/path/file') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr("No such file or directory") } its(:command) { should eq 'test_cmd /test/path/file' } end describe 'complete matching of stderr' do context command('test_cmd /test/path/file') do let(:stdout) { "No such file or directory\r\n" } it { should_not return_stdout('file') } end end describe 'regexp matching of stderr' do context command('test_cmd /test/path/file') do let(:stdout) { "No such file or directory\r\n" } it { should return_stderr(/file/) } end end describe command('test_cmd /test/path/file') do it { should return_exit_status 0 } its(:command) { should eq 'test_cmd /test/path/file' } end describe command('dir "c:\"') do let(:stdout) { < [], :be_mode => 644, :be_owned_by => 'root', :be_grouped_into => 'root', :be_linked_to => '/some/other/file', :be_mounted => [], :match_md5checksum => '35435ea447c19f0ea5ef971837ab9ced', :match_sha256checksum => '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' }.each do |method, args| expect { should self.send(method, *args) }.to raise_error SpecInfra::Command::Windows::NotSupportedError end end end serverspec-0.14.2/spec/windows/group_spec.rb000066400000000000000000000013501225742352600211050ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Cmd include SpecInfra::Helper::Windows describe group('test.group') do it { should exist } its(:command) { should eq "(FindGroup -groupName 'test.group') -ne $null" } end describe group('test.domain\test.group') do it { should exist } its(:command) { should eq "(FindGroup -groupName 'test.group' -domain 'test.domain') -ne $null" } end describe group('invalid-group') do it { should_not 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 SpecInfra::Command::Windows::NotSupportedError end end end serverspec-0.14.2/spec/windows/port_spec.rb000066400000000000000000000013571225742352600207440ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Cmd include SpecInfra::Helper::Windows describe port(80) do it { should be_listening } its(:command) { should eq 'IsPortListening -portNumber 80' } end describe port('invalid') do it { should_not be_listening } end describe port(80) do it { should be_listening.with("tcp") } its(:command) { should eq "IsPortListening -portNumber 80 -protocol 'tcp'" } end describe port(123) do it { should be_listening.with("udp") } its(:command) { should eq "IsPortListening -portNumber 123 -protocol '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-0.14.2/spec/windows/service_spec.rb000066400000000000000000000015521225742352600214150ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Cmd include SpecInfra::Helper::Windows describe service('Test Service') do it { should be_enabled } its(:command) { should eq "(FindService -name 'Test Service').StartMode -eq 'Auto'" } end describe service('invalid-service') do it { should_not be_enabled } end describe service('Test Service') do it { should be_running } its(:command) { should eq "(FindService -name 'Test Service').State -eq 'Running'" } end describe service('invalid-daemon') do it { should_not be_running } 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 end it "should raise error if trying to check service monitoring" do expect { should_not be_monitored_by('monit') }.to raise_error end end serverspec-0.14.2/spec/windows/user_spec.rb000066400000000000000000000025131225742352600207310ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Cmd include SpecInfra::Helper::Windows describe user('test.user') do it { should exist } its(:command) { should eq "(FindUser -userName 'test.user') -ne $null" } end describe user('test.domain\test.user') do it { should exist } its(:command) { should eq "(FindUser -userName 'test.user' -domain 'test.domain') -ne $null" } end describe user('invalid-user') do it { should_not exist } end describe user('test.user') do it { should belong_to_group 'test.group' } its(:command) { should eq "(FindUserGroup -userName 'test.user' -groupName 'test.group') -ne $null" } end describe user('test.user.domain\test.user') do it { should belong_to_group 'test.group.domain\test.group' } its(:command) { should eq "(FindUserGroup -userName 'test.user' -userDomain 'test.user.domain' -groupName 'test.group' -groupDomain 'test.group.domain') -ne $null" } end describe user('test.user') do it { should_not belong_to_group 'invalid-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 SpecInfra::Command::Windows::NotSupportedError end end end serverspec-0.14.2/spec/windows/windows_registry_key_spec.rb000066400000000000000000000046571225742352600242600ustar00rootroot00000000000000require 'spec_helper' include SpecInfra::Helper::Cmd include SpecInfra::Helper::Windows describe windows_registry_key('PATH/TO/THE_KEY') do it { should exist } its(:command) { should == "(Get-Item 'Registry::PATH/TO/THE_KEY') -ne $null" } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_value('Test Value') } its(:command) { should == "(Compare-Object (Get-Item 'Registry::PATH/TO/THE_KEY').GetValue('') @('Test Value')) -eq $null" } end describe 'Key value types' do context 'default type' do describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property('TestProperty') } its(:command) { should == "(Get-Item 'Registry::PATH/TO/THE_KEY').GetValueKind('TestProperty') -eq 'String'" } 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) } its(:command) { should == "(Get-Item 'Registry::PATH/TO/THE_KEY').GetValueKind('TestProperty') -eq '#{type}'" } end end end end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_binary, '12a07b') } its(:command) { should == "(Compare-Object (Get-Item 'Registry::PATH/TO/THE_KEY').GetValue('TestProperty') ([byte[]] 18,160,123)) -eq $null" } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_dword, 'fffffd6c') } its(:command) { should == "(Compare-Object (Get-Item 'Registry::PATH/TO/THE_KEY').GetValue('TestProperty') -660) -eq $null" } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_qword, '1e240') } its(:command) { should == "(Compare-Object (Get-Item 'Registry::PATH/TO/THE_KEY').GetValue('TestProperty') 123456) -eq $null" } 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) } its(:command) { should == "(Compare-Object (Get-Item 'Registry::PATH/TO/THE_KEY').GetValue('TestProperty') @('test line1','test line2','test line3')) -eq $null" } end