From a82266c256784c4af229e026b00a4dcf9e779270 Mon Sep 17 00:00:00 2001 From: Eli Young Date: Mon, 26 Jan 2015 19:17:53 -0800 Subject: (MODULES-1715) Add fqdn_rand string generators --- spec/acceptance/fqdn_rand_string_spec.rb | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 spec/acceptance/fqdn_rand_string_spec.rb (limited to 'spec/acceptance/fqdn_rand_string_spec.rb') diff --git a/spec/acceptance/fqdn_rand_string_spec.rb b/spec/acceptance/fqdn_rand_string_spec.rb new file mode 100644 index 0000000..0e79723 --- /dev/null +++ b/spec/acceptance/fqdn_rand_string_spec.rb @@ -0,0 +1,60 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper_acceptance' + +describe 'fqdn_rand_string function', :unless => unsupported_platforms.include?(fact('operatingsystem')) do + describe 'success' do + let(:facts_d) do + if fact('is_pe', '--puppet') == "true" + if fact('osfamily') =~ /windows/i + if fact('kernelmajversion').to_f < 6.0 + 'c:/documents and settings/all users/application data/puppetlabs/facter/facts.d' + else + 'c:/programdata/puppetlabs/facter/facts.d' + end + else + '/etc/puppetlabs/facter/facts.d' + end + else + '/etc/facter/facts.d' + end + end + after :each do + shell("if [ -f '#{facts_d}/fqdn.txt' ] ; then rm '#{facts_d}/fqdn.txt' ; fi") + end + before :each do + #no need to create on windows, pe creates by default + if fact('osfamily') !~ /windows/i + shell("mkdir -p '#{facts_d}'") + end + end + it 'generates random alphanumeric strings' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-eos + $l = 10 + $o = fqdn_rand_string($l) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "7oDp0KOr1b"/) + end + end + it 'generates random alphanumeric strings with custom seeds' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-eos + $l = 10 + $s = 'seed' + $o = fqdn_rand_string($l, $s) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "3HS4mbuI3E"/) + end + end + end + describe 'failure' do + it 'handles improper argument counts' + it 'handles non-numbers for length argument' + end +end -- cgit v1.2.3 From e43f0582960707f8a7ff9f087ca2b521c1797a91 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Thu, 9 Apr 2015 15:47:04 -0700 Subject: Fix unsupported platforms variable name in tests unsupported_platforms is not a valid identifier, and trying to use it causes acceptance tests to error out before running any tests. The correct identifier for the unsupported platforms constants is UNSUPPORTED_PLATFORMS. --- spec/acceptance/fqdn_rand_string_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/acceptance/fqdn_rand_string_spec.rb') diff --git a/spec/acceptance/fqdn_rand_string_spec.rb b/spec/acceptance/fqdn_rand_string_spec.rb index 0e79723..a934fbb 100644 --- a/spec/acceptance/fqdn_rand_string_spec.rb +++ b/spec/acceptance/fqdn_rand_string_spec.rb @@ -1,7 +1,7 @@ #! /usr/bin/env ruby -S rspec require 'spec_helper_acceptance' -describe 'fqdn_rand_string function', :unless => unsupported_platforms.include?(fact('operatingsystem')) do +describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do let(:facts_d) do if fact('is_pe', '--puppet') == "true" -- cgit v1.2.3 From 65116dafd507c5111044853861f9b10b02c91854 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Fri, 10 Apr 2015 09:09:46 -0700 Subject: Fix acceptance tests for #405 This fixes the acceptance tests by: - Ensuring the fqdn_rand_string spec is passed undef as the second parameter so that the seed is not used as the charset - Ensuring the pw_hash spec is passed the key specifying the type of hash, rather than the value that will be used to generate the password - Expecting puppet to report nil instead of empty string for undef passwords - Removing the fqdn_rand_base64 test because there is no such function --- spec/acceptance/fqdn_rand_string_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/acceptance/fqdn_rand_string_spec.rb') diff --git a/spec/acceptance/fqdn_rand_string_spec.rb b/spec/acceptance/fqdn_rand_string_spec.rb index a934fbb..8fe1a69 100644 --- a/spec/acceptance/fqdn_rand_string_spec.rb +++ b/spec/acceptance/fqdn_rand_string_spec.rb @@ -44,7 +44,7 @@ describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?( pp = <<-eos $l = 10 $s = 'seed' - $o = fqdn_rand_string($l, $s) + $o = fqdn_rand_string($l, undef, $s) notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) eos -- cgit v1.2.3 From 98c2f283b0ad4c3017dd4189a4a44d4af37f9f2b Mon Sep 17 00:00:00 2001 From: Eli Young Date: Mon, 1 Jun 2015 16:46:26 -0700 Subject: fqdn_rand_string: Add acceptance tests for custom charsets --- spec/acceptance/fqdn_rand_string_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'spec/acceptance/fqdn_rand_string_spec.rb') diff --git a/spec/acceptance/fqdn_rand_string_spec.rb b/spec/acceptance/fqdn_rand_string_spec.rb index 8fe1a69..881cff3 100644 --- a/spec/acceptance/fqdn_rand_string_spec.rb +++ b/spec/acceptance/fqdn_rand_string_spec.rb @@ -39,6 +39,19 @@ describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?( expect(r.stdout).to match(/fqdn_rand_string is "7oDp0KOr1b"/) end end + it 'generates random alphanumeric strings with custom charsets' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-eos + $l = 10 + $c = '0123456789' + $o = fqdn_rand_string($l, $c) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "7203048515"/) + end + end it 'generates random alphanumeric strings with custom seeds' do shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") pp = <<-eos @@ -52,6 +65,20 @@ describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?( expect(r.stdout).to match(/fqdn_rand_string is "3HS4mbuI3E"/) end end + it 'generates random alphanumeric strings with custom charsets and seeds' do + shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") + pp = <<-eos + $l = 10 + $c = '0123456789' + $s = 'seed' + $o = fqdn_rand_string($l, $c, $s) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "3104058232"/) + end + end end describe 'failure' do it 'handles improper argument counts' -- cgit v1.2.3 From 78e8c73671d0d3b69b2999094ec3af638327f7c0 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Mon, 20 Jul 2015 14:35:57 -0700 Subject: (maint) Fix test to not assume is_pe fact on > 4.0.0 puppet --- spec/acceptance/fqdn_rand_string_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/acceptance/fqdn_rand_string_spec.rb') diff --git a/spec/acceptance/fqdn_rand_string_spec.rb b/spec/acceptance/fqdn_rand_string_spec.rb index 881cff3..fec3c93 100644 --- a/spec/acceptance/fqdn_rand_string_spec.rb +++ b/spec/acceptance/fqdn_rand_string_spec.rb @@ -4,7 +4,8 @@ require 'spec_helper_acceptance' describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do let(:facts_d) do - if fact('is_pe', '--puppet') == "true" + puppet_version = (on default, puppet('--version')).output.chomp + if puppet_version < '4.0.0' && fact('is_pe', '--puppet') == "true" if fact('osfamily') =~ /windows/i if fact('kernelmajversion').to_f < 6.0 'c:/documents and settings/all users/application data/puppetlabs/facter/facts.d' -- cgit v1.2.3 From a8d7563a441834ba5e4b9029c9446bb8f41f0921 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 22 Jul 2015 17:30:39 +0100 Subject: (main) clean up fqdn_rand acceptance tests to work on windows --- spec/acceptance/fqdn_rand_string_spec.rb | 112 +++++++++++++------------------ 1 file changed, 45 insertions(+), 67 deletions(-) (limited to 'spec/acceptance/fqdn_rand_string_spec.rb') diff --git a/spec/acceptance/fqdn_rand_string_spec.rb b/spec/acceptance/fqdn_rand_string_spec.rb index fec3c93..9c6d701 100644 --- a/spec/acceptance/fqdn_rand_string_spec.rb +++ b/spec/acceptance/fqdn_rand_string_spec.rb @@ -3,81 +3,59 @@ require 'spec_helper_acceptance' describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do describe 'success' do - let(:facts_d) do - puppet_version = (on default, puppet('--version')).output.chomp - if puppet_version < '4.0.0' && fact('is_pe', '--puppet') == "true" - if fact('osfamily') =~ /windows/i - if fact('kernelmajversion').to_f < 6.0 - 'c:/documents and settings/all users/application data/puppetlabs/facter/facts.d' - else - 'c:/programdata/puppetlabs/facter/facts.d' - end - else - '/etc/puppetlabs/facter/facts.d' - end - else - '/etc/facter/facts.d' - end - end - after :each do - shell("if [ -f '#{facts_d}/fqdn.txt' ] ; then rm '#{facts_d}/fqdn.txt' ; fi") - end - before :each do - #no need to create on windows, pe creates by default - if fact('osfamily') !~ /windows/i - shell("mkdir -p '#{facts_d}'") + include_context "with faked facts" + context "when the FQDN is 'fakehost.localdomain'" do + before :each do + fake_fact("fqdn", "fakehost.localdomain") end - end - it 'generates random alphanumeric strings' do - shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") - pp = <<-eos - $l = 10 - $o = fqdn_rand_string($l) - notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) - eos - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/fqdn_rand_string is "7oDp0KOr1b"/) + it 'generates random alphanumeric strings' do + pp = <<-eos + $l = 10 + $o = fqdn_rand_string($l) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos + + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "7oDp0KOr1b"/) + end end - end - it 'generates random alphanumeric strings with custom charsets' do - shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") - pp = <<-eos - $l = 10 - $c = '0123456789' - $o = fqdn_rand_string($l, $c) - notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) - eos + it 'generates random alphanumeric strings with custom charsets' do + pp = <<-eos + $l = 10 + $c = '0123456789' + $o = fqdn_rand_string($l, $c) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/fqdn_rand_string is "7203048515"/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "7203048515"/) + end end - end - it 'generates random alphanumeric strings with custom seeds' do - shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") - pp = <<-eos - $l = 10 - $s = 'seed' - $o = fqdn_rand_string($l, undef, $s) - notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) - eos + it 'generates random alphanumeric strings with custom seeds' do + pp = <<-eos + $l = 10 + $s = 'seed' + $o = fqdn_rand_string($l, undef, $s) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/fqdn_rand_string is "3HS4mbuI3E"/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "3HS4mbuI3E"/) + end end - end - it 'generates random alphanumeric strings with custom charsets and seeds' do - shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'") - pp = <<-eos - $l = 10 - $c = '0123456789' - $s = 'seed' - $o = fqdn_rand_string($l, $c, $s) - notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) - eos + it 'generates random alphanumeric strings with custom charsets and seeds' do + pp = <<-eos + $l = 10 + $c = '0123456789' + $s = 'seed' + $o = fqdn_rand_string($l, $c, $s) + notice(inline_template('fqdn_rand_string is <%= @o.inspect %>')) + eos - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/fqdn_rand_string is "3104058232"/) + apply_manifest(pp, :catch_failures => true) do |r| + expect(r.stdout).to match(/fqdn_rand_string is "3104058232"/) + end end end end -- cgit v1.2.3 From 7943b25ec1abcb1c0e86cd42cdfd3b2d3d511ee8 Mon Sep 17 00:00:00 2001 From: Bryan Jen Date: Wed, 16 Mar 2016 13:57:36 -0700 Subject: (maint) Fixes fqdn_rand_string tests Puppet 4.4.0 and later has changed fqdn_rand to use a higher ceiling (PUP-5646), the tests for fqdn_rand_string needed to be updated to reflect the new expected output. --- spec/acceptance/fqdn_rand_string_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/acceptance/fqdn_rand_string_spec.rb') diff --git a/spec/acceptance/fqdn_rand_string_spec.rb b/spec/acceptance/fqdn_rand_string_spec.rb index 9c6d701..065a517 100644 --- a/spec/acceptance/fqdn_rand_string_spec.rb +++ b/spec/acceptance/fqdn_rand_string_spec.rb @@ -17,7 +17,7 @@ describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?( eos apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/fqdn_rand_string is "7oDp0KOr1b"/) + expect(r.stdout).to match(/fqdn_rand_string is "(7oDp0KOr1b|9Acvnhkt4J)"/) end end it 'generates random alphanumeric strings with custom charsets' do @@ -29,7 +29,7 @@ describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?( eos apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/fqdn_rand_string is "7203048515"/) + expect(r.stdout).to match(/fqdn_rand_string is "(7203048515|2383756694)"/) end end it 'generates random alphanumeric strings with custom seeds' do @@ -41,7 +41,7 @@ describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?( eos apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/fqdn_rand_string is "3HS4mbuI3E"/) + expect(r.stdout).to match(/fqdn_rand_string is "(3HS4mbuI3E|1jJtAMs94d)"/) end end it 'generates random alphanumeric strings with custom charsets and seeds' do @@ -54,7 +54,7 @@ describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?( eos apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(/fqdn_rand_string is "3104058232"/) + expect(r.stdout).to match(/fqdn_rand_string is "(3104058232|7100592312)"/) end end end -- cgit v1.2.3