From 5683eaf74edc5ee4ff9258e9c6762872c3e34a49 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 13 Aug 2014 12:10:49 -0700 Subject: [PATCH] Add some validation and more tests --- manifests/init.pp | 3 + spec/acceptance/install_spec.rb | 102 ++++++++++++++++++++++++++------ spec/classes/java_spec.rb | 39 ++++++++++++ 3 files changed, 126 insertions(+), 18 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 2b11483..3071190 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -47,6 +47,9 @@ class java( include java::params validate_re($version, 'present|installed|latest|^[.+_0-9a-zA-Z:-]+$') + if $package != undef { + validate_slength($package,255,1) + } if has_key($java::params::java, $distribution) { $default_package_name = $java::params::java[$distribution]['package'] diff --git a/spec/acceptance/install_spec.rb b/spec/acceptance/install_spec.rb index a090643..f43b236 100644 --- a/spec/acceptance/install_spec.rb +++ b/spec/acceptance/install_spec.rb @@ -24,23 +24,6 @@ require 'spec_helper_acceptance' # C14722 describe "installing java", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do describe "jre" do - #case "#{fact('osfamily')} #{fact('operatingsystemrelease')}" - #when /RedHat 4/ - # # How does it work? yum is not present... - #when /RedHat 5/ - # java_version = 'java version "1.6.0' - #when /RedHat (6|7)/ - # java_version = 'java version "1.7.0' - #when /Debian (5|6|10|11)/ - # java_version = 'java version "1.6.0' - #when /Debian (7|jesse|12|14)6/ - # java_version = 'java version "1.7.0' - #when /Solaris / - # java_version = - #when /Suse/ - # java_version = - #end - it 'should install jre' do pp = <<-EOS class { 'java': @@ -125,7 +108,90 @@ describe 'oracle', :if => (fact('operatingsystem') == 'Debian' and fact('operati describe 'jdk' do it 'should install oracle-jdk' do pp = <<-EOS - class { 'java': } + class { 'java': + distribution => 'oracle-jdk', + } + EOS + + apply_manifest(pp, :expect_failures => true) + end + end +end + +describe 'failure cases' do + # C14711 + it 'should fail to install java with an incorrect version' do + pp = <<-EOS + class { 'java': + version => '14.5', + } + EOS + + apply_manifest(pp, :expect_failures => true) + end + + # C14712 + it 'should fail to install java with a blank version' do + pp = <<-EOS + class { 'java': + version => '', + } + EOS + + apply_manifest(pp, :expect_failures => true) + end + + # C14713 + it 'should fail to install java with an incorrect distribution' do + pp = <<-EOS + class { 'java': + distribution => 'xyz', + } + EOS + + apply_manifest(pp, :expect_failures => true) + end + + # C14714 + it 'should fail to install java with a blank distribution' do + pp = <<-EOS + class { 'java': + distribution => '', + } + EOS + + apply_manifest(pp, :expect_failures => true) + end + + # C14715 + it 'should fail to install java with an incorrect package' do + pp = <<-EOS + class { 'java': + package => 'xyz', + } + EOS + + apply_manifest(pp, :expect_failures => true) + end + + # C14716 + it 'should fail to install java with a blank package' do + pp = <<-EOS + class { 'java': + package => '', + } + EOS + + apply_manifest(pp, :expect_failures => true) + end + + context 'non-debian systems', :if => fact('osfamily') != 'Debian' do + # C14717 + it 'should fail to install java with a blank package' do + pp = <<-EOS + class { 'java': + package => '', + } EOS apply_manifest(pp, :expect_failures => true) diff --git a/spec/classes/java_spec.rb b/spec/classes/java_spec.rb index 8f48e85..de1eda3 100644 --- a/spec/classes/java_spec.rb +++ b/spec/classes/java_spec.rb @@ -112,4 +112,43 @@ describe 'java', :type => :class do it { should contain_package('java').with_name('java-1_7_0-openjdk-devel')} end + describe 'incompatible OSs' do + [ + { + # C14706 + :osfamily => 'windows', + :operatingsystem => 'windows', + :operatingsystemrelease => '8.1', + }, + { + # C14707 + :osfamily => 'Darwin', + :operatingsystem => 'Darwin', + :operatingsystemrelease => '13.3.0', + }, + { + # C14708 + :osfamily => 'AIX', + :operatingsystem => 'AIX', + :operatingsystemrelease => '7100-02-00-000', + }, + { + # C14708 + :osfamily => 'AIX', + :operatingsystem => 'AIX', + :operatingsystemrelease => '6100-07-04-1216', + }, + { + # C14708 + :osfamily => 'AIX', + :operatingsystem => 'AIX', + :operatingsystemrelease => '5300-12-01-1016', + }, + ].each do |facts| + let(:facts) { facts } + it "should fail on #{facts[:operatingsystem]} #{facts[:operatingsystemrelease]}" do + expect { subject }.to raise_error Puppet::Error, /unsupported platform/ + end + end + end end