pax_global_header00006660000000000000000000000064150025316420014510gustar00rootroot0000000000000052 comment=ed7f83d54024c41fd13f5f915b2afaa7f4bb0fe2 mizzy-serverspec-5c0c869/000077500000000000000000000000001500253164200154145ustar00rootroot00000000000000mizzy-serverspec-5c0c869/.github/000077500000000000000000000000001500253164200167545ustar00rootroot00000000000000mizzy-serverspec-5c0c869/.github/stale.yml000066400000000000000000000012551500253164200206120ustar00rootroot00000000000000# Number of days of inactivity before an issue becomes stale daysUntilStale: 60 # Number of days of inactivity before a stale issue is closed daysUntilClose: 7 # Issues with these labels will never be considered stale exemptLabels: - pinned - security # Label to use when marking an issue as stale staleLabel: wontfix # Comment to post when marking an issue as stale. Set to `false` to disable markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. # Comment to post when closing a stale issue. Set to `false` to disable closeComment: false mizzy-serverspec-5c0c869/.github/workflows/000077500000000000000000000000001500253164200210115ustar00rootroot00000000000000mizzy-serverspec-5c0c869/.github/workflows/ci.yml000066400000000000000000000012071500253164200221270ustar00rootroot00000000000000--- name: ci on: push: pull_request: types: - opened - synchronize - reopened permissions: {} jobs: ci: runs-on: ubuntu-latest strategy: fail-fast: false matrix: ruby-version: - "2.2" - "2.3" - "2.4" - "2.5" - "2.6" - "2.7" - "3.0" - "3.1" - "3.2" - "3.3" - "3.4" steps: - uses: actions/checkout@v4 with: persist-credentials: false - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - run: bundle exec rake mizzy-serverspec-5c0c869/.gitignore000066400000000000000000000003751500253164200174110ustar00rootroot00000000000000*.gem *.rbc *.swp .bundle .rvmrc .versions.conf .config .yardoc .rspec .idea/ Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp Vagrantfile vendor/ .DS_Store Gemfile.local upstream.sh mizzy-serverspec-5c0c869/.gitmodules000066400000000000000000000001751500253164200175740ustar00rootroot00000000000000[submodule "integration-test"] path = integration-test url = https://github.com/serverspec/serverspec-integration-test.git mizzy-serverspec-5c0c869/.travis.yml000066400000000000000000000010761500253164200175310ustar00rootroot00000000000000language: ruby rvm: - 1.9.3 - 2.0.0 - 2.1.1 - 2.2.4 - 2.3.6 - 2.4.3 - 2.5.0 before_install: - travis_retry gem update --system 2.7.8 - travis_retry gem install bundler -v 1.17.3 - travis_retry gem uninstall -i /home/travis/.rvm/gems/ruby-2.3.7@global bundler || echo script: - bundle exec rake spec dist: trusty sudo: false cache: bundler notifications: slack: secure: X1umGErES0zd+LXX1EqZZxrPZv2YOzbCNxiLLiSGmJLlZAEtlSkMPyr+M00Lrs2DFhn4blwKPm+5YCBvU7f9F4K5GthSl0qZYNpNX/lGNn6EGeBnzJ8rFVgwXPUv1rvrJq0NjeSGni3yAK69K/uX6QohGojAI3iI28/EbJ+uYQM= mizzy-serverspec-5c0c869/Gemfile000066400000000000000000000003621500253164200167100ustar00rootroot00000000000000source 'https://rubygems.org' # Specify your gem's dependencies in serverspec.gemspec gemspec if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0') # net-ssh 3.x dropped Ruby 1.8 and 1.9 support. gem 'net-ssh', '~> 2.7' end mizzy-serverspec-5c0c869/Guardfile000066400000000000000000000001421500253164200172360ustar00rootroot00000000000000guard :rspec do watch(%r{^spec/.+/.+_spec\.rb$}) watch('spec/spec_helper.rb') { "spec" } end mizzy-serverspec-5c0c869/LICENSE.txt000066400000000000000000000020611500253164200172360ustar00rootroot00000000000000Copyright (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. mizzy-serverspec-5c0c869/README.md000066400000000000000000000027471500253164200167050ustar00rootroot00000000000000# Serverspec [![Gem Version](https://badge.fury.io/rb/serverspec.svg)](http://badge.fury.io/rb/serverspec) [![BuildStatus](https://secure.travis-ci.org/mizzy/serverspec.svg)](http://travis-ci.org/mizzy/serverspec) [![wercker status](https://app.wercker.com/status/526d1ff4df6eadaa793dca1affcaed35/s/ "wercker status")](https://app.wercker.com/project/bykey/526d1ff4df6eadaa793dca1affcaed35) RSpec tests for your servers configured by Puppet, Chef or anything else You can see the details of serverspec on [serverspec.org](http://serverspec.org/). ---- ## Running the gem's tests Use ```bundle exec rake``` (Using ```rspec``` alone will not work). ## Maintenance policy of Serverspec/Specinfra * The person who found a bug should fix the bug by themself. * If you find a bug and cannot fix it by yourself, send a pull request and attach test code to reproduce the bug, please. * The person who want a new feature should implement it by themself. * For above reasons, I accept pull requests only and disable issues. * If you'd like to discuss about a new feature before implement it, make an empty commit and send [a WIP pull request](http://ben.straub.cc/2015/04/02/wip-pull-request/). But It is better that the WIP PR has some code than an empty commit. ---- ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request mizzy-serverspec-5c0c869/Rakefile000066400000000000000000000012401500253164200170560ustar00rootroot00000000000000require "bundler/gem_tasks" begin require "rspec/core/rake_task" require "octorelease" rescue LoadError end if defined?(RSpec) task :default => 'spec:all' task :spec => 'spec:all' namespace :spec do task :all => [ 'spec:type:all', 'spec:helper' ] namespace :type do oses = Dir.glob('spec/type/*').map {|d| File.basename(d)} task :all => oses.map {|os| "spec:type:#{os}" } oses.each do |os| RSpec::Core::RakeTask.new(os.to_sym) do |t| t.pattern = "spec/type/#{os}/*_spec.rb" end end end RSpec::Core::RakeTask.new(:helper) do |t| t.pattern = "spec/helper/*_spec.rb" end end end mizzy-serverspec-5c0c869/WINDOWS_SUPPORT.md000066400000000000000000000102361500253164200203260ustar00rootroot00000000000000## Windows support Serverspec is now providing a limited support for Microsoft Windows. If you want to test Windows based machines you need to set the target host's OS explicitly in your `spec/spec_helper.rb` For local testing (equivalent to the Exec option in Linux/Unix systems) simply do: ```ruby require 'serverspec' set :backend, :cmd set :os, :family => 'windows' ``` For remote testing you have to configure Windows Remote Management in order to communicate to the target host: ```ruby require 'serverspec' require 'winrm' set :backend, :winrm set :os, :family => 'windows' user = pass = endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" if Gem::Version.new(WinRM::VERSION) < Gem::Version.new('2') winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true) winrm.set_timeout 300 # 5 minutes max timeout for any operation else opts = { user: user, password: pass, endpoint: endpoint, operation_timeout: 300, no_ssl_peer_verification: false, } winrm = ::WinRM::Connection.new(opts) end Specinfra.configuration.winrm = winrm ``` For how to configure the guest to accept WinRM connections and the different authentication mechanisms check the Microsoft WinRM documentation and verify the ones that are supported by [WinRb/WinRM](https://github.com/WinRb/WinRM). ###RSpec Examples for windows target hosts ```ruby describe file('c:/windows') do it { should be_directory } it { should be_readable } it { should_not be_writable.by('Everyone') } end describe file('c:/temp/test.txt') do it { should be_file } it { should contain "some text" } end describe package('Adobe AIR') do it { should be_installed} end describe service('DNS Client') do it { should be_installed } it { should be_enabled } it { should be_running } it { should have_start_mode("Manual") } end describe port(139) do it { should be_listening } end describe user('some.admin') do it { should exist } it { should belong_to_group('Administrators')} end describe group('Guests') do it { should exist } end describe group('MYDOMAIN\Domain Users') do it { should exist } end describe command('& "ipconfig"') do its(:stdout) { should match /IPv4 Address(\.| )*: 192\.168\.1\.100/ } end describe windows_registry_key('HKEY_USERS\S-1-5-21-1319311448-2088773778-316617838-32407\Test MyKey') do it { should exist } it { should have_property('string value') } it { should have_property('binary value', :type_binary) } it { should have_property('dword value', :type_dword) } it { should have_value('test default data') } it { should have_property_value('multistring value', :type_multistring, "test\nmulti\nstring\ndata") } it { should have_property_value('qword value', :type_qword, 'adff32') } it { should have_property_value('binary value', :type_binary, 'dfa0f066') } end describe windows_feature('Minesweeper') do it{ should be_installed } it{ should be_installed.by("dism") } it{ should be_installed.by("powershell") } end describe iis_website("Default Website") do it { should exist } it { should be_enabled } it { should be_running } it { should be_in_app_pool "DefaultAppPool" } it { should have_physical_path "c:/inetpub/wwwroot" } end describe iis_app_pool("DefaultAppPool") do it { should exist } it { should have_dotnet_version "2.0" } end ``` ###Notes: * Not all the matchers you are used to in Linux-like OS are supported in Windows, some because of differences between the operating systems (e.g. users and permissions model), some because they haven't been yet implemented. * All commands in the windows backend are run via powershell, so the output in case of stderr is a pretty ugly xml-like thing. Still it should contain some information to help troubleshooting. * The *command* type is executed again through powershell, so bear that in mind if you mean to run old CMD windows batch or programs. (i.e run the command using the **Invoke-Expression** Cmdlet, or the **&** Call Operator) * You may have to change Exectution Policy on the machine at both, machine and user level in order for tests to run: Get-ExecutionPolicy -list|%{set-executionpolicy bypass -scope $_.scope} mizzy-serverspec-5c0c869/appveyor.yml000066400000000000000000000044621500253164200200120ustar00rootroot00000000000000version: "{build}" image: Previous Visual Studio 2015 platform: - x64 environment: bundle_gemfile: integration-test/Gemfile.winrm bundler_url: https://rubygems.org/downloads/bundler-1.9.9.gem matrix: - ruby_version: "193" - ruby_version: "200" - ruby_version: "21" - ruby_version: "22" - ruby_version: "23" - ruby_version: "24" - ruby_version: "25" - ruby_version: "26" matrix: allow_failures: - ruby_version: "193" clone_depth: 5 cache: - C:\Ruby193\lib\ruby\gems\1.9.1 -> appveyor.yml - C:\Ruby193\bin -> appveyor.yml - C:\Ruby200\lib\ruby\gems\2.0.0 -> appveyor.yml - C:\Ruby200\bin -> appveyor.yml - C:\Ruby21\lib\ruby\gems\2.1.0 -> appveyor.yml - C:\Ruby21\bin -> appveyor.yml - C:\Ruby22\lib\ruby\gems\2.2.0 -> appveyor.yml - C:\Ruby22\bin -> appveyor.yml - C:\Ruby23\lib\ruby\gems\2.2.0 -> appveyor.yml - C:\Ruby23\bin -> appveyor.yml - C:\Ruby24\lib\ruby\gems\2.4.0 -> appveyor.yml - C:\Ruby24\bin -> appveyor.yml - C:\Ruby25\lib\ruby\gems\2.5.0 -> appveyor.yml - C:\Ruby25\bin -> appveyor.yml - C:\Ruby26\lib\ruby\gems\2.6.0 -> appveyor.yml - C:\Ruby26\bin install: - git submodule update --init --recursive - ps: Enable-PSRemoting -Force - winrm quickconfig -q - winrm set winrm/config/client @{TrustedHosts="*"} - winrm set winrm/config/client/auth @{Basic="true"} - winrm set winrm/config/service/auth @{Basic="true"} - winrm set winrm/config/service @{AllowUnencrypted="true"} - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - echo %PATH% - ruby --version - gem --version - appveyor DownloadFile -Url %bundler_url% -FileName bundler.gem - gem install --local bundler.gem --no-document --force ## appveyor often stops `gem install bundler`..? - ps: $PSVersionTable build_script: - set SSL_CERT_FILE=C:/ruby24-x64/ssl/cert.pem - ruby -rfileutils -e 'FileUtils.rm_r(File.join(Gem.dir, "cache", "bundler")) if Dir.exist?(File.join(Gem.dir, "cache", "bundler"))' - bundle install --jobs 3 --retry 3 - net user - net localgroup test_script: - net user appveyor %WINDOWS_PASSWORD% # set by webui - bundle exec rspec -fd --backtrace -r .\integration-test\winrm\spec_helper.rb .\integration-test\winrm mizzy-serverspec-5c0c869/bin/000077500000000000000000000000001500253164200161645ustar00rootroot00000000000000mizzy-serverspec-5c0c869/bin/serverspec-init000077500000000000000000000002041500253164200212300ustar00rootroot00000000000000#!/usr/bin/env ruby $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) require 'serverspec' Serverspec::Setup.run mizzy-serverspec-5c0c869/integration-test/000077500000000000000000000000001500253164200207145ustar00rootroot00000000000000mizzy-serverspec-5c0c869/lib/000077500000000000000000000000001500253164200161625ustar00rootroot00000000000000mizzy-serverspec-5c0c869/lib/serverspec.rb000066400000000000000000000043141500253164200206720ustar00rootroot00000000000000require 'rubygems' require 'rspec' require 'rspec/its' require 'specinfra' require 'serverspec/version' require 'serverspec/matcher' require 'serverspec/helper' require 'serverspec/setup' require 'serverspec/subject' require 'serverspec/commands/base' require 'rspec/core/formatters/base_formatter' require 'specinfra/helper/set' include Specinfra::Helper::Set module RSpec::Core::Notifications class FailedExampleNotification < ExampleNotification def failure_lines host = ENV['TARGET_HOST'] || Specinfra.configuration.host @failure_lines ||= begin lines = [] lines << "On host `#{host}'" if host lines << "Failure/Error: #{read_failed_line.strip}" lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/ exception.message.to_s.split("\n").each do |line| lines << " #{line}" if exception.message end lines << " #{example.metadata[:command]}" lines << " #{example.metadata[:stdout]}" if example.metadata[:stdout] lines << " #{example.metadata[:stderr]}" if example.metadata[:stderr] lines end end end end # For RSpec 3.3.x if defined?(RSpec::Core::Formatters::ExceptionPresenter) class RSpec::Core::Formatters::ExceptionPresenter def failure_lines host = ENV['TARGET_HOST'] || Specinfra.configuration.host @failure_lines ||= begin lines = [] lines << "On host `#{host}'" if host error_lines = [] error_lines = [failure_slash_error_line] if defined?(failure_slash_error_line) error_lines = failure_slash_error_lines if defined?(failure_slash_error_lines) lines += error_lines unless (description == error_lines.join('')) lines << "#{exception_class_name}:" unless exception_class_name =~ /RSpec/ encoded_string(exception.message.to_s).split("\n").each do |line| lines << " #{line}" end lines << " #{example.metadata[:command]}" lines << " #{example.metadata[:stdout]}" if example.metadata[:stdout] lines << " #{example.metadata[:stderr]}" if example.metadata[:stderr] lines end end end end mizzy-serverspec-5c0c869/lib/serverspec/000077500000000000000000000000001500253164200203435ustar00rootroot00000000000000mizzy-serverspec-5c0c869/lib/serverspec/commands/000077500000000000000000000000001500253164200221445ustar00rootroot00000000000000mizzy-serverspec-5c0c869/lib/serverspec/commands/base.rb000066400000000000000000000001411500253164200233770ustar00rootroot00000000000000module Serverspec module Commands class Base < Specinfra::Command::Base end end end mizzy-serverspec-5c0c869/lib/serverspec/helper.rb000066400000000000000000000003011500253164200221410ustar00rootroot00000000000000# Subject type helper require 'serverspec/helper/type' extend Serverspec::Helper::Type class RSpec::Core::ExampleGroup extend Serverspec::Helper::Type include Serverspec::Helper::Type end mizzy-serverspec-5c0c869/lib/serverspec/helper/000077500000000000000000000000001500253164200216225ustar00rootroot00000000000000mizzy-serverspec-5c0c869/lib/serverspec/helper/type.rb000066400000000000000000000016311500253164200231310ustar00rootroot00000000000000module Serverspec module Helper module Type types = %w( base bridge bond cgroup command cron default_gateway file fstab group host iis_website iis_app_pool interface ipfilter ipnat iptables ip6tables json_file kernel_module kvm linux_kernel_parameter lxc mail_alias mysql_config package php_config port ppa process routing_table selinux selinux_module service user yumrepo windows_feature windows_hot_fix windows_registry_key windows_scheduled_task zfs docker_base docker_image docker_container x509_certificate x509_private_key linux_audit_system hadoop_config php_extension windows_firewall ) types.each {|type| require "serverspec/type/#{type}" } types.each do |type| define_method type do |*args| eval "Serverspec::Type::#{type.to_camel_case}.new(*args)" end end end end end mizzy-serverspec-5c0c869/lib/serverspec/matcher.rb000066400000000000000000000020331500253164200223110ustar00rootroot00000000000000# file require 'serverspec/matcher/be_mounted' require 'serverspec/matcher/contain' require 'serverspec/matcher/be_readable' require 'serverspec/matcher/be_writable' require 'serverspec/matcher/be_executable' # port require 'serverspec/matcher/be_listening' # host require 'serverspec/matcher/be_resolvable' require 'serverspec/matcher/be_reachable' # package require 'serverspec/matcher/be_installed' # selinux require 'serverspec/matcher/be_enforcing' require 'serverspec/matcher/be_permissive' # service require 'serverspec/matcher/be_enabled' require 'serverspec/matcher/be_running' require 'serverspec/matcher/be_monitored_by' # user require 'serverspec/matcher/belong_to_group' require 'serverspec/matcher/belong_to_primary_group' # ipfiter, ipnat, iptables, ip6tables require 'serverspec/matcher/have_rule' # cron, fstab, routing_table require 'serverspec/matcher/have_entry' # iis_website require 'serverspec/matcher/have_site_application' require 'serverspec/matcher/have_site_bindings' require 'serverspec/matcher/have_virtual_dir' mizzy-serverspec-5c0c869/lib/serverspec/matcher/000077500000000000000000000000001500253164200217665ustar00rootroot00000000000000mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_enabled.rb000066400000000000000000000007261500253164200243600ustar00rootroot00000000000000RSpec::Matchers.define :be_enabled do match do |subject| if subject.class.name == 'Serverspec::Type::Service' subject.enabled?(@level, @under) else subject.enabled? end end description do message = 'be enabled' message << " under #{@under}" if @under message << " with level #{@level}" if @level message end chain :with_level do |level| @level = level end chain :under do |under| @under = under end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_enforcing.rb000066400000000000000000000002711500253164200247330ustar00rootroot00000000000000RSpec::Matchers.define :be_enforcing do match do |selinux| selinux.enforcing?(@with_policy) end chain :with_policy do |with_policy| @with_policy = with_policy end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_executable.rb000066400000000000000000000003411500253164200251000ustar00rootroot00000000000000RSpec::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 mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_installed.rb000066400000000000000000000010201500253164200247310ustar00rootroot00000000000000RSpec::Matchers.define :be_installed do match do |subject| if subject.class.name == 'Serverspec::Type::SelinuxModule' subject.installed?(@version) else subject.installed?(@provider, @version) end end description do message = 'be installed' message << %( by "#{@provider}") if @provider message << %( with version "#{@version}") if @version message end chain :by do |provider| @provider = provider end chain :with_version do |version| @version = version end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_listening.rb000066400000000000000000000006121500253164200247540ustar00rootroot00000000000000RSpec::Matchers.define :be_listening do match do |port| port.listening? @with, @local_address end description do message = 'be listening' message << " on #{@local_address}" if @local_address message << " with #{@with}" if @with message end chain :with do |with| @with = with end chain :on do |local_address| @local_address = local_address end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_monitored_by.rb000066400000000000000000000005661500253164200254620ustar00rootroot00000000000000RSpec::Matchers.define :be_monitored_by do |monitor| match do |service| service.monitored_by?(monitor, @monitor_name) end description do if @monitor_name "be monitored by #{monitor} with name #{@monitor_name}" else "be monitored by #{monitor}" end end chain :with_name do |name| @monitor_name = (name ? name : nil) end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_mounted.rb000066400000000000000000000004031500253164200244310ustar00rootroot00000000000000RSpec::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 mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_permissive.rb000066400000000000000000000002731500253164200251510ustar00rootroot00000000000000RSpec::Matchers.define :be_permissive do match do |selinux| selinux.permissive?(@with_policy) end chain :with_policy do |with_policy| @with_policy = with_policy end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_reachable.rb000066400000000000000000000005321500253164200246670ustar00rootroot00000000000000RSpec::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 mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_readable.rb000066400000000000000000000003351500253164200245210ustar00rootroot00000000000000RSpec::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 mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_resolvable.rb000066400000000000000000000002171500253164200251170ustar00rootroot00000000000000RSpec::Matchers.define :be_resolvable do match do |name| name.resolvable?(@type) end chain :by do |type| @type = type end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_running.rb000066400000000000000000000005441500253164200244440ustar00rootroot00000000000000RSpec::Matchers.define :be_running do match do |subject| if subject.class.name == 'Serverspec::Type::Service' subject.running?(@under) else subject.running? end end description do message = 'be running' message << " under #{@under}" if @under message end chain :under do |under| @under = under end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/be_writable.rb000066400000000000000000000003351500253164200245730ustar00rootroot00000000000000RSpec::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 mizzy-serverspec-5c0c869/lib/serverspec/matcher/belong_to_group.rb000066400000000000000000000001611500253164200254750ustar00rootroot00000000000000RSpec::Matchers.define :belong_to_group do |group| match do |user| user.belongs_to_group?(group) end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/belong_to_primary_group.rb000066400000000000000000000002011500253164200272330ustar00rootroot00000000000000RSpec::Matchers.define :belong_to_primary_group do |group| match do |user| user.belongs_to_primary_group?(group) end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/contain.rb000066400000000000000000000012231500253164200237440ustar00rootroot00000000000000RSpec::Matchers.define :contain do |pattern| match do |resource| if resource.is_a?(String) resource.match(Regexp.new([@from, pattern, @to].compact.join.gsub('/', '.*'), Regexp::MULTILINE)) else resource.contain(pattern, @from, @to) end end # for contain(pattern).from(/A/).to(/B/) chain :from do |from| @from = Regexp.new(from).inspect end chain :to do |to| @to = Regexp.new(to).inspect end # for contain(pattern).after(/A/) chain :after do |after| @from = Regexp.new(after).inspect end # for contain(pattern).before(/B/) chain :before do |before| @to = Regexp.new(before).inspect end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/have_entry.rb000066400000000000000000000005041500253164200244560ustar00rootroot00000000000000RSpec::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 mizzy-serverspec-5c0c869/lib/serverspec/matcher/have_rule.rb000066400000000000000000000011411500253164200242620ustar00rootroot00000000000000RSpec::Matchers.define :have_rule do |rule| match do |subject| if subject.class.name == 'Serverspec::Type::Iptables' || subject.class.name == 'Serverspec::Type::Ip6tables' subject.has_rule?(rule, @table, @chain) else subject.has_rule?(rule) end end description do message = %Q{have rule "#{rule}"} message << " with table #{@table}" if @table message << ' and' if @table && @chain message << " with chain #{@chain}" if @chain message end chain :with_table do |table| @table = table end chain :with_chain do |chain| @chain = chain end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/have_site_application.rb000066400000000000000000000007071500253164200266510ustar00rootroot00000000000000RSpec::Matchers.define :have_site_application do |app| match do |subject| if subject.class.name == 'Serverspec::Type::IisWebsite' subject.has_site_application?(app, @pool, @physical_path) else className = subject.class.name raise "not supported class #{className}" end end chain :with_pool do |pool| @pool = pool end chain :with_physical_path do |physical_path| @physical_path = physical_path end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/have_site_bindings.rb000066400000000000000000000010401500253164200261320ustar00rootroot00000000000000RSpec::Matchers.define :have_site_bindings do |port| match do |subject| if subject.class.name == 'Serverspec::Type::IisWebsite' subject.has_site_bindings?(port, @protocol, @ipaddress, @host_header) else className = subject.class.name raise "not supported class #{className}" end end chain :with_protocol do |protocol| @protocol = protocol end chain :with_ipaddress do |ipaddress| @ipaddress = ipaddress end chain :with_host_header do |host_header| @host_header = host_header end end mizzy-serverspec-5c0c869/lib/serverspec/matcher/have_virtual_dir.rb000066400000000000000000000005241500253164200256430ustar00rootroot00000000000000RSpec::Matchers.define :have_virtual_dir do |vdir| match do |subject| if subject.class.name == 'Serverspec::Type::IisWebsite' subject.has_virtual_dir?(vdir, @path) else className = subject.class.name raise "not supported class #{className}" end end chain :with_path do |path| @path = path end end mizzy-serverspec-5c0c869/lib/serverspec/power_assert.rb000066400000000000000000000004041500253164200234030ustar00rootroot00000000000000require 'test/unit' require 'specinfra' require 'serverspec/helper/type' PowerAssert.configure do |c| c.lazy_inspection = true end class Serverspec::TestCase < Test::Unit::TestCase extend Serverspec::Helper::Type include Serverspec::Helper::Type end mizzy-serverspec-5c0c869/lib/serverspec/setup.rb000066400000000000000000000206671500253164200220430ustar00rootroot00000000000000require 'pathname' require 'fileutils' require 'erb' module Serverspec class Setup def self.run ask_os_type if @os_type == 'UN*X' ask_unix_backend else ask_windows_backend end if @backend_type == 'ssh' print 'Vagrant instance y/n: ' @vagrant = $stdin.gets.chomp if @vagrant =~ (/(true|t|yes|y|1)$/i) @vagrant = true print 'Auto-configure Vagrant from Vagrantfile? y/n: ' auto_config = $stdin.gets.chomp if auto_config =~ (/(true|t|yes|y|1)$/i) auto_vagrant_configuration else print('Input vagrant instance name: ') @hostname = $stdin.gets.chomp end else @vagrant = false print('Input target host name: ') @hostname = $stdin.gets.chomp end elsif @backend_type == 'winrm' print('Input target host name: ') @hostname = $stdin.gets.chomp else @hostname = 'localhost' end ['spec', "spec/#{@hostname}"].each { |dir| safe_mkdir(dir) } safe_create_spec safe_create_spec_helper safe_create_rakefile safe_create_dotrspec end def self.ask_os_type prompt = <<-EOF Select OS type: 1) UN*X 2) Windows Select number: EOF print prompt.chop num = $stdin.gets.to_i - 1 puts @os_type = ['UN*X', 'Windows'][num] || 'UN*X' end def self.ask_unix_backend prompt = <<-EOF Select a backend type: 1) SSH 2) Exec (local) Select number: EOF print prompt.chop num = $stdin.gets.to_i - 1 puts @backend_type = ['ssh', 'exec'][num] || 'exec' end def self.ask_windows_backend prompt = <<-EOF Select a backend type: 1) WinRM 2) Cmd (local) Select number: EOF print prompt.chop num = $stdin.gets.to_i - 1 puts @backend_type = ['winrm', 'cmd'][num] || 'exec' end def self.safe_create_spec content = <<-EOF require 'spec_helper' describe package('httpd'), :if => os[:family] == 'redhat' do it { should be_installed } end describe package('apache2'), :if => os[:family] == 'ubuntu' do it { should be_installed } end describe service('httpd'), :if => os[:family] == 'redhat' do it { should be_enabled } it { should be_running } end describe service('apache2'), :if => os[:family] == 'ubuntu' do it { should be_enabled } it { should be_running } end describe service('org.apache.httpd'), :if => os[:family] == 'darwin' do it { should be_enabled } it { should be_running } end describe port(80) do it { should be_listening } end EOF if File.exist? "spec/#{@hostname}/sample_spec.rb" old_content = File.read("spec/#{@hostname}/sample_spec.rb") if old_content != content $stderr.puts "!! spec/#{@hostname}/sample_spec.rb already exists and differs from template" end else File.open("spec/#{@hostname}/sample_spec.rb", 'w') do |f| f.puts content end puts " + spec/#{@hostname}/sample_spec.rb" end end def self.safe_mkdir(dir) if File.exist? 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 erb = if RUBY_VERSION >= "2.6" ERB.new(spec_helper_template, :trim_mode => '-') else ERB.new(spec_helper_template, nil, '-') end content = erb.result(binding) if File.exist? 'spec/spec_helper.rb' old_content = File.read('spec/spec_helper.rb') if old_content != content $stderr.puts "!! spec/spec_helper.rb already exists and differs from template" end else File.open('spec/spec_helper.rb', 'w') do |f| f.puts content end puts ' + spec/spec_helper.rb' end end def self.safe_create_rakefile content = <<-'EOF' require 'rake' require 'rspec/core/rake_task' task :spec => 'spec:all' task :default => :spec namespace :spec do targets = [] Dir.glob('./spec/*').each do |dir| next unless File.directory?(dir) target = File.basename(dir) target = "_#{target}" if target == "default" targets << target end task :all => targets task :default => :all targets.each do |target| original_target = target == "_default" ? target[1..-1] : target desc "Run serverspec tests to #{original_target}" RSpec::Core::RakeTask.new(target.to_sym) do |t| ENV['TARGET_HOST'] = original_target t.pattern = "spec/#{original_target}/*_spec.rb" end end end EOF if File.exist? '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.exist?(path) end nil end def self.auto_vagrant_configuration if find_vagrantfile vagrant_list = `vagrant status` list_of_vms = [] if vagrant_list != '' vagrant_list.each_line do |line| if match = /([\w-]+[\s]+)(created|aborted|not created|poweroff|running|saved)[\s](\(virtualbox\)|\(vmware\)|\(vmware_fusion\)|\(libvirt\))/.match(line) list_of_vms << match[1].strip! end end if list_of_vms.length == 1 @hostname = list_of_vms[0] else list_of_vms.each_with_index { |vm, index | puts "#{index}) #{vm}\n" } print 'Choose a VM from the Vagrantfile: ' chosen_vm = $stdin.gets.chomp @hostname = list_of_vms[chosen_vm.to_i] end else $stderr.puts 'Vagrant status error - Check your Vagrantfile or .vagrant' exit 1 end else $stderr.puts 'Vagrantfile not found in directory!' exit 1 end end def self.spec_helper_template template = <<-'EOF' require 'serverspec' <% if @backend_type == 'ssh' -%> require 'net/ssh' <% end -%> <%- if @vagrant -%> require 'tempfile' <% end -%> <% if @backend_type == 'winrm' -%> require 'winrm' <% end -%> set :backend, :<%= @backend_type %> <% if @os_type == 'UN*X' && @backend_type == 'ssh' -%> if ENV['ASK_SUDO_PASSWORD'] begin require 'highline/import' rescue LoadError fail "highline is not available. Try installing it." end set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false } else set :sudo_password, ENV['SUDO_PASSWORD'] end <%- if @backend_type == 'ssh' -%> host = ENV['TARGET_HOST'] <%- if @vagrant -%> `vagrant up #{host}` config = Tempfile.new('', Dir.tmpdir) config.write(`vagrant ssh-config #{host}`) config.close options = Net::SSH::Config.for(host, [config.path]) <%- else -%> options = Net::SSH::Config.for(host) <%- end -%> options[:user] ||= Etc.getlogin set :host, options[:host_name] || host set :ssh_options, options # Disable sudo # set :disable_sudo, true <%- end -%> # Set environment variables # set :env, :LANG => 'C', :LC_MESSAGES => 'C' # Set PATH # set :path, '/sbin:/usr/local/sbin:$PATH' <%- end -%> <% if @backend_type == 'winrm'-%> user = pass = endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" if Gem::Version.new(WinRM::VERSION) < Gem::Version.new('2') winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true) winrm.set_timeout 300 # 5 minutes max timeout for any operation else opts = { user: user, password: pass, endpoint: endpoint, operation_timeout: 300, no_ssl_peer_verification: false, } winrm = ::WinRM::Connection.new(opts) end Specinfra.configuration.winrm = winrm <% end -%> EOF template end def self.safe_create_dotrspec content = <<-'EOF' --color --format documentation EOF if File.exist? '.rspec' old_content = File.read('.rspec') if old_content != content $stderr.puts '!! .rspec already exists and differs from template' end else File.open('.rspec', 'w') do |f| f.puts content end puts ' + .rspec' end end end end mizzy-serverspec-5c0c869/lib/serverspec/subject.rb000066400000000000000000000002351500253164200223270ustar00rootroot00000000000000module Serverspec class Subject def value(v=nil) if v.nil? @value else @value = v self end end end end mizzy-serverspec-5c0c869/lib/serverspec/type/000077500000000000000000000000001500253164200213245ustar00rootroot00000000000000mizzy-serverspec-5c0c869/lib/serverspec/type/base.rb000066400000000000000000000010241500253164200225600ustar00rootroot00000000000000module Serverspec::Type class Base attr_reader :name def initialize(name=nil, options = {}) @name = name @options = options @runner = Specinfra::Runner end def to_s type = self.class.name.split(':')[-1] type.gsub!(/([a-z\d])([A-Z])/, '\1 \2') type.capitalize! %Q!#{type} "#{@name}"! end def inspect if defined?(PowerAssert) @inspection else to_s end end def to_ary to_s.split(" ") end end end mizzy-serverspec-5c0c869/lib/serverspec/type/bond.rb000066400000000000000000000003311500253164200225700ustar00rootroot00000000000000module Serverspec::Type class Bond < Base def exists? @runner.check_bond_exists(@name) end def has_interface?(interface) @runner.check_bond_has_interface(@name, interface) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/bridge.rb000066400000000000000000000003401500253164200231020ustar00rootroot00000000000000module Serverspec::Type class Bridge < Base def exists? @runner.check_bridge_exists(@name) end def has_interface?(interface) @runner.check_bridge_has_interface(@name, interface) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/cgroup.rb000066400000000000000000000006571500253164200231600ustar00rootroot00000000000000module Serverspec::Type class Cgroup < Base attr_accessor :subsystem def method_missing(meth) if @subsystem.nil? @subsystem = meth.to_s self else param = "#{@subsystem}.#{meth.to_s}" ret = @runner.run_command("cgget -n -r #{param} #{@name} | awk '{print $2}'") val = ret.stdout.strip val = val.to_i if val.match(/^\d+$/) val end end end end mizzy-serverspec-5c0c869/lib/serverspec/type/command.rb000066400000000000000000000007351500253164200232740ustar00rootroot00000000000000require 'multi_json' module Serverspec::Type class Command < Base def stdout command_result.stdout end def stdout_as_json MultiJson.load(command_result.stdout) end def stderr command_result.stderr end def exit_status command_result.exit_status.to_i end protected def command @name end private def command_result() @command_result ||= @runner.run_command(command) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/cron.rb000066400000000000000000000003541500253164200226140ustar00rootroot00000000000000module Serverspec::Type class Cron < Base def has_entry?(user, entry) @runner.check_cron_has_entry(user, entry) end def table @runner.get_cron_table.stdout end def to_s 'Cron' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/default_gateway.rb000066400000000000000000000003751500253164200250230ustar00rootroot00000000000000module Serverspec::Type class DefaultGateway < Base def ipaddress @runner.get_default_gateway(:gateway) end def interface @runner.get_default_gateway(:interface) end def to_s 'Default Gateway' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/docker_base.rb000066400000000000000000000010601500253164200241070ustar00rootroot00000000000000require 'multi_json' module Serverspec::Type class DockerBase < Base def exist? get_inspection.success? end def [](key) value = inspection key.split('.').each do |k| is_index = k.start_with?('[') && k.end_with?(']') value = value[is_index ? k[1..-2].to_i : k] end value end def inspection @inspection ||= ::MultiJson.load(get_inspection.stdout)[0] end private def get_inspection @get_inspection ||= @runner.run_command("docker inspect #{@name}") end end end mizzy-serverspec-5c0c869/lib/serverspec/type/docker_container.rb000066400000000000000000000013071500253164200251630ustar00rootroot00000000000000module Serverspec::Type class DockerContainer < DockerBase def running? inspection['State']['Running'] && !inspection['State']['Restarting'] end def has_volume?(container_path, host_path) if (inspection['Mounts']) check_volume(container_path, host_path) else check_volume_pre_1_8(container_path, host_path) end end private def check_volume(container_path, host_path) inspection['Mounts'].find {|mount| mount['Destination'] == container_path && mount['Source'] == host_path } end def check_volume_pre_1_8(container_path, host_path) inspection['Volumes'][container_path] == host_path end end end mizzy-serverspec-5c0c869/lib/serverspec/type/docker_image.rb000066400000000000000000000001031500253164200242540ustar00rootroot00000000000000module Serverspec::Type class DockerImage < DockerBase end end mizzy-serverspec-5c0c869/lib/serverspec/type/file.rb000066400000000000000000000072661500253164200226030ustar00rootroot00000000000000require 'date' require 'multi_json' require 'yaml' module Serverspec::Type class File < Base attr_accessor :content def file? cmd = Specinfra.command.get(:check_file_is_file, @name) @inspection = Specinfra.backend.build_command(cmd.to_s) @runner.check_file_is_file(@name) end def block_device? @runner.check_file_is_block_device(@name) end def character_device? @runner.check_file_is_character_device(@name) end def socket? @runner.check_file_is_socket(@name) end def directory? @runner.check_file_is_directory(@name) end def symlink? @runner.check_file_is_symlink(@name) end def pipe? @runner.check_file_is_pipe(@name) end def contain(pattern, from, to) if pattern.is_a?(Array) @runner.check_file_contains_lines(@name, pattern, from, to) else if (from || to).nil? @runner.check_file_contains(@name, pattern) else @runner.check_file_contains_within(@name, pattern, from, to) end end end def mode?(mode) @runner.check_file_has_mode(@name, mode) end def owned_by?(owner) @runner.check_file_is_owned_by(@name, owner) end def grouped_into?(group) @runner.check_file_is_grouped(@name, group) end def linked_to?(target) @runner.check_file_is_linked_to(@name, target) end def readable?(by_whom, by_user) if by_user != nil @runner.check_file_is_accessible_by_user(@name, by_user, 'r') else @runner.check_file_is_readable(@name, by_whom) end end def writable?(by_whom, by_user) if by_user != nil @runner.check_file_is_accessible_by_user(@name, by_user, 'w') else @runner.check_file_is_writable(@name, by_whom) end end def executable?(by_whom, by_user) if by_user != nil @runner.check_file_is_accessible_by_user(@name, by_user, 'x') else @runner.check_file_is_executable(@name, by_whom) end end def mounted?(attr, only_with) @runner.check_file_is_mounted(@name, attr, only_with) end def immutable? @runner.check_file_is_immutable(@name) end def exists? @runner.check_file_exists(@name) end def md5sum @runner.get_file_md5sum(@name).stdout.strip end def sha256sum @runner.get_file_sha256sum(@name).stdout.strip end def content if @content.nil? @content = @runner.get_file_content(@name).stdout end @content end def content_as_json @content_as_json = MultiJson.load(content) if @content_as_json.nil? @content_as_json end def content_as_yaml if @content_as_yaml.nil? @content_as_yaml = if YAML.respond_to?(:unsafe_load) YAML.unsafe_load(content) else YAML.load(content) end end @content_as_yaml end def group @runner.get_file_owner_group(@name).stdout.strip end def version?(version) @runner.check_file_has_version(@name, version) end def link_target @runner.get_file_link_target(@name).stdout.strip end def mode @runner.get_file_mode(@name).stdout.strip end def mtime d = @runner.get_file_mtime(@name).stdout.strip DateTime.strptime(d, '%s').new_offset(DateTime.now.offset) end def owner @runner.get_file_owner_user(@name).stdout.strip end def size @runner.get_file_size(@name).stdout.strip.to_i end def selinux_label @runner.get_file_selinuxlabel(@name).stdout.strip end end end mizzy-serverspec-5c0c869/lib/serverspec/type/fstab.rb000066400000000000000000000002501500253164200227450ustar00rootroot00000000000000module Serverspec::Type class Fstab < Base def has_entry?(entry) @runner.check_fstab_has_entry(entry) end def to_s 'Fstab' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/group.rb000066400000000000000000000005331500253164200230060ustar00rootroot00000000000000module Serverspec::Type class Group < Base def exists? @runner.check_group_exists(@name) end def gid @runner.get_group_gid(@name).stdout.to_i end def has_gid?(gid) @runner.check_group_has_gid(@name, gid) end def is_system_group? @runner.check_group_is_system_group(@name) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/hadoop_config.rb000066400000000000000000000013431500253164200244510ustar00rootroot00000000000000module Serverspec::Type class HadoopConfig < Base def initialize(name=nil, options={}) super begin require 'nokogiri' rescue LoadError fail "nokogiri is not available. Try installing it." end end def value @runner.run_command("find /etc/hadoop/conf/ -type f -name \"*.xml\" ").stdout.split(/\n/).each do |file| @doc = ::Nokogiri::XML( @runner.get_file_content("#{file}").stdout.strip ) @doc.xpath('/configuration/property').each do |property| case property.xpath('name').text when /#{@name}/ ret = property.xpath('value').text val = ret.to_s return val end end end end end end mizzy-serverspec-5c0c869/lib/serverspec/type/host.rb000066400000000000000000000007731500253164200226350ustar00rootroot00000000000000module Serverspec::Type class Host < Base def resolvable?(type) @runner.check_host_is_resolvable(@name, type) end def reachable?(port, proto, timeout) @runner.check_host_is_reachable(@name, port, proto, timeout) end def ipaddress @runner.get_host_ipaddress(@name).stdout.strip end def ipv4_address @runner.get_host_ipv4_address(@name).stdout.strip end def ipv6_address @runner.get_host_ipv6_address(@name).stdout.strip end end end mizzy-serverspec-5c0c869/lib/serverspec/type/iis_app_pool.rb000066400000000000000000000020751500253164200243320ustar00rootroot00000000000000module Serverspec::Type class IisAppPool < Base def exists?() @runner.check_iis_app_pool_exists(@name) end def has_dotnet_version?(dotnet) @runner.check_iis_app_pool_has_dotnet_version(@name, dotnet) end def has_32bit_enabled?() @runner.check_iis_app_pool_has_32bit_enabled(@name) end def has_idle_timeout?(minutes) @runner.check_iis_app_pool_has_idle_timeout(@name, minutes) end def has_identity_type?(identity_type) @runner.check_iis_app_pool_has_identity_type(@name, identity_type) end def has_periodic_restart?(minutes) @runner.check_iis_app_pool_has_periodic_restart(@name, minutes) end def has_user_profile_enabled?() @runner.check_iis_app_pool_has_user_profile(@name) end def has_username?(username) @runner.check_iis_app_pool_has_username(@name, username) end def has_managed_pipeline_mode?(mode) @runner.check_iis_app_pool_has_managed_pipeline_mode(@name, mode) end def to_s %Q[IIS Application Pool "#{@name}"] end end end mizzy-serverspec-5c0c869/lib/serverspec/type/iis_website.rb000066400000000000000000000017601500253164200241630ustar00rootroot00000000000000module Serverspec::Type class IisWebsite < Base def exists?() @runner.check_iis_website_is_installed(@name) end def enabled?() @runner.check_iis_website_is_enabled(@name) end def running?() @runner.check_iis_website_is_running(@name) end def in_app_pool?(app_pool) @runner.check_iis_website_is_in_app_pool(@name, app_pool) end def has_physical_path?(path) @runner.check_iis_website_has_physical_path(@name, path) end def has_site_bindings?(port, protocol, ipaddress, host_header) @runner.check_iis_website_has_site_bindings(@name, port, protocol, ipaddress, host_header) end def has_virtual_dir?(vdir, path) @runner.check_iis_website_has_virtual_dir(@name, vdir, path) end def has_site_application?(app, pool, physical_path) @runner.check_iis_website_has_site_application(@name, app, pool, physical_path) end def to_s %Q[IIS Website "#{@name}"] end end end mizzy-serverspec-5c0c869/lib/serverspec/type/interface.rb000066400000000000000000000017061500253164200236150ustar00rootroot00000000000000module Serverspec::Type class Interface < Base def exists? @runner.check_interface_exists(@name) end def speed ret = @runner.get_interface_speed_of(@name) val_to_integer(ret) end def mtu ret = @runner.get_interface_mtu_of(@name) val_to_integer(ret) end def has_ipv4_address?(ip_address) @runner.check_interface_has_ipv4_address(@name, ip_address) end def has_ipv6_address?(ip_address) @runner.check_interface_has_ipv6_address(@name, ip_address) end def ipv4_address @runner.get_interface_ipv4_address(@name).stdout.strip end def ipv6_address @runner.get_interface_ipv6_address(@name).stdout.strip end def up? ret = @runner.get_interface_link_state(@name) ret.stdout.strip == 'up' end private def val_to_integer(ret) val = ret.stdout.strip val = val.to_i if val.match(/^\d+$/) val end end end mizzy-serverspec-5c0c869/lib/serverspec/type/ip6tables.rb000066400000000000000000000003521500253164200235420ustar00rootroot00000000000000module Serverspec module Type class Ip6tables < Base def has_rule?(rule, table, chain) @runner.check_ip6tables_has_rule(rule, table, chain) end def to_s 'ip6tables' end end end end mizzy-serverspec-5c0c869/lib/serverspec/type/ipfilter.rb000066400000000000000000000002551500253164200234710ustar00rootroot00000000000000module Serverspec::Type class Ipfilter < Base def has_rule?(rule) @runner.check_ipfilter_has_rule(rule) end def to_s 'ipfilter' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/ipnat.rb000066400000000000000000000002441500253164200227640ustar00rootroot00000000000000module Serverspec::Type class Ipnat < Base def has_rule?(rule) @runner.check_ipnat_has_rule(rule) end def to_s 'ipnat' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/iptables.rb000066400000000000000000000003111500253164200234470ustar00rootroot00000000000000module Serverspec::Type class Iptables < Base def has_rule?(rule, table, chain) @runner.check_iptables_has_rule(rule, table, chain) end def to_s 'iptables' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/json_file.rb000066400000000000000000000002041500253164200236150ustar00rootroot00000000000000require 'multi_json' module Serverspec::Type class JsonFile < File def content MultiJson.load(super) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/kernel_module.rb000066400000000000000000000002111500253164200244700ustar00rootroot00000000000000module Serverspec::Type class KernelModule < Base def loaded? @runner.check_kernel_module_is_loaded(@name) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/kvm.rb000066400000000000000000000004571500253164200224540ustar00rootroot00000000000000module Serverspec::Type class Kvm < Base def exists? @runner.check_kvm_guest_exists(@name) end def running? @runner.check_kvm_guest_is_running(@name) end def enabled? @runner.check_kvm_guest_is_enabled(@name) end def to_s 'KVM' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/linux_audit_system.rb000066400000000000000000000021211500253164200255760ustar00rootroot00000000000000module Serverspec::Type class LinuxAuditSystem < Base def initialize(name=nil) @name = 'linux_audit_system' @runner = Specinfra::Runner @rules_content = nil end def enabled? status_of('enabled') == '1' end def running? pid = status_of('pid') (!pid.nil? && pid.size > 0 && pid != '0') end def rules if @rules_content.nil? @rules_content = @runner.run_command('/sbin/auditctl -l').stdout || '' end @rules_content end private def status_of(part) cmd = "/sbin/auditctl -s" status_str = @runner.run_command(cmd).stdout.chomp status_map = parse_status(status_str) status_map[part] || '' end def parse_status(status_str) map = nil if status_str =~ /^AUDIT_STATUS/ then map = status_str.split(' ')[1..-1].inject({}) { |res,elem| a = elem.split('='); res.store(a[0],a[1] || ''); res } else map = status_str.split("\n").inject({}) { |res,elem| a = elem.split(' '); res.store(a[0],a[1] || ''); res } end map end end end mizzy-serverspec-5c0c869/lib/serverspec/type/linux_kernel_parameter.rb000066400000000000000000000003551500253164200264130ustar00rootroot00000000000000module Serverspec::Type class LinuxKernelParameter < Base def value ret = @runner.run_command("/sbin/sysctl -q -n #{@name}") val = ret.stdout.strip val = val.to_i if val.match(/^\d+$/) val end end end mizzy-serverspec-5c0c869/lib/serverspec/type/lxc.rb000066400000000000000000000003551500253164200224420ustar00rootroot00000000000000module Serverspec::Type class Lxc < Base def exists? @runner.check_lxc_container_exists(@name) end def running? @runner.check_lxc_container_is_running(@name) end def to_s 'LXC' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/mail_alias.rb000066400000000000000000000002331500253164200237420ustar00rootroot00000000000000module Serverspec::Type class MailAlias < Base def aliased_to?(target) @runner.check_mail_alias_is_aliased_to(@name, target) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/mysql_config.rb000066400000000000000000000004271500253164200243460ustar00rootroot00000000000000module Serverspec::Type class MysqlConfig < Base def value ret = @runner.run_command("mysqld --verbose --help 2> /dev/null | grep '^#{@name}'") val = ret.stdout.match(/#{@name}\s+(.+)$/)[1] val = val.to_i if val.match(/^\d+$/) val end end end mizzy-serverspec-5c0c869/lib/serverspec/type/package.rb000066400000000000000000000032431500253164200232460ustar00rootroot00000000000000module Serverspec::Type class Package < Base def installed?(provider=nil, version=nil) if provider.nil? @inspection = Specinfra.command.get(:check_package_is_installed, @name, version) @runner.check_package_is_installed(@name, version) else check_method = "check_package_is_installed_by_#{provider}".to_sym @runner.send(check_method, @name, version) end end def version ret = @runner.get_package_version(@name).stdout.strip if ret.empty? nil else Version.new(ret) end end class Version include Comparable attr_reader :epoch, :version def initialize(val) matches = val.match(/^(?:(\d+):)?(\d[0-9a-zA-Z.+:~_-]*)$/) if matches.nil? raise ArgumentError, "Malformed version number string #{val}" end @epoch = matches[1].to_i @version = matches[2].to_s end def <=>(other) other = Version.new(other) if other.is_a?(String) rv = @epoch <=> other.epoch return rv if rv != 0 self.ver_array <=> other.ver_array end def ver_array val = @version re = /^(?:(\d+)|(\D+))(.*)$/ res = [] until val.empty? matches = val.match(re) if matches[1].nil? # String matches[2].to_s.each_byte do |b| code_point = defined?("~".ord) ? "~".ord : ?~ res << ((b == code_point) ? -2 : b) end else # Digits res << matches[1].to_i end val = matches[3].to_s end res << -1 end end end end mizzy-serverspec-5c0c869/lib/serverspec/type/php_config.rb000066400000000000000000000005161500253164200237670ustar00rootroot00000000000000module Serverspec::Type class PhpConfig < Base def value extra = ''; extra = extra + "-c #{@options[:ini]}" if @options.has_key?(:ini) ret = @runner.run_command("php #{extra} -r 'echo get_cfg_var( \"#{@name}\" );'") val = ret.stdout val = val.to_i if val.match(/^\d+$/) val end end end mizzy-serverspec-5c0c869/lib/serverspec/type/php_extension.rb000066400000000000000000000003111500253164200245270ustar00rootroot00000000000000module Serverspec::Type class PhpExtension < Base def loaded? ret = @runner.run_command("php --ri '#{@name}'") return false if ret.exit_status.to_i > 0 true end end end mizzy-serverspec-5c0c869/lib/serverspec/type/port.rb000066400000000000000000000020231500253164200226320ustar00rootroot00000000000000require 'resolv' module Serverspec::Type class Port < Base def protocols %w(udp tcp tcp6 udp6) end def options @options ||= {} end def protocol_matcher(protocol) protocol = protocol.to_s.downcase if protocols.include?(protocol) options[:protocol] = protocol else raise ArgumentError.new("`be_listening` matcher doesn't support #{protocol}") end end def local_address_matcher(local_address) if valid_ip_address?(local_address) options[:local_address] = local_address else raise ArgumentError.new("`be_listening` matcher requires valid IPv4 or IPv6 address") end end def listening?(protocol, local_address) protocol_matcher(protocol) if protocol local_address_matcher(local_address) if local_address @runner.check_port_is_listening(@name, options) end def valid_ip_address?(ip_address) !!(ip_address =~ Resolv::IPv4::Regex) || !!(ip_address =~ Resolv::IPv6::Regex) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/ppa.rb000066400000000000000000000002671500253164200224360ustar00rootroot00000000000000module Serverspec::Type class Ppa < Base def exists? @runner.check_ppa_exists(@name) end def enabled? @runner.check_ppa_is_enabled(@name) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/process.rb000066400000000000000000000011161500253164200233260ustar00rootroot00000000000000module Serverspec::Type class Process < Base def running? pid = @runner.get_process(@name, :format => "pid=").stdout not pid.empty? end def user get_column("user") end def group get_column("group") end def count @runner.count_process(@name).stdout.strip.to_i end def method_missing(meth) get_column(meth.to_s) end def get_column(keyword) ret = @runner.get_process(@name, :format => "#{keyword}=") val = ret.stdout.strip val = val.to_i if val.match(/^\d+$/) val end end end mizzy-serverspec-5c0c869/lib/serverspec/type/routing_table.rb000066400000000000000000000002771500253164200245150ustar00rootroot00000000000000module Serverspec::Type class RoutingTable < Base def has_entry?(entry) @runner.check_routing_table_has_entry(entry) end def to_s 'Routing Table' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/selinux.rb000066400000000000000000000005741500253164200233460ustar00rootroot00000000000000module Serverspec::Type class Selinux < Base def disabled? @runner.check_selinux_has_mode('disabled') end def enforcing?(with_policy) @runner.check_selinux_has_mode('enforcing', with_policy) end def permissive?(with_policy) @runner.check_selinux_has_mode('permissive', with_policy) end def to_s 'SELinux' end end end mizzy-serverspec-5c0c869/lib/serverspec/type/selinux_module.rb000066400000000000000000000004611500253164200247060ustar00rootroot00000000000000module Serverspec::Type class SelinuxModule < Base def enabled? @runner.check_selinux_module_is_enabled(@name) end def installed?(version = nil) @runner.check_selinux_module_is_installed(@name, version) end def to_s %(SELinux module "#{@name}") end end end mizzy-serverspec-5c0c869/lib/serverspec/type/service.rb000066400000000000000000000027711500253164200233200ustar00rootroot00000000000000module Serverspec::Type class Service < Base def enabled?(level, under=nil) under = under ? "_under_#{under.gsub(/^under_/, '')}" : '' check_method = "check_service_is_enabled#{under}" if level @runner.send(check_method.to_sym, @name, level) else @runner.send(check_method.to_sym, @name) end end def installed?(name, version) @runner.check_service_is_installed(@name) end def has_start_mode?(mode) @runner.check_service_has_start_mode(@name, mode) end def running?(under) if under check_method = "check_service_is_running_under_#{under}".to_sym @runner.send(check_method, @name) else @runner.check_service_is_running(@name) end end def monitored_by?(monitor, monitor_name) check_method = "check_service_is_monitored_by_#{monitor}".to_sym # use the with_name value if set instead of the service name monitor_name = (monitor_name ? monitor_name : @name) res = @runner.send(check_method, monitor_name) end def has_property?(property) @runner.check_service_has_property(@name, property) end def property get_property if @property.nil? @property end private def get_property @property = {} props = @runner.get_service_property(@name).stdout props.split(/\n/).each do |line| property, _type, *value = line.split(/\s+/) @property[property] = value.join(' ') end end end end mizzy-serverspec-5c0c869/lib/serverspec/type/user.rb000066400000000000000000000022731500253164200226330ustar00rootroot00000000000000module Serverspec::Type class User < Base def exists? @runner.check_user_exists(@name) end def belongs_to_group?(group) @runner.check_user_belongs_to_group(@name, group) end def belongs_to_primary_group?(group) @runner.check_user_belongs_to_primary_group(@name, group) end def uid @runner.get_user_uid(@name).stdout.to_i end def has_uid?(uid) @runner.check_user_has_uid(@name, uid) end def has_home_directory?(path) @runner.check_user_has_home_directory(@name, path) end def has_login_shell?(shell) @runner.check_user_has_login_shell(@name, shell) end def has_authorized_key?(key) @runner.check_user_has_authorized_key(@name, key) end def minimum_days_between_password_change @runner.get_user_minimum_days_between_password_change(@name).stdout.to_i end def maximum_days_between_password_change @runner.get_user_maximum_days_between_password_change(@name).stdout.to_i end def encrypted_password @runner.get_user_encrypted_password(@name).stdout.strip end def is_system_user? @runner.check_user_is_system_user(@name) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/windows_feature.rb000066400000000000000000000002461500253164200250600ustar00rootroot00000000000000module Serverspec::Type class WindowsFeature < Base def installed?(provider, version) @runner.check_feature_is_enabled(@name, provider) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/windows_firewall.rb000066400000000000000000000010431500253164200252260ustar00rootroot00000000000000module Serverspec::Type class WindowsFirewall < Base def exists? @runner.check_firewall_exists(@name) end def tcp? @runner.check_firewall_has_protocol(@name, 'TCP') end def has_localport?(port) @runner.check_firewall_has_localport(@name, port) end def inbound? @runner.check_firewall_has_direction(@name, 'Inbound') end def enabled? @runner.check_firewall_is_enabled(@name) end def allowed? @runner.check_firewall_has_action(@name, 'Allow') end end end mizzy-serverspec-5c0c869/lib/serverspec/type/windows_hot_fix.rb000066400000000000000000000002461500253164200250650ustar00rootroot00000000000000module Serverspec::Type class WindowsHotFix < Base def installed?(provider, version) @runner.check_hot_fix_is_installed(@name, version) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/windows_registry_key.rb000066400000000000000000000012111500253164200261360ustar00rootroot00000000000000module Serverspec::Type class WindowsRegistryKey < Base def exists? @runner.check_registry_key_exists(@name) end def has_property?(property_name, property_type = :type_string) @runner.check_registry_key_has_property(@name, {:name => property_name, :type => property_type}) end def has_value?(value) @runner.check_registry_key_has_value(@name, {:name => '', :type => :type_string, :value => value}) end def has_property_value?(property_name, property_type, value) @runner.check_registry_key_has_value(@name, {:name => property_name, :type => property_type, :value => value}) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/windows_scheduled_task.rb000066400000000000000000000002171500253164200264050ustar00rootroot00000000000000module Serverspec::Type class WindowsScheduledTask < Base def exists? @runner.check_scheduled_task_exists(@name) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/x509_certificate.rb000066400000000000000000000052741500253164200247300ustar00rootroot00000000000000require 'time' module Serverspec::Type class X509Certificate < Base def certificate? (run_openssl_command_with("-noout").exit_status == 0) end def subject normalize_dn(run_openssl_command_with("-subject -noout").stdout.chomp.gsub(/^subject= */,'')) end def issuer normalize_dn(run_openssl_command_with("-issuer -noout").stdout.chomp.gsub(/^issuer= */,'')) end def email run_openssl_command_with("-email -noout").stdout.chomp end def fingerprint run_openssl_command_with("-fingerprint -noout").stdout.chomp end def alias run_openssl_command_with("-alias -noout").stdout.chomp end # Modern openssl use following output format for key length: # Public-Key: (4096 bit) # while ancient (0.9.8 for example) use # RSA Public Key: (2048 bit) def keylength len_str = run_openssl_command_with("-text -noout | grep -E 'Public(-| )Key: \\([[:digit:]]+ bit\\)'").stdout.chomp len_str.gsub(/^.*\(/,'').gsub(/ bit\)$/,'').to_i end def has_purpose?(p) grep_str = "#{p} : Yes" ( run_openssl_command_with("-purpose -noout | grep -wq \"#{grep_str}\""). exit_status == 0 ) end def valid? runner_res = run_openssl_command_with("-startdate -enddate -noout") return false if runner_res.exit_status != 0 date_map = parse_dates_str_to_map(runner_res.stdout) now = Time.now ( now >= date_map[:notBefore] && now <= date_map[:notAfter]) end def validity_in_days runner_res = run_openssl_command_with("-enddate -noout") return 0 if runner_res.exit_status != 0 date_map = parse_dates_str_to_map(runner_res.stdout) diff = date_map[:notAfter] - Time.now ( diff/(60*60*24) ) end def subject_alt_names text = run_openssl_command_with('-text -noout').stdout # X509v3 Subject Alternative Name: # DNS:*.example.com, DNS:www.example.net, IP:192.0.2.10 if text =~ /^ *X509v3 Subject Alternative Name:.*\n *(.*)$/ $1.split(/, +/) end end private def run_openssl_command_with(param_str) @runner.run_command("openssl x509 -in #{name} #{param_str}") end def parse_dates_str_to_map(dates_str) dates_str.split("\n").inject({}) do |res,line| kv_arr = line.split '=' time = Time.strptime(kv_arr[1],'%b %e %T %Y %Z') rescue Time.parse(kv_arr[1] || '') res.merge({ kv_arr[0].to_sym => time }) end end # Normalize output between openssl versions. def normalize_dn(dn) return dn unless dn.start_with?('/') # normalize openssl < 1.1 to >= 1.1 output dn[1..-1].split('/').join(', ').gsub('=', ' = ') end end end mizzy-serverspec-5c0c869/lib/serverspec/type/x509_private_key.rb000066400000000000000000000015251500253164200247630ustar00rootroot00000000000000require 'time' module Serverspec::Type class X509PrivateKey < Base def valid? runner_res = @runner.run_command("echo | openssl rsa -in #{name} -check -noout -passin #{@options[:passin] || "stdin"}") ( runner_res.exit_status == 0 && runner_res.stdout.chomp == 'RSA key ok' ) && (!@options.has_key?(:passin) || encrypted?) end def encrypted? @runner.run_command("grep -Ewq \"^(Proc-Type.*ENCRYPTED|-----BEGIN ENCRYPTED PRIVATE KEY-----)$\" #{name}").exit_status == 0 end def has_matching_certificate?(cert_file) h1 = @runner.run_command("openssl x509 -noout -modulus -in #{cert_file}") h2 = @runner.run_command("echo | openssl rsa -noout -modulus -in #{name} -passin #{@options[:passin] || "stdin"}") (h1.stdout == h2.stdout) && (h1.exit_status == 0) && (h2.exit_status == 0) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/yumrepo.rb000066400000000000000000000003031500253164200233450ustar00rootroot00000000000000module Serverspec::Type class Yumrepo < Base def exists? @runner.check_yumrepo_exists(@name) end def enabled? @runner.check_yumrepo_is_enabled(@name) end end end mizzy-serverspec-5c0c869/lib/serverspec/type/zfs.rb000066400000000000000000000010521500253164200224510ustar00rootroot00000000000000module Serverspec::Type class Zfs < Base def exists? @runner.check_zfs_exists(@name) end def has_property?(property) @runner.check_zfs_has_property(@name, property) end def to_s 'ZFS' end def property get_property if @property.nil? @property end private def get_property @property = Hash.new @runner.get_zfs_property(@name).stdout.split(/\n/).each do |line| property, value = line.split(/\s+/) @property[property] = value end end end end mizzy-serverspec-5c0c869/lib/serverspec/version.rb000066400000000000000000000000531500253164200223530ustar00rootroot00000000000000module Serverspec VERSION = "2.43.0" end mizzy-serverspec-5c0c869/serverspec.gemspec000066400000000000000000000023401500253164200211410ustar00rootroot00000000000000# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'serverspec/version' Gem::Specification.new do |spec| spec.name = "serverspec" spec.version = Serverspec::VERSION spec.authors = ["Gosuke Miyashita"] spec.email = ["gosukenator@gmail.com"] spec.description = %q{RSpec tests for your servers configured by Puppet, Chef, Itamae or anything else} spec.summary = %q{RSpec tests for your servers configured by Puppet, Chef, Itamae or anything else} spec.homepage = "http://serverspec.org/" spec.license = "MIT" spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_runtime_dependency "rspec", "~> 3.0" spec.add_runtime_dependency "rspec-its" spec.add_runtime_dependency "multi_json" spec.add_runtime_dependency "specinfra", "~> 2.72" if RUBY_VERSION < "1.9" spec.add_development_dependency "json", "~> 1.8" spec.add_development_dependency "rake", "~> 10.1.1" else spec.add_development_dependency "rake" end end mizzy-serverspec-5c0c869/spec/000077500000000000000000000000001500253164200163465ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/helper/000077500000000000000000000000001500253164200176255ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/helper/type_spec.rb000066400000000000000000000001541500253164200221450ustar00rootroot00000000000000require 'spec_helper' describe String do subject { String.new } it { should_not respond_to :host } end mizzy-serverspec-5c0c869/spec/spec_helper.rb000066400000000000000000000013301500253164200211610ustar00rootroot00000000000000require 'serverspec' set :backend, :exec module Specinfra module Backend class Exec < Base def run_command cmd CommandResult.new({ :stdout => ::Specinfra.configuration.stdout, :stderr => ::Specinfra.configuration.stderr, :exit_status => ::Specinfra.configuration.exit_status, :exit_signal => nil, }) end end class Cmd < Base def run_command cmd CommandResult.new({ :stdout => ::Specinfra.configuration.stdout, :stderr => ::Specinfra.configuration.stderr, :exit_status => ::Specinfra.configuration.exit_status, :exit_signal => nil, }) end end end end mizzy-serverspec-5c0c869/spec/type/000077500000000000000000000000001500253164200173275ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/aix/000077500000000000000000000000001500253164200201105ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/aix/file_spec.rb000066400000000000000000000007501500253164200223700ustar00rootroot00000000000000require 'spec_helper' set :os, {:family => 'aix'} describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end mizzy-serverspec-5c0c869/spec/type/aix/group_spec.rb000066400000000000000000000001531500253164200226020ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'aix' describe group('root') do it { should have_gid 0 } end mizzy-serverspec-5c0c869/spec/type/aix/package_spec.rb000066400000000000000000000001601500253164200230370ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'aix' describe package('httpd') do it { should be_installed } end mizzy-serverspec-5c0c869/spec/type/aix/port_spec.rb000066400000000000000000000004661500253164200224410ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'aix' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(53) do it { should be_listening.with('udp') } end mizzy-serverspec-5c0c869/spec/type/aix/service_spec.rb000066400000000000000000000002701500253164200231060ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'aix' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end mizzy-serverspec-5c0c869/spec/type/aix/user_spec.rb000066400000000000000000000004141500253164200224240ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'aix' describe user('root') do it { should belong_to_group 'root' } end describe user('root') do it { should have_login_shell '/bin/bash' } end describe user('root') do it { should have_home_directory '/root' } end mizzy-serverspec-5c0c869/spec/type/arch/000077500000000000000000000000001500253164200202445ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/arch/file_spec.rb000066400000000000000000000004221500253164200225200ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'arch' describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end mizzy-serverspec-5c0c869/spec/type/arch/package_spec.rb000066400000000000000000000006461500253164200232040ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'arch' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end mizzy-serverspec-5c0c869/spec/type/arch/service_spec.rb000066400000000000000000000002121500253164200232360ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'arch' describe service('sshd') do it { should be_enabled } it { should be_running } end mizzy-serverspec-5c0c869/spec/type/base/000077500000000000000000000000001500253164200202415ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/base/command_spec.rb000066400000000000000000000055341500253164200232250ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } its(:stdout) { should match /nameserver 127.0.0.1/ } end describe 'complete matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } its(:stdout) { should_not eq 'content-should-be-included' } end end describe 'regexp matching of stdout' do context command('cat /etc/resolv.conf') do let(:stdout) { "nameserver 127.0.0.1\r\n" } its(:stdout) { should match /127\.0\.0\.1/ } end end describe command('cat /etc/resolv.conf') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should match /No such file or directory/ } end describe 'complete matching of stderr' do context command('cat /etc/resolv.conf') do let(:stderr) { "No such file or directory\r\n" } its(:stdout) { should_not eq 'file' } end end describe 'regexp matching of stderr' do context command('cat /etc/resolv.conf') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should match /file/ } end end describe command('cat /etc/resolv.conf') do its(:exit_status) { should eq 0 } end describe command('ls -al /') do let(:stdout) { < include('version' => '0.26.5')) } its(:stdout_as_json) { should include('transport' => include('keepalives' => include('consumers' => 1))) } its(:stdout_as_json) { should include('transport' => include('connected' => true)) } its(:stdout_as_json) { should include('array' => include('title' => 'array 2')) } end mizzy-serverspec-5c0c869/spec/type/base/cron_spec.rb000066400000000000000000000003571500253164200225460ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe cron do it { should have_entry '* * * * * /usr/local/bin/batch.sh' } end describe cron do it { should have_entry('* * * * * /usr/local/bin/batch.sh').with_user('root') } end mizzy-serverspec-5c0c869/spec/type/base/default_gateway_spec.rb000066400000000000000000000005071500253164200247470ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe default_gateway do let(:stdout) { "default via 192.168.1.1 dev eth1 \r\n" } its(:ipaddress) { should eq '192.168.1.1' } its(:interface) { should eq 'eth1' } its(:ipaddress) { should_not eq '192.168.1.2' } its(:interface) { should_not eq 'eth0' } end mizzy-serverspec-5c0c869/spec/type/base/file_spec.rb000066400000000000000000000236261500253164200225300ustar00rootroot00000000000000require 'spec_helper' set :os, {:family => 'base'} describe file('/etc/ssh/sshd_config') do it { should be_file } end describe file('/etc/ssh') do it { should be_directory } end describe file('/var/run/unicorn.sock') do it { should be_socket } end describe file('/dev/disk0') do it { should be_block_device } end describe file('/dev/ttys0') do it { should be_character_device } end describe file('/var/run/pure-ftpd/pure-ftpd.upload.pipe') do it { should be_pipe } end describe file('/bin/sh') do it { should be_symlink } end describe file('/bin/sh') do it { should exist } end describe file('/etc/ssh/sshd_config') do it { should contain 'This is the sshd server system-wide configuration file' } end describe file('/etc/ssh/sshd_config') do it { should contain /^This is the sshd server system-wide configuration file/ } end describe file('Gemfile') do it { should contain('rspec').from(/^group :test do/).to(/^end/) } end describe file('Gemfile') do it { should contain('rspec').after(/^group :test do/) } end describe file('Gemfile') do it { should contain('rspec').before(/^end/) } end describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_readable } end describe file('/dev') do let(:stdout) { "333\r\n" } it { should_not be_readable } end describe file('/dev') do let(:stdout) { "400\r\n" } it { should be_readable.by('owner') } end describe file('/dev') do let(:stdout) { "044\r\n" } it { should_not be_readable.by('owner') } end describe file('/dev') do let(:stdout) { "040\r\n" } it { should be_readable.by('group') } end describe file('/dev') do let(:stdout) { "404\r\n" } it { should_not be_readable.by('group') } end describe file('/dev') do let(:stdout) { "044\r\n" } it { should be_readable.by('others') } end describe file('/dev') do let(:stdout) { "443\r\n" } it { should_not be_readable.by('others') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_writable } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable } end describe file('/dev') do let(:stdout) { "200\r\n" } it { should be_writable.by('owner') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('owner') } end describe file('/dev') do let(:stdout) { "030\r\n" } it { should be_writable.by('group') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('group') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should be_writable.by('others') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('others') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_executable } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable } end describe file('/dev') do let(:stdout) { "100\r\n" } it { should be_executable.by('owner') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('owner') } end describe file('/dev') do let(:stdout) { "070\r\n" } it { should be_executable.by('group') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('group') } end describe file('/dev') do let(:stdout) { "001\r\n" } it { should be_executable.by('others') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('others') } end describe file('/') do it { should be_mounted } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :rw => true } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :mode => 620 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :rw => false } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :mode => 600 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_r00t' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, :bind => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_roooooooooot', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/etc/invalid-mount') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.only_with( :type => 'ext4' ) } end describe file('/etc/services') do let(:stdout) { "35435ea447c19f0ea5ef971837ab9ced\n" } its(:md5sum) { should eq '35435ea447c19f0ea5ef971837ab9ced' } end describe file('invalid-file') do its(:md5sum) { should_not eq 'INVALIDMD5CHECKSUM' } end describe file('/etc/services') do let(:stdout) {"0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } its(:sha256sum) { should eq '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } end describe file('invalid-file') do its(:sha256sum) { should_not eq 'INVALIDSHA256CHECKSUM' } end describe file('/etc/passwd') do let(:stdout) { "root\r\n" } its(:group) { should eq 'root' } end describe file('/etc/passwd') do let(:stdout) {< include('title' => 'this is a json')) } its(:content_as_json) { should include('json' => include('array' => include('title' => 'array 2'))) } end describe file('example.yml') do let(:stdout) {< include('title' => 'this is a yaml')) } its(:content_as_yaml) { should include('yaml' => include('array' => include('title' => 'array 2'))) } its(:content_as_yaml) { should include('yaml' => include('date' => Date.new(2023, 2, 3))) } its(:content_as_yaml) { should include('yaml' => include('Reuse anchor' => 'this is a yaml')) } end describe file('/etc/pam.d/system-auth') do let(:stdout) { "/etc/pam.dsystem-auth-ac\r\n" } its(:link_target) { should eq '/etc/pam.dsystem-auth-ac' } end describe file('/etc/passwd') do let(:stdout) { "644\r\n" } its(:mode) { should eq '644' } end describe file('/etc/passwd') do let(:stdout) { Time.now.to_i.to_s } its(:mtime) { should > DateTime.now - 1 } end describe file('/etc/passwd') do let(:stdout) { "root\r\n" } its(:owner) { should eq 'root' } end describe file('/etc/passwod') do let(:stdout) { 100.to_s } its(:size) { should > 0 } end describe file('/etc/passwd') do it 'be_immutable is not implemented in base class' do expect { should be_immutable }.to raise_error(/is not implemented in Specinfra/) end end mizzy-serverspec-5c0c869/spec/type/base/group_spec.rb000066400000000000000000000004721500253164200227370ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe group('root') do it { should exist } end describe group('root') do it { should have_gid 0 } end describe group('root') do its(:gid) { should == 0 } its(:gid) { should < 10 } end describe group('root') do it { should be_is_system_group } end mizzy-serverspec-5c0c869/spec/type/base/host_spec.rb000066400000000000000000000017731500253164200225650ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe host('127.0.0.1') do it { should be_resolvable } end describe host('127.0.0.1') do it { should be_resolvable.by('hosts') } end describe host('127.0.0.1') do it { should be_resolvable.by('dns') } end describe host('127.0.0.1') do it { should be_reachable } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "icmp", :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end describe host('example.jp') do let(:stdout) { "1.2.3.4\r\n" } its(:ipaddress) { should eq '1.2.3.4' } end describe host('example.jp') do let(:stdout) { "1.2.3.4\r\n" } its(:ipv4_address) { should match(/^[\d.]+$/) } end describe host('example.jp') do let(:stdout) { "2001:db8::1234\r\n" } its(:ipv6_address) { should match(/^[a-f\d:]+$/i) } end mizzy-serverspec-5c0c869/spec/type/base/json_file_spec.rb000066400000000000000000000007751500253164200235610ustar00rootroot00000000000000require 'spec_helper' set :os, {:family => 'base'} describe json_file('example.json') do let(:stdout) {< include('title' => 'this is a json')) } its(:content) { should include('json' => include('array' => include('title' => 'array 2'))) } end mizzy-serverspec-5c0c869/spec/type/base/mail_alias_spec.rb000066400000000000000000000001751500253164200236760ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe mail_alias('daemon') do it { should be_aliased_to "root" } end mizzy-serverspec-5c0c869/spec/type/base/mysql_config_spec.rb000066400000000000000000000005571500253164200243010ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe mysql_config('innodb-buffer-pool-size') do let(:stdout) { 'innodb-buffer-pool-size 134217728' } its(:value) { should eq 134217728 } end describe mysql_config('socket') do let(:stdout) { 'socket /tmp/mysql.sock' } its(:value) { should eq '/tmp/mysql.sock' } end mizzy-serverspec-5c0c869/spec/type/base/package_spec.rb000066400000000000000000000020741500253164200231760ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe package('jekyll') do it { should be_installed.by(:gem) } end describe package('jekyll') do it { should be_installed.by(:gem).with_version('1.1.1') } end describe package('ruby') do it { should be_installed.by(:rvm) } end describe package('ruby') do it { should be_installed.by(:rvm).with_version('2.2.0') } end describe package('bower') do it { should be_installed.by(:npm) } end describe package('bower') do it { should be_installed.by(:npm).with_version('0.9.2') } end describe package('mongo') do it { should be_installed.by(:pecl) } end describe package('mongo') do it { should be_installed.by(:pecl).with_version('1.4.1') } end describe package('XML_Util') do it { should be_installed.by(:pear).with_version('1.2.1') } end describe package('supervisor') do it { should be_installed.by(:pip).with_version('3.0') } end describe package('App::Ack') do it { should be_installed.by(:cpan) } end describe package('App::Ack') do it { should be_installed.by(:cpan).with_version('2.04') } end mizzy-serverspec-5c0c869/spec/type/base/php_config_spec.rb000066400000000000000000000016651500253164200237240ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } end describe php_config('default_mimetype') do let(:stdout) { 'text/html' } its(:value) { should_not eq 'text/plain' } end describe php_config('session.cache_expire') do let(:stdout) { '180' } its(:value) { should eq 180 } end describe php_config('session.cache_expire') do let(:stdout) { '180' } its(:value) { should_not eq 360 } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should match /application/ } end describe php_config('mbstring.http_output_conv_mimetypes') do let(:stdout) { 'application' } its(:value) { should_not match /html/ } end describe php_config('default_mimetype', :ini => '/etc/php5/php.ini') do let(:stdout) { 'text/html' } its(:value) { should eq 'text/html' } end mizzy-serverspec-5c0c869/spec/type/base/php_extension_spec.rb000066400000000000000000000003621500253164200244640ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe php_extension('tillext') do let(:exit_status) { 1 } it { should_not be_loaded } end describe php_extension('session') do let(:exit_status) { 0 } it { should be_loaded } end mizzy-serverspec-5c0c869/spec/type/base/port_spec.rb000066400000000000000000000011501500253164200225610ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it do expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) end end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(80) do it do expect{ should be_listening.on('') }.to raise_error(ArgumentError) end end describe port(53) do it { should be_listening.with('udp') } end mizzy-serverspec-5c0c869/spec/type/base/process_spec.rb000066400000000000000000000013741500253164200232630ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe process("memcached") do let(:stdout) { " 1407\n" } its(:pid) { should eq 1407 } end describe process("memcached") do let(:stdout) { "/usr/bin/memcached -m 14386 -p 11211 -u nobody -l 10.11.1.53 -c 30000\n" } its(:args) { should match /-c 30000\b/ } end describe process("memcached") do let(:stdout) { "nobody\n" } its(:user) { should eq "nobody" } end describe process("memcached") do let(:stdout) { "nobody\n" } its(:group) { should eq "nobody" } end describe process("memcached") do context "when running" do let(:stdout) { " 1407\n" } it { should be_running } end context "when not running" do let(:stdout) { " 1407\n" } it { should be_running } end end mizzy-serverspec-5c0c869/spec/type/base/routing_table_spec.rb000066400000000000000000000026601500253164200244420ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\n" } it { should have_entry( :destination => '192.168.100.0/24' ) } end describe routing_table do let(:exit_status) { 1 } it { should_not have_entry( :destination => '192.168.100.100/24' ) } end describe routing_table do let(:stdout) { "192.168.100.0/24 dev eth1 proto kernel scope link src 192.168.100.10 \r\n" } it do should have_entry( :destination => '192.168.100.0/24', :interface => 'eth1' ) end end describe routing_table do let(:stdout) { "192.168.200.0/24 via 192.168.200.1 dev eth0 \r\n" } it { should have_entry( :destination => '192.168.200.0/24' ) } it do should have_entry( :destination => '192.168.200.0/24', :gateway => '192.168.200.1' ) end it do should have_entry( :destination => '192.168.200.0/24', :gateway => '192.168.200.1', :interface => 'eth0' ) end end describe routing_table do let(:stdout) { "default via 10.0.2.2 dev eth0 \r\n" } it { should have_entry( :destination => 'default' ) } it do should have_entry( :destination => 'default', :gateway => '10.0.2.2' ) end it do should have_entry( :destination => 'default', :gateway => '10.0.2.2', :interface => 'eth0' ) end end mizzy-serverspec-5c0c869/spec/type/base/service_spec.rb000066400000000000000000000022411500253164200232370ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe service('sshd') do it { should be_running } end describe service('sshd') do let(:stdout) { "sshd is stopped\r\n" } it { should be_running } end describe service('sshd') do it { should be_running.under(:supervisor) } end describe service('sshd') do it { should be_running.under(:upstart) } end describe service('sshd') do it { should be_running.under(:daemontools) } end describe service('sshd') do it { expect { should be_running.under('not implemented') }.to raise_error(/is not implemented in Specinfra/) } end describe service('sshd') do let(:stdout) { "Process 'sshd'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by(:monit) } end describe service('tinc') do let(:stdout) { "Process 'tinc-myvpn'\r\n status running\r\n monitoring status monitored" } it { should be_monitored_by(:monit).with_name('tinc-myvpn') } end describe service('unicorn') do it { should be_monitored_by(:god) } end describe service('sshd') do it { expect { should be_monitored_by('not implemented') }.to raise_error(NotImplementedError) } end mizzy-serverspec-5c0c869/spec/type/base/user_spec.rb000066400000000000000000000026111500253164200225560ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'base' describe user('root') do it { should exist } end describe user('root') do it { should belong_to_group 'root' } end describe user('root') do it { should belong_to_primary_group 'root' } end describe user('root') do it { should have_uid 0 } end describe user('root') do its(:uid) { should == 0 } its(:uid) { should < 10 } end describe user('root') do it { should have_login_shell '/bin/bash' } end describe user('root') do it { should have_home_directory '/root' } end describe user('root') do it { should have_authorized_key 'ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH foo@bar.local' } end describe user('root') do let(:stdout) { "$1$T0aTw9NJ$NdMldLUQ8WqhlEEGToNzl/\n" } its(:encrypted_password) { should eq '$1$T0aTw9NJ$NdMldLUQ8WqhlEEGToNzl/' } end describe user('root') do its(:minimum_days_between_password_change) { should == 0 } end describe user('root') do its(:maximum_days_between_password_change) { should == 0 } end describe user('root') do it { should be_is_system_user } end mizzy-serverspec-5c0c869/spec/type/darwin/000077500000000000000000000000001500253164200206135ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/darwin/file_spec.rb000066400000000000000000000017211500253164200230720ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'darwin' describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end describe file('/etc/services') do let(:stdout) { "35435ea447c19f0ea5ef971837ab9ced\n" } its(:md5sum) { should eq '35435ea447c19f0ea5ef971837ab9ced' } end describe file('/etc/services') do let(:stdout) {"0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } its(:sha256sum) { should eq '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } end describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end mizzy-serverspec-5c0c869/spec/type/darwin/package_spec.rb000066400000000000000000000005531500253164200235500ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'darwin' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('homebrew') } end describe package('httpd') do it { should be_installed.by('pkgutil') } end mizzy-serverspec-5c0c869/spec/type/darwin/port_spec.rb000066400000000000000000000007631500253164200231440ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'darwin' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it do expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) end end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(53) do it { should be_listening.with('udp') } end mizzy-serverspec-5c0c869/spec/type/darwin/service_spec.rb000066400000000000000000000003671500253164200236200ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'darwin' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/debian/000077500000000000000000000000001500253164200205515ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/debian/package_spec.rb000066400000000000000000000010171500253164200235020ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'debian' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('apt').with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end mizzy-serverspec-5c0c869/spec/type/debian/service_spec.rb000066400000000000000000000002721500253164200235510ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'debian' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end mizzy-serverspec-5c0c869/spec/type/fedora/000077500000000000000000000000001500253164200205675ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/fedora/service_spec.rb000066400000000000000000000003661500253164200235730ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'fedora' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/fedora15/000077500000000000000000000000001500253164200207355ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/fedora15/service_spec.rb000066400000000000000000000004061500253164200237340ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'fedora', :release => 15 describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/fedora20/000077500000000000000000000000001500253164200207315ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/fedora20/service_spec.rb000066400000000000000000000004061500253164200237300ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'fedora', :release => 20 describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/freebsd/000077500000000000000000000000001500253164200207415ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/freebsd/file_spec.rb000066400000000000000000000010671500253164200232230ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'freebsd' describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end describe file('/sbin/nologin') do it { should be_linked_to '/usr/sbin/nologin' } end describe file('/etc/passwd') do let(:stdout) { Time.now.to_i.to_s } its(:mtime) { should > DateTime.now - 1 } end describe file('/etc/passwod') do let(:stdout) { 100.to_s } its(:size) { should > 0 } end mizzy-serverspec-5c0c869/spec/type/freebsd/package_spec.rb000066400000000000000000000006511500253164200236750ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'freebsd' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end mizzy-serverspec-5c0c869/spec/type/freebsd/port_spec.rb000066400000000000000000000007641500253164200232730ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'freebsd' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it do expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) end end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(53) do it { should be_listening.with('udp') } end mizzy-serverspec-5c0c869/spec/type/freebsd/service_spec.rb000066400000000000000000000001621500253164200237370ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'freebsd' describe service('sshd') do it { should be_enabled } end mizzy-serverspec-5c0c869/spec/type/freebsd10/000077500000000000000000000000001500253164200211025ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/freebsd10/package_spec.rb000066400000000000000000000006711500253164200240400ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'freebsd', :release => 10 describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end mizzy-serverspec-5c0c869/spec/type/gentoo/000077500000000000000000000000001500253164200206225ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/gentoo/package_spec.rb000066400000000000000000000001631500253164200235540ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'gentoo' describe package('httpd') do it { should be_installed } end mizzy-serverspec-5c0c869/spec/type/gentoo/service_spec.rb000066400000000000000000000002551500253164200236230ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'gentoo' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/linux/000077500000000000000000000000001500253164200204665ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/linux/bond_spec.rb000066400000000000000000000003071500253164200227470ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe bond('bond0') do it { should exist } end describe bond('bond0') do let(:stdout) { 'eth0' } it { should have_interface 'eth0' } end mizzy-serverspec-5c0c869/spec/type/linux/bridge_spec.rb000066400000000000000000000003071500253164200232610ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe bridge('br0') do it { should exist } end describe bridge('br0') do let(:stdout) { 'eth0' } it { should have_interface 'eth0' } end mizzy-serverspec-5c0c869/spec/type/linux/cgroup_spec.rb000066400000000000000000000003731500253164200233270ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should eq 1 } end describe cgroup('group1') do let(:stdout) { "1\r\n" } its('cpuset.cpus') { should_not eq 0 } end mizzy-serverspec-5c0c869/spec/type/linux/docker_container_pre_1_8_spec.rb000066400000000000000000000064471500253164200266660ustar00rootroot00000000000000# -*- coding: utf-8 -*- require 'spec_helper' require 'json' property[:os] = nil set :os, {:family => 'linux'} describe docker_container('c1') do it { should exist } end describe docker_container('c1 pre 1.8') do let(:stdout) { inspect_container } it { should be_running } it { should have_volume('/tmp', '/data') } it { should_not have_volume('/tmp', '/data-bad') } its(:inspection) { should include 'Driver' => 'aufs' } its(['Config.Cmd']) { should include '/bin/sh' } its(['HostConfig.PortBindings.80.[0].HostPort']) { should eq '8080' } end describe docker_container('restarting pre 1.8') do let(:stdout) do attrs = JSON.parse(inspect_container) attrs.first['State']['Restarting'] = true attrs.to_json end it { should_not be_running } end def inspect_container <<'EOS' [{ "Args": [], "Config": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "/bin/sh" ], "CpuShares": 0, "Cpuset": "", "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "65cd2e2d7963", "Image": "busybox", "Memory": 0, "MemorySwap": 0, "NetworkDisabled": false, "OnBuild": null, "OpenStdin": true, "PortSpecs": null, "StdinOnce": false, "Tty": true, "User": "", "Volumes": null, "WorkingDir": "" }, "Created": "2014-09-26T15:08:37.527931773Z", "Driver": "aufs", "ExecDriver": "native-0.2", "HostConfig": { "Binds": [ "/data:/tmp" ], "ContainerIDFile": "", "Dns": null, "DnsSearch": null, "Links": null, "LxcConf": [], "NetworkMode": "bridge", "PortBindings": { "80": [ { "HostIp": "", "HostPort": "8080" } ] }, "Privileged": false, "PublishAllPorts": false, "VolumesFrom": null }, "HostnamePath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hostname", "HostsPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hosts", "Id": "65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545", "Image": "e72ac664f4f0c6a061ac4ef332557a70d69b0c624b6add35f1c181ff7fff2287", "MountLabel": "", "Name": "/c1", "NetworkSettings": { "Bridge": "docker0", "Gateway": "172.17.42.1", "IPAddress": "172.17.0.24", "IPPrefixLen": 16, "PortMapping": null, "Ports": {} }, "Path": "/bin/sh", "ProcessLabel": "", "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/resolv.conf", "State": { "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "Paused": false, "Pid": 4123, "Running": true, "StartedAt": "2014-09-26T15:08:37.737780273Z" }, "Volumes": { "/tmp": "/data" }, "VolumesRW": { "/tmp": true } } ] EOS end mizzy-serverspec-5c0c869/spec/type/linux/docker_container_spec.rb000066400000000000000000000070261500253164200253430ustar00rootroot00000000000000# -*- coding: utf-8 -*- require 'spec_helper' require 'multi_json' property[:os] = nil set :os, {:family => 'linux'} describe docker_container('c1') do it { should exist } end describe docker_container('c1') do let(:stdout) { inspect_container } it { should be_running } it { should have_volume('/tmp', '/data') } it { should_not have_volume('/tmp', '/data-bad') } its(:inspection) { should include 'Driver' => 'aufs' } its(['Config.Cmd']) { should include '/bin/sh' } its(['HostConfig.PortBindings.80.[0].HostPort']) { should eq '8080' } its(['HostConfig.PortBindings.80.[1].HostPort']) { should eq '8081' } end describe docker_container('restarting') do let(:stdout) do attrs = MultiJson.load(inspect_container) attrs.first['State']['Restarting'] = true attrs.to_json end it { should_not be_running } end def inspect_container <<'EOS' [{ "Args": [], "Config": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "/bin/sh" ], "CpuShares": 0, "Cpuset": "", "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "65cd2e2d7963", "Image": "busybox", "Memory": 0, "MemorySwap": 0, "NetworkDisabled": false, "OnBuild": null, "OpenStdin": true, "PortSpecs": null, "StdinOnce": false, "Tty": true, "User": "", "Volumes": null, "WorkingDir": "" }, "Created": "2014-09-26T15:08:37.527931773Z", "Driver": "aufs", "ExecDriver": "native-0.2", "HostConfig": { "Binds": [ "/data:/tmp" ], "ContainerIDFile": "", "Dns": null, "DnsSearch": null, "Links": null, "LxcConf": [], "NetworkMode": "bridge", "PortBindings": { "80": [ { "HostIp": "", "HostPort": "8080" }, { "HostIp": "", "HostPort": "8081" } ] }, "Privileged": false, "PublishAllPorts": false, "VolumesFrom": null }, "HostnamePath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hostname", "HostsPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/hosts", "Id": "65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545", "Image": "e72ac664f4f0c6a061ac4ef332557a70d69b0c624b6add35f1c181ff7fff2287", "MountLabel": "", "Name": "/c1", "NetworkSettings": { "Bridge": "docker0", "Gateway": "172.17.42.1", "IPAddress": "172.17.0.24", "IPPrefixLen": 16, "PortMapping": null, "Ports": {} }, "Path": "/bin/sh", "ProcessLabel": "", "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/65cd2e2d7963bacaecda2d7fcd89499010bc0d38d70bce5ad0af7112a94a4545/resolv.conf", "State": { "ExitCode": 0, "FinishedAt": "0001-01-01T00:00:00Z", "Paused": false, "Pid": 4123, "Running": true, "StartedAt": "2014-09-26T15:08:37.737780273Z" }, "Mounts": [ { "Source": "/data", "Destination": "/tmp", "Mode": "", "RW": true } ] } ] EOS end mizzy-serverspec-5c0c869/spec/type/linux/docker_image_spec.rb000066400000000000000000000050371500253164200244430ustar00rootroot00000000000000# -*- coding: utf-8 -*- require 'spec_helper' property[:os] = nil set :os, {:family => 'linux'} describe docker_image('busybox:latest') do it { should exist } end describe docker_image('busybox:latest') do let(:stdout) { inspect_image } its(:inspection) { should include 'Architecture' => 'amd64' } its(['Architecture']) { should eq 'amd64' } its(['Config.Cmd']) { should include '/bin/sh' } end def inspect_image <<'EOS' [{ "Architecture": "amd64", "Author": "Jérôme Petazzoni \u003cjerome@docker.com\u003e", "Comment": "", "Config": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "/bin/sh" ], "CpuShares": 0, "Cpuset": "", "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "88f18f678e5d", "Image": "e433a6c5b276a31aa38bf6eaba9cd1cfd69ea33f706ed72b3f20bafde5cd8644", "Memory": 0, "MemorySwap": 0, "NetworkDisabled": false, "OnBuild": [], "OpenStdin": false, "PortSpecs": null, "StdinOnce": false, "Tty": false, "User": "", "Volumes": null, "WorkingDir": "" }, "Container": "8e73b239682fe73338323d9af83d3c5aa5bb7d22a3fe84cbfcf5f47e756d6636", "ContainerConfig": { "AttachStderr": false, "AttachStdin": false, "AttachStdout": false, "Cmd": [ "/bin/sh", "-c", "#(nop) CMD [/bin/sh]" ], "CpuShares": 0, "Cpuset": "", "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "88f18f678e5d", "Image": "e433a6c5b276a31aa38bf6eaba9cd1cfd69ea33f706ed72b3f20bafde5cd8644", "Memory": 0, "MemorySwap": 0, "NetworkDisabled": false, "OnBuild": [], "OpenStdin": false, "PortSpecs": null, "StdinOnce": false, "Tty": false, "User": "", "Volumes": null, "WorkingDir": "" }, "Created": "2014-10-01T20:46:08.914288461Z", "DockerVersion": "1.2.0", "Id": "e72ac664f4f0c6a061ac4ef332557a70d69b0c624b6add35f1c181ff7fff2287", "Os": "linux", "Parent": "e433a6c5b276a31aa38bf6eaba9cd1cfd69ea33f706ed72b3f20bafde5cd8644", "Size": 0 } ] EOS end mizzy-serverspec-5c0c869/spec/type/linux/file_spec.rb000066400000000000000000000010541500253164200227440ustar00rootroot00000000000000require 'spec_helper' property[:os] = nil set :os, {:family => 'linux'} describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end describe file('/tmp') do it { should be_immutable } end describe file('/tmp') do let(:exit_status) { 0 } let(:stdout) { 'unconfined_u:unconfined_r:unconfined_t:s0' } its(:selinux_label) { should eq 'unconfined_u:unconfined_r:unconfined_t:s0' } end mizzy-serverspec-5c0c869/spec/type/linux/fstab_spec.rb000066400000000000000000000012521500253164200231240ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe fstab do let(:stdout) { "/dev/sda1 /mnt ext4 ro,errors=remount-ro,barrier=0 0 2\r\n" } it { should have_entry( :mount_point => '/mnt' ) } end describe fstab do let(:exit_status) { 1 } it { should_not have_entry( :mount_point => '/mnt' ) } end describe fstab do let(:stdout) { "/dev/sda1 /mnt ext4 ro,errors=remount-ro,barrier=0 0 2\r\n" } it do should have_entry( :device => '/dev/sda1', :mount_point => '/mnt', :type => 'ext4', :options => { :ro => true, :errors => 'remount-ro', :barrier => 0 }, :dump => 0, :pass => 2 ) end end mizzy-serverspec-5c0c869/spec/type/linux/interface_spec.rb000066400000000000000000000020751500253164200237710ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe interface('eth0') do let(:stdout) { '1000' } its(:speed) { should eq 1000 } end describe interface('eth0') do let(:stdout) { '1500' } its(:mtu) { should eq 1500 } end describe interface('eth0') do it { should have_ipv4_address('192.168.10.10') } end describe interface('eth0') do it { should have_ipv4_address('192.168.10.10/24') } end describe interface('eth0') do it { should have_ipv6_address('2001:0db8:bd05:01d2:288a:1fc0:0001:10ee') } end describe interface('eth1') do let(:stdout) { "1.2.3.4/1\r\n" } its(:ipv4_address) { should match(/^[\d.]+\/\d+$/) } end describe interface('eth1') do let(:stdout) { "2001:db8::1234/1\r\n" } its(:ipv6_address) { should match(/^[a-f\d:]+\/\d+$/i) } end describe interface('eth0') do let(:stdout) { 'up' } it { should be_up } end describe interface('invalid-interface') do let(:stdout) { '1000' } its(:speed) { should_not eq 100 } end describe interface('invalid-interface') do let(:stdout) { '9001' } its(:mtu) { should_not eq 1500 } end mizzy-serverspec-5c0c869/spec/type/linux/ip6tables_spec.rb000066400000000000000000000003631500253164200237200ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe ip6tables do it { should have_rule '-P INPUT ACCEPT' } end describe ip6tables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } end mizzy-serverspec-5c0c869/spec/type/linux/iptables_spec.rb000066400000000000000000000003511500253164200236270ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe iptables do it { should have_rule '-P INPUT ACCEPT' } end describe iptables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } end mizzy-serverspec-5c0c869/spec/type/linux/kernel_module_spec.rb000066400000000000000000000001621500253164200246510ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe kernel_module('lp') do it { should be_loaded } end mizzy-serverspec-5c0c869/spec/type/linux/kvm_guest_spec.rb000066400000000000000000000003261500253164200240320ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe kvm('ct01') do it { should exist } end describe kvm('ct01') do it { should be_running } end describe kvm('ct01') do it { should be_enabled } end mizzy-serverspec-5c0c869/spec/type/linux/linux_audit_system_spec.rb000066400000000000000000000047761500253164200257740ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe linux_audit_system do let(:stdout) { out_auditctl1_1 } it { should be_enabled } end describe linux_audit_system do let(:stdout) { out_auditctl1_2 } it { should_not be_enabled } end describe linux_audit_system do let(:stdout) { out_auditctl1_1 } it { should be_running } end describe linux_audit_system do let(:stdout) { out_auditctl1_3 } it { should_not be_running } end describe linux_audit_system do let(:stdout) { out_auditctl1_4 } it { should_not be_running } end describe linux_audit_system do let(:stdout) { out_auditctl2_1 } it { should be_enabled } end describe linux_audit_system do let(:stdout) { out_auditctl2_2 } it { should_not be_enabled } end describe linux_audit_system do let(:stdout) { out_auditctl2_1 } it { should be_running } end describe linux_audit_system do let(:stdout) { out_auditctl2_3 } it { should_not be_running } end describe linux_audit_system do let(:stdout) { out_auditctl2_4 } it { should_not be_running } end describe linux_audit_system do let(:stdout) { '-a -w /etc/sysconfig -p wa -k test' } its(:rules) { should match %r!-w /etc/sysconfig.*-k test! } end describe linux_audit_system do let(:stdout) { 'test' } its(:rules) { should eq 'test' } its(:rules) { should match /es/ } its(:rules) { should_not match /ab/ } end # variants of auditctl -s output for different versions def out_auditctl1_1 "AUDIT_STATUS: enabled=1 flag=1 pid=881 rate_limit=0 backlog_limit=320 lost=0 backlog=0" end def out_auditctl1_2 "AUDIT_STATUS: enabled=0 flag=1 pid=881 rate_limit=0 backlog_limit=320 lost=0 backlog=0" end def out_auditctl1_3 "AUDIT_STATUS: enabled=1 flag=1 pid=0 rate_limit=0 backlog_limit=320 lost=0 backlog=0" end def out_auditctl1_4 "AUDIT_STATUS: enabled=1 flag=1 pid= rate_limit=0 backlog_limit=320 lost=0 backlog=0" end def out_auditctl2_1 < 'linux' describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do let(:stdout) { "1\n" } its(:value) { should eq 1 } end describe linux_kernel_parameter('net.ipv4.tcp_syncookies') do let(:stdout) { "1\n" } its(:value) { should_not eq 2 } end describe linux_kernel_parameter('kernel.osrelease') do let(:stdout) { "2.6.32-131.0.15.el6.x86_64\n" } its(:value) { should eq "2.6.32-131.0.15.el6.x86_64" } end describe linux_kernel_parameter('kernel.osrelease') do let(:stdout) { "2.6.32-131.0.15.el6.x86_64\n" } its(:value) { should_not eq "2.6.32-131.0.15.el6.i386" } end describe linux_kernel_parameter('net.ipv4.tcp_wmem') do let(:stdout) { "4096 16384 4194304\n" } its(:value) { should match /16384/ } end describe linux_kernel_parameter('net.ipv4.tcp_wmem') do let(:stdout) { "4096 16384 4194304\n" } its(:value) { should_not match /123456/ } end mizzy-serverspec-5c0c869/spec/type/linux/lxc_container_spec.rb000066400000000000000000000002371500253164200246570ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe lxc('ct01') do it { should exist } end describe lxc('ct01') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/linux/selinux_module_spec.rb000066400000000000000000000004501500253164200250600ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe selinux_module('bootloader') do it { should be_installed } end describe selinux_module('bootloader') do it { should be_installed.with_version('1.10') } end describe selinux_module('bootloader') do it { should be_enabled } end mizzy-serverspec-5c0c869/spec/type/linux/selinux_spec.rb000066400000000000000000000005551500253164200235210ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe selinux do it { should be_enforcing } end describe selinux do it { should be_enforcing.with_policy('mls') } end describe selinux do it { should be_permissive } end describe selinux do it { should be_permissive.with_policy('targeted') } end describe selinux do it { should be_disabled } end mizzy-serverspec-5c0c869/spec/type/linux/x509_certificate_spec.rb000066400000000000000000000042001500253164200250700ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe x509_certificate('test.pem') do let(:exit_status) { 0 } it { should be_certificate } end describe x509_certificate('test.pem') do let(:exit_status) { 1 } it { should_not be_certificate } end describe x509_certificate('test-openssl-1.0.pem') do let(:stdout) { sample_subj_openssl_1_0 } its(:subject) { should eq 'O = some, OU = thing' } end describe x509_certificate('test-openssl-1.1.pem') do let(:stdout) { sample_subj_openssl_1_1 } its(:subject) { should eq 'O = some, OU = thing' } end describe x509_certificate('test-openssl-1.0.pem') do let(:stdout) { sample_issuer_openssl_1_0 } its(:issuer) { should eq 'O = some, OU = issuer' } end describe x509_certificate('test-openssl-1.1.pem') do let(:stdout) { sample_issuer_openssl_1_1 } its(:issuer) { should eq 'O = some, OU = issuer' } end describe x509_certificate('test.pem') do let(:stdout) { sample_validity } it { should be_valid } its(:validity_in_days) { should be >= 1000 } end describe x509_certificate('test.pem') do let(:stdout) { sample_validity2 } it { should_not be_valid } end describe x509_certificate('test.pem') do let(:stdout) { sample_san } its(:subject_alt_names) { should eq %w[DNS:*.example.com DNS:www.example.net IP:192.0.2.10] } end def sample_subj_openssl_1_0 <<'EOS' subject= /O=some/OU=thing EOS end def sample_subj_openssl_1_1 <<'EOS' subject=O = some, OU = thing EOS end def sample_issuer_openssl_1_0 <<'EOS' issuer= /O=some/OU=issuer EOS end def sample_issuer_openssl_1_1 <<'EOS' issuer=O = some, OU = issuer EOS end def sample_validity <<'EOS' notBefore=Jul 1 11:11:00 2000 GMT notAfter=Jul 1 11:11:00 2050 GMT EOS end def sample_validity2 <<'EOS' notBefore=Jul 1 11:11:00 2000 GMT notAfter=Jul 1 11:11:00 2010 GMT EOS end def sample_san <<'EOS' Certificate: Data: Version: 3 (0x2) X509v3 extensions: X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication X509v3 Subject Alternative Name: DNS:*.example.com, DNS:www.example.net, IP:192.0.2.10 EOS end mizzy-serverspec-5c0c869/spec/type/linux/x509_private_key_spec.rb000066400000000000000000000012341500253164200251340ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe x509_private_key('key.pem') do let(:exit_status) { 0 } let(:stdout) { 'RSA key ok' } it { should be_valid } end describe x509_private_key('key.pem') do let(:exit_status) { 1 } let(:stdout) { 'RSA key ok' } it { should_not be_valid } end describe x509_private_key('key.pem') do let(:exit_status) { 0 } it { should be_encrypted } end describe x509_private_key('key.pem') do let(:exit_status) { 1 } it { should_not be_encrypted } end describe x509_private_key('key.pem') do let(:exit_status) { 0 } let(:stdout) { 'SHA1SUM' } it { should have_matching_certificate('cert.pem') } endmizzy-serverspec-5c0c869/spec/type/linux/zfs_spec.rb000066400000000000000000000004521500253164200226300ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'linux' describe zfs('rpool') do it { should exist } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } end mizzy-serverspec-5c0c869/spec/type/nixos/000077500000000000000000000000001500253164200204675ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/nixos/package_spec.rb000066400000000000000000000004661500253164200234270ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'nixos' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('nix').with_version('2.2.15-28.el6') } end mizzy-serverspec-5c0c869/spec/type/nixos/service_spec.rb000066400000000000000000000002131500253164200234620ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'nixos' describe service('sshd') do it { should be_enabled } it { should be_running } end mizzy-serverspec-5c0c869/spec/type/openbsd/000077500000000000000000000000001500253164200207615ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/openbsd/file_spec.rb000066400000000000000000000073221500253164200232430ustar00rootroot00000000000000require 'spec_helper' set :os, {:family => 'openbsd'} describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } end describe file('/') do it { should be_mounted } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :rw => true } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :mode => 620 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :rw => false } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :mode => 600 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_r00t' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, :bind => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_roooooooooot', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/etc/services') do let(:stdout) { "35435ea447c19f0ea5ef971837ab9ced\n" } its(:md5sum) { should eq '35435ea447c19f0ea5ef971837ab9ced' } end describe file('/etc/services') do let(:stdout) {"0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } its(:sha256sum) { should eq '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } end mizzy-serverspec-5c0c869/spec/type/openbsd/interface_spec.rb000066400000000000000000000012651500253164200242640ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'openbsd' describe interface('eth0') do let(:stdout) { '1000' } its(:speed) { should eq 1000 } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10") } end describe interface('eth0') do it { should have_ipv4_address("192.168.10.10/24") } end describe interface('eth1') do let(:stdout) { "1.2.3.4/1\r\n" } its(:ipv4_address) { should match(/^[\d.]+\/\d+$/) } end describe interface('eth1') do let(:stdout) { "2001:db8::1234/1\r\n" } its(:ipv6_address) { should match(/^[a-f\d:]+\/\d+$/i) } end describe interface('invalid-interface') do let(:stdout) { '1000' } its(:speed) { should_not eq 100 } end mizzy-serverspec-5c0c869/spec/type/openbsd/mail_alias_spec.rb000066400000000000000000000002001500253164200244030ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'openbsd' describe mail_alias('daemon') do it { should be_aliased_to "root" } end mizzy-serverspec-5c0c869/spec/type/openbsd/package_spec.rb000066400000000000000000000003211500253164200237070ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'openbsd' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end mizzy-serverspec-5c0c869/spec/type/openbsd/port_spec.rb000066400000000000000000000001541500253164200233040ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'openbsd' describe port(80) do it { should be_listening } end mizzy-serverspec-5c0c869/spec/type/openbsd/service_spec.rb000066400000000000000000000002571500253164200237640ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'openbsd' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/openbsd/user_spec.rb000066400000000000000000000003131500253164200232730ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'openbsd' describe user('root') do it { should have_login_shell '/bin/bash' } end describe user('root') do it { should have_home_directory '/root' } end mizzy-serverspec-5c0c869/spec/type/opensuse/000077500000000000000000000000001500253164200211705ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/opensuse/service_spec.rb000066400000000000000000000003711500253164200241700ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'opensuse' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end describe service('sshd') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/plamo/000077500000000000000000000000001500253164200204375ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/plamo/package_spec.rb000066400000000000000000000001631500253164200233710ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'plamo' describe package('httpd') do it { should be_installed } end mizzy-serverspec-5c0c869/spec/type/plamo/service_spec.rb000066400000000000000000000001601500253164200234330ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'plamo' describe service('sshd') do it { should be_enabled } end mizzy-serverspec-5c0c869/spec/type/redhat/000077500000000000000000000000001500253164200205765ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/redhat/file_spec.rb000066400000000000000000000005171500253164200230570ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'redhat' describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end describe file('/tmp') do it { should be_immutable } end mizzy-serverspec-5c0c869/spec/type/redhat/package_spec.rb000066400000000000000000000010171500253164200235270ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'redhat' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('rpm').with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end mizzy-serverspec-5c0c869/spec/type/redhat/service_spec.rb000066400000000000000000000002721500253164200235760ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'redhat' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end mizzy-serverspec-5c0c869/spec/type/redhat/yumrepo_spec.rb000066400000000000000000000002471500253164200236400ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'redhat' describe yumrepo('epel') do it { should exist } end describe yumrepo('epel') do it { should be_enabled } end mizzy-serverspec-5c0c869/spec/type/redhat5/000077500000000000000000000000001500253164200206635ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/redhat5/iptables_spec.rb000066400000000000000000000003711500253164200240260ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'redhat', :release => 5 describe iptables do it { should have_rule '-P INPUT ACCEPT' } end describe iptables do it { should have_rule('-P INPUT ACCEPT').with_table('mangle').with_chain('INPUT') } end mizzy-serverspec-5c0c869/spec/type/redhat7/000077500000000000000000000000001500253164200206655ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/redhat7/service_spec.rb000066400000000000000000000002331500253164200236620ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'redhat', :release => 7 describe service('sshd') do it { should be_enabled } it { should be_running } end mizzy-serverspec-5c0c869/spec/type/smartos/000077500000000000000000000000001500253164200210175ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/smartos/package_spec.rb000066400000000000000000000006511500253164200237530ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'smartos' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end mizzy-serverspec-5c0c869/spec/type/smartos/service_spec.rb000066400000000000000000000003731500253164200240210ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'smartos' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_running } end describe service('sshd') do it { should have_property :foo => 'bar' } end mizzy-serverspec-5c0c869/spec/type/solaris/000077500000000000000000000000001500253164200210035ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/solaris/cron_spec.rb000066400000000000000000000003621500253164200233040ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe cron do it { should have_entry '* * * * * /usr/local/bin/batch.sh' } end describe cron do it { should have_entry('* * * * * /usr/local/bin/batch.sh').with_user('root') } end mizzy-serverspec-5c0c869/spec/type/solaris/file_spec.rb000066400000000000000000000004251500253164200232620ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe file('/tmp') do it { should be_readable.by_user('mail') } end describe file('/tmp') do it { should be_writable.by_user('mail') } end describe file('/tmp') do it { should be_executable.by_user('mail') } end mizzy-serverspec-5c0c869/spec/type/solaris/group_spec.rb000066400000000000000000000001571500253164200235010ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe group('root') do it { should have_gid 0 } end mizzy-serverspec-5c0c869/spec/type/solaris/host_spec.rb000066400000000000000000000006741500253164200233260ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe host('127.0.0.1') do it { should be_reachable } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'icmp', :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'tcp', :port => 22, :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'udp', :port => 53, :timeout=> 1) } end mizzy-serverspec-5c0c869/spec/type/solaris/ipfilter_spec.rb000066400000000000000000000002041500253164200241540ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe ipfilter do it { should have_rule 'pass in quick on lo0 all' } end mizzy-serverspec-5c0c869/spec/type/solaris/ipnat_spec.rb000066400000000000000000000002161500253164200234540ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe ipnat do it { should have_rule 'map net1 192.168.0.0/24 -> 0.0.0.0/32' } end mizzy-serverspec-5c0c869/spec/type/solaris/package_spec.rb000066400000000000000000000001641500253164200237360ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe package('httpd') do it { should be_installed } end mizzy-serverspec-5c0c869/spec/type/solaris/port_spec.rb000066400000000000000000000011451500253164200233270ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with('tcp') } end describe port(80) do it do expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) end end describe port(80) do it { should be_listening.on('127.0.0.1') } end describe port(80) do it do expect{ should be_listening.on('') }.to raise_error(ArgumentError) end end describe port(123) do it { should be_listening.with('udp') } end mizzy-serverspec-5c0c869/spec/type/solaris/service_spec.rb000066400000000000000000000003731500253164200240050ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_running } end describe service('sshd') do it { should have_property :foo => 'bar' } end mizzy-serverspec-5c0c869/spec/type/solaris/user_spec.rb000066400000000000000000000004201500253164200233140ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe user('root') do it { should belong_to_group 'root' } end describe user('root') do it { should have_login_shell '/bin/bash' } end describe user('root') do it { should have_home_directory '/root' } end mizzy-serverspec-5c0c869/spec/type/solaris/zfs_spec.rb000066400000000000000000000004541500253164200231470ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris' describe zfs('rpool') do it { should exist } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool' } end describe zfs('rpool') do it { should have_property 'mountpoint' => '/rpool', 'compression' => 'off' } end mizzy-serverspec-5c0c869/spec/type/solaris10/000077500000000000000000000000001500253164200211445ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/solaris10/file_spec.rb000066400000000000000000000166771500253164200234430ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris', :release => 10 describe file('/etc/ssh/sshd_config') do it { should be_file } end describe file('/etc/ssh') do it { should be_directory } end describe file('/var/run/unicorn.sock') do it { should be_socket } end describe file('/etc/ssh/sshd_config') do it { should contain 'This is the sshd server system-wide configuration file' } end describe file('/etc/ssh/sshd_config') do it { should contain /^This is the sshd server system-wide configuration file/ } end describe file('Gemfile') do it { should contain('rspec').from(/^group :test do/).to(/^end/) } end describe file('Gemfile') do it { should contain('rspec').after(/^group :test do/) } end describe file('Gemfile') do it { should contain('rspec').before(/^end/) } end describe file('/etc/passwd') do it { should be_mode 644 } end describe file('/etc/passwd') do it { should be_owned_by 'root' } end describe file('/etc/passwd') do it { should be_grouped_into 'root' } end describe file('/etc/pam.d/system-auth') do it { should be_linked_to '/etc/pam.d/system-auth-ac' } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_readable } end describe file('/dev') do let(:stdout) { "333\r\n" } it { should_not be_readable } end describe file('/dev') do let(:stdout) { "400\r\n" } it { should be_readable.by('owner') } end describe file('/dev') do let(:stdout) { "044\r\n" } it { should_not be_readable.by('owner') } end describe file('/dev') do let(:stdout) { "040\r\n" } it { should be_readable.by('group') } end describe file('/dev') do let(:stdout) { "404\r\n" } it { should_not be_readable.by('group') } end describe file('/dev') do let(:stdout) { "044\r\n" } it { should be_readable.by('others') } end describe file('/dev') do let(:stdout) { "443\r\n" } it { should_not be_readable.by('others') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_writable } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable } end describe file('/dev') do let(:stdout) { "200\r\n" } it { should be_writable.by('owner') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('owner') } end describe file('/dev') do let(:stdout) { "030\r\n" } it { should be_writable.by('group') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('group') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should be_writable.by('others') } end describe file('/dev') do let(:stdout) { "555\r\n" } it { should_not be_writable.by('others') } end describe file('/dev') do let(:stdout) { "755\r\n" } it { should be_executable } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable } end describe file('/dev') do let(:stdout) { "100\r\n" } it { should be_executable.by('owner') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('owner') } end describe file('/dev') do let(:stdout) { "070\r\n" } it { should be_executable.by('group') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('group') } end describe file('/dev') do let(:stdout) { "001\r\n" } it { should be_executable.by('others') } end describe file('/dev') do let(:stdout) { "666\r\n" } it { should_not be_executable.by('others') } end describe file('/') do it { should be_mounted } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :rw => true } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :options => { :mode => 620 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :rw => false } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :options => { :mode => 600 } ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'xfs', :device => '/dev/mapper/VolGroup-lv_root' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it { should_not be_mounted.with( :type => 'ext4', :device => '/dev/mapper/VolGroup-lv_r00t' ) } end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, :mode => 620, :bind => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_root', :type => 'ext4', :options => { :rw => true, } ) end end describe file('/') do let(:stdout) { "/dev/mapper/VolGroup-lv_root on / type ext4 (rw,mode=620)\r\n" } it do should_not be_mounted.only_with( :device => '/dev/mapper/VolGroup-lv_roooooooooot', :type => 'ext4', :options => { :rw => true, :mode => 620, } ) end end describe file('/etc/services') do let(:stdout) { "35435ea447c19f0ea5ef971837ab9ced\n" } its(:md5sum) { should eq '35435ea447c19f0ea5ef971837ab9ced' } end describe file('/etc/services') do let(:stdout) {"0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a" } its(:md5sum) { should eq '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' } end describe file('/etc/passwd') do let(:stdout) {< 'solaris', :release => 10 describe group('root') do it { should exist } end mizzy-serverspec-5c0c869/spec/type/solaris10/host_spec.rb000066400000000000000000000005341500253164200234620ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris', :release => 10 describe host('127.0.0.1') do it { should be_reachable } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'icmp', :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => 'tcp', :port => 22, :timeout=> 1) } end mizzy-serverspec-5c0c869/spec/type/solaris10/package_spec.rb000066400000000000000000000002051500253164200240730ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris', :release => 10 describe package('httpd') do it { should be_installed } end mizzy-serverspec-5c0c869/spec/type/solaris10/user_spec.rb000066400000000000000000000002321500253164200234560ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'solaris', :release => 10 describe user('root') do it { should have_authorized_key 'XXXXXXXXXXXXXXX' } end mizzy-serverspec-5c0c869/spec/type/suse/000077500000000000000000000000001500253164200203065ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/suse/package_spec.rb000066400000000000000000000010151500253164200232350ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'suse' describe package('httpd') do it { should be_installed } end describe package('httpd') do it { should be_installed.with_version('2.2.15-28.el6') } end describe package('httpd') do it { should be_installed.by('rpm').with_version('2.2.15-28.el6') } end describe package('httpd') do let(:stdout) { "2.2.15\n" } its(:version) { should eq '2.2.15' } its(:version) { should > '2.2.14' } its(:version) { should < '2.2.16' } its(:version) { should > '2.2.9' } end mizzy-serverspec-5c0c869/spec/type/suse/service_spec.rb000066400000000000000000000002701500253164200233040ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'suse' describe service('sshd') do it { should be_enabled } end describe service('sshd') do it { should be_enabled.with_level(4) } end mizzy-serverspec-5c0c869/spec/type/ubuntu/000077500000000000000000000000001500253164200206515ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/ubuntu/ppa_spec.rb000066400000000000000000000002711500253164200227700ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'ubuntu' describe ppa('username/ppa-name') do it { should exist } end describe ppa('username/ppa-name') do it { should be_enabled } end mizzy-serverspec-5c0c869/spec/type/ubuntu/service_spec.rb000066400000000000000000000001601500253164200236450ustar00rootroot00000000000000require 'spec_helper' set :os, :family => 'ubuntu' describe service('sshd') do it { should be_running } end mizzy-serverspec-5c0c869/spec/type/windows/000077500000000000000000000000001500253164200210215ustar00rootroot00000000000000mizzy-serverspec-5c0c869/spec/type/windows/command_spec.rb000066400000000000000000000034511500253164200240010ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe command('test_cmd /test/path/file') do let(:stdout) { "test output 1.2.3\r\n" } its(:stdout) { should match /test output 1.2.3/ } end describe 'complete matching of stdout' do context command('test_cmd /test/path/file') do let(:stdout) { "foocontent-should-be-includedbar\r\n" } its(:stdout) { should_not eq 'content-should-be-included' } end end describe 'regexp matching of stdout' do context command('test_cmd /test/path/file') do let(:stdout) { "test output 1.2.3\r\n" } its(:stdout) { should match /1\.2\.3/ } end end describe command('test_cmd /test/path/file') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should match /No such file or directory/ } end describe 'complete matching of stderr' do context command('test_cmd /test/path/file') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should_not eq 'file' } end end describe 'regexp matching of stderr' do context command('test_cmd /test/path/file') do let(:stderr) { "No such file or directory\r\n" } its(:stderr) { should match /file/ } end end describe command('test_cmd /test/path/file') do its(:exit_status) { should eq 0 } end describe command('dir "c:\"') do let(:stdout) { < 'windows' describe windows_feature('Minesweeper') do it{ should be_installed } end describe windows_feature('IIS-Webserver') do it{ should be_installed.by(:dism) } end describe windows_feature('Web-Webserver') do it{ should be_installed.by(:powershell) } end mizzy-serverspec-5c0c869/spec/type/windows/file_spec.rb000066400000000000000000000055671500253164200233140ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe file('/some/valid/file') do it { should be_file } end describe file('/some/valid/folder') do it { should be_directory } end describe file('/some/file') do it { should contain 'search text' } end describe file('/some/file') do it { should contain /^search text/ } end describe file('Gemfile') do it { should contain('rspec').from(/^group :test do/).to(/^end/) } end describe file('Gemfile') do it { should contain('rspec').after(/^group :test do/) } end describe file('Gemfile') do it { should contain('rspec').before(/end/) } end describe file('/some/file') do it { should be_readable } end describe file('/some/file') do it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do ['owner', 'group', 'others'].each do |access| expect { should be_readable.by(access) }.to raise_error(RuntimeError) end end end describe file('/some/file') do it { should be_readable.by('test.identity') } end describe file('/some/file') do it { should be_readable.by_user('test.identity') } end describe file('/some/file') do it { should be_writable } end describe file('/some/file') do it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do ['owner', 'group', 'others'].each do |access| expect { should be_writable.by(access) }.to raise_error(RuntimeError) end end end describe file('/some/file') do it { should be_writable.by('test.identity') } end describe file('/some/file') do it { should be_writable.by_user('test.identity') } end describe file('/some/file') do it { should be_executable } end describe file('/some/file') do it "should raise error if trying to check access by 'owner' or 'group' or 'others'" do ['owner', 'group', 'others'].each do |access| expect { should be_executable.by(access) }.to raise_error(RuntimeError) end end end describe file('/some/file') do it { should be_executable.by('test.identity') } end describe file('/some/file') do it { should be_executable.by_user('test.identity') } end describe file('/some/file') do it { should be_version 1 } end describe file('/some/test/file') do it "should raise error if command is not implemented" do { :be_socket => [], :be_mode => 644, :be_grouped_into => 'root', :be_linked_to => '/some/other/file', :be_mounted => [] }.each do |method, args| expect { should self.send(method, *args) }.to raise_error(NotImplementedError) end end it "should raise error if command is not defined" do { :match_md5checksum => '35435ea447c19f0ea5ef971837ab9ced', :match_sha256checksum => '0c3feee1353a8459f8c7d84885e6bc602ef853751ffdbce3e3b6dfa1d345fc7a' }.each do |method, args| expect { should self.send(method, *args) }.to raise_error(NoMethodError) end end end mizzy-serverspec-5c0c869/spec/type/windows/group_spec.rb000066400000000000000000000007121500253164200235140ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe group('test.group') do it { should exist } end describe group('test.domain\test.group') do it { should exist } end describe group('test.group') do it "should raise error if command is not supported" do { :have_gid => [nil], }.each do |method, args| expect { should self.send(method, *args) }.to raise_error(NotImplementedError) end end end mizzy-serverspec-5c0c869/spec/type/windows/host_spec.rb000066400000000000000000000012501500253164200233330ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe host('127.0.0.1') do it { should be_resolvable } end describe host('127.0.0.1') do it { should be_resolvable.by('hosts') } end describe host('127.0.0.1') do it { should be_resolvable.by('dns') } end describe host('127.0.0.1') do it { should be_reachable } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "icmp", :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "tcp", :port => 22, :timeout=> 1) } end describe host('127.0.0.1') do it { should be_reachable.with(:proto => "udp", :port => 53, :timeout=> 1) } end mizzy-serverspec-5c0c869/spec/type/windows/hot_fix_spec.rb000066400000000000000000000007161500253164200240240ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe windows_hot_fix('DESCRIPTION-OR-KB-ID') do it { should be_installed } end describe windows_hot_fix('DESCRIPTION') do it { should be_installed.with_version('KB-ID') } end describe windows_hot_fix('DESCRIPTION_WITH_KB123456789_INLINED') do it { should be_installed } end describe windows_hot_fix('DESCRIPTION_WITH_SUFFIX_KB123456789') do it { should be_installed } end mizzy-serverspec-5c0c869/spec/type/windows/iis_app_pool_spec.rb000066400000000000000000000007331500253164200250400ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe iis_app_pool('Default App Pool') do it { should exist } it { should have_dotnet_version('2.0') } it { should have_32bit_enabled } it { should have_idle_timeout(5) } it { should have_identity_type('foo') } it { should have_periodic_restart(60) } it { should have_user_profile_enabled } it { should have_username('user') } it { should have_managed_pipeline_mode('mode') } end mizzy-serverspec-5c0c869/spec/type/windows/iis_webisite_spec.rb000066400000000000000000000011171500253164200250370ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe iis_website('Default Website') do it { should exist } it { should be_enabled } it { should be_running } it { should be_in_app_pool('Default App Pool') } it { should have_physical_path('C:\\inetpub\\www') } it { should have_site_bindings('port').with_protocol('protocol').with_ipaddress('ipaddress').with_host_header('host_header') } it { should have_virtual_dir('vdir').with_path('path') } it { should have_site_application('app').with_pool('pool').with_physical_path('physical_path') } end mizzy-serverspec-5c0c869/spec/type/windows/package_spec.rb000066400000000000000000000002071500253164200237520ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe package('foo') do it { should be_installed } end mizzy-serverspec-5c0c869/spec/type/windows/port_spec.rb000066400000000000000000000006771500253164200233560ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe port(80) do it { should be_listening } end describe port(80) do it { should be_listening.with("tcp") } end describe port(123) do it { should be_listening.with("udp") } end describe port(80) do it { expect { should be_listening.with('not implemented') }.to raise_error(ArgumentError, %r/\A`be_listening` matcher doesn\'t support/) } end mizzy-serverspec-5c0c869/spec/type/windows/registry_key_spec.rb000066400000000000000000000026511500253164200251040ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe windows_registry_key('PATH/TO/THE_KEY') do it { should exist } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_value('Test Value') } end describe 'Key value types' do context 'default type' do describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property('TestProperty') } end end { :type_string => 'String', :type_binary => 'Binary', :type_dword => 'DWord', :type_qword => 'QWord', :type_multistring => 'MultiString', :type_expandstring => 'ExpandString' }.each do |sym, type| context "type #{type}" do describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property('TestProperty', sym) } end end end end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_binary, '12a07b') } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_dword, 'fffffd6c') } end describe windows_registry_key('PATH/TO/THE_KEY') do it { should have_property_value('TestProperty', :type_qword, '1e240') } end describe windows_registry_key('PATH/TO/THE_KEY') do it { value = <<-EOF test line1 test line2 test line3 EOF should have_property_value('TestProperty', :type_multistring, value) } end mizzy-serverspec-5c0c869/spec/type/windows/scheduled_task_spec.rb000066400000000000000000000002161500253164200253410ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe windows_scheduled_task('foo') do it { should exist } end mizzy-serverspec-5c0c869/spec/type/windows/service_spec.rb000066400000000000000000000013141500253164200240170ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe service('Test Service') do it { should be_enabled } end describe service('Test Service') do it { should be_running } end describe service('service') do it { should be_installed } end describe service('service') do it { should have_start_mode 'mode' } end describe service('Test service') do it "should raise error if trying to check service process controller" do expect { should be_running.under('supervisor') }.to raise_error(NotImplementedError) end it "should raise error if trying to check service monitoring" do expect { should_not be_monitored_by('monit') }.to raise_error(NotImplementedError) end end mizzy-serverspec-5c0c869/spec/type/windows/user_spec.rb000066400000000000000000000013161500253164200233370ustar00rootroot00000000000000require 'spec_helper' set :backend, :cmd set :os, :family => 'windows' describe user('test.user') do it { should exist } end describe user('test.domain\test.user') do it { should exist } end describe user('test.user') do it { should belong_to_group 'test.group' } end describe user('test.user.domain\test.user') do it { should belong_to_group 'test.group.domain\test.group' } end describe user('test.user') do it "should raise error if command is not supported" do { :have_uid => [nil], :have_login_shell => [nil], :have_authorized_key => [nil], }.each do |method, args| expect { should self.send(method, *args) }.to raise_error(NotImplementedError) end end end mizzy-serverspec-5c0c869/wercker.yml000066400000000000000000000005651500253164200176070ustar00rootroot00000000000000build: box: id: mizzy/wercker-serverspec steps: - script: name: initialize git submodules code: git submodule update --init --recursive - script: name: Run walter code: ./$WORKING_DIR/walter -config ./$WORKING_DIR/pipeline.yml -build after-steps: - wantedly/pretty-slack-notify: webhook_url: $SLACK_WEBHOOK_URL