From 6c1f805b0c4f4c4c55ac0df06f16daaaa885e440 Mon Sep 17 00:00:00 2001 From: Jonathan Gazeley Date: Thu, 19 Nov 2015 16:45:02 +0000 Subject: [PATCH] Add auto generated spec tests --- .bundle/config | 2 + .fixtures.yml | 8 + .puppet-lint.rc | 8 + .travis.yml | 14 + Gemfile | 27 ++ Rakefile | 76 +++- Vagrantfile | 95 +++++ spec/classes/control_socket_spec.rb | 36 ++ spec/classes/freeradius_spec.rb | 365 ++++++++++++++++++ spec/classes/params_spec.rb | 29 ++ spec/classes/status_server_spec.rb | 38 ++ spec/defines/attr_spec.rb | 54 +++ spec/defines/blank_spec.rb | 41 ++ spec/defines/cert_spec.rb | 48 +++ spec/defines/client_spec.rb | 54 +++ spec/defines/config_spec.rb | 46 +++ spec/defines/dictionary_spec.rb | 54 +++ spec/defines/home_server_pool_spec.rb | 42 ++ spec/defines/home_server_spec.rb | 45 +++ spec/defines/instantiate_spec.rb | 43 +++ spec/defines/ldap_spec.rb | 62 +++ spec/defines/module_spec.rb | 46 +++ spec/defines/policy_spec.rb | 54 +++ spec/defines/realm_spec.rb | 43 +++ spec/defines/script_spec.rb | 44 +++ spec/defines/site_spec.rb | 46 +++ spec/defines/sql_spec.rb | 87 +++++ spec/defines/statusclient_spec.rb | 49 +++ spec/shared_contexts.rb | 57 +++ spec/spec_helper.rb | 42 +- .../facter/freeradius_maj_version_spec.rb | 21 + spec/unit/facter/freeradius_version_spec.rb | 21 + 32 files changed, 1672 insertions(+), 25 deletions(-) create mode 100644 .bundle/config create mode 100644 .fixtures.yml create mode 100644 .puppet-lint.rc create mode 100644 .travis.yml create mode 100644 Gemfile create mode 100644 Vagrantfile create mode 100644 spec/classes/control_socket_spec.rb create mode 100644 spec/classes/freeradius_spec.rb create mode 100644 spec/classes/params_spec.rb create mode 100644 spec/classes/status_server_spec.rb create mode 100644 spec/defines/attr_spec.rb create mode 100644 spec/defines/blank_spec.rb create mode 100644 spec/defines/cert_spec.rb create mode 100644 spec/defines/client_spec.rb create mode 100644 spec/defines/config_spec.rb create mode 100644 spec/defines/dictionary_spec.rb create mode 100644 spec/defines/home_server_pool_spec.rb create mode 100644 spec/defines/home_server_spec.rb create mode 100644 spec/defines/instantiate_spec.rb create mode 100644 spec/defines/ldap_spec.rb create mode 100644 spec/defines/module_spec.rb create mode 100644 spec/defines/policy_spec.rb create mode 100644 spec/defines/realm_spec.rb create mode 100644 spec/defines/script_spec.rb create mode 100644 spec/defines/site_spec.rb create mode 100644 spec/defines/sql_spec.rb create mode 100644 spec/defines/statusclient_spec.rb create mode 100644 spec/shared_contexts.rb create mode 100644 spec/unit/facter/freeradius_maj_version_spec.rb create mode 100644 spec/unit/facter/freeradius_version_spec.rb diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 00000000..df11c751 --- /dev/null +++ b/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_DISABLE_SHARED_GEMS: '1' diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 00000000..d9e7c493 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,8 @@ +fixtures: + symlinks: + freeradius: "#{source_dir}" + repositories: + stdlib: + repo: https://github.com/puppetlabs/puppetlabs-stdlib.git + ref: 4.3.2 + forge_modules: diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 00000000..a37b48e6 --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,8 @@ +# Use this file to instruct puppet-lint to ignore certain checks. +# For the complete list of checks and flags to disable them, +# refer to . + +# Examples (uncomment before use): +#--no-80chars-check +#--no-class_inherits_from_params_class-check +#--no-inherits_across_namespaces-check diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..4c446464 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +branches: +script: "bundle exec rake spec SPEC_OPTS='--format documentation'" +bundler_args: --without development + +rvm: +- 1.9.3 +- 2.0.0 +- 2.1.5 +- 2.2.0 +env: + matrix: + - PUPPET_GEM_VERSION="~> 3.2" + - PUPPET_GEM_VERSION="~> 3.7" + diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..64c93492 --- /dev/null +++ b/Gemfile @@ -0,0 +1,27 @@ +source "https://rubygems.org" + +group :test do + gem "rake" + gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.8.3' + gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git' + gem "puppetlabs_spec_helper" + gem 'rspec-puppet-utils', :git => 'https://github.com/Accuity/rspec-puppet-utils.git' + gem 'hiera-puppet-helper', :git => 'https://github.com/bobtfish/hiera-puppet-helper.git' + gem "metadata-json-lint" + gem 'puppet-syntax' + gem 'puppet-lint' +end + +group :integration do + gem "beaker", :git => 'https://github.com/puppetlabs/beaker.git' + gem "beaker-rspec", :git => 'https://github.com/puppetlabs/beaker-rspec.git' + gem "vagrant-wrapper" + gem 'serverspec' +end + +group :development do + gem "travis" + gem "travis-lint" + gem "puppet-blacksmith" + gem "guard-rake" +end diff --git a/Rakefile b/Rakefile index d1e11f79..cb628a0a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,18 +1,72 @@ -require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' -PuppetLint.configuration.send('disable_80chars') -PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] +require 'puppet-syntax/tasks/puppet-syntax' -desc "Validate manifests, templates, and ruby files" -task :validate do - Dir['manifests/**/*.pp'].each do |manifest| - sh "puppet parser validate --noop #{manifest}" +# These two gems aren't always present, for instance +# on Travis with --without development +begin + require 'puppet_blacksmith/rake_tasks' + Blacksmith::RakeTask.new do |t| + t.tag_pattern = "v%s" # Use a custom pattern with git tag. %s is replaced with the version number. end - Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| - sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ +rescue LoadError +end + +PuppetLint.configuration.relative = true +PuppetLint.configuration.send("disable_80chars") +PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" +PuppetLint.configuration.fail_on_warnings = true + +# Forsake support for Puppet 2.6.2 for the benefit of cleaner code. +# http://puppet-lint.com/checks/class_parameter_defaults/ +PuppetLint.configuration.send('disable_class_parameter_defaults') +# http://puppet-lint.com/checks/class_inherits_from_params_class/ +PuppetLint.configuration.send('disable_class_inherits_from_params_class') + +exclude_paths = [ + "pkg/**/*", + "vendor/**/*", + "spec/**/*", +] +PuppetLint.configuration.ignore_paths = exclude_paths +PuppetSyntax.exclude_paths = exclude_paths + +task :metadata do + sh "metadata-json-lint metadata.json" +end + +desc "Run syntax, lint, and spec tests." +task :test => [ + :syntax, + :lint, + :spec, + :metadata, + ] +def io_popen(command) + IO.popen(command) do |io| + io.each do |line| + print line + yield line if block_given? + end end - Dir['templates/**/*.erb'].each do |template| - sh "erb -P -x -T '-' #{template} | ruby -c" +end + +desc 'Vagrant VM power up and provision' +task :vagrant_up, [:manifest, :hostname] do |t, args| + args.with_defaults(:manifest => 'init.pp', :hostname => '') + Rake::Task['spec_prep'].execute + ENV['VAGRANT_MANIFEST'] = args[:manifest] + provision = false + io_popen("vagrant up #{args[:hostname]}") do |line| + provision = true if line =~ /is already running./ end + io_popen("vagrant provision #{args[:hostname]}") if provision +end + +# Cleanup vagrant environment +desc 'Vagrant VM shutdown and fixtures cleanup' +task :vagrant_destroy do + Rake::Task['spec_prep'].execute + `vagrant destroy -f` + Rake::Task['spec_clean'].execute end diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..573b9032 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,95 @@ +def vm(opt) + module_name = opt.fetch(:module).to_s || raise(ArgumentError, 'Must provide puppet module name') + hostname = opt.fetch(:hostname, module_name).to_s + memory = opt.fetch(:memory, 512) + cpu = opt.fetch(:cpu, 1) + box = opt.fetch(:box).to_s || raise(ArgumentError, 'Must provide box type.') + url = opt.fetch(:url, '').to_s + os_type = opt[:os_type] || opt[:type] || :linux + gui = opt.fetch(:gui, false) + ports = Array(opt.fetch(:port, [])) + iso = opt.fetch(:iso, nil) + proj_root = File.expand_path(File.join(File.dirname(__FILE__))) + fixture_modules = File.join(proj_root, 'spec', 'fixtures', 'modules') + + Vagrant.configure('2') do |conf| + + # forward all the ports + ports.each do |p| + conf.vm.network(:forwarded_port, guest: p, host: p, auto_correct: true) + end + + if os_type == :windows + conf.ssh.username = 'vagrant' + conf.winrm.username = 'vagrant' + conf.winrm.password = 'vagrant' + end + + conf.vm.define hostname.to_sym do |mod| + mod.vm.box = box + mod.vm.box_url = url + + if os_type == :windows + mod.vm.guest = :windows + mod.vm.communicator = 'winrm' + mod.vm.synced_folder './' , "/ProgramData/PuppetLabs/puppet/etc/modules/#{module_name}" + mod.vm.synced_folder 'spec/fixtures/modules' , '/temp/modules' + else + mod.vm.synced_folder './', "/etc/puppet/modules/#{module_name}" + mod.vm.synced_folder 'spec/fixtures/modules', '/tmp/puppet/modules' + end + + mod.vm.hostname = hostname + + mod.vm.provider :vmware_fusion do |f| + f.gui = gui + f.vmx['displayName'] = hostname + f.vmx['memsize'] = memory + f.vmx['numvcpus'] = cpu + if iso + f.vmx['ide1:0.devicetype'] = "cdrom-image" + f.vmx['ide1:0.filename'] = iso + end + end + + mod.vm.provider :vmware_workstation do |f| + f.gui = gui + f.vmx['displayName'] = hostname + f.vmx['memsize'] = memory + f.vmx['numvcpus'] = cpu + if iso + f.vmx['ide1:0.devicetype'] = "cdrom-image" + f.vmx['ide1:0.filename'] = iso + end + end + + mod.vm.provider :virtualbox do |v| + v.gui = gui + v.name = hostname + v.memory = memory + v.cpus = cpu + end + + if os_type == :windows + manifest = ENV['VAGRANT_MANIFEST'] || 'init.pp' + #mod.vm.provision :shell, :inline => "@powershell -NoProfile -ExecutionPolicy Bypass -Command \"iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))\" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" + #mod.vm.provision :shell, :inline => "choco install puppet" + mod.vm.provision :shell, :inline => "puppet apply --modulepath 'C:/ProgramData/PuppetLabs/puppet/etc/modules;C:/temp/modules' --verbose C:/ProgramData/PuppetLabs/puppet/etc/modules/#{module_name}/tests/#{manifest}" + else + mod.vm.provision :puppet do |p| + p.manifests_path = 'tests' + # p.hiera_config_path = File.join(fixture_modules, 'hieradata', 'hiera.yaml') + p.manifest_file = ENV['VAGRANT_MANIFEST'] || 'init.pp' + #p.module_path = fixture_modules + # because of how symlinks are handled via the spec_helper we are forced to mount the modules is different locations + # otherwise we could just use the above option + p.options = '--modulepath="/etc/puppet/modules:/tmp/puppet/modules"' + end + end + end + end +end +module_name = File.basename(File.expand_path(File.join(File.dirname(__FILE__)))) +vm :hostname => 'win2012r2', :module => module_name, :box => 'opentable/win-2012r2-standard-amd64-nocm', :url => 'opentable/win-2012r2-standard-amd64-nocm', :os_type => :windows, :cpu => 1, :memory => 4096, :gui => true +vm :hostname => 'win2008r2', :module => module_name, :box => 'opentable/win-2008r2-standard-amd64-nocm', :url => 'opentable/win-2008r2-standard-amd64-nocm', :os_type => :windows, :cpu => 1, :memory => 4096, :gui => true +vm :hostname => 'centos6', :module => module_name, :box => 'puppetlabs/centos-6.6-64-puppet', :url => 'puppetlabs/centos-6.6-64-puppet', :cpu => 1, :memory => 2048, :gui => false diff --git a/spec/classes/control_socket_spec.rb b/spec/classes/control_socket_spec.rb new file mode 100644 index 00000000..cde5609d --- /dev/null +++ b/spec/classes/control_socket_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::control_socket' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + #:mode => "ro", + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_freeradius__site('control-socket') + .with( + 'content' => 'template(freeradius/sites-enabled/control-socket.erb)' + ) + end +end diff --git a/spec/classes/freeradius_spec.rb b/spec/classes/freeradius_spec.rb new file mode 100644 index 00000000..5f6d633a --- /dev/null +++ b/spec/classes/freeradius_spec.rb @@ -0,0 +1,365 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + #:control_socket => false, + #:max_servers => "4096", + #:max_requests => "4096", + #:mysql_support => false, + #:perl_support => false, + #:utils_support => false, + #:ldap_support => false, + #:wpa_supplicant => false, + #:winbind_support => false, + #:syslog => false, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('radiusd.conf') + .with( + 'content' => 'template(freeradius/radiusd.conf.fr$freeradius::fr_version.erb)', + 'group' => '$freeradius::fr_group', + 'mode' => '0640', + 'name' => '$freeradius::fr_basepath/radiusd.conf', + 'notify' => 'Service[$freeradius::fr_service]', + 'owner' => 'root', + 'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]' + ) + end + it do + is_expected.to contain_file('[$freeradius::fr_basepath/statusclients.d, $freeradius::fr_basepath, $freeradius::fr_basepath/conf.d, $freeradius::fr_basepath/attr.d, $freeradius::fr_basepath/users.d, $freeradius::fr_basepath/policy.d, $freeradius::fr_basepath/dictionary.d, $freeradius::fr_basepath/scripts]') + .with( + 'ensure' => 'directory', + 'group' => '$freeradius::fr_group', + 'mode' => '0750', + 'notify' => 'Service[$freeradius::fr_service]', + 'owner' => 'root', + 'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]' + ) + end + it do + is_expected.to contain_file('[$freeradius::fr_basepath/certs, $freeradius::fr_basepath/clients.d, $freeradius::fr_basepath/sites-enabled, $freeradius::fr_basepath/sites-available, $freeradius::fr_basepath/instantiate]') + .with( + 'ensure' => 'directory', + 'group' => '$freeradius::fr_group', + 'mode' => '0750', + 'notify' => 'Service[$freeradius::fr_service]', + 'owner' => 'root', + 'purge' => 'true', + 'recurse' => 'true', + 'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]' + ) + end + it do + is_expected.to contain_freeradius__module('eap') + .with( + 'ensure' => 'absent' + ) + end + it do + is_expected.to contain_concat('$freeradius::fr_basepath/policy.conf') + .with( + 'group' => '$freeradius::fr_group', + 'mode' => '0640', + 'notify' => 'Service[$freeradius::fr_service]', + 'owner' => 'root', + 'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]' + ) + end + it do + is_expected.to contain_concat__fragment('policy_header') + .with( + 'content' => 'policy {\\n', + 'order' => '10', + 'target' => '$freeradius::fr_basepath/policy.conf' + ) + end + it do + is_expected.to contain_concat__fragment('policy_footer') + .with( + 'content' => '}\\n', + 'order' => '99', + 'target' => '$freeradius::fr_basepath/policy.conf' + ) + end + it do + is_expected.to contain_concat('$freeradius::fr_basepath/proxy.conf') + .with( + 'group' => '$freeradius::fr_group', + 'mode' => '0640', + 'notify' => 'Service[$freeradius::fr_service]', + 'owner' => 'root', + 'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]' + ) + end + it do + is_expected.to contain_concat__fragment('proxy_header') + .with( + 'content' => '# Proxy config\\n\\n', + 'order' => '05', + 'target' => '$freeradius::fr_basepath/proxy.conf' + ) + end + it do + is_expected.to contain_concat('$freeradius::fr_modulepath/attr_filter') + .with( + 'group' => '$freeradius::fr_group', + 'mode' => '0640', + 'notify' => 'Service[$freeradius::fr_service]', + 'owner' => 'root', + 'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]' + ) + end + it do + is_expected.to contain_concat__fragment('attr-default') + .with( + 'content' => 'template(freeradius/attr_default.fr$freeradius::fr_version.erb)', + 'order' => '10', + 'target' => '$freeradius::fr_modulepath/attr_filter' + ) + end + it do + is_expected.to contain_concat('$freeradius::fr_basepath/dictionary') + .with( + 'group' => '$freeradius::fr_group', + 'mode' => '0640', + 'owner' => 'root', + 'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]' + ) + end + it do + is_expected.to contain_concat__fragment('dictionary_header') + .with( + 'order' => '10', + 'source' => 'puppet:///modules/freeradius/dictionary.header', + 'target' => '$freeradius::fr_basepath/dictionary' + ) + end + it do + is_expected.to contain_concat__fragment('dictionary_footer') + .with( + 'order' => '90', + 'source' => 'puppet:///modules/freeradius/dictionary.footer', + 'target' => '$freeradius::fr_basepath/dictionary' + ) + end + it do + is_expected.to contain_package('freeradius') + .with( + 'ensure' => 'installed', + 'name' => '$freeradius::fr_package' + ) + end + it do + is_expected.to contain_service('$freeradius::fr_service') + .with( + 'enable' => 'true', + 'ensure' => 'running', + 'hasrestart' => 'true', + 'hasstatus' => '$freeradius::fr_service_has_status', + 'name' => '$freeradius::fr_service', + 'require' => '[Exec[radiusd-config-test], File[radiusd.conf], User[$freeradius::fr_user], Package[$freeradius::fr_package]]' + ) + end + it do + is_expected.to contain_user('$freeradius::fr_user') + .with( + 'ensure' => 'present', + 'groups' => '$winbind_support ? { true => $freeradius::fr_wbpriv_user, default => undef }', + 'require' => 'Package[$freeradius::fr_package]' + ) + end + it do + is_expected.to contain_group('$freeradius::fr_group') + .with( + 'ensure' => 'present', + 'require' => 'Package[$freeradius::fr_package]' + ) + end + it do + is_expected.to contain_freeradius__module('always') + .with( ) + end + it do + is_expected.to contain_freeradius__module('detail') + .with( ) + end + it do + is_expected.to contain_freeradius__module('detail.log') + .with( ) + end + it do + is_expected.to contain_file('[$freeradius::fr_logpath, $freeradius::fr_logpath/radacct]') + .with( + 'mode' => '0750', + 'require' => 'Package[$freeradius::fr_package]' + ) + end + it do + is_expected.to contain_file('$freeradius::fr_logpath/radius.log') + .with( + 'group' => '$freeradius::fr_group', + 'owner' => '$freeradius::fr_user', + 'require' => '[Package[$freeradius::fr_package], User[$freeradius::fr_user], Group[$freeradius::fr_group]]', + 'seltype' => 'radiusd_log_t' + ) + end + it do + is_expected.to contain_logrotate__rule('radacct') + .with( + 'compress' => 'true', + 'create' => 'false', + 'missingok' => 'true', + 'path' => '$freeradius::fr_logpath/radacct/*/*.log', + 'postrotate' => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`', + 'rotate' => '7', + 'rotate_every' => 'day', + 'sharedscripts' => 'true' + ) + end + it do + is_expected.to contain_logrotate__rule('checkrad') + .with( + 'compress' => 'true', + 'create' => 'true', + 'missingok' => 'true', + 'path' => '$freeradius::fr_logpath/checkrad.log', + 'postrotate' => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`', + 'rotate' => '1', + 'rotate_every' => 'week', + 'sharedscripts' => 'true' + ) + end + it do + is_expected.to contain_logrotate__rule('radiusd') + .with( + 'compress' => 'true', + 'create' => 'true', + 'missingok' => 'true', + 'path' => '$freeradius::fr_logpath/radius*.log', + 'postrotate' => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`', + 'rotate' => '26', + 'rotate_every' => 'week', + 'sharedscripts' => 'true' + ) + end + it do + is_expected.to contain_file('[$freeradius::fr_basepath/certs/dh, $freeradius::fr_basepath/certs/random]') + .with( + 'require' => 'Exec[dh, random]' + ) + end + it do + is_expected.to contain_exec('dh') + .with( + 'command' => 'openssl dhparam -out $freeradius::fr_basepath/certs/dh 1024', + 'creates' => '$freeradius::fr_basepath/certs/dh', + 'path' => '/usr/bin' + ) + end + it do + is_expected.to contain_exec('random') + .with( + 'command' => 'dd if=/dev/urandom of=$freeradius::fr_basepath/certs/random count=10 >/dev/null 2>&1', + 'creates' => '$freeradius::fr_basepath/certs/random', + 'path' => '/bin' + ) + end + it do + is_expected.to contain_exec('radiusd-config-test') + .with( + 'command' => 'sudo radiusd -XC | grep 'Configuration appears to be OK.' | wc -l', + 'logoutput' => 'on_failure', + 'path' => '[/bin/, /sbin/, /usr/bin/, /usr/sbin/]', + 'refreshonly' => 'true', + 'returns' => '0' + ) + end + it do + is_expected.to contain_file('[$freeradius::fr_basepath/sites-available/default, $freeradius::fr_basepath/sites-available/inner-tunnel, $freeradius::fr_basepath/clients.conf, $freeradius::fr_basepath/sql.conf]') + .with( + 'content' => '# FILE INTENTIONALLY BLANK\\n', + 'group' => '$freeradius::fr_group', + 'mode' => '0644', + 'notify' => 'Service[$freeradius::fr_service]', + 'owner' => 'root', + 'require' => '[Package[$freeradius::fr_package], Group[$freeradius::fr_group]]' + ) + end + it do + is_expected.to contain_package('freeradius-mysql') + .with( + 'ensure' => 'installed' + ) + end + it do + is_expected.to contain_package('freeradius-perl') + .with( + 'ensure' => 'installed' + ) + end + it do + is_expected.to contain_package('freeradius-utils') + .with( + 'ensure' => 'installed' + ) + end + it do + is_expected.to contain_package('freeradius-ldap') + .with( + 'ensure' => 'installed' + ) + end + it do + is_expected.to contain_package('wpa_supplicant') + .with( + 'ensure' => 'installed', + 'name' => '$freeradius::fr_wpa_supplicant' + ) + end + it do + is_expected.to contain_syslog__rule('radiusd-log') + .with( + 'command' => 'if $programname == 'radiusd' then $freeradius::fr_logpath/radius.log\\n&~', + 'order' => '12' + ) + end + it do + is_expected.to contain_exec('delete-radius-rpmnew') + .with( + 'command' => 'find $freeradius::fr_basepath -name *.rpmnew -delete', + 'onlyif' => 'find $freeradius::fr_basepath -name *.rpmnew | grep rpmnew', + 'path' => '[/bin/, /sbin/, /usr/bin/, /usr/sbin/]' + ) + end + it do + is_expected.to contain_exec('delete-radius-rpmsave') + .with( + 'command' => 'find $freeradius::fr_basepath -name *.rpmsave -delete', + 'onlyif' => 'find $freeradius::fr_basepath -name *.rpmsave | grep rpmsave', + 'path' => '[/bin/, /sbin/, /usr/bin/, /usr/sbin/]' + ) + end +end diff --git a/spec/classes/params_spec.rb b/spec/classes/params_spec.rb new file mode 100644 index 00000000..e6740c08 --- /dev/null +++ b/spec/classes/params_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::params' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) +end diff --git a/spec/classes/status_server_spec.rb b/spec/classes/status_server_spec.rb new file mode 100644 index 00000000..b676286e --- /dev/null +++ b/spec/classes/status_server_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::status_server' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :secret => 'place_value_here', + #:port => "18121", + #:listen => "*", + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_freeradius__site('status') + .with( + 'content' => 'template(freeradius/sites-enabled/status.erb)' + ) + end +end diff --git a/spec/defines/attr_spec.rb b/spec/defines/attr_spec.rb new file mode 100644 index 00000000..cf4a92a8 --- /dev/null +++ b/spec/defines/attr_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::attr' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :source => 'place_value_here', + #:ensure => present, + #:key => "User-Name", + #:prefix => "filter", + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$fr_version ? { 2 => $fr_basepath, 3 => $fr_moduleconfigpath/attr_filter, default => $fr_moduleconfigpath }/XXreplace_meXX') + .with( + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[Package[$fr_package], Group[$fr_group]]', + 'source' => '' + ) + end + it do + is_expected.to contain_concat__fragment('attr-XXreplace_meXX') + .with( + 'content' => 'template(freeradius/attr.fr$fr_version.erb)', + 'order' => '20', + 'target' => '$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/$fr_version ? { 2 => modules, 3 => mods-enabled, default => modules }/attr_filter' + ) + end +end diff --git a/spec/defines/blank_spec.rb b/spec/defines/blank_spec.rb new file mode 100644 index 00000000..6883c8fa --- /dev/null +++ b/spec/defines/blank_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::blank' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/XXreplace_meXX') + .with( + 'content' => '# This file is intentionally left blank to reduce complexity. Blanking it but leaving it present is safer than deleting it, since the package manager will replace some files if they are deleted, leading to unexpected behaviour!', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0644', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[File[$fr_basepath], Package[$fr_package], Group[$fr_group]]' + ) + end +end diff --git a/spec/defines/cert_spec.rb b/spec/defines/cert_spec.rb new file mode 100644 index 00000000..7470b589 --- /dev/null +++ b/spec/defines/cert_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::cert' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + #:source => undef, + #:content => undef, + #:type => "key", + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/certs/XXreplace_meXX') + .with( + 'content' => 'undef', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '$type ? { key => 0640, cert => 0644, default => 0644 }', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[File[$fr_basepath/certs], Package[$fr_package], Group[$fr_group]]', + 'show_diff' => 'false', + 'source' => 'undef' + ) + end +end diff --git a/spec/defines/client_spec.rb b/spec/defines/client_spec.rb new file mode 100644 index 00000000..b926357d --- /dev/null +++ b/spec/defines/client_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::client' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :shortname => 'place_value_here', + :secret => 'place_value_here', + #:ip => undef, + #:ip6 => undef, + #:virtual_server => undef, + #:nastype => undef, + #:netmask => undef, + #:redirect => undef, + #:port => undef, + #:srcip => undef, + #:firewall => false, + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/clients.d/.conf') + .with( + 'content' => 'template(freeradius/client.conf.fr$fr_version.erb)', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[File[$fr_basepath/clients.d], Group[$fr_group]]' + ) + end +end diff --git a/spec/defines/config_spec.rb b/spec/defines/config_spec.rb new file mode 100644 index 00000000..c5be2bab --- /dev/null +++ b/spec/defines/config_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::config' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + #:source => undef, + #:content => undef, + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/$fr_version ? { 2 => conf.d, 3 => mods-config, default => conf.d }/XXreplace_meXX') + .with( + 'content' => 'undef', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[Package[$fr_package], Group[$fr_group]]', + 'source' => 'undef' + ) + end +end diff --git a/spec/defines/dictionary_spec.rb b/spec/defines/dictionary_spec.rb new file mode 100644 index 00000000..7f628164 --- /dev/null +++ b/spec/defines/dictionary_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::dictionary' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :source => 'place_value_here', + #:order => 50, + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/dictionary.d/dictionary.XXreplace_meXX') + .with( + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0644', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[File[$fr_basepath/dictionary.d], Package[$fr_package], Group[$fr_group]]', + 'source' => '' + ) + end + it do + is_expected.to contain_concat__fragment('dictionary.XXreplace_meXX') + .with( + 'content' => '$INCLUDE $::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/dictionary.d/dictionary.XXreplace_meXX\\n', + 'order' => '50', + 'require' => 'File[$fr_basepath/dictionary.d/dictionary.$name]', + 'target' => '$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/dictionary' + ) + end +end diff --git a/spec/defines/home_server_pool_spec.rb b/spec/defines/home_server_pool_spec.rb new file mode 100644 index 00000000..3f00fa65 --- /dev/null +++ b/spec/defines/home_server_pool_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::home_server_pool' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :home_server => 'place_value_here', + #:type => "fail-over", + #:virtual_server => "", + #:fallback => "", + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_concat__fragment('homeserverpool-XXreplace_meXX') + .with( + 'content' => 'template(freeradius/home_server_pool.erb)', + 'order' => '20', + 'target' => '$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/proxy.conf' + ) + end +end diff --git a/spec/defines/home_server_spec.rb b/spec/defines/home_server_spec.rb new file mode 100644 index 00000000..bc385872 --- /dev/null +++ b/spec/defines/home_server_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::home_server' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :secret => 'place_value_here', + #:type => "auth", + #:ipaddr => "", + #:ipv6addr => "", + #:virtual_server => "", + #:port => 1812, + #:proto => "udp", + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_concat__fragment('homeserver-XXreplace_meXX') + .with( + 'content' => 'template(freeradius/home_server.erb)', + 'order' => '10', + 'target' => '$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/proxy.conf' + ) + end +end diff --git a/spec/defines/instantiate_spec.rb b/spec/defines/instantiate_spec.rb new file mode 100644 index 00000000..436ef83c --- /dev/null +++ b/spec/defines/instantiate_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::instantiate' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/instantiate/XXreplace_meXX') + .with( + 'content' => 'XXreplace_meXX', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[Package[$fr_package], Group[$fr_group]]' + ) + end +end diff --git a/spec/defines/ldap_spec.rb b/spec/defines/ldap_spec.rb new file mode 100644 index 00000000..b621e9e2 --- /dev/null +++ b/spec/defines/ldap_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::ldap' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :identity => 'place_value_here', + :password => 'place_value_here', + :basedn => 'place_value_here', + #:server => ["localhost"], + #:port => 389, + #:uses => 0, + #:idle => 60, + #:probes => 3, + #:interval => 3, + #:timeout => 10, + #:start => "${thread[pool].start_servers}", + #:min => "${thread[pool].min_spare_servers}", + #:max => "${thread[pool].max_servers}", + #:spare => "${thread[pool].max_spare_servers}", + #:ensure => "present", + #:starttls => "no", + #:cafile => undef, + #:certfile => undef, + #:keyfile => undef, + #:requirecert => "allow", + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/$fr_version ? { 2 => modules, 3 => mods-enabled, default => modules }/XXreplace_meXX') + .with( + 'content' => 'template(freeradius/ldap.fr$fr_version.erb)', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[Package[$fr_package], Group[$fr_group]]' + ) + end +end diff --git a/spec/defines/module_spec.rb b/spec/defines/module_spec.rb new file mode 100644 index 00000000..8b1917b3 --- /dev/null +++ b/spec/defines/module_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::module' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + #:source => undef, + #:content => undef, + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/$fr_version ? { 2 => modules, 3 => mods-enabled, default => modules }/XXreplace_meXX') + .with( + 'content' => 'undef', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[Package[$fr_package], Group[$fr_group]]', + 'source' => 'undef' + ) + end +end diff --git a/spec/defines/policy_spec.rb b/spec/defines/policy_spec.rb new file mode 100644 index 00000000..711008bc --- /dev/null +++ b/spec/defines/policy_spec.rb @@ -0,0 +1,54 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::policy' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :source => 'place_value_here', + #:order => 50, + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/policy.d/XXreplace_meXX') + .with( + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0644', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[Package[$fr_package], Group[$fr_group]]', + 'source' => '' + ) + end + it do + is_expected.to contain_concat__fragment('policy-XXreplace_meXX') + .with( + 'content' => '\\t$INCLUDE $::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/policy.d/XXreplace_meXX\\n', + 'order' => '50', + 'require' => 'File[$fr_basepath/policy.d/$name]', + 'target' => '$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/policy.conf' + ) + end +end diff --git a/spec/defines/realm_spec.rb b/spec/defines/realm_spec.rb new file mode 100644 index 00000000..9d68cfc3 --- /dev/null +++ b/spec/defines/realm_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::realm' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + #:virtual_server => "", + #:auth_pool => "", + #:acct_pool => "", + #:pool => "", + #:nostrip => false, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_concat__fragment('realm-XXreplace_meXX') + .with( + 'content' => 'template(freeradius/realm.erb)', + 'order' => '30', + 'target' => '$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/proxy.conf' + ) + end +end diff --git a/spec/defines/script_spec.rb b/spec/defines/script_spec.rb new file mode 100644 index 00000000..60d48ced --- /dev/null +++ b/spec/defines/script_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::script' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :source => 'place_value_here', + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/scripts/XXreplace_meXX') + .with( + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0750', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[File[$fr_basepath/scripts], Package[$fr_package], Group[$fr_group]]', + 'source' => '' + ) + end +end diff --git a/spec/defines/site_spec.rb b/spec/defines/site_spec.rb new file mode 100644 index 00000000..42496939 --- /dev/null +++ b/spec/defines/site_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::site' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + #:source => undef, + #:content => undef, + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/sites-enabled/XXreplace_meXX') + .with( + 'content' => 'undef', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[Package[$fr_package], Group[$fr_group]]', + 'source' => 'undef' + ) + end +end diff --git a/spec/defines/sql_spec.rb b/spec/defines/sql_spec.rb new file mode 100644 index 00000000..7a46a1bf --- /dev/null +++ b/spec/defines/sql_spec.rb @@ -0,0 +1,87 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::sql' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :database => 'place_value_here', + :password => 'place_value_here', + #:server => "localhost", + #:login => "radius", + #:radius_db => "radius", + #:num_sql_socks => "${thread[pool].max_servers}", + #:query_file => "sql/${database}/dialup.conf", + #:custom_query_file => "", + #:lifetime => "0", + #:max_queries => "0", + #:ensure => present, + #:acct_table1 => "radacct", + #:acct_table2 => "radacct", + #:postauth_table => "radpostauth", + #:authcheck_table => "radcheck", + #:authreply_table => "radreply", + #:groupcheck_table => "radgroupcheck", + #:groupreply_table => "radgroupreply", + #:usergroup_table => "radusergroup", + #:deletestalesessions => "yes", + #:sqltrace => "no", + #:sqltracefile => "${logdir}/sqltrace.sql", + #:connect_failure_retry_delay => "60", + #:nas_table => "nas", + #:read_groups => "yes", + #:port => "3306", + #:readclients => "no", + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/$fr_version ? { 2 => modules, 3 => mods-enabled, default => modules }/XXreplace_meXX') + .with( + 'content' => 'template(freeradius/sql.conf.fr$fr_version.erb)', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[Package[$fr_package], Group[$fr_group]]' + ) + end + it do + is_expected.to contain___freeradius__config('XXreplace_meXX-queries.conf') + .with( + 'source' => '' + ) + end + it do + is_expected.to contain_logrotate__rule('sqltrace') + .with( + 'compress' => 'true', + 'create' => 'true', + 'missingok' => 'true', + 'path' => '$::osfamily ? { RedHat => /var/log/radius, Debian => /var/log/freeradius, default => /var/log/radius }/${logdir}/sqltrace.sql', + 'postrotate' => 'kill -HUP `cat /var/run/radiusd/radiusd.pid`', + 'rotate' => '1', + 'rotate_every' => 'week' + ) + end +end diff --git a/spec/defines/statusclient_spec.rb b/spec/defines/statusclient_spec.rb new file mode 100644 index 00000000..4f961f96 --- /dev/null +++ b/spec/defines/statusclient_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' +require 'shared_contexts' + +describe 'freeradius::statusclient' do + # by default the hiera integration uses hiera data from the shared_contexts.rb file + # but basically to mock hiera you first need to add a key/value pair + # to the specific context in the spec/shared_contexts.rb file + # Note: you can only use a single hiera context per describe/context block + # rspec-puppet does not allow you to swap out hiera data on a per test block + #include_context :hiera + + let(:title) { 'XXreplace_meXX' } + + # below is the facts hash that gives you the ability to mock + # facts on a per describe/context block. If you use a fact in your + # manifest you should mock the facts below. + let(:facts) do + {} + end + # below is a list of the resource parameters that you can override. + # By default all non-required parameters are commented out, + # while all required parameters will require you to add a value + let(:params) do + { + :secret => 'place_value_here', + #:ip => undef, + #:ip6 => undef, + #:port => undef, + #:shortname => XXreplace_meXX, + #:netmask => undef, + #:ensure => present, + } + end + # add these two lines in a single test block to enable puppet and hiera debug mode + # Puppet::Util::Log.level = :debug + # Puppet::Util::Log.newdestination(:console) + it do + is_expected.to contain_file('$::osfamily ? { RedHat => /etc/raddb, Debian => /etc/freeradius, default => /etc/raddb }/statusclients.d/XXreplace_meXX.conf') + .with( + 'content' => 'template(freeradius/client.conf.fr$fr_version.erb)', + 'ensure' => 'present', + 'group' => '$::osfamily ? { RedHat => radiusd, Debian => freerad, default => radiusd }', + 'mode' => '0640', + 'notify' => 'Service[$fr_service]', + 'owner' => 'root', + 'require' => '[File[$fr_basepath/clients.d], Package[$fr_package], Group[$fr_group]]' + ) + end +end diff --git a/spec/shared_contexts.rb b/spec/shared_contexts.rb new file mode 100644 index 00000000..e90abe86 --- /dev/null +++ b/spec/shared_contexts.rb @@ -0,0 +1,57 @@ +# optional, this should be the path to where the hiera data config file is in this repo +# You must update this if your actual hiera data lives inside your module. +# I only assume you have a separate repository for hieradata and its include in your .fixtures +hiera_config_file = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures','modules','hieradata', 'hiera.yaml')) + +# hiera_config and hiera_data are mutually exclusive contexts. + +shared_context :global_hiera_data do + let(:hiera_data) do + { + #"freeradius::control_socket" => '', + #"freeradius::control_socket::mode" => '', + #"freeradius::ldap_support" => '', + #"freeradius::max_requests" => '', + #"freeradius::max_servers" => '', + #"freeradius::mysql_support" => '', + #"freeradius::perl_support" => '', + #"freeradius::status_server::listen" => '', + #"freeradius::status_server::port" => '', + #"freeradius::status_server::secret" => '', + #"freeradius::syslog" => '', + #"freeradius::utils_support" => '', + #"freeradius::winbind_support" => '', + #"freeradius::wpa_supplicant" => '', + + } + end +end + +shared_context :hiera do + # example only, + let(:hiera_data) do + {:some_key => "some_value" } + end +end + +shared_context :linux_hiera do + # example only, + let(:hiera_data) do + {:some_key => "some_value" } + end +end + +# In case you want a more specific set of mocked hiera data for windows +shared_context :windows_hiera do + # example only, + let(:hiera_data) do + {:some_key => "some_value" } + end +end + +# you cannot use this in addition to any of the hiera_data contexts above +shared_context :real_hiera_data do + let(:hiera_config) do + hiera_config_file + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5fda5887..6655d16a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,17 +1,31 @@ -dir = File.expand_path(File.dirname(__FILE__)) -$LOAD_PATH.unshift File.join(dir, 'lib') +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-utils' +# if your using puppet4, the following gem seems to causes issues +require 'hiera-puppet-helper' -require 'mocha' -require 'puppet' -require 'rspec' -require 'spec/autorun' +# Uncomment this to show coverage report, also useful for debugging +#at_exit { RSpec::Puppet::Coverage.report! } -Spec::Runner.configure do |config| - config.mock_with :mocha -end +#set to "yes" to enable the future parser, the equivalent of setting parser=future in puppet.conf. +#ENV['FUTURE_PARSER'] = 'yes' -# We need this because the RAL uses 'should' as a method. This -# allows us the same behaviour but with a different method name. -class Object - alias :must :should -end +# set to "yes" to enable strict variable checking, the equivalent of setting strict_variables=true in puppet.conf. +#ENV['STRICT_VARIABLES'] = 'yes' + +# set to the desired ordering method ("title-hash", "manifest", or "random") to set the order of unrelated resources +# when applying a catalog. Leave unset for the default behavior, currently "random". This is equivalent to setting +# ordering in puppet.conf. +#ENV['ORDERING'] = 'random' + +# set to "no" to enable structured facts, otherwise leave unset to retain the current default behavior. +# This is equivalent to setting stringify_facts=false in puppet.conf. +#ENV['STRINGIFY_FACTS'] = 'no' + +# set to "yes" to enable the $facts hash and trusted node data, which enabled $facts and $trusted hashes. +# This is equivalent to setting trusted_node_data=true in puppet.conf. +#ENV['TRUSTED_NODE_DATA'] = 'yes' + +RSpec.configure do |c| + c.formatter = 'documentation' + c.mock_with :rspec +end \ No newline at end of file diff --git a/spec/unit/facter/freeradius_maj_version_spec.rb b/spec/unit/facter/freeradius_maj_version_spec.rb new file mode 100644 index 00000000..c6556396 --- /dev/null +++ b/spec/unit/facter/freeradius_maj_version_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' +require 'facter' + +describe :freeradius_maj_version, :type => :fact do + + before :all do + # perform any action that should be run for the entire test suite + end + + before :each do + # perform any action that should be run before every test + Facter.clear + # This will mock the facts that confine uses to limit facts running under certain conditions + # below is how you mock responses from the command line + # you will need to built tests that plugin different mocked values in order to fully test your facter code + end + + it 'should return a value' do + expect(Facter.fact(:freeradius_maj_version).value).to eq('value123') #<-- change the value to match your expectation + end +end diff --git a/spec/unit/facter/freeradius_version_spec.rb b/spec/unit/facter/freeradius_version_spec.rb new file mode 100644 index 00000000..fde23a4a --- /dev/null +++ b/spec/unit/facter/freeradius_version_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' +require 'facter' + +describe :freeradius_version, :type => :fact do + + before :all do + # perform any action that should be run for the entire test suite + end + + before :each do + # perform any action that should be run before every test + Facter.clear + # This will mock the facts that confine uses to limit facts running under certain conditions + # below is how you mock responses from the command line + # you will need to built tests that plugin different mocked values in order to fully test your facter code + end + + it 'should return a value' do + expect(Facter.fact(:freeradius_version).value).to eq('value123') #<-- change the value to match your expectation + end +end