repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/should_remove.rb | acceptance/tests/resource/package/ips/should_remove.rb | test_name "Package:IPS basic tests"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
on agent, "pkg install mypkg"
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
step "IPS: ensure removed."
apply_manifest_on(agent, 'package {mypkg : ensure=>absent}')
on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do
refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/should_be_updatable.rb | acceptance/tests/resource/package/ips/should_be_updatable.rb | test_name "Package:IPS test for updatable (update, latest)"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: basic - it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: ask to be latest"
send_pkg agent, :pkg => 'mypkg@0.0.2'
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
step "IPS: ensure it was upgraded"
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}")
end
step "IPS: when there are more than one option, choose latest."
send_pkg agent,:pkg => 'mypkg@0.0.3'
send_pkg agent,:pkg => 'mypkg@0.0.4'
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.4/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/should_be_versionable.rb | acceptance/tests/resource/package/ips/should_be_versionable.rb | test_name "Package:IPS versionable"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
send_pkg agent, :pkg => 'mypkg@0.0.2'
set_publisher agent
step "IPS: basic - it should create a specific version"
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1"}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
on agent, "pkg list mypkg" do
assert_match( /0.0.1/, result.stdout, "err: #{agent}")
end
step "IPS: it should upgrade if asked for next version"
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.2"}') do
assert_match( /ensure changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list mypkg" do
refute_match( /0.0.1/, result.stdout, "err: #{agent}")
assert_match( /0.0.2/, result.stdout, "err: #{agent}")
end
step "IPS: it should downpgrade if asked for previous version"
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1"}') do
assert_match( /ensure changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list mypkg" do
refute_match( /0.0.2/, result.stdout, "err: #{agent}")
assert_match( /0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/should_be_idempotent.rb | acceptance/tests/resource/package/ips/should_be_idempotent.rb | test_name "Package:IPS idempotency"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: should be idempotent (present)"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
refute_match( /created/, result.stdout, "err: #{agent}")
refute_match( /changed/, result.stdout, "err: #{agent}")
end
send_pkg agent, :pkg => 'mypkg@0.0.2'
step "IPS: ask for latest version"
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
step "IPS: ask for latest version again: should be idempotent (latest)"
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}') do
refute_match( /created/, result.stdout, "err: #{agent}")
end
step "IPS: ask for specific version"
send_pkg agent,:pkg => 'mypkg@0.0.3'
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3"}') do
assert_match( /changed/, result.stdout, "err: #{agent}")
end
step "IPS: ask for specific version again: should be idempotent (version)"
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3"}') do
refute_match( /created/, result.stdout, "err: #{agent}")
refute_match( /changed/, result.stdout, "err: #{agent}")
end
step "IPS: ensure removed."
apply_manifest_on(agent, 'package {mypkg : ensure=>absent}')
on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do
refute_match( /mypkg/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/basic_tests.rb | acceptance/tests/resource/package/ips/basic_tests.rb | test_name "Package:IPS basic tests"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: clean slate"
clean agent
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: basic ensure we are clean"
apply_manifest_on(agent, 'package {mypkg : ensure=>absent}')
on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do
refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
step "IPS: basic - it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: check it was created"
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}")
end
step "IPS: do not upgrade until latest is mentioned"
send_pkg agent,:pkg => 'mypkg@0.0.2'
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
refute_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: verify it was not upgraded"
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}")
end
step "IPS: ask to be latest"
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
step "IPS: ensure it was upgraded"
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.2[,:]?.*'/, result.stdout, "err: #{agent}")
end
step "IPS: when there are more than one option, choose latest."
send_pkg agent,:pkg => 'mypkg@0.0.3'
send_pkg agent,:pkg => 'mypkg@0.0.4'
apply_manifest_on(agent, 'package {mypkg : ensure=>latest}')
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.4[,:]?.*'/, result.stdout, "err: #{agent}")
end
step "IPS: ensure removed."
apply_manifest_on(agent, 'package {mypkg : ensure=>absent}')
on(agent, "pkg list -v mypkg", :acceptable_exit_codes => [1]) do
refute_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/should_be_holdable.rb | acceptance/tests/resource/package/ips/should_be_holdable.rb | test_name "Package:IPS versionable"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent, :pkg => 'mypkg2'
clean agent, :pkg => 'mypkg'
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
setup_fakeroot2 agent
send_pkg2 agent, :pkg => 'mypkg2@0.0.1'
set_publisher agent
step "IPS: basic - it should create a specific version and install dependent package"
apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.1"}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg2" do
assert_match( /mypkg2@0.0.1/, result.stdout, "err: #{agent}")
end
step "IPS: it should upgrade current and dependent package"
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.2'
setup_fakeroot2 agent
send_pkg2 agent, :pkg => 'mypkg2@0.0.2', :pkgdep => 'mypkg@0.0.2'
apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.2"}') do
assert_match( /changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg2" do
assert_match( /mypkg2@0.0.2/, result.stdout, "err: #{agent}")
end
step "IPS: it should not upgrade current and dependent package if dependent package is hold"
apply_manifest_on(agent, 'package {mypkg : ensure=>"present", mark=>"hold", provider=>"pkg"}') do
assert_match( //, result.stdout, "err: #{agent}")
end
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.3'
setup_fakeroot2 agent
send_pkg2 agent, :pkg => 'mypkg2@0.0.3', :pkgdep => 'mypkg@0.0.3'
apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.2"}') do
refute_match( /changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg2" do
assert_match( /mypkg2@0.0.2/, result.stdout, "err: #{agent}")
end
step "IPS: it should upgrade if hold was released."
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.3", provider=>"pkg"}') do
assert_match( //, result.stdout, "err: #{agent}")
end
apply_manifest_on(agent, 'package {mypkg2 : ensure=>"0.0.3"}') do
assert_match( /changed/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.3/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg2" do
assert_match( /mypkg2@0.0.3/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/should_be_updateable_and_unholdable_at_same_time.rb | acceptance/tests/resource/package/ips/should_be_updateable_and_unholdable_at_same_time.rb | test_name "Package:IPS test for updatable holded package" do
confine :to, :platform => 'solaris-11'
tag 'audit:high'
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
agents.each do |agent|
teardown do
clean agent
end
step "IPS: setup" do
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
end
step "IPS: it should create and hold in same manifest" do
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.1", mark=>hold}') do |result|
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
end
step "IPS: it should update and unhold in same manifest" do
send_pkg agent, :pkg => 'mypkg@0.0.2'
apply_manifest_on(agent, 'package {mypkg : ensure=>"0.0.2", mark=>"none"}')
end
step "IPS: ensure it was upgraded" do
on agent, "pkg list -v mypkg" do |result|
assert_match( /mypkg@0.0.2/, result.stdout, "err: #{agent}")
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/should_create.rb | acceptance/tests/resource/package/ips/should_create.rb | test_name "Package:IPS basic tests"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: clean slate"
clean agent
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: basic - it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>present}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
step "IPS: check it was created"
on(agent, puppet("resource package mypkg")) do
assert_match( /ensure\s+=> '0\.0\.1[,:]?.*'/, result.stdout, "err: #{agent}")
end
on agent, "pkg list -v mypkg" do
assert_match( /mypkg@0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/package/ips/should_query.rb | acceptance/tests/resource/package/ips/should_query.rb | test_name "Package:IPS query"
confine :to, :platform => 'solaris-11'
tag 'audit:medium',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
# actual changing of resources could irreparably damage a
# host running this, or require special permissions.
require 'puppet/acceptance/solaris_util'
extend Puppet::Acceptance::IPSUtils
teardown do
step "cleanup"
agents.each do |agent|
clean agent
end
end
agents.each do |agent|
step "IPS: setup"
setup agent
setup_fakeroot agent
send_pkg agent, :pkg => 'mypkg@0.0.1'
set_publisher agent
step "IPS: basic - it should create"
apply_manifest_on(agent, 'package {mypkg : ensure=>"present"}') do
assert_match( /ensure: created/, result.stdout, "err: #{agent}")
end
on(agent, puppet("resource package mypkg")) do
assert_match( /0.0.1/, result.stdout, "err: #{agent}")
end
on(agent, puppet("resource package")) do
assert_match( /0.0.1/, result.stdout, "err: #{agent}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/tidy/should_remove_old_files.rb | acceptance/tests/resource/tidy/should_remove_old_files.rb | test_name "Tidying files by date"
tag 'audit:high',
'audit:refactor', # Use block style `test_run`
'audit:integration'
agents.each do |agent|
step "Create a directory of old and new files"
dir = agent.tmpdir('tidy-test')
on agent, "mkdir -p #{dir}"
# YYMMddhhmm, so 03:04 Jan 2 1970
old = %w[one two three four five]
new = %w[a b c d e]
on agent, "touch -t 7001020304 #{dir}/{#{old.join(',')}}"
on agent, "touch #{dir}/{#{new.join(',')}}"
step "Run a tidy resource to remove the old files"
manifest = <<-MANIFEST
tidy { "#{dir}":
age => '1d',
recurse => true,
}
MANIFEST
apply_manifest_on agent, manifest
step "Ensure the old files are gone"
old_test = old.map {|name| "-f #{File.join(dir, name)}"}.join(' -o ')
on agent, "[ #{old_test} ]", :acceptable_exit_codes => [1]
step "Ensure the new files are still present"
new_test = new.map {|name| "-f #{File.join(dir, name)}"}.join(' -a ')
on agent, "[ #{new_test} ]"
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/resource/tidy/resources_should_be_non_isomorphic.rb | acceptance/tests/resource/tidy/resources_should_be_non_isomorphic.rb | # This test is to verify multi tidy resources with same path but
# different matches should not cause error as found in the bug PUP-6508
test_name "PUP-6655 - C98145 tidy resources should be non-isomorphic" do
tag 'audit:high',
'audit:integration'
agents. each do |agent|
dir = agent.tmpdir('tidy-test-dir')
on(agent, "mkdir -p #{dir}")
files = %w{file1.txt file2.doc}
on(agent, "touch #{dir}/{#{files.join(',')}}")
manifest = <<-MANIFEST
tidy {'tidy-resource1':
path => "#{dir}",
matches => "*.txt",
recurse => true,
}
tidy {'tidy-resource2':
path => "#{dir}",
matches => "*.doc",
recurse => true,
}
MANIFEST
step "Ensure the newly created files are present:" do
present = files.map {|file| "-f #{File.join(dir, file)}"}.join(' -a ')
on(agent, "[ #{present} ]")
end
step "Create multiple tidy resources with same path" do
apply_manifest_on(agent, manifest) do |result|
refute_match(/Error:/, result.stderr, "Unexpected error was detected")
end
end
step "Verify that the files are actually removed successfully:" do
present = files.map {|file| "-f #{File.join(dir, file)}"}.join(' -o ')
on(agent, "[ #{present} ]", :acceptable_exit_codes => [1])
end
teardown do
on(agent, puppet("apply -e \"file{'#{dir}': ensure => absent, force => true}\""))
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/aix/nim_package_provider.rb | acceptance/tests/aix/nim_package_provider.rb | test_name "NIM package provider should work correctly"
tag 'audit:high',
'audit:acceptance' # OS specific by definition
# nim test is slow, confine to only aix 7.2 and recent puppet versions
confine :to, :platform => "aix" do |aix|
version = on(aix, 'puppet --version').stdout
version &&
Gem::Version.new(version) > Gem::Version.new('6.4.0') &&
on(aix, 'facter os.release.full').stdout == '7.2'
end
teardown do
test_apply('cdrecord', 'absent', '')
test_apply('puppet.test.rte', 'absent', '')
end
def assert_package_version(package, expected_version)
# The output of lslpp is a colon-delimited list like:
# sudo:sudo.rte:1.8.6.4: : :C: :Configurable super-user privileges runtime: : : : : : :0:0:/:
# We want the version, so grab the third field
on(hosts, "lslpp -qLc #{package} | cut -f3 -d:") do |result|
actual_version = result.stdout.chomp
assert_equal(expected_version, actual_version, "Installed package version #{actual_version} does not match expected version #{expected_version}")
end
end
def get_manifest(package, ensure_value)
<<MANIFEST
package {'#{package}':
ensure => '#{ensure_value}',
source => 'lpp_custom',
provider => nim,
}
MANIFEST
end
def test_apply(package_name, ensure_value, expected_version)
manifest = get_manifest(package_name, ensure_value)
on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]),
{:stdin => manifest, :acceptable_exit_codes => [2]}
step "validate installed package version" do
assert_package_version package_name, expected_version
end
step "run again to ensure idempotency" do
on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]),
{:stdin => manifest, :acceptable_exit_codes => [0]}
end
step "validate installed package version" do
assert_package_version package_name, expected_version
end
end
# These two packages live in an LPP source on the NIM master. Details
# on our nim masters are available at
# https://confluence.puppetlabs.com/display/OPS/IBM+Power+LPARs
package_types = {
"RPM" => {
:package_name => "cdrecord",
:old_version => '1.9-6',
:new_version => '1.9-9'
},
"BFF" => {
:package_name => "puppet.test.rte",
:old_version => '1.0.0.0',
:new_version => '2.0.0.0'
}
}
step "Setup: ensure test packages are not installed" do
pkgs = ['cdrecord', 'puppet.test.rte']
pkgs.each do |pkg|
on hosts, puppet_apply(["--detailed-exitcodes", "--verbose"]),
{:stdin => get_manifest(pkg, 'absent'), :acceptable_exit_codes => [0,2]}
end
end
package_types.each do |package_type, details|
step "install a #{package_type} package via 'ensure=>present'" do
package_name = details[:package_name]
version = details[:new_version]
test_apply(package_name, 'present', version)
end
step "uninstall a #{package_type} package via 'ensure=>absent'" do
package_name = details[:package_name]
version = ''
test_apply(package_name, 'absent', version)
end
step "install a #{package_type} package via 'ensure=><OLD_VERSION>'" do
package_name = details[:package_name]
version = details[:old_version]
test_apply(package_name, version, version)
end
step "upgrade a #{package_type} package via 'ensure=><NEW_VERSION>'" do
package_name = details[:package_name]
version = details[:new_version]
test_apply(package_name, version, version)
end
step "attempt to downgrade a #{package_type} package via 'ensure=><OLD_VERSION>'" do
package_name = details[:package_name]
version = details[:old_version]
manifest = get_manifest(package_name, version)
on(hosts, puppet_apply("--verbose", "--detailed-exitcodes"),
{ :stdin => manifest,
:acceptable_exit_codes => [4,6] }) do |result|
assert_match(/NIM package provider is unable to downgrade packages/, result.stderr, "Didn't get an error about downgrading packages")
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/aix/aix_package_provider.rb | acceptance/tests/aix/aix_package_provider.rb | test_name "aix package provider should work correctly" do
tag 'audit:high',
'audit:acceptance' # OS specific by definition.
confine :to, :platform => /aix/
dir = "/tmp/aix-packages-#{$$}"
def assert_package_version(package, expected_version)
# The output of lslpp is a colon-delimited list like:
# sudo:sudo.rte:1.8.6.4: : :C: :Configurable super-user privileges runtime: : : : : : :0:0:/:
# We want the version, so grab the third field
on(hosts, "lslpp -qLc #{package} | cut -f3 -d:") do |result|
actual_version = result.stdout.chomp
assert_equal(expected_version, actual_version, "Installed package version #{actual_version} does not match expected version #{expected_version}")
end
end
def get_package_manifest(package, version, sourcedir)
<<-MANIFEST
package { '#{package}':
ensure => '#{version}',
provider => aix,
source => '#{sourcedir}',
}
MANIFEST
end
package = 'sudo.rte'
version1 = '1.7.10.4'
version2 = '1.8.6.4'
teardown do
on hosts, "rm -rf #{dir}"
on hosts, "installp -u #{package}"
end
step "download packages to use for test" do
on hosts, "mkdir -p #{dir}"
on hosts, "curl https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/misc/sudo.#{version1}.aix51.lam.bff > #{dir}/sudo.#{version1}.aix51.lam.bff"
on hosts, "curl https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/misc/sudo.#{version2}.aix51.lam.bff > #{dir}/sudo.#{version2}.aix51.lam.bff"
end
step "install the older version of package" do
apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :catch_failures => true)
end
step "verify package is installed and at the correct version" do
assert_package_version package, version1
end
step "install a newer version of the package" do
apply_manifest_on(hosts, get_package_manifest(package, version2, dir), :catch_failures => true)
end
step "verify package is installed and at the newer version" do
assert_package_version package, version2
end
step "test that downgrading fails by trying to install an older version of the package" do
apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :acceptable_exit_codes => [4,6]) do |res|
assert_match(/aix package provider is unable to downgrade packages/, res.stderr, "Didn't get an error about downgrading packages")
end
end
step "uninstall the package" do
apply_manifest_on(hosts, get_package_manifest(package, 'absent', dir), :catch_failures => true)
end
step "verify the package is gone" do
on hosts, "lslpp -qLc #{package}", :acceptable_exit_codes => [1]
end
step "install the older version of package" do
apply_manifest_on(hosts, get_package_manifest(package, version1, dir), :catch_failures => true)
end
step "verify package is installed and at the correct version" do
assert_package_version package, version1
end
step "install latest version of the package" do
apply_manifest_on(hosts, get_package_manifest(package, 'latest', dir), :catch_failures => true)
end
step "verify package is installed and at the correct version" do
assert_package_version package, version2
end
step "PUP-7818 remove a package without defining the source metaparameter" do
manifest = get_package_manifest(package, 'latest', dir)
manifest = manifest + "package { 'nonexistant_example_package.rte': ensure => absent, }"
apply_manifest_on(hosts, manifest, :catch_failures => true)
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/loader/func4x_loadable_from_modules.rb | acceptance/tests/loader/func4x_loadable_from_modules.rb | test_name "Exercise a module with 4x function and 4x system function"
# Purpose:
# Test that a packed puppet can call a 4x system function, and that a 4x function in
# a module can be called.
#
# Method:
# * Manually construct a very simple module with a manifest that creates a file.
# * The file has content that depends on logic that calls both a system function (reduce), and
# a function supplied in the module (helloworld::mul10).
# * The module is manually constructed to allow the test to also run on Windows where the module tool
# is not supported.
# * The module is included by calling 'include' from 'puppet apply'.
# * Puppet apply is executed to generate the file with the content.
# * The generated contents is asserted.
# TODO: The test can be improved by adding yet another module that calls the function in helloworld.
# TODO: The test can be improved to also test loading of a non namespaced function
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
tag 'audit:high',
'audit:unit' # This should be covered adequately by unit tests
initialize_temp_dirs
agents.each do |agent|
# The modulepath to use in environment 'dev'
envs_path = get_test_file_path(agent, 'environments')
dev_modulepath = get_test_file_path(agent, 'environments/dev/modules')
target_path = get_test_file_path(agent, 'output')
mkdirs agent, target_path
# make sure that we use the modulepath from the dev environment
puppetconf = get_test_file_path(agent, 'puppet.conf')
on agent, puppet("config", "set", "environmentpath", envs_path, "--section", "main", "--config", puppetconf)
on agent, puppet("config", "set", "environment", "dev", "--section", "user", "--config", puppetconf)
# Where the functions in the written modules should go
helloworld_functions = 'helloworld/lib/puppet/functions/helloworld'
# Clean out the module that will be written to ensure no interference from a previous run
on agent, "rm -rf #{File.join(dev_modulepath, 'helloworld')}"
mkdirs agent, File.join(dev_modulepath, helloworld_functions)
# Write a module
# Write the function helloworld::mul10, that multiplies its argument by 10
create_remote_file(agent, File.join(dev_modulepath, helloworld_functions, "mul10.rb"), <<'SOURCE')
Puppet::Functions.create_function(:'helloworld::mul10') do
def mul10(x)
x * 10
end
end
SOURCE
# Write a manifest that calls a 4x function (reduce), and calls a function defined in the module
# (helloworld::mul10).
#
mkdirs agent, File.join(dev_modulepath, "helloworld", "manifests")
create_remote_file(agent, File.join(dev_modulepath, "helloworld", "manifests", "init.pp"), <<SOURCE)
class helloworld {
file { "#{target_path}/result.txt":
ensure => 'file',
mode => '0666',
content => [1,2,3].reduce("Generated") |$memo, $n| {
"${memo}, ${n} => ${helloworld::mul10($n)}"
}
}
}
SOURCE
# Run apply to generate the file with the output
on(agent, puppet('apply', '-e', "'include helloworld'", '--config', puppetconf))
# Assert that the file was written with the generated content
on(agent, "cat #{File.join(target_path, 'result.txt')}") do |result|
assert_match(/^Generated, 1 => 10, 2 => 20, 3 => 30$/, result.stdout, "Generated the wrong content")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/loader/autoload_from_resource_type_decl.rb | acceptance/tests/loader/autoload_from_resource_type_decl.rb | test_name 'C100303: Resource type statement triggered auto-loading works both with and without generated types' do
tag 'risk:high'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/agent_fqdn_utils'
extend Puppet::Acceptance::AgentFqdnUtils
# create the file and make sure its empty and accessible by everyone
def empty_execution_log_file(host, path)
create_remote_file(host, path, '')
on(host, "chmod 777 '#{path}'")
end
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
relative_type_dir = 'modules/one/lib/puppet/type'
relative_type_path = "#{relative_type_dir}/type_tst.rb"
execution_log = {}
execution_log[agent_to_fqdn(master)] = master.tmpfile('master_autoload_resource')
agents.each do |agent|
execution_log[agent_to_fqdn(agent)] = agent.tmpfile('agent_autoload_resource')
end
teardown do
on(master, "rm -f '#{execution_log[agent_to_fqdn(master)]}'")
agents.each do |agent|
on(agent, "rm -f '#{execution_log[agent_to_fqdn(agent)]}'")
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step 'create custom type' do
on(master, "mkdir -p '#{fq_tmp_environmentpath}/#{relative_type_dir}'")
# create a custom type that will write out to a different file on each agent
# this way we can verify whether the newtype code was executed on each system
custom_type = <<-END
Puppet::Type.newtype(:type_tst) do
newparam(:name, :namevar => true) do
fqdn = Facter.value('networking.fqdn')
if fqdn == '#{agent_to_fqdn(master)}'
File.open("#{execution_log[agent_to_fqdn(master)]}", 'a+') { |f| f.puts("found_type_tst: " + Time.now.to_s) }
end
END
agents.each do |agent|
custom_type << <<-END
if fqdn == '#{agent_to_fqdn(agent)}'
File.open("#{execution_log[agent_to_fqdn(agent)]}", 'a+') { |f| f.puts("found_type_tst: " + Time.now.to_s) }
end
END
end
custom_type << <<-END
Puppet.notice("found_type_tst")
end
end
END
create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_type_path}", custom_type)
site_pp = <<-PP
Resource['type_tst'] { 'found_type': }
PP
create_sitepp(master, tmp_environment, site_pp)
end
on(master, "chmod -R 755 '/tmp/#{tmp_environment}'")
# when the agent does its run, the newtype is executed on both the agent and master nodes
# so we should see a message in the execution log file on the agent and the master
agents.each do |agent|
with_puppet_running_on(master, {}) do
empty_execution_log_file(master, execution_log[agent_to_fqdn(master)])
empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)])
on(agent, puppet("agent -t --environment '#{tmp_environment}'")) do |puppet_result|
assert_match(/\/File\[.*\/type_tst.rb\]\/ensure: defined content as/, puppet_result.stdout,
'Expected to see defined content message for type: type_tst')
assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see the notice from the new type: type_tst')
end
on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result|
assert_match(/found_type_tst:/, cat_result.stdout,
"Expected to see execution log entry on master #{agent_to_fqdn(master)}")
end
on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result|
assert_match(/found_type_tst:/, cat_result.stdout,
"Expected to see execution log entry on agent #{agent_to_fqdn(agent)}")
end
end
end
# when generating the pcore the newtype should only be run on the master node
step 'generate pcore files' do
# start with an empty execution log
empty_execution_log_file(master, execution_log[agent_to_fqdn(master)])
agents.each do |agent|
empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)])
end
on(master, puppet("generate types --environment '#{tmp_environment}'")) do |puppet_result|
assert_match(/Notice: Generating '\/.*\/type_tst\.pp' using 'pcore' format/, puppet_result.stdout,
'Expected to see Generating message for type: type_tst')
assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see log entry on master ')
end
# we should see a log entry on the master node
on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result|
assert_match(/found_type_tst:/, cat_result.stdout,
"Expected to see execution log entry on master #{agent_to_fqdn(master)}")
end
# we should not see any log entries on any of the agent nodes
agents.each do |agent|
next if agent == master
on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result|
assert_empty(cat_result.stdout.chomp, "Expected execution log file to be empty on agent node #{agent_to_fqdn(agent)}")
end
end
end
empty_execution_log_file(master, execution_log[agent_to_fqdn(master)])
agents.each do |agent|
next if agent == master
empty_execution_log_file(agent, execution_log[agent_to_fqdn(agent)])
# this test is relying on the beaker helper with_puppet_running_on() to restart the server
# Compilation should now work using the generated types,
# so we should only see a log entry on the agent node and nothing on the master node
with_puppet_running_on(master, {}) do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"),
:acceptable_exit_codes => 0) do |puppet_result|
assert_match(/Notice: found_type_tst/, puppet_result.stdout, 'Expected to see output from new type: type_tst')
end
end
on(agent, "cat '#{execution_log[agent_to_fqdn(agent)]}'") do |cat_result|
assert_match(/found_type_tst:/, cat_result.stdout,
"Expected to see an execution log entry on agent #{agent_to_fqdn(agent)}")
end
end
on(master, "cat '#{execution_log[agent_to_fqdn(master)]}'") do |cat_result|
assert_empty(cat_result.stdout.chomp, "Expected master execution log to be empty #{agent_to_fqdn(master)}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/loader/resource_triggers_autoload.rb | acceptance/tests/loader/resource_triggers_autoload.rb | test_name 'C100296: can auto-load defined types using a Resource statement' do
tag 'risk:high'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
relative_define_type_dir = 'modules/one/manifests'
relative_define_type_1_path = "#{relative_define_type_dir}/tst1.pp"
relative_define_type_2_path = "#{relative_define_type_dir}/tst2.pp"
step 'create custom type in two environments' do
on(master, "mkdir -p #{fq_tmp_environmentpath}/#{relative_define_type_dir}")
define_type_1 = <<-END
define one::tst1($var) {
notify { "tst1: ${var}": }
}
END
define_type_2 = <<-END
define one::tst2($var) {
notify { "tst2: ${var}": }
}
END
create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_define_type_1_path}", define_type_1)
create_remote_file(master, "#{fq_tmp_environmentpath}/#{relative_define_type_2_path}", define_type_2)
site_pp = <<-PP
each(['tst1', 'tst2']) |$nr| {
Resource["one::${nr}"] { "some_title_${nr}": var => "Define found one::${nr}" }
}
PP
create_sitepp(master, tmp_environment, site_pp)
end
on(master, "chmod -R 755 /tmp/#{tmp_environment}")
with_puppet_running_on(master, {}) do
agents.each do |agent|
on(agent, puppet("agent -t --environment #{tmp_environment}"),
:acceptable_exit_codes => 2) do |puppet_result|
assert_match(/Notice: tst1: Define found one::tst1/, puppet_result.stdout, 'Expected to see output from define notify')
assert_match(/Notice: tst2: Define found one::tst2/, puppet_result.stdout, 'Expected to see output from define notify')
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/ordering/master_agent_application.rb | acceptance/tests/ordering/master_agent_application.rb | test_name "Puppet applies resources without dependencies in file order over the network"
tag 'audit:high',
'audit:integration',
'server'
testdir = master.tmpdir('application_order')
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0750",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}':;
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/production/manifests/site.pp':
ensure => file,
mode => "0640",
content => '
notify { "first": }
notify { "second": }
notify { "third": }
notify { "fourth": }
notify { "fifth": }
notify { "sixth": }
notify { "seventh": }
notify { "eighth": }
';
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
}
}
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
on(agent, puppet('agent', "--no-daemonize --onetime --verbose")) do |result|
if result.stdout !~ /Notice: first.*Notice: second.*Notice: third.*Notice: fourth.*Notice: fifth.*Notice: sixth.*Notice: seventh.*Notice: eighth/m
fail_test "Output did not include the notify resources in the correct order"
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/apply/classes/should_allow_param_undef_override.rb | acceptance/tests/apply/classes/should_allow_param_undef_override.rb | test_name "should allow overriding a parameter to undef in inheritence"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
agents.each do |agent|
dir = agent.tmpdir('class_undef_override')
out = File.join(dir, 'class_undef_override_out')
source = File.join(dir, 'class_undef_override_test')
manifest = %Q{
class parent {
file { 'test':
path => '#{out}',
source => '#{source}',
}
}
class child inherits parent {
File['test'] {
source => undef,
content => 'hello new world!',
}
}
include parent
include child
}
step "prepare the target file on all systems"
on(agent, "echo 'hello world!' > #{out}")
step "apply the manifest"
apply_manifest_on(agent, manifest)
step "verify the file content"
on(agent, "cat #{out}") do |result|
fail_test "the file was not touched" if result.stdout.include? "hello world!"
fail_test "the file was not updated" unless result.stdout.include? "hello new world"
end
on(agent, "rm -rf #{dir}")
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/apply/classes/should_include_resources_from_class.rb | acceptance/tests/apply/classes/should_include_resources_from_class.rb | test_name "resources declared in a class can be applied with include"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
manifest = %q{
class x {
notify{'a':}
}
include x
}
apply_manifest_on(agents, manifest) do |result|
fail_test "the resource did not apply" unless result.stdout.include?("defined 'message' as 'a'")
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb | acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb | test_name "resources declared in classes are not applied without include"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
manifest = %q{ class x { notify { 'test': message => 'never invoked' } } }
apply_manifest_on(agents, manifest) do |result|
fail_test "found the notify despite not including it" if
result.stdout.include? "never invoked"
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/apply/classes/parameterized_classes.rb | acceptance/tests/apply/classes/parameterized_classes.rb | test_name "parametrized classes"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
########################################################################
step "should allow param classes"
manifest = %q{
class x($y, $z) {
notice("${y}-${z}")
}
class {x: y => '1', z => '2'}
}
apply_manifest_on(agents, manifest) do |result|
fail_test "inclusion after parameterization failed" unless result.stdout.include? "1-2"
end
########################################################################
# REVISIT: This was ported from the old set of tests, but I think that
# the desired behaviour has recently changed. --daniel 2010-12-23
step "should allow param class post inclusion"
manifest = %q{
class x($y, $z) {
notice("${y}-${z}")
}
class {x: y => '1', z => '2'}
include x
}
apply_manifest_on(agents, manifest) do |result|
fail_test "inclusion after parameterization failed" unless result.stdout.include? "1-2"
end
########################################################################
step "should allow param classes defaults"
manifest = %q{
class x($y, $z='2') {
notice("${y}-${z}")
}
class {x: y => '1'}
}
apply_manifest_on(agents, manifest) do |result|
fail_test "the default didn't apply as expected" unless result.stdout.include? "1-2"
end
########################################################################
step "should allow param class defaults to be overridden"
manifest = %q{
class x($y, $z='2') {
notice("${y}-${z}")
}
class {x: y => '1', z => '3'}
}
apply_manifest_on(agents, manifest) do |result|
fail_test "the override didn't happen as we expected" unless result.stdout.include? "1-3"
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/apply/classes/should_allow_param_override.rb | acceptance/tests/apply/classes/should_allow_param_override.rb | test_name "should allow param override"
tag 'audit:high',
'audit:unit' # This should be covered at the unit layer.
manifest = %q{
class parent {
notify { 'msg':
message => parent,
}
}
class child inherits parent {
Notify['msg'] {message => 'child'}
}
include parent
include child
}
apply_manifest_on(agents, manifest) do |result|
fail_test "parameter override didn't work" unless
result.stdout.include? "defined 'message' as 'child'"
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/lookup/v4_hieradata_with_v5_configs.rb | acceptance/tests/lookup/v4_hieradata_with_v5_configs.rb | test_name 'C99572: v4 hieradata with v5 configs' do
require 'puppet/acceptance/puppet_type_test_tools.rb'
extend Puppet::Acceptance::PuppetTypeTestTools
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
confdir = puppet_config(master, 'confdir', section: 'master')
hiera_conf_backup = master.tmpfile('C99572-hiera-yaml')
step "backup global hiera.yaml" do
on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1])
end
teardown do
step "restore global hiera.yaml" do
on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create global hiera.yaml and data" do
create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: "%{environment}"
data_hash: yaml_data
path: "%{environment}.yaml"
- name: common
data_hash: yaml_data
path: "common.yaml"
HIERA
on(master, "chmod 755 #{confdir}/hiera.yaml")
create_remote_file(master, "#{confdir}/#{tmp_environment}.yaml", <<-YAML)
---
environment_key: environment_key-global_env_file
global_key: global_key-global_env_file
YAML
create_remote_file(master, "#{confdir}/common.yaml", <<-YAML)
---
environment_key: environment_key-global_common_file
global_key: global_key-global_common_file
YAML
end
step "create environment hiera.yaml and data" do
on(master, "mkdir -p #{fq_tmp_environmentpath}/data")
create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: "%{environment}"
data_hash: yaml_data
path: "%{environment}.yaml"
- name: common
data_hash: yaml_data
path: "common.yaml"
- name: hocon
data_hash: hocon_data
path: "common.conf"
HIERA
create_remote_file(master, "#{fq_tmp_environmentpath}/data/#{tmp_environment}.yaml", <<-YAML)
---
environment_key: "environment_key-env_file"
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/data/common.yaml", <<-YAML)
---
environment_key: "environment_key-common_file"
global_key: "global_key-common_file"
YAML
step "C99628: add hocon backend and data" do
create_remote_file(master, "#{fq_tmp_environmentpath}/data/common.conf", <<-HOCON)
environment_key2 = "hocon value",
HOCON
end
create_sitepp(master, tmp_environment, <<-SITE)
notify { "${lookup('environment_key')}": }
notify { "${lookup('global_key')}": }
notify { "${lookup('environment_key2')}": }
SITE
on(master, "chmod -R 755 #{fq_tmp_environmentpath}")
end
step 'assert lookups using lookup subcommand' do
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "1: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/environment_key-env_file/, result.stdout,
'lookup environment_key subcommand didn\'t find correct key')
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'global_key'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "2: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/global_key-common_file/, result.stdout,
'lookup global_key subcommand didn\'t find correct key')
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "3: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/hocon value/, result.stdout,
'lookup environment_key2 subcommand didn\'t find correct key')
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step 'agent lookup' do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/global_key-common_file/m, result.stdout,
'agent lookup didn\'t find global key')
assert_match(/environment_key-env_file/m, result.stdout,
'agent lookup didn\'t find environment_key')
assert_match(/hocon value/m, result.stdout,
'agent lookup didn\'t find environment_key2')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/lookup/merge_strategies.rb | acceptance/tests/lookup/merge_strategies.rb | test_name 'C99903: merge strategies' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type + '1')
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
tmp_environment2 = mk_tmp_environment_with_teardown(master, app_type + '2')
fq_tmp_environmentpath2 = "#{environmentpath}/#{tmp_environment2}"
master_confdir = puppet_config(master, 'confdir', section: 'master')
hiera_conf_backup = master.tmpfile(app_type)
teardown do
step "restore default global hiera.yaml" do
on(master, "mv #{hiera_conf_backup} #{master_confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create global hiera.yaml and environment data" do
step "backup global hiera.yaml" do
on(master, "cp -a #{master_confdir}/hiera.yaml #{hiera_conf_backup}")
end
create_remote_file(master, "#{master_confdir}/hiera.yaml", <<-HIERA)
---
:backends:
- yaml
:yaml:
:datadir: "/etc/puppetlabs/code/environments/%{::environment}/hieradata"
:hierarchy:
- "host"
- "roles"
- "profiles"
- "%{facts.os.name}"
- "%{facts.os.family}"
- "%{facts.kernel}"
- "common"
:merge_behavior: deeper
:deep_merge_options:
:merge_hash_arrays: true
HIERA
on(master, "chown puppet:puppet #{master_confdir}/hiera.yaml")
on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/")
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/host.yaml", <<-YAML)
---
profiles:
webserver:
apache:
httpd:
modules:
- mpm_prefork
- php
- ssl
arrayed_hash:
the_hash:
- array1:
key1: val1
key2: val2
array:
- foo
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/profiles.yaml", <<-YAML)
profiles:
webserver:
apache:
httpd:
modules:
- auth_kerb
- authnz_ldap
- cgid
- php
- status
array:
- bar
YAML
create_sitepp(master, tmp_environment, <<-SITE)
notify { "hiera_hash: ${hiera_hash ('profiles')['webserver']['apache']['httpd']['modules']}": }
notify { "lookup1: ${lookup ('profiles')['webserver']['apache']['httpd']['modules']}": }
notify { "lookup1b: ${lookup ({'name' => 'profiles', 'merge' => 'deep'})['webserver']['apache']['httpd']['modules']}": }
notify { "hiera_merge_hash: ${hiera_hash ('arrayed_hash')}": }
notify { "lookup_arrayed_hash: ${lookup ({'name' => 'arrayed_hash', 'merge' => {'strategy' => 'deep', 'merge_hash_arrays' => true}})}": }
notify { "hiera-array: ${hiera ('array')}": }
notify { "hiera_array: ${hiera_array ('array')}": }
notify { "lookup-array: ${lookup ('array')}": }
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath}")
end
step "create another environment, hiera5 config and environment data: #{tmp_environment2}" do
create_remote_file(master, "#{fq_tmp_environmentpath2}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: "%{environment}/host"
data_hash: yaml_data
path: "hieradata/host.yaml"
- name: "%{environment}/profiles"
data_hash: yaml_data
path: "hieradata/profiles.yaml"
HIERA
on(master, "mkdir -p #{fq_tmp_environmentpath2}/hieradata/")
create_remote_file(master, "#{fq_tmp_environmentpath2}/hieradata/host.yaml", <<-YAML)
---
profiles:
webserver:
apache:
httpd:
modules:
- mpm_prefork
- php
- ssl
arrayed_hash:
the_hash:
- array1:
key1: val1
key2: val2
array:
- foo
lookup_options:
'profiles':
merge:
strategy: deep
YAML
create_remote_file(master, "#{fq_tmp_environmentpath2}/hieradata/profiles.yaml", <<-YAML)
profiles:
webserver:
apache:
httpd:
modules:
- auth_kerb
- authnz_ldap
- cgid
- php
- status
array:
- bar
lookup_options:
'profiles':
merge:
strategy: deep
YAML
create_sitepp(master, tmp_environment2, <<-SITE)
notify { "hiera_hash: ${hiera_hash ('profiles')['webserver']['apache']['httpd']['modules']}": }
notify { "lookup2: ${lookup ('profiles')['webserver']['apache']['httpd']['modules']}": }
notify { "lookup2b: ${lookup ({'name' => 'profiles', 'merge' => 'first'})['webserver']['apache']['httpd']['modules']}": }
notify { "hiera_merge_hash: ${hiera_hash ('arrayed_hash')}": }
notify { "lookup_arrayed_hash: ${lookup ({'name' => 'arrayed_hash', 'merge' => {'strategy' => 'deep', 'merge_hash_arrays' => true}})}": }
notify { "hiera-array: ${hiera ('array')}": }
notify { "hiera_array: ${hiera_array ('array')}": }
notify { "lookup-array: ${lookup ('array')}": }
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath2}")
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookups #{agent.hostname}, hiera3" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
# hiera_hash will honor old global merge strategies, which were a bad idea
assert_match(/hiera_hash: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout,
"1: agent hiera_hash didn't find correct key")
# so, lookup doesn't honor them except on a by-key or by-lookup basis
assert_match(/lookup1: \[mpm_prefork, php, ssl\]/, result.stdout,
"1: agent lookup didn't find correct key")
assert_match(/lookup1b: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout,
"1b: agent lookup didn't find correct key")
assert_match(/hiera_merge_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout,
"agent hiera_hash 1 merge_hash_arrays didn't work properly")
assert_match(/lookup_arrayed_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout,
"agent lookup 1 deep merge with merge_hash_arrays didn't work properly")
assert_match(/hiera-array: \[foo\]/, result.stdout,
"hiera() lookup of an array with deeper should be merged")
assert_match(/hiera_array: \[foo, bar\]/, result.stdout,
"hiera_array() lookup of an array should be merged")
assert_match(/lookup-array: \[foo\]/, result.stdout,
"lookup() lookup of an array should default to first")
end
end
step "agent lookups #{agent.hostname}, hiera5" do
on(agent, puppet('agent', "-t --environment #{tmp_environment2}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/hiera_hash: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout,
"2: agent hiera_hash didn't find correct key")
assert_match(/lookup2: \[auth_kerb, authnz_ldap, cgid, php, status, mpm_prefork, ssl\]/, result.stdout,
"2: agent lookup didn't find correct key")
assert_match(/lookup2b: \[mpm_prefork, php, ssl\]/, result.stdout,
"2b: agent lookup didn't find correct key")
assert_match(/hiera_merge_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout,
"agent hiera_hash 2 merge_hash_arrays didn't work properly")
assert_match(/lookup_arrayed_hash: {the_hash => \[{array1 => {key1 => val1, key2 => val2}}\]}/, result.stdout,
"agent lookup 2 deep merge with merge_hash_arrays didn't work properly")
assert_match(/hiera-array: \[foo\]/, result.stdout,
"hiera() 2 lookup in hiera5 of an array should default to first")
assert_match(/hiera_array: \[foo, bar\]/, result.stdout,
"hiera_array() 2 lookup of an array should be merged")
assert_match(/lookup-array: \[foo\]/, result.stdout,
"lookup() 2 lookup in hiera5 of an array should default to first")
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/lookup/config5_interpolation.rb | acceptance/tests/lookup/config5_interpolation.rb | test_name 'C99578: hiera5 lookup config with interpolated scoped nested variables' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # This test specifically tests interpolation on the master.
# Recommend adding an additonal test that validates
# lookup in a masterless setup.
'server'
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type + '1')
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create environment hiera5.yaml and environment data" do
create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA)
---
version: 5
defaults:
datadir: 'hieradata'
data_hash: yaml_data
hierarchy:
- name: "Global settings"
path: "global.yaml"
- name: "Role specific settings"
paths:
- "roles/%{::roles.0}.yaml"
- name: "Other Role specific settings"
paths:
- "roles/%{roles2.0}.yaml"
- name: "scoped variable"
paths:
- "roles/%{::myclass::myvar.0}.yaml"
- name: "nested hash variable"
paths:
- "roles/%{::hash_array.key1.0}.yaml"
HIERA
on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/roles")
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/global.yaml", <<-YAML)
roles:
- test1
roles2:
- test2
data:
- "from global"
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test1.yaml", <<-YAML)
data:
- 'from test1'
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test2.yaml", <<-YAML)
data:
- 'from test2'
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test3.yaml", <<-YAML)
data:
- 'from test3'
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/roles/test4.yaml", <<-YAML)
data:
- 'from test4'
YAML
create_sitepp(master, tmp_environment, <<-SITE)
class myclass {
$myvar = ['test3']
}
include myclass
$hash_array = {key1 => ['test4']}
$roles = lookup('roles')
$data = lookup('data', Array[String], 'unique')
notify{"data: ${data}":}
$hiera_array_data = hiera_array('data')
notify{"hiera_array_data: ${hiera_array_data}":}
$roles2 = lookup('roles2')
$data2 = lookup('data', Array[String], 'unique')
notify{"data2: ${data2}":}
$hiera_array_data2 = hiera_array('data')
notify{"hiera_array_data2: ${hiera_array_data2}":}
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath}")
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookups: #{agent.hostname}, hiera5" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/data: \[from global, from test1/, result.stdout,
"agent lookup didn't interpolate with hiera value")
assert_match(/hiera_array_data: \[from global, from test1/, result.stdout,
"agent hiera_array didn't interpolate with hiera value")
assert_match(/data2: \[from global, from test1, from test2/, result.stdout,
"agent lookup didn't interpolate non-global scope with hiera value")
assert_match(/hiera_array_data2: \[from global, from test1, from test2/, result.stdout,
"agent hiera_array didn't interpolate non-global scope with hiera value")
assert_match(/data2: \[from global, from test1, from test2, from test3/, result.stdout,
"agent lookup didn't interpolate class scope with hiera value")
assert_match(/hiera_array_data2: \[from global, from test1, from test2, from test3/, result.stdout,
"agent hiera_array didn't interpolate class scope with hiera value")
assert_match(/data2: \[from global, from test1, from test2, from test3, from test4\]/, result.stdout,
"agent lookup didn't interpolate nested hashes with hiera value")
assert_match(/hiera_array_data2: \[from global, from test1, from test2, from test3, from test4\]/, result.stdout,
"agent hiera_array didn't interpolate nested hashes with hiera value")
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/lookup/lookup_rich_values.rb | acceptance/tests/lookup/lookup_rich_values.rb | test_name 'C99044: lookup should allow rich data as values' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local environment.
'server'
# The following two lines are required for the puppetserver service to
# start correctly. These should be removed when PUP-7102 is resolved.
confdir = puppet_config(master, 'confdir', section: 'master')
on(master, "chown puppet:puppet #{confdir}/hiera.yaml")
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
sensitive_value_rb = 'foot, no mouth'
sensitive_value_pp = 'toe, no step'
sensitive_value_pp2 = 'toe, no module'
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create ruby lookup function in #{tmp_environment}" do
on(master, "mkdir -p #{fq_tmp_environmentpath}/lib/puppet/functions/environment")
create_remote_file(master, "#{fq_tmp_environmentpath}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: Test
data_hash: rich_data_test
- name: Test2
data_hash: some_mod::rich_data_test2
- name: Test3
data_hash: rich_data_test3
HIERA
create_remote_file(master, "#{fq_tmp_environmentpath}/lib/puppet/functions/rich_data_test.rb", <<-FUNC)
Puppet::Functions.create_function(:rich_data_test) do
def rich_data_test(options, context)
rich_type_instance = Puppet::Pops::Types::PSensitiveType::Sensitive.new("#{sensitive_value_rb}")
{
'environment_key' => rich_type_instance,
}
end
end
FUNC
end
step "create puppet language lookup function in #{tmp_environment} module" do
on(master, "mkdir -p #{fq_tmp_environmentpath}/modules/some_mod/functions")
create_remote_file(master, "#{fq_tmp_environmentpath}/modules/some_mod/functions/rich_data_test2.pp", <<-FUNC)
function some_mod::rich_data_test2($options, $context) {
{
"environment_key2" => Sensitive('#{sensitive_value_pp}'),
}
}
FUNC
on(master, "chmod -R a+rw #{fq_tmp_environmentpath}")
end
step "C99571: create puppet language lookup function in #{tmp_environment}" do
on(master, "mkdir -p #{fq_tmp_environmentpath}/functions")
create_remote_file(master, "#{fq_tmp_environmentpath}/functions/rich_data_test3.pp", <<-FUNC)
function rich_data_test3($options, $context) {
{
"environment_key3" => Sensitive('#{sensitive_value_pp2}'),
}
}
FUNC
on(master, "chmod -R a+rw #{fq_tmp_environmentpath}")
end
step "create site.pp which calls lookup on our keys" do
create_sitepp(master, tmp_environment, <<-SITE)
notify { "${unwrap(lookup('environment_key'))}": }
notify { "${unwrap(lookup('environment_key2'))}": }
notify { "${unwrap(lookup('environment_key3'))}": }
SITE
end
step 'assert lookups using lookup subcommand' do
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "lookup subcommand using ruby function didn't exit properly: (#{result.exit_code})")
assert_match(sensitive_value_rb, result.stdout,
"lookup subcommand using ruby function didn't find correct key")
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "lookup subcommand using puppet function in module didn't exit properly: (#{result.exit_code})")
assert_match(sensitive_value_pp, result.stdout,
"lookup subcommand using puppet function in module didn't find correct key")
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key3'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "lookup subcommand using puppet function didn't exit properly: (#{result.exit_code})")
assert_match(sensitive_value_pp2, result.stdout,
"lookup subcommand using puppet function didn't find correct key")
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookup in ruby function" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup using ruby function didn't exit properly: (#{result.exit_code})")
assert_match(sensitive_value_rb, result.stdout,
"agent lookup using ruby function didn't find correct key")
assert_match(sensitive_value_pp, result.stdout,
"agent lookup using puppet function in module didn't find correct key")
assert_match(sensitive_value_pp2, result.stdout,
"agent lookup using puppet function didn't find correct key")
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/lookup/lookup.rb | acceptance/tests/lookup/lookup.rb | test_name "Lookup data using the agnostic lookup function" do
# pre-docs:
# https://puppet-on-the-edge.blogspot.com/2015/01/puppet-40-data-in-modules-and.html
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
# Use mk_tmp_environment_with_teardown to create environment.
'server'
testdir = master.tmpdir('lookup')
module_name = "data_module"
module_name2 = "other_module"
hash_name = "hash_name"
array_key = "array_key"
env_data_implied_key = "env_data_implied"
env_data_implied_value = "env_implied_a"
env_data_key = "env_data"
env_data_value = "env_a"
env_hash_key = "env_hash_key"
env_hash_value = "env_class_a"
env_array_value0 = "env_array_a"
env_array_value1 = "env_array_b"
module_data_implied_key = "module_data_implied"
module_data_implied_value = "module_implied_b"
module_data_key = "module_data"
module_data_value = "module_b"
module_data_value_other = "other_module_b"
module_hash_key = "module_hash_key"
module_hash_value = "module_class_b"
module_array_value0 = "module_array_a"
module_array_value1 = "module_array_b"
env_data_override_implied_key = "env_data_override_implied"
env_data_override_implied_value = "env_override_implied_c"
env_data_override_key = "env_data_override"
env_data_override_value = "env_override_c"
hiera_data_implied_key = "apache_server_port_implied"
hiera_data_implied_value = "8080"
hiera_data_key = "apache_server_port"
hiera_data_value = "9090"
hiera_hash_key = "hiera_hash_key"
hiera_hash_value = "hiera_class_c"
hiera_array_value0 = "hiera_array_a"
hiera_array_value1 = "hiera_array_b"
automatic_data_key = "automatic_data_key"
automatic_data_value = "automatic_data_value"
automatic_default_value = "automatic_default_value"
def mod_manifest_entry(module_name = nil, testdir, module_data_implied_key,
module_data_implied_value, module_data_key,
module_data_value, hash_name, module_hash_key,
module_hash_value, array_key, module_array_value0,
module_array_value1)
if module_name
module_files_manifest = <<PP
# the function to provide data for this module
file { '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/functions/#{module_name}/data.rb':
ensure => file,
content => "
Puppet::Functions.create_function(:'#{module_name}::data') do
def data()
{ '#{module_name}::#{module_data_implied_key}' => '#{module_data_implied_value}',
'#{module_name}::#{module_data_key}' => '#{module_data_value}',
'#{module_name}::#{hash_name}' => {'#{module_hash_key}' => '#{module_hash_value}'},
'#{module_name}::#{array_key}' => ['#{module_array_value0}', '#{module_array_value1}']
}
end
end
",
mode => "0640",
}
PP
module_files_manifest
end
end
def mod_manifest_metadata_json(module_name = nil, testdir)
if module_name
<<PPmetadata
file { '#{testdir}/environments/production/modules/#{module_name}/metadata.json':
ensure => file,
content => '
{
"name": "tester-#{module_name}",
"version": "0.1.0",
"author": "tester",
"summary": null,
"license": "Apache-2.0",
"source": "",
"project_page": null,
"issues_url": null,
"dependencies": [
],
"data_provider": "function"
}
',
mode => "0644",
}
file { '#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings':
ensure => absent,
force => true,
}
PPmetadata
end
end
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
module_manifest1 = mod_manifest_entry(module_name, testdir, module_data_implied_key,
module_data_implied_value, module_data_key, module_data_value,
hash_name, module_hash_key, module_hash_value, array_key,
module_array_value0, module_array_value1)
module_manifest2 = mod_manifest_entry(module_name2, testdir, module_data_implied_key,
module_data_implied_value, module_data_key, module_data_value_other,
hash_name, module_hash_key, module_hash_value, array_key,
module_array_value0, module_array_value1)
metadata_manifest1 = mod_manifest_metadata_json(module_name, testdir)
metadata_manifest2 = mod_manifest_metadata_json(module_name2, testdir)
apply_manifest_on(master, <<-PP, :catch_failures => true)
File {
ensure => directory,
mode => "0750",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}':;
'#{testdir}/hieradata':;
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/production/modules':;
'#{testdir}/environments/production/lib':;
'#{testdir}/environments/production/lib/puppet':;
'#{testdir}/environments/production/lib/puppet/functions':;
'#{testdir}/environments/production/lib/puppet/functions/environment':;
'#{testdir}/environments/production/modules/#{module_name}':;
'#{testdir}/environments/production/modules/#{module_name}/manifests':;
'#{testdir}/environments/production/modules/#{module_name}/lib':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet/bindings/#{module_name}':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet/functions':;
'#{testdir}/environments/production/modules/#{module_name}/lib/puppet/functions/#{module_name}':;
'#{testdir}/environments/production/modules/#{module_name2}':;
'#{testdir}/environments/production/modules/#{module_name2}/manifests':;
'#{testdir}/environments/production/modules/#{module_name2}/lib':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/bindings':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/bindings/#{module_name2}':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/functions':;
'#{testdir}/environments/production/modules/#{module_name2}/lib/puppet/functions/#{module_name2}':;
}
file { '#{testdir}/hiera.yaml':
ensure => file,
content => '---
:backends:
- "yaml"
:logger: "console"
:hierarchy:
- "global"
:yaml:
:datadir: "#{testdir}/hieradata"
',
mode => "0640",
}
file { '#{testdir}/hieradata/global.yaml':
ensure => file,
content => "---
#{hiera_data_key}: #{hiera_data_value}
#{module_name}::#{hiera_data_implied_key}: #{hiera_data_implied_value}
#{module_name}::#{hash_name}:
#{hiera_hash_key}: #{hiera_hash_value}
#{module_name}::#{array_key}:
- #{hiera_array_value0}
- #{hiera_array_value1}
#{module_name}::#{automatic_data_key}: #{automatic_data_value}
",
mode => "0640",
}
file { '#{testdir}/environments/production/environment.conf':
ensure => file,
content => '
environment_timeout = 0
# for this environment, provide our own function to supply data to lookup
# implies a ruby function in <environment>/lib/puppet/functions/environment/data.rb
# named environment::data()
environment_data_provider = "function"
',
mode => "0640",
}
# the function to provide data for this environment
file { '#{testdir}/environments/production/lib/puppet/functions/environment/data.rb':
ensure => file,
content => "
Puppet::Functions.create_function(:'environment::data') do
def data()
{ '#{module_name}::#{env_data_implied_key}' => '#{env_data_implied_value}',
'#{module_name}::#{env_data_override_implied_key}' => '#{env_data_override_implied_value}',
'#{env_data_key}' => '#{env_data_value}',
'#{module_name}::#{hash_name}' => {'#{env_hash_key}' => '#{env_hash_value}'},
'#{env_data_override_key}' => '#{env_data_override_value}',
'#{module_name}::#{array_key}' => ['#{env_array_value0}', '#{env_array_value1}']
}
end
end
",
mode => "0640",
}
# place module file segments here
#{module_manifest1}
# same key, different module and values
#{module_manifest2}
file { '#{testdir}/environments/production/modules/#{module_name}/manifests/init.pp':
ensure => file,
content => '
class #{module_name}($#{env_data_implied_key},
$#{module_data_implied_key},
$#{env_data_override_implied_key},
$#{hiera_data_implied_key},
$#{automatic_data_key}=$#{automatic_default_value}) {
# lookup data from the environment function databinding
notify { "#{env_data_implied_key} $#{env_data_implied_key}": }
$lookup_env = lookup("#{env_data_key}")
notify { "#{env_data_key} $lookup_env": }
# lookup data from the module databinding
notify { "#{module_data_implied_key} $#{module_data_implied_key}": }
$lookup_module = lookup("#{module_name}::#{module_data_key}")
notify { "#{module_data_key} $lookup_module": }
# lookup data from another modules databinding
$lookup_module2 = lookup("#{module_name2}::#{module_data_key}")
notify { "#{module_data_key} $lookup_module2": }
# ensure env can override module
notify { "#{env_data_override_implied_key} $#{env_data_override_implied_key}": }
$lookup_override = lookup("#{env_data_override_key}")
notify { "#{env_data_override_key} $lookup_override": }
# should fall-back to hiera global.yaml data
notify { "#{hiera_data_implied_key} $#{hiera_data_implied_key}": }
$lookup_port = lookup("#{hiera_data_key}")
notify { "#{hiera_data_key} $lookup_port": }
# should be able to merge hashes across sources
# this mimicks/covers behavior for including classes
$lookup_hash = lookup("#{module_name}::#{hash_name}",Hash[String,String],\\'hash\\')
notify { "#{hash_name} $lookup_hash": }
# should be able to make an array across sources
# this mimicks/covers behavior for including classes
$lookup_array = lookup("#{module_name}::#{array_key}",Array[String],\\'unique\\')
notify { "yep": message => "#{array_key} $lookup_array" }
# automatic data lookup of parametrized class
notify { "#{automatic_data_key} $#{automatic_data_key}": }
}',
mode => "0640",
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
content => "
node default {
include #{module_name}
}",
mode => "0640",
}
PP
apply_manifest_on(master, <<-PP, :catch_failures => true)
#{metadata_manifest1}
#{metadata_manifest2}
PP
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
'hiera_config' => "#{testdir}/hiera.yaml",
},
}
with_puppet_running_on master, master_opts, testdir do
step "Lookup string data, binding specified in metadata.json" do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [0, 2]) do |result|
assert_match("#{env_data_implied_key} #{env_data_implied_value}", result.stdout)
assert_match("#{env_data_key} #{env_data_value}", result.stdout)
assert_match("#{module_data_implied_key} #{module_data_implied_value}", result.stdout)
assert_match("#{module_data_key} #{module_data_value}", result.stdout)
assert_match("#{module_data_key} #{module_data_value_other}", result.stdout)
assert_match("#{env_data_override_implied_key} #{env_data_override_implied_value}", result.stdout)
assert_match("#{env_data_override_key} #{env_data_override_value}", result.stdout)
assert_match("#{hiera_data_implied_key} #{hiera_data_implied_value}", result.stdout)
assert_match("#{hiera_data_key} #{hiera_data_value}", result.stdout)
assert_match("#{hash_name} {#{module_hash_key} => #{module_hash_value}, #{env_hash_key} => #{env_hash_value}, #{hiera_hash_key} => #{hiera_hash_value}}", result.stdout)
assert_match("#{array_key} [#{hiera_array_value0}, #{hiera_array_value1}, #{env_array_value0}, #{env_array_value1}, #{module_array_value0}, #{module_array_value1}]", result.stdout)
assert_match("#{automatic_data_key} #{automatic_data_value}", result.stdout)
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/lookup/v3_config_and_data.rb | acceptance/tests/lookup/v3_config_and_data.rb | test_name 'C99629: hiera v5 can use v3 config and data' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
hiera_conf_backup = master.tmpfile('C99629-hiera-yaml')
step "create hiera v3 global config and data" do
confdir = puppet_config(master, 'confdir', section: 'master')
step "backup global hiera.yaml" do
on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1])
end
teardown do
step "restore global hiera.yaml" do
on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create global hiera.yaml and module data" do
create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA)
---
:backends:
- "yaml"
- "json"
- "hocon"
:hierarchy:
- "somesuch"
- "common"
HIERA
on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/")
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.yaml", <<-YAML)
---
environment_key1: "env value1"
environment_key3: "env value3"
YAML
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.json", <<-JSON)
{
"environment_key1" : "wrong value",
"environment_key2" : "env value2"
}
JSON
step "C99628: add hocon backend and data" do
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/somesuch.conf", <<-HOCON)
environment_key4 = "hocon value",
HOCON
end
create_sitepp(master, tmp_environment, <<-SITE)
notify { "${lookup('environment_key1')}": }
notify { "${lookup('environment_key2')}": }
notify { "${lookup('environment_key3')}": }
notify { "${lookup('environment_key4')}": }
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath}")
on(master, "chmod -R 775 #{confdir}")
end
end
step 'assert lookups using lookup subcommand' do
step 'assert lookup --explain using lookup subcommand' do
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key1 --explain'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "1: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/env value1/, result.stdout,
"1: lookup subcommand didn't find correct key")
assert_match(/hiera configuration version 3/, result.stdout,
"hiera config version not reported properly")
assert_match(/#{fq_tmp_environmentpath}\/hieradata\/somesuch\.yaml/, result.stdout,
"hiera hierarchy abs path not reported properly")
assert_match(/path: "somesuch"/, result.stdout,
"hiera hierarchy path not reported properly")
end
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key2'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "2: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/env value2/, result.stdout,
"2: lookup subcommand didn't find correct key")
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key3'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "3: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/env value3/, result.stdout,
"3: lookup subcommand didn't find correct key")
end
on(master, puppet('lookup', "--environment #{tmp_environment}", 'environment_key4'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "4: lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/hocon value/, result.stdout,
"4: lookup subcommand didn't find correct key")
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookup" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/env value1/, result.stdout,
"1: agent lookup didn't find correct key")
assert_match(/env value2/, result.stdout,
"2: agent lookup didn't find correct key")
assert_match(/env value3/, result.stdout,
"3: agent lookup didn't find correct key")
assert_match(/hocon value/, result.stdout,
"4: agent lookup didn't find correct key")
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/lookup/config3_interpolation.rb | acceptance/tests/lookup/config3_interpolation.rb | test_name 'C99578: lookup should allow interpolation in hiera3 configs' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # This test specifically tests interpolation on the master.
# Recommend adding an additonal test that validates
# lookup in a masterless setup.
'server'
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
master_confdir = puppet_config(master, 'confdir', section: 'master')
hiera_conf_backup = master.tmpfile('C99578-hiera-yaml')
step "backup global hiera.yaml" do
on(master, "cp -a #{master_confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1])
end
teardown do
on(master, "mv #{hiera_conf_backup} #{master_confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create hiera configs in #{tmp_environment} and global" do
step "create global hiera.yaml and module data" do
create_remote_file(master, "#{master_confdir}/hiera.yaml", <<-HIERA)
---
:backends:
- "yaml"
:hierarchy:
- "%{calling_class_path}"
- "%{calling_class}"
- "%{calling_module}"
- "common"
HIERA
on(master, "mkdir -p #{fq_tmp_environmentpath}/hieradata/")
on(master, "mkdir -p #{fq_tmp_environmentpath}/modules/some_mod/manifests")
create_remote_file(master, "#{fq_tmp_environmentpath}/modules/some_mod/manifests/init.pp", <<-PP)
class some_mod {
notify { "${lookup('environment_key')}": }
}
PP
create_remote_file(master, "#{fq_tmp_environmentpath}/hieradata/some_mod.yaml", <<-YAML)
---
environment_key: "env value"
YAML
create_sitepp(master, tmp_environment, <<-SITE)
include some_mod
SITE
on(master, "chmod -R 775 #{fq_tmp_environmentpath}")
on(master, "chmod -R 775 #{master_confdir}")
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent lookup" do
on(agent, puppet('agent', "-t --environment #{tmp_environment} --debug"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/env value/, result.stdout,
"agent lookup didn't find correct key")
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/lookup/hiera3_custom_backend.rb | acceptance/tests/lookup/hiera3_custom_backend.rb | test_name 'C99630: hiera v3 custom backend' do
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/temp_file_utils.rb'
extend Puppet::Acceptance::TempFileUtils
tag 'audit:high',
'audit:acceptance',
'audit:refactor', # Master is not needed for this test. Refactor
# to use puppet apply with a local module tree.
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
puppetserver_config = "#{master['puppetserver-confdir']}/puppetserver.conf"
existing_loadpath = read_tk_config_string(on(master, "cat #{puppetserver_config}").stdout.strip)['jruby-puppet']['ruby-load-path'].first
confdir = puppet_config(master, 'confdir', section: 'master')
hiera_conf_backup = master.tmpfile('C99629-hiera-yaml')
step "backup global hiera.yaml" do
on(master, "cp -a #{confdir}/hiera.yaml #{hiera_conf_backup}", :acceptable_exit_codes => [0,1])
end
teardown do
step 'delete custom backend, restore default hiera config' do
on(master, "rm #{existing_loadpath}/hiera/backend/custom_backend.rb", :acceptable_exit_codes => [0,1])
on(master, "mv #{hiera_conf_backup} #{confdir}/hiera.yaml", :acceptable_exit_codes => [0,1])
on(master, "/opt/puppetlabs/server/bin/puppetserver gem uninstall --executables --force hiera")
on(master, "/opt/puppetlabs/puppet/bin/gem uninstall --executables --force hiera")
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "install hiera v3 gem" do
# for puppet agent <-> server, hiera must be installed using puppetserver's gem command
on(master, "/opt/puppetlabs/server/bin/puppetserver gem install --no-document hiera")
# for puppet lookup, hiera must be installed using puppet's gem command
on(master, "/opt/puppetlabs/puppet/bin/gem install --no-document hiera")
end
step "create hiera v5 config and v3 custom backend" do
on(master, "cp #{confdir}/hiera.yaml /tmp")
create_remote_file(master, "#{confdir}/hiera.yaml", <<-HIERA)
---
version: 5
hierarchy:
- name: Test
hiera3_backend: custom
HIERA
on(master, "chmod -R #{PUPPET_CODEDIR_PERMISSIONS} #{confdir}")
on(master, "mkdir -p #{existing_loadpath}/hiera/backend/")
custom_backend_rb = <<-RB
class Hiera
module Backend
class Custom_backend
def lookup(key, scope, order_override, resolution_type, context)
return 'custom value' unless (key == 'lookup_options')
end
end
end
end
RB
create_remote_file(master, "#{existing_loadpath}/hiera/backend/custom_backend.rb", custom_backend_rb)
on(master, "chmod #{PUPPET_CODEDIR_PERMISSIONS} #{existing_loadpath}/hiera/backend/custom_backend.rb")
end
step "create site.pp which calls lookup on our keys" do
create_sitepp(master, tmp_environment, <<-SITE)
notify { "${lookup('anykey')}": }
SITE
on(master, "chmod -R #{PUPPET_CODEDIR_PERMISSIONS} #{fq_tmp_environmentpath}")
end
step 'assert lookups using lookup subcommand on the master' do
on(master, puppet('lookup', "--environment #{tmp_environment}", '--explain', 'anykey'), :accept_all_exit_codes => true) do |result|
assert(result.exit_code == 0, "lookup subcommand didn't exit properly: (#{result.exit_code})")
assert_match(/custom value/, result.stdout,
"lookup subcommand didn't find correct key")
end
end
with_puppet_running_on(master,{}) do
agents.each do |agent|
step "agent manifest lookup on #{agent.hostname}" do
on(agent, puppet('agent', "-t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert(result.exit_code == 2, "agent lookup didn't exit properly: (#{result.exit_code})")
assert_match(/custom value/, result.stdout,
"agent lookup didn't find correct key")
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/enable_option_disable_i18n.rb | acceptance/tests/i18n/enable_option_disable_i18n.rb | test_name 'Verify that disable_i18n can be set to true and have translations disabled' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
step "configure server locale to #{language}" do
configure_master_system_locale(language)
end
tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*'))
step 'install a i18ndemo module' do
install_i18n_demo_module(master, tmp_environment)
end
disable_i18n_default_master = master.puppet['disable_i18n']
teardown do
step 'resetting the server locale' do
on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }"))
reset_master_system_locale
end
step 'uninstall the module' do
agents.each do |agent|
uninstall_i18n_demo_module(agent)
end
uninstall_i18n_demo_module(master)
end
end
agents.each do |agent|
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
on(master, puppet("config set disable_i18n false"))
reset_master_system_locale
end
step 'expect #{language} translation for a custom type' do
site_pp_content = <<-PP
node default {
i18ndemo_type { '12345': }
}
PP
create_sitepp(master, tmp_environment, site_pp_content)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, result.stderr, 'missing error from invalid value for custom type param')
end
end
step 'disable i18n' do
on(agent, puppet("config set disable_i18n true"))
on(master, puppet("config set disable_i18n true"))
reset_master_system_locale
end
step 'expect no #{language} translation for a custom type' do
site_pp_content = <<-PP
node default {
i18ndemo_type { '12345': }
}
PP
create_sitepp(master, tmp_environment, site_pp_content)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Error: .* Value 12345 is not a valid value for i18ndemo_type\:\:name/, result.stderr)
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/translation_fallback.rb | acceptance/tests/i18n/translation_fallback.rb | test_name 'C100560: puppet agent run output falls back to english when language not available' do
# No confines because even on non-translation supported OS' we should still fall back to english
tag 'audit:medium',
'audit:acceptance'
agents.each do |agent|
step 'Run Puppet apply with language Hungarian and check the output' do
unsupported_language='hu_HU'
on(agent, puppet("agent -t",
'ENV' => {'LANG' => unsupported_language, 'LANGUAGE' => ''})) do |apply_result|
assert_match(/Applying configuration version '[^']*'/, apply_result.stdout,
'agent run should default to english translation')
assert_match(/Applied catalog in [0-9.]* seconds/, apply_result.stdout,
'agent run should default to english translation')
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_resource.rb | acceptance/tests/i18n/modules/puppet_resource.rb | test_name 'C100572: puppet resource with module translates messages' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step "Run puppet resource for a module with language #{agent_language} and verify the translations" do
step 'puppet resource i18ndemo_type information contains translation' do
on(agent, puppet('resource i18ndemo_type', 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Warning: Puppet::Type::I18ndemo_type::ProviderRuby: \w+-i18ndemo type: i18ndemo_typeからの警告メッセージ/, result.stderr, 'missing translation of resource i18ndemo_type information')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_apply_module_lang.rb | acceptance/tests/i18n/modules/puppet_apply_module_lang.rb | test_name 'C100574: puppet apply using a module should translate messages in a language not supported by puppet' do
confine :except, :platform => /^windows/ # Can't print Finish on an English or Japanese code page
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language='fi_FI'
agents.each do |agent|
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
type_path = agent.tmpdir('provider')
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
on(agent, "rm -rf '#{type_path}'")
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step "Run puppet apply of a module with language #{agent_language} and verify default english returned" do
step 'verify custom fact message translated and applied catalog message not translatated' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/i18ndemo_fact: tämä on korotus mukautetusta tosiasiasta \w+-i18ndemo/,
apply_result.stderr, 'missing translated message for raise from ruby fact')
assert_match(/Notice: Applied catalog in [0-9.]+ seconds/, apply_result.stdout, 'missing untranslated message for catalog applied')
end
end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved
step 'verify warning translated from init.pp' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning: .*I18ndemo-tiedoston luominen/, apply_result.stderr, 'missing translated warning from init.pp')
end
on(agent, puppet("apply -e \"class { 'i18ndemo': param1 => false }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error: .* tiedostoa ei voitu luoda./, apply_result.stderr, 'missing translated message for fail from init.pp')
end
end
step 'verify custom type messages translated' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Warning: .* Hyvä arvo i18ndemo_type::name/, apply_result.stderr, 'missing translated warning from custom type')
end
on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error: .* Arvo 12345 ei ole kelvollinen arvo i18ndemo_type::name/, apply_result.stderr, 'missing translated error from invalid value for custom type param')
end
end
step 'verify custom provider translation' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning: .* Onko i18ndemo_type olemassa\?/, apply_result.stderr, 'missing translated provider message')
end
end
step 'verify function string translation' do
on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Notice: --\*SE ON HAUSKAA AIKAA\*--/, apply_result.stdout, 'missing translated notice message')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_describe.rb | acceptance/tests/i18n/modules/puppet_describe.rb | test_name 'C100576: puppet describe with module type translates message' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step "Run puppet describe from a module with language #{agent_language} and verify the translations" do
on(agent, puppet('describe i18ndemo_type', 'ENV' => shell_env_language)) do |result|
assert_match(/\w+-i18ndemo type: dirパラメータは、検査するディレクトリパスをとります/, result.stdout, 'missing translation of dir parameter from i18ndemo_type')
assert_match(/\w+-i18ndemo type: nameパラメータには、大文字と小文字の変数A-Za-zが使用されます/, result.stdout, 'missing translation of name parameter from i18ndemo_type')
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_apply_unsupported_lang.rb | acceptance/tests/i18n/modules/puppet_apply_unsupported_lang.rb | test_name 'C100568: puppet apply of module for an unsupported language should fall back to english' do
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
unsupported_language='hu_HU'
shell_env_language = { 'LANGUAGE' => unsupported_language, 'LANG' => unsupported_language }
agents.each do |agent|
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
type_path = agent.tmpdir('provider')
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
on(agent, "rm -rf '#{type_path}'")
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step "Run puppet apply of a module with language #{unsupported_language} and verify default english returned" do
step 'verify custom fact messages not translatated' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/.*i18ndemo_fact: this is a raise from a custom fact from \w+-i18ndemo/, apply_result.stderr, 'missing untranslated message for raise from ruby fact')
end
end
step 'verify warning not translated from init.pp' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning:.*Creating an i18ndemo file/, apply_result.stderr, 'missing untranslated warning from init.pp')
end
on(agent, puppet("apply -e \"class { 'i18ndemo': param1 => false }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error:.*Failed to create/, apply_result.stderr, 'missing untranslated message for fail from init.pp')
end
end
step 'verify custom type messages not translated' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Warning:.*Good value for i18ndemo_type::name/, apply_result.stderr, 'missing untranslated warning from custom type')
end
on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error:.*Value 12345 is not a valid value for i18ndemo_type::name/, apply_result.stderr, 'missing untranslated error from invalid value for custom type param')
end
end
step 'verify custom provider translation' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning:.* Does i18ndemo_type exist\?/, apply_result.stderr, 'missing untranslated provider message')
end
end
step 'verify function string translation' do
on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Notice: --\*IT'S HAPPY FUN TIME\*--/, apply_result.stdout, 'missing untranslated notice message')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_agent_cached_catalog.rb | acceptance/tests/i18n/modules/puppet_agent_cached_catalog.rb | test_name 'C100566: puppet agent with module should translate messages when using a cached catalog' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
disable_i18n_default_master = master.puppet['disable_i18n']
step 'enable i18n on master' do
on(master, puppet("config set disable_i18n false"))
end
step "configure server locale to #{language}" do
configure_master_system_locale(language)
end
tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*'))
step 'install a i18ndemo module' do
install_i18n_demo_module(master, tmp_environment)
end
teardown do
step 'resetting the server locale' do
on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }"))
reset_master_system_locale
end
step 'uninstall the module' do
agents.each do |agent|
uninstall_i18n_demo_module(agent)
end
uninstall_i18n_demo_module(master)
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
type_path = agent.tmpdir('provider')
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
agent.rm_rf(type_path)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
unresolved_server = 'puppet.unresolved.host.example.com'
step "Run puppet apply of a module with language #{agent_language} and verify the translations using the cached catalog" do
step 'verify custom fact translations' do
site_pp_content_1 = <<-PP
node default {
class { 'i18ndemo':
filename => '#{type_path}'
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_1)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact')
end
on(agent, puppet("agent -t --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact when using cached catalog')
end
end
step 'verify custom provider translation' do
site_pp_content_2 = <<-PP
node default {
i18ndemo_type { 'hello':
ensure => present,
dir => '#{type_path}',
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_2)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message')
end
on(agent, puppet("agent -t --server #{unresolved_server} --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message when using cached catalog')
end
end
step 'verify function string translation' do
site_pp_content_3 = <<-PP
node default {
notify { 'happy':
message => happyfuntime('happy')
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_3)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message')
end
on(agent, puppet("agent -t --server #{unresolved_server} --environment #{tmp_environment} --use_cached_catalog", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message when using cached catalog')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_face.rb | acceptance/tests/i18n/modules/puppet_face.rb | test_name 'C100573: puppet application/face with module translates messages' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
step "Run puppet i18ndemo (face/application from a module with language #{agent_language} and verify the translations" do
step 'puppet --help contains i18ndemo summary translation' do
on(agent, puppet('--help', 'ENV' => shell_env_language)) do |result|
assert_match(/\s*i18ndemo\s+\w+-i18ndemo face: I18ndemoモジュールの人形の顔の例/, result.stdout, 'missing translation of i18ndemo help summary')
end
end
step 'puppet i18ndemo --help contains test_face summary' do
on(agent, puppet('i18ndemo --help', 'ENV' => shell_env_language)) do |result|
assert_match(/\s*test_face\s+\w+-i18ndemo face: test_faceアクションのヘルプの要約/, result.stdout, 'missing translation of i18ndemo face help summary')
end
end
step 'puppet i18ndemo test_face contains translated warning' do
on(agent, puppet('i18ndemo', 'ENV' => shell_env_language)) do |result|
assert_match(/Warning: \w+-i18ndemo face: i18ndemo test_faceが呼び出されました/, result.stderr, 'missing translation of Warning message from i18ndemo face')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_apply.rb | acceptance/tests/i18n/modules/puppet_apply.rb | test_name 'C100567: puppet apply of module should translate messages' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
# REMIND - It was noted that skipping tests on certain platforms sometimes causes
# beaker to mark the test as a failed even if the test succeeds on other targets.
# Hence we just print a message and skip w/o telling beaker about it.
if on(agent, facter("fips_enabled")).stdout =~ /true/
puts "Module build, loading and installing is not supported on fips enabled platforms"
next
end
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
type_path = agent.tmpdir('provider')
step 'install a i18ndemo module' do
install_i18n_demo_module(agent)
end
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
uninstall_i18n_demo_module(agent)
on(agent, "rm -rf '#{type_path}'")
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step "Run puppet apply of a module with language #{agent_language} and verify the translations" do
step 'verify custom fact translations' do
on(agent, puppet("apply -e \"class { 'i18ndemo': filename => '#{type_path}' }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, apply_result.stderr, 'missing translation for raise from ruby fact')
end
end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved
step 'verify custom translations' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Warning:.*\w+-i18ndemo type: 良い値/, apply_result.stderr, 'missing warning from custom type')
end
on(agent, puppet("apply -e \"i18ndemo_type { '12345': }\"", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |apply_result|
assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, apply_result.stderr, 'missing error from invalid value for custom type param')
end
end
step 'verify custom provider translation' do
on(agent, puppet("apply -e \"i18ndemo_type { 'hello': ensure => present, dir => '#{type_path}', }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, apply_result.stderr, 'missing translated provider message')
end
end
step 'verify function string translation' do
on(agent, puppet("apply -e \"notify { 'happy': message => happyfuntime('happy') }\"", 'ENV' => shell_env_language)) do |apply_result|
assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, apply_result.stdout, 'missing translated notice message')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_agent.rb | acceptance/tests/i18n/modules/puppet_agent.rb | test_name 'C100565: puppet agent with module should translate messages' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
skip_test('i18n test module uses deprecated function; update module to resume testing.')
# function validate_absolute_path used https://github.com/eputnam/eputnam-i18ndemo/blob/621d06d/manifests/init.pp#L15
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
disable_i18n_default_master = master.puppet['disable_i18n']
step 'enable i18n on master' do
on(master, puppet("config set disable_i18n false"))
end
step "configure server locale to #{language}" do
configure_master_system_locale(language)
end
tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*'))
step 'install a i18ndemo module' do
install_i18n_demo_module(master, tmp_environment)
end
teardown do
step 'resetting the server locale' do
on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }"))
reset_master_system_locale
end
step 'uninstall the module' do
agents.each do |agent|
uninstall_i18n_demo_module(agent)
end
uninstall_i18n_demo_module(master)
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
type_path = agent.tmpdir('provider')
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
agent.rm_rf(type_path)
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
step "Run puppet agent of a module with language #{agent_language} and verify the translations" do
step 'verify custom fact translations' do
site_pp_content_1 = <<-PP
node default {
class { 'i18ndemo':
filename => '#{type_path}'
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_1)
on(agent, puppet("agent -t --no-disable_i18n --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/.*\w+-i18ndemo fact: これは\w+-i18ndemoからのカスタムファクトからのレイズです/, result.stderr, 'missing translation for raise from ruby fact')
end
end unless agent['platform'] =~ /ubuntu-16.04/ # Condition to be removed after FACT-2799 gets resolved
step 'verify custom type translations' do
site_pp_content_2 = <<-PP
node default {
i18ndemo_type { 'hello': }
}
PP
create_sitepp(master, tmp_environment, site_pp_content_2)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Warning:.*\w+-i18ndemo type: 良い値/, result.stderr, 'missing warning from custom type')
end
site_pp_content_3 = <<-PP
node default {
i18ndemo_type { '12345': }
}
PP
create_sitepp(master, tmp_environment, site_pp_content_3)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 1) do |result|
assert_match(/Error: .* \w+-i18ndemo type: 値は有12345効な値ではありません/, result.stderr, 'missing error from invalid value for custom type param')
end
end
step 'verify custom provider translation' do
site_pp_content_4 = <<-PP
node default {
i18ndemo_type { 'hello':
ensure => present,
dir => '#{type_path}',
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_4)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language)) do |result|
assert_match(/Warning:.*\w+-i18ndemo provider: i18ndemo_typeは存在しますか/, result.stderr, 'missing translated provider message')
end
end
step 'verify function string translation' do
site_pp_content_5 = <<-PP
node default {
notify { 'happy':
message => happyfuntime('happy')
}
}
PP
create_sitepp(master, tmp_environment, site_pp_content_5)
on(agent, puppet("agent -t --environment #{tmp_environment}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result|
assert_match(/Notice: --\*\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/i18n/modules/puppet_agent_with_multiple_environments.rb | acceptance/tests/i18n/modules/puppet_agent_with_multiple_environments.rb | test_name 'C100575: puppet agent with different modules in different environments should translate based on their module' do
confine :except, :platform => /^solaris/ # translation not supported
tag 'audit:medium',
'audit:acceptance'
require 'puppet/acceptance/environment_utils.rb'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/i18n_utils'
extend Puppet::Acceptance::I18nUtils
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
language = 'ja_JP'
app_type_1 = File.basename(__FILE__, '.*') + "_env_1"
app_type_2 = File.basename(__FILE__, '.*') + "_env_2"
tmp_environment_1 = mk_tmp_environment_with_teardown(master, app_type_1)
tmp_environment_2 = mk_tmp_environment_with_teardown(master, app_type_2)
full_path_env_1 = File.join('/tmp', tmp_environment_1)
full_path_env_2 = File.join('/tmp', tmp_environment_2)
tmp_po_file = master.tmpfile('tmp_po_file')
disable_i18n_default_master = master.puppet['disable_i18n']
step 'enable i18n on master' do
on(master, puppet("config set disable_i18n false"))
end
step 'install a i18ndemo module' do
install_i18n_demo_module(master, tmp_environment_1)
install_i18n_demo_module(master, tmp_environment_2)
end
step "configure server locale to #{language}" do
configure_master_system_locale(language)
end
teardown do
on(master, "rm -f '#{tmp_po_file}'")
step 'uninstall the module' do
agents.each do |agent|
uninstall_i18n_demo_module(agent)
end
uninstall_i18n_demo_module(master)
end
step 'resetting the server locale' do
on(master, puppet("config set disable_i18n #{ disable_i18n_default_master }"))
reset_master_system_locale
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
agents.each do |agent|
skip_test('on windows this test only works on a machine with a japanese code page set') if agent['platform'] =~ /windows/ && agent['locale'] != 'ja'
agent_language = enable_locale_language(agent, language)
skip_test("test machine is missing #{agent_language} locale. Skipping") if agent_language.nil?
shell_env_language = { 'LANGUAGE' => agent_language, 'LANG' => agent_language }
disable_i18n_default_agent = agent.puppet['disable_i18n']
teardown do
on(agent, puppet("config set disable_i18n #{ disable_i18n_default_agent }"))
end
step 'enable i18n' do
on(agent, puppet("config set disable_i18n false"))
end
env_1_po_file = File.join(full_path_env_1, 'modules', I18NDEMO_NAME, 'locales', 'ja', "#{I18NDEMO_MODULE_NAME}.po")
on(master, "sed -e 's/\\(msgstr \"\\)\\([^\"]\\)/\\1'\"ENV_1\"':\\2/' #{env_1_po_file} > #{tmp_po_file} && mv #{tmp_po_file} #{env_1_po_file}")
env_2_po_file = File.join(full_path_env_2, 'modules', I18NDEMO_NAME, 'locales', 'ja', "#{I18NDEMO_MODULE_NAME}.po")
on(master, "sed -e 's/\\(msgstr \"\\)\\([^\"]\\)/\\1'\"ENV_2\"':\\2/' #{env_2_po_file} > #{tmp_po_file} && mv #{tmp_po_file} #{env_2_po_file}")
on(master, "chmod a+r '#{env_1_po_file}' '#{env_2_po_file}'")
step 'verify function string translation' do
site_pp_content = <<-PP
node default {
notify { 'happy':
message => happyfuntime('happy')
}
}
PP
create_sitepp(master, tmp_environment_1, site_pp_content)
on(agent, puppet("agent -t --environment #{tmp_environment_1}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result|
assert_match(/Notice: --\*(ENV_1:)?ENV_1:\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message for environment 1')
end
create_sitepp(master, tmp_environment_2, site_pp_content)
on(agent, puppet("agent -t --environment #{tmp_environment_2}", 'ENV' => shell_env_language), :acceptable_exit_codes => 2) do |result|
assert_match(/Notice: --\*(ENV_2:)?ENV_2:\w+-i18ndemo function: それは楽しい時間です\*--/, result.stdout, 'missing translated notice message for environment 2')
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/reports/corrective_change_via_puppet.rb | acceptance/tests/reports/corrective_change_via_puppet.rb | test_name "C98094 - a resource changed via Puppet manifest will not be reported as a corrective change" do
require 'yaml'
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/agent_fqdn_utils'
extend Puppet::Acceptance::AgentFqdnUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # Uses a server currently, but is testing agent report
'broken:images',
'server'
test_file_name = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name)
tmp_file = {}
original_test_data = 'this is my original important data'
modified_test_data = 'this is my modified important data'
agents.each do |agent|
tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment)
end
teardown do
# Remove all traces of the last used environment
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
step 'clean out produced resources' do
agents.each do |agent|
if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != ''
on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)
end
end
end
end
def create_manifest_for_file_resource(file_resource, file_contents, environment_name)
manifest = <<-MANIFEST
file { '#{environmentpath}/#{environment_name}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$facts["networking"]["fqdn"] ? #{file_resource}
file { \$test_path:
content => @(UTF8)
#{file_contents}
| UTF8
}
',
}
MANIFEST
apply_manifest_on(master, manifest, :catch_failures => true)
end
step 'create file resource in site.pp' do
create_manifest_for_file_resource(tmp_file, original_test_data, tmp_environment)
end
step 'run agent(s) to create the new resource' do
with_puppet_running_on(master, {}) do
agents.each do |agent|
step 'Run agent once to create new File resource' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_contents|
assert_equal(original_test_data, file_contents, 'file contents did not match expected contents')
end
end
end
step 'Change the manifest for the resource' do
create_manifest_for_file_resource(tmp_file, modified_test_data, tmp_environment)
end
agents.each do |agent|
step 'Run agent a 2nd time to change the File resource' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_contents|
assert_equal(modified_test_data, file_contents, 'file contents did not match expected contents')
end
end
end
end
end
# Open last_run_report.yaml
step 'Check report' do
agents.each do |agent|
on(agent, puppet('config print statedir')) do |command_result|
report_path = command_result.stdout.chomp + '/last_run_report.yaml'
on(agent, "cat '#{report_path}'").stdout do |report_contents|
yaml_data = YAML::parse(report_contents)
# Remove any Ruby class tags from the yaml
yaml_data.root.each do |o|
if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby")
o.tag = nil
end
end
report_yaml = yaml_data.to_ruby
file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"]
assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing')
corrective_change_value = file_resource_details["corrective_change"]
assert_equal(false, corrective_change_value, 'corrective_change flag for the changed resource should be false')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/reports/cached_catalog_status_in_report.rb | acceptance/tests/reports/cached_catalog_status_in_report.rb | test_name "PUP-5867: The report specifies whether a cached catalog was used, and if so, why" do
tag 'audit:high',
'audit:integration',
'server'
master_reportdir = create_tmpdir_for_user(master, 'report_dir')
teardown do
on(master, "rm -rf #{master_reportdir}")
end
def remove_reports_on_master(master_reportdir, agent_node_name)
on(master, "rm -rf #{master_reportdir}/#{agent_node_name}/*")
end
with_puppet_running_on(master, :master => { :reportdir => master_reportdir, :reports => 'store' }) do
agents.each do |agent|
step "cached_catalog_status should be 'not used' when a new catalog is retrieved" do
step "Initial run: cache a newly retrieved catalog" do
on(agent, puppet("agent", "-t"), :acceptable_exit_codes => [0,2])
end
step "Run again and ensure report indicates that the cached catalog was not used" do
on(agent, puppet("agent", "--onetime", "--no-daemonize"), :acceptable_exit_codes => [0, 2])
on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result|
assert_match(/cached_catalog_status: not_used/, result.stdout, "expected to find 'cached_catalog_status: not_used' in the report")
end
remove_reports_on_master(master_reportdir, agent.node_name)
end
end
step "Run with --use_cached_catalog and ensure report indicates cached catalog was explicitly requested" do
on(agent, puppet("agent", "--onetime", "--no-daemonize", "--use_cached_catalog"), :acceptable_exit_codes => [0, 2])
on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result|
assert_match(/cached_catalog_status: explicitly_requested/, result.stdout, "expected to find 'cached_catalog_status: explicitly_requested' in the report")
end
remove_reports_on_master(master_reportdir, agent.node_name)
end
step "On a run which fails to retrieve a new catalog, ensure report indicates cached catalog was used on failure" do
on(agent, puppet("agent", "--onetime", "--no-daemonize", "--report_server #{master}", "--server nonexist"), :acceptable_exit_codes => [0, 2])
on(master, "cat #{master_reportdir}/#{agent.node_name}/*") do |result|
assert_match(/cached_catalog_status: on_failure/, result.stdout, "expected to find 'cached_catalog_status: on_failure' in the report")
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/reports/corrective_change_outside_puppet.rb | acceptance/tests/reports/corrective_change_outside_puppet.rb | test_name "C98093 - a resource changed outside of Puppet will be reported as a corrective change" do
require 'yaml'
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/agent_fqdn_utils'
extend Puppet::Acceptance::AgentFqdnUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # Uses a server currently, but is testing agent report
'broken:images'
test_file_name = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name)
tmp_file = {}
agents.each do |agent|
tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment)
end
teardown do
step 'clean out produced resources' do
agents.each do |agent|
if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != ''
on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)
end
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
end
step 'create file resource - site.pp to verify corrective change flag' do
file_contents = 'this is a test'
manifest = <<-MANIFEST
file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$facts["networking"]["fqdn"] ? #{tmp_file}
file { \$test_path:
content => @(UTF8)
#{file_contents}
| UTF8
}
',
}
MANIFEST
apply_manifest_on(master, manifest, :catch_failures => true)
end
step 'run agent(s)' do
with_puppet_running_on(master, {}) do
agents.each do |agent|
#Run agent once to create new File resource
step 'Run agent once to create new File resource' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
#Verify the file resource is created
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result|
assert_equal(file_contents, file_result, 'file contents did not match accepted')
end
end
#Delete the file
step 'Delete the file' do
on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)
end
#Run agent to correct the file's absence
step 'Run agent to correct the files absence' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
#Verify the file resource is created
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result|
assert_equal(file_contents, file_result, 'file contents did not match accepted')
end
end
end
end
end
# Open last_run_report.yaml
step 'Check report' do
agents.each do |agent|
on(agent, puppet('config print statedir')) do |command_result|
report_path = command_result.stdout.chomp + '/last_run_report.yaml'
on(agent, "cat '#{report_path}'").stdout do |report_contents|
yaml_data = YAML::parse(report_contents)
# Remove any Ruby class tags from the yaml
yaml_data.root.each do |o|
if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby")
o.tag = nil
end
end
report_yaml = yaml_data.to_ruby
file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"]
assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing')
corrective_change_value = file_resource_details["corrective_change"]
assert_equal(true, corrective_change_value, 'corrective_change flag should be true')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/reports/submission.rb | acceptance/tests/reports/submission.rb | test_name "Report submission"
tag 'audit:high',
'audit:integration'
if master.is_pe?
require "time"
def puppetdb
hosts.detect { |h| h['roles'].include?('database') }
end
def sleep_until_queue_empty(timeout=60)
metric = "org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=com.puppetlabs.puppetdb.commands"
queue_size = nil
begin
Timeout.timeout(timeout) do
until queue_size == 0
result = on(puppetdb, %Q{curl http://localhost:8080/v3/metrics/mbean/#{CGI.escape(metric)}})
if md = /"?QueueSize"?\s*:\s*(\d+)/.match(result.stdout.chomp)
queue_size = Integer(md[1])
end
sleep 1
end
end
rescue Timeout::Error
raise "Queue took longer than allowed #{timeout} seconds to empty"
end
end
def query_last_report_time_on(agent)
time_query_script = <<-EOS
require "net/http"
require "json"
puppetdb_url = URI("http://localhost:8080/v3/reports")
puppetdb_url.query = CGI.escape(%Q{query=["=","certname","#{agent}"]})
result = Net::HTTP.get(puppetdb_url)
json = JSON.load(result)
puts json.first["receive-time"]
EOS
on(puppetdb, "#{master[:privatebindir]}/ruby -e '#{time_query_script}'").output.chomp
end
last_times = {}
agents.each do |agent|
last_times[agent] = query_last_report_time_on(agent)
end
with_puppet_running_on(master, {}) do
agents.each do |agent|
on(agent, puppet('agent', "-t"))
sleep_until_queue_empty
current_time = Time.parse(query_last_report_time_on(agent))
last_time = Time.parse(last_times[agent])
assert(current_time > last_time, "Most recent report time #{current_time} is not newer than last report time #{last_time}")
end
end
else
testdir = create_tmpdir_for_user master, 'report_submission'
teardown do
on master, "rm -rf #{testdir}"
end
with_puppet_running_on(master, :main => { :reportdir => testdir, :reports => 'store' }) do
agents.each do |agent|
on(agent, puppet('agent', "-t"))
on master, "grep -q #{agent.node_name} #{testdir}/*/*"
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/reports/corrective_change_new_resource.rb | acceptance/tests/reports/corrective_change_new_resource.rb | test_name "C98092 - a new resource should not be reported as a corrective change" do
require 'yaml'
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/agent_fqdn_utils'
extend Puppet::Acceptance::AgentFqdnUtils
tag 'audit:high',
'audit:integration',
'audit:refactor', # Uses a server currently but is testing agent report
'broken:images'
test_file_name = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, test_file_name)
tmp_file = {}
agents.each do |agent|
tmp_file[agent_to_fqdn(agent)] = agent.tmpfile(tmp_environment)
end
teardown do
step 'clean out produced resources' do
agents.each do |agent|
if tmp_file.has_key?(agent_to_fqdn(agent)) && tmp_file[agent_to_fqdn(agent)] != ''
on(agent, "rm '#{tmp_file[agent_to_fqdn(agent)]}'", :accept_all_exit_codes => true)
end
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
end
step 'create file resource - site.pp to verify corrective change flag' do
file_contents = 'this is a test'
manifest = <<-MANIFEST
file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$facts["networking"]["fqdn"] ? #{tmp_file}
file { \$test_path:
content => @(UTF8)
#{file_contents}
| UTF8
}
',
}
MANIFEST
apply_manifest_on(master, manifest, :catch_failures => true)
end
step 'run agent(s)' do
with_puppet_running_on(master, {}) do
agents.each do |agent|
#Run agent once to create new File resource
step 'Run agent once to create new File resource' do
on(agent, puppet("agent -t --environment '#{tmp_environment}'"), :acceptable_exit_codes => 2)
end
#Verify the file resource is created
step 'Verify the file resource is created' do
on(agent, "cat '#{tmp_file[agent_to_fqdn(agent)]}'").stdout do |file_result|
assert_equal(file_contents, file_result, 'file contents did not match accepted')
end
end
end
end
end
# Open last_run_report.yaml
step 'Check report' do
agents.each do |agent|
on(agent, puppet('config print statedir')) do |command_result|
report_path = command_result.stdout.chomp + '/last_run_report.yaml'
on(agent, "cat '#{report_path}'").stdout do |report_contents|
yaml_data = YAML::parse(report_contents)
# Remove any Ruby class tags from the yaml
yaml_data.root.each do |o|
if o.respond_to?(:tag=) and o.tag != nil and o.tag.start_with?("!ruby")
o.tag = nil
end
end
report_yaml = yaml_data.to_ruby
file_resource_details = report_yaml["resource_statuses"]["File[#{tmp_file[agent_to_fqdn(agent)]}]"]
assert(file_resource_details.has_key?("corrective_change"), 'corrective_change key is missing')
corrective_change_value = file_resource_details["corrective_change"]
assert_equal(false, corrective_change_value, 'corrective_change flag should be false')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/reports/agent_sends_json_report_for_cached_catalog.rb | acceptance/tests/reports/agent_sends_json_report_for_cached_catalog.rb | test_name "C100533: Agent sends json report for cached catalog" do
tag 'risk:high',
'audit:high',
'audit:integration',
'server'
with_puppet_running_on(master, :main => {}) do
expected_format = 'json'
step "Perform agent run to ensure that catalog is cached" do
agents.each do |agent|
on(agent, puppet('agent', '-t'), :acceptable_exit_codes => [0,2])
end
end
step "Ensure agent sends #{expected_format} report for cached catalog" do
agents.each do |agent|
on(agent, puppet('agent', '-t',
'--http_debug'), :acceptable_exit_codes => [0,2]) do |res|
# Expected content-type should be in the headers of the
# HTTP report payload being PUT to the server by the agent.
unless res.stderr =~ /<- "PUT \/puppet\/v[3-9]\/report.*Content-Type: .*\/#{expected_format}/
fail_test("Report was not submitted in #{expected_format} format")
end
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/yum_semantic_versioning.rb | acceptance/tests/provider/package/yum_semantic_versioning.rb | test_name "yum provider should use semantic versioning for ensuring desired version" do
confine :to, :platform => /el-7/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = 'yum-utils'
lower_package_version = '1.1.31-34.el7'
middle_package_version = '1.1.31-42.el7'
higher_package_version = '1.1.31-45.el7'
agents.each do |agent|
yum_command = 'yum'
step "Setup: Skip test if box already has the package installed" do
on(agent, "rpm -q #{package}", :acceptable_exit_codes => [1,0]) do |result|
skip_test "package #{package} already installed on this box" unless result.output =~ /package #{package} is not installed/
end
end
step "Setup: Skip test if package versions are not available" do
on(agent, "yum list #{package} --showduplicates", :acceptable_exit_codes => [1,0]) do |result|
versions_available = [lower_package_version, middle_package_version, higher_package_version].all? {
|needed_versions| result.output.include? needed_versions }
skip_test "package #{package} versions not available on the box" unless versions_available
end
end
step "Using semantic versioning to downgrade to a desired version <= X" do
on(agent, "#{yum_command} install #{package} -y")
package_manifest = resource_manifest('package', package, { ensure: "<=#{lower_package_version}", provider: 'yum' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(/#{lower_package_version}/, installed_version)
end
# idempotency test
package_manifest = resource_manifest('package', package, { ensure: "<=#{lower_package_version}", provider: 'yum' } )
apply_manifest_on(agent, package_manifest, :catch_changes => true)
on(agent, "#{yum_command} remove #{package} -y")
end
step "Using semantic versioning to ensure a version >X <=Y" do
on(agent, "#{yum_command} install #{package} -y")
package_manifest = resource_manifest('package', package, { ensure: ">#{lower_package_version} <=#{higher_package_version}", provider: 'yum' } )
apply_manifest_on(agent, package_manifest) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(/#{higher_package_version}/, installed_version)
end
on(agent, "#{yum_command} remove #{package} -y")
end
step "Using semantic versioning to install a version >X <Y" do
package_manifest = resource_manifest('package', package, { ensure: ">#{lower_package_version} <#{higher_package_version}", provider: 'yum' } )
# installing a version >X <Y will install the highet version in between
apply_manifest_on(agent, package_manifest) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(/#{middle_package_version}/, installed_version)
end
on(agent, "#{yum_command} remove #{package} -y")
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/dpkg_hold_true_package_is_latest.rb | acceptance/tests/provider/package/dpkg_hold_true_package_is_latest.rb | test_name "dpkg ensure hold package is latest installed" do
confine :to, :platform => /debian-9-amd64/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "nginx"
agents.each do |agent|
teardown do
package_absent(agent, package, '--force-yes')
end
end
step"Ensure that package is installed first if not present" do
expected_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Candidate: //p'").stdout
package_manifest = resource_manifest('package', package, mark: "hold")
apply_manifest_on(agent, package_manifest) do |result|
installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout
assert_match(expected_package_version, installed_package_version)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/dnfmodule_enable_only.rb | acceptance/tests/provider/package/dnfmodule_enable_only.rb | test_name "dnfmodule can change flavors" do
confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
without_profile = '389-ds'
with_profile = 'swig'
agents.each do |agent|
skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream')
teardown do
apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'absent', provider: 'dnfmodule'))
apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'absent', provider: 'dnfmodule'))
end
end
step "Enable module with no default profile: #{without_profile}" do
apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'present', provider: 'dnfmodule'), expect_changes: true)
on(agent, "dnf module list --enabled | grep #{without_profile}")
end
step "Ensure idempotency for: #{without_profile}" do
apply_manifest_on(agent, resource_manifest('package', without_profile, ensure: 'present', provider: 'dnfmodule'), catch_changes: true)
end
step "Enable module with a profile: #{with_profile}" do
apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', enable_only: true, provider: 'dnfmodule'), expect_changes: true)
on(agent, "dnf module list --enabled | grep #{with_profile}")
end
step "Ensure idempotency for: #{with_profile}" do
apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', enable_only: true, provider: 'dnfmodule'), catch_changes: true)
end
step "Install a flavor for: #{with_profile}" do
apply_manifest_on(agent, resource_manifest('package', with_profile, ensure: 'present', flavor: 'common', provider: 'dnfmodule'), expect_changes: true)
on(agent, "dnf module list --installed | grep #{with_profile}")
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/dnfmodule_manages_flavors.rb | acceptance/tests/provider/package/dnfmodule_manages_flavors.rb | test_name "dnfmodule can change flavors" do
confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "postgresql"
agents.each do |agent|
skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream')
teardown do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'absent', provider: 'dnfmodule'))
end
end
step "Install the client #{package} flavor" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', flavor: 'client', provider: 'dnfmodule'))
on(agent, "dnf module list --installed | grep #{package} | sed -E 's/\\[d\\] //g'") do |output|
assert_match('client [i]', output.stdout, 'installed flavor not correct')
end
end
step "Install the server #{package} flavor" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', flavor: 'server', provider: 'dnfmodule'))
on(agent, "dnf module list --installed | grep #{package} | sed -E 's/\\[d\\] //g'") do |output|
assert_match('server [i]', output.stdout, 'installed flavor not correct')
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/dpkg_hold_true_should_preserve_version.rb | acceptance/tests/provider/package/dpkg_hold_true_should_preserve_version.rb | test_name "dpkg ensure hold package should preserve version if package is already installed" do
confine :to, :platform => /debian-9-amd64/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "openssl"
step "Ensure hold should lock to specific installed version" do
existing_installed_version = on(agent.name, "dpkg -s #{package} | sed -n -e 's/Version: //p'").stdout
existing_installed_version.delete!(' ')
package_manifest_hold = resource_manifest('package', package, mark: "hold")
apply_manifest_on(agent, package_manifest_hold) do
installed_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout
installed_version.delete!(' ')
assert_match(existing_installed_version, installed_version)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/puppetserver_gem.rb | acceptance/tests/provider/package/puppetserver_gem.rb | test_name "puppetserver_gem provider should install and uninstall" do
tag 'audit:high',
'server'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
skip_test 'puppetserver_gem is only suitable on server nodes' unless master
package = 'world_airports'
teardown do
# Ensure the gem is uninstalled if anything goes wrong
# TODO maybe execute this only if something fails, as it takes time
on(master, "puppetserver gem uninstall #{package}")
end
step "Installing a gem executes without error" do
package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'puppetserver_gem' } )
apply_manifest_on(master, package_manifest, catch_failures: true) do
list = on(master, "puppetserver gem list").stdout
assert_match(/#{package} \(/, list)
end
# Run again for idempotency
apply_manifest_on(master, package_manifest, catch_changes: true)
end
step "Uninstalling a gem executes without error" do
package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'puppetserver_gem' } )
apply_manifest_on(master, package_manifest, catch_failures: true) do
list = on(master, "puppetserver gem list").stdout
refute_match(/#{package} \(/, list)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/dnfmodule_ensure_versionable.rb | acceptance/tests/provider/package/dnfmodule_ensure_versionable.rb | test_name "dnfmodule is versionable" do
confine :to, :platform => /el-8-x86_64/ # only el/centos 8 have the appstream repo
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "postgresql"
agents.each do |agent|
skip_test('appstream repo not present') unless on(agent, 'dnf repolist').stdout.include?('appstream')
teardown do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'absent', provider: 'dnfmodule'))
end
end
step "Ensure we get the newer version by default" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: 'present', provider: 'dnfmodule'))
on(agent, 'postgres --version') do |version|
assert_match('postgres (PostgreSQL) 10', version.stdout, 'package version not correct')
end
end
step "Ensure we get a specific version if we want it" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: '9.6', provider: 'dnfmodule'))
on(agent, 'postgres --version') do |version|
assert_match('postgres (PostgreSQL) 9.6', version.stdout, 'package version not correct')
end
end
step "Ensure we can disable a package" do
apply_manifest_on(agent, resource_manifest('package', package, ensure: :disabled, provider: 'dnfmodule'))
on(agent, "dnf module list | grep #{package}") do |output|
output.stdout.each_line do |line|
assert_match("\[x\]", line, 'package not disabled')
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/dpkg_ensure_latest_virtual_packages.rb | acceptance/tests/provider/package/dpkg_ensure_latest_virtual_packages.rb | test_name "dpkg ensure latest with allow_virtual set to true, the virtual package should detect and install a real package" do
confine :to, :platform => /debian/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
pkg = "rubygems"
agents.each do |agent|
ruby_present = on(agent, 'dpkg -s ruby', accept_all_exit_codes: true).exit_code == 0
teardown do
if ruby_present
apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'present'))
else
apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'absent'))
end
end
step "Uninstall system ruby if already present" do
apply_manifest_on(agent, resource_manifest('package', 'ruby', ensure: 'absent')) if ruby_present
end
step "Ensure latest should install ruby instead of rubygems when allow_virtual is set to true" do
package_manifest_with_allow_virtual = resource_manifest('package', pkg, ensure: 'latest', allow_virtual: true)
apply_manifest_on(agent, package_manifest_with_allow_virtual, expect_changes: true)
output = on(agent, "dpkg-query -W --showformat='${Status} ${Package} ${Version} [${Provides}]\n' ").output
lines = output.split("\n")
matched_line = lines.find { |package| package.match(/[\[ ](#{Regexp.escape(pkg)})[\],]/)}
package_line_info = matched_line.split
real_package_name = package_line_info[3]
real_package_installed_version = package_line_info[4]
installed_version = on(agent, "apt-cache policy #{real_package_name} | sed -n -e 's/Installed: //p'").stdout.strip
assert_match(real_package_installed_version, installed_version)
end
step "Ensure latest should not install ruby package if it's already installed and exit code should be 0" do
package_manifest_with_allow_virtual = resource_manifest('package', pkg, ensure: 'latest', allow_virtual: true)
apply_manifest_on(agent, package_manifest_with_allow_virtual, :catch_changes => true)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/pip.rb | acceptance/tests/provider/package/pip.rb | test_name "pip provider should install, use install_options with latest, and uninstall" do
confine :to, :template => /centos/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = 'colorize'
pip_command = 'pip'
teardown do
on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes", :accept_all_exit_codes => true)
end
agents.each do |agent|
step "Setup: Install EPEL Repository, Python and Pip" do
package_present(agent, 'epel-release')
if agent.platform =~ /el-8/
package_present(agent, 'python2')
package_present(agent, 'python2-pip')
pip_command = 'pip2'
else
package_present(agent, 'python')
package_present(agent, 'python-pip')
end
end
step "Ensure presence of a pip package" do
package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'pip' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout
assert_match(/#{package} \(/, list)
end
on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes")
end
step "Install a pip package using version range" do
package_manifest1 = resource_manifest('package', package, { ensure: '<=1.1.0', provider: 'pip' } )
package_manifest2 = resource_manifest('package', package, { ensure: '<1.0.4', provider: 'pip' } )
# Make a fresh package install (with version lower than or equal to 1.1.0)
apply_manifest_on(agent, package_manifest1, :expect_changes => true) do
list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout
match = list.match(/#{package} \((.+)\)/)
installed_version = match[1] if match
assert_match(installed_version, '1.1.0')
end
# Reapply same manifest and expect no changes
apply_manifest_on(agent, package_manifest1, :catch_changes => true)
# Reinstall over existing package (with version lower than 1.0.4) and expect changes (to be 1.0.3)
apply_manifest_on(agent, package_manifest2, :expect_changes => true) do
list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout
match = list.match(/#{package} \((.+)\)/)
installed_version = match[1] if match
assert_match(installed_version, '1.0.3')
end
on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes")
end
step "Ensure latest with pip uses install_options" do
on(agent, "#{pip_command} install #{package} --disable-pip-version-check")
package_manifest = resource_manifest('package', package, { ensure: 'latest', provider: 'pip', install_options: { '--index' => 'https://pypi.python.org/simple' } } )
result = apply_manifest_on(agent, package_manifest, { :catch_failures => true, :debug => true } )
assert_match(/--index=https:\/\/pypi.python.org\/simple/, result.stdout)
on(agent, "#{pip_command} uninstall #{package} --disable-pip-version-check --yes")
end
step "Uninstall a pip package" do
on(agent, "#{pip_command} install #{package} --disable-pip-version-check")
package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'pip' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{pip_command} list --disable-pip-version-check").stdout
refute_match(/#{package} \(/, list)
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/zypper_install_package_with_range.rb | acceptance/tests/provider/package/zypper_install_package_with_range.rb | test_name "zypper can install range if package is not installed" do
confine :to, :platform => /sles/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "helloworld"
available_package_versions = ['1.0-2', '1.19-2', '2.0-2']
repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'sles-repo')
repo_content = <<-REPO
[local]
name=local - test packages
baseurl=file:///tmp/sles-repo
enabled=1
gpgcheck=0
REPO
agents.each do |agent|
scp_to(agent, repo_fixture_path, '/tmp')
file_manifest = resource_manifest('file', '/etc/zypp/repos.d/local.repo', ensure: 'present', content: repo_content)
apply_manifest_on(agent, file_manifest)
teardown do
package_absent(agent, package, '--force-yes')
file_manifest = resource_manifest('file', '/etc/zypp/repos.d/local.repo', ensure: 'absent')
apply_manifest_on(agent, file_manifest)
on(agent, 'rm -rf /tmp/sles-repo')
end
step "Ensure that package is installed first if not present" do
package_manifest = resource_manifest('package', package, ensure: "<=#{available_package_versions[1]}")
apply_manifest_on(agent, package_manifest)
installed_package_version = on(agent, "rpm -q #{package}").stdout
assert_match(available_package_versions[1], installed_package_version)
end
step "Ensure that package is updated" do
package_manifest = resource_manifest('package', package, ensure: ">#{available_package_versions[1]}")
apply_manifest_on(agent, package_manifest)
installed_package_version = on(agent, "rpm -q #{package}").stdout
assert_match(available_package_versions[2], installed_package_version)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/apt_install_package_with_range.rb | acceptance/tests/provider/package/apt_install_package_with_range.rb | test_name "apt can install range if package is not installed" do
confine :to, :platform => /debian|ubuntu/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "helloworld"
available_package_versions = ['1.0-1', '1.19-1', '2.0-1']
repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'debian-repo')
agents.each do |agent|
scp_to(agent, repo_fixture_path, '/tmp')
file_manifest = resource_manifest('file', '/etc/apt/sources.list.d/tmp.list', ensure: 'present', content: 'deb [trusted=yes] file:/tmp/debian-repo ./')
apply_manifest_on(agent, file_manifest)
on(agent, 'apt-get update')
teardown do
package_absent(agent, package, '--force-yes')
file_manifest = resource_manifest('file', '/etc/apt/sources.list.d/tmp.list', ensure: 'absent')
apply_manifest_on(agent, file_manifest)
on(agent, 'rm -rf /tmp/debian-repo')
on(agent, 'apt-get update')
end
step "Ensure that package is installed first if not present" do
package_manifest = resource_manifest('package', package, ensure: "<=#{available_package_versions[1]}")
apply_manifest_on(agent, package_manifest)
installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout
assert_match(available_package_versions[1], installed_package_version)
end
step "Ensure that package is updated" do
package_manifest = resource_manifest('package', package, ensure: ">#{available_package_versions[1]}")
apply_manifest_on(agent, package_manifest)
installed_package_version = on(agent.name, "apt-cache policy #{package} | sed -n -e 's/Installed: //p'").stdout
assert_match(available_package_versions[2], installed_package_version)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/gem.rb | acceptance/tests/provider/package/gem.rb | test_name "gem provider should install and uninstall" do
confine :to, :template => /centos-7-x86_64|redhat-7-x86_64/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = 'colorize'
agents.each do |agent|
# On a Linux host with only the 'agent' role, the puppet command fails when another Ruby is installed earlier in the PATH:
#
# [root@agent ~]# env PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/puppetlabs/bin" puppet apply -e ' notify { "Hello": }'
# Activating bundler (2.0.2) failed:
# Could not find 'bundler' (= 2.0.2) among 5 total gem(s)
# To install the version of bundler this project requires, run `gem install bundler -v '2.0.2'`
#
# Magically, the puppet command succeeds on a Linux host with both the 'master' and 'agent' roles.
#
# Puppet's Ruby makes a fine target. Unfortunately, it's first in the PATH on Windows: PUP-6134.
# Also, privatebindir isn't a directory on Windows, it's a PATH:
# https://github.com/puppetlabs/beaker-puppet/blob/master/lib/beaker-puppet/install_utils/aio_defaults.rb
#
# These tests depend upon testing being confined to /centos-7-x86_64|redhat-7-x86_64/.
if agent['roles'].include?('master')
original_path = agent.get_env_var('PATH').split('=').last
# https://github.com/puppetlabs/puppet-agent/blob/master/resources/files/puppet-agent.sh
puppet_agent_sh_path = '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/puppetlabs/bin'
system_gem_command = '/usr/bin/gem'
teardown do
step "Teardown: Uninstall System Ruby, and reset PATH" do
package_absent(agent, 'ruby')
agent.clear_env_var('PATH')
agent.add_env_var('PATH', original_path)
end
end
step "Setup: Install System Ruby, and set PATH to place System Ruby ahead of Puppet Ruby" do
package_present(agent, 'ruby')
agent.add_env_var('PATH', puppet_agent_sh_path)
end
step "Install a gem package in System Ruby" do
package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'gem' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{system_gem_command} list").stdout
assert_match(/#{package} \(/, list)
end
on(agent, "#{system_gem_command} uninstall #{package}")
end
step "Uninstall a gem package in System Ruby" do
on(agent, "/usr/bin/gem install #{package}")
package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'gem' } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{system_gem_command} list").stdout
refute_match(/#{package} \(/, list)
end
on(agent, "#{system_gem_command} uninstall #{package}")
end
step "Uninstall System Ruby, and reset PATH" do
package_absent(agent, 'ruby')
agent.add_env_var('PATH', original_path)
end
end
puppet_gem_command = "#{agent['privatebindir']}/gem"
step "Install a gem package with a target command" do
package_manifest = resource_manifest('package', package, { ensure: 'present', provider: 'gem', command: puppet_gem_command } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{puppet_gem_command} list").stdout
assert_match(/#{package} \(/, list)
end
on(agent, "#{puppet_gem_command} uninstall #{package}")
end
step "Install a gem package in a certain min max range" do
package_manifest1 = resource_manifest('package', package, { ensure: '>0.5 <0.7', provider: 'gem' } )
package_manifest2 = resource_manifest('package', package, { ensure: '>0.7 <0.8.1', provider: 'gem' } )
# Install package (with version between 0.5 and 0.7)
apply_manifest_on(agent, package_manifest1, :expect_changes => true) do
list = on(agent, "#{puppet_gem_command} list").stdout
assert_match(/#{package} \((0.6.0)\)/, list)
end
# Reapply same manifest and expect no changes
apply_manifest_on(agent, package_manifest1, :catch_changes => true)
# Install besides existing package (with version between 0.7 and 0.8.1) and expect changes
apply_manifest_on(agent, package_manifest2, :expect_changes => true) do
list = on(agent, "#{puppet_gem_command} list").stdout
assert_match(/#{package} \((0.8.0, 0.6.0)\)/, list)
end
on(agent, "#{puppet_gem_command} uninstall #{package} --all")
end
step "Uninstall a gem package with a target command" do
on(agent, "#{puppet_gem_command} install #{package}")
package_manifest = resource_manifest('package', package, { ensure: 'absent', provider: 'gem', command: puppet_gem_command } )
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
list = on(agent, "#{puppet_gem_command} list").stdout
refute_match(/#{package} \(/, list)
end
on(agent, "#{puppet_gem_command} uninstall #{package}")
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/provider/package/rpm_ensure_install_multiversion_package.rb | acceptance/tests/provider/package/rpm_ensure_install_multiversion_package.rb | test_name "rpm should install packages with multiple versions" do
confine :to, :platform => /redhat|centos|el|fedora/
tag 'audit:high'
require 'puppet/acceptance/common_utils'
extend Puppet::Acceptance::PackageUtils
extend Puppet::Acceptance::ManifestUtils
package = "kernel-devel-puppet"
repo_fixture_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'fixtures', 'el-repo')
repo_content = <<-REPO
[local]
name=EL-releasever - test packages
baseurl=file:///tmp/el-repo
enabled=1
gpgcheck=0
protect=1
REPO
agents.each do |agent|
initially_installed_versions = []
scp_to(agent, repo_fixture_path, '/tmp')
file_manifest = resource_manifest('file', '/etc/yum.repos.d/local.repo', ensure: 'present', content: repo_content)
apply_manifest_on(agent, file_manifest)
teardown do
on(agent, 'rm -rf /tmp/el-repo')
on(agent, 'rm -f /etc/yum.repos.d/local.repo')
available_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | awk '{print $2}'").stdout
initially_installed_versions.each do |version|
if available_versions.include? version
package_manifest = resource_manifest('package', package, ensure: version, install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true)
end
end
end
step "Uninstall package versions for clean setup" do
initially_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout.split("\n")
package_manifest = resource_manifest('package', package, ensure: 'absent', install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
remaining_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout
assert(remaining_installed_versions.empty?)
end
available_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | awk '{print $2}'").stdout.split("\n")
if available_versions.size < 2
skip_test "we need at least two package versions to perform the multiversion rpm test"
end
end
step "Ensure oldest version of multiversion package is installed" do
oldest_version = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | head -1 | awk '{print $2}'").stdout.strip
package_manifest = resource_manifest('package', package, ensure: oldest_version, install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(oldest_version, installed_version)
end
end
step "Ensure newest package multiversion package in installed" do
newest_version = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Available Packages/ d' | tail -1 | awk '{print $2}'").stdout.strip
package_manifest = resource_manifest('package', package, ensure: newest_version, install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
installed_version = on(agent, "rpm -q #{package}").stdout
assert_match(newest_version, installed_version)
end
end
step "Ensure rpm will uninstall multiversion package" do
package_manifest = resource_manifest('package', package, ensure: 'absent', install_only: true)
apply_manifest_on(agent, package_manifest, :catch_failures => true) do
remaining_installed_versions = on(agent, "yum --showduplicates list #{package} | sed -e '1,/Installed Packages/ d' -e '/Available Packages/,$ d' | awk '{print $2}'").stdout
assert(remaining_installed_versions.empty?)
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/parser_functions/hiera_in_templates.rb | acceptance/tests/parser_functions/hiera_in_templates.rb | test_name "Calling Hiera function from inside templates"
tag 'audit:high',
'audit:integration',
'audit:refactor' # Master is not required for this test. Replace with agents.each
@module_name = "hieratest"
@coderoot = master.tmpdir("#{@module_name}")
@msg_default = 'message from default.yaml'
@msg_production = 'message from production.yaml'
@msg1os = 'message1 from {osfamily}.yaml'
@msg2os = 'message2 from {osfamily}.yaml'
@msg_fqdn = 'messsage from {fqdn}.yaml'
@k1 = 'key1'
@k2 = 'key2'
@k3 = 'key3'
@hval2p = 'hash_value2 from production.yaml'
@hval3p = 'hash_value3 from production.yaml'
@hval1os = 'hash_value1 from {osfamily}.yaml'
@hval2os = 'hash_value2 from {osfamily}.yaml'
@h_m_call = "hiera\\('message'\\)"
@h_h_call = "hiera\\('hash_value'\\)"
@h_i_call = "hiera\\('includes'\\)"
@ha_m_call = "hiera_array\\('message'\\)"
@ha_i_call = "hiera_array\\('includes'\\)"
@hh_h_call = "hiera_hash\\('hash_value'\\)"
@mod_default_msg = 'This file created by mod_default.'
@mod_osfamily_msg = 'This file created by mod_osfamily.'
@mod_production_msg = 'This file created by mod_production.'
@mod_fqdn_msg = 'This file created by mod_fqdn.'
@master_opts = {
'main' => {
'environmentpath' => "#{@coderoot}/environments",
'hiera_config' => "#{@coderoot}/hiera.yaml",
},
}
def create_environment(osfamilies, tmp_dirs)
envroot = "#{@coderoot}/environments"
production = "#{envroot}/production"
modroot = "#{production}/modules"
moduledir = "#{modroot}/#{@module_name}"
hieradir = "#{@coderoot}/hieradata"
osfamily_yamls = ""
osfamilies.each do |osf|
new_yaml = <<NEW_YAML
file {"#{hieradir}/#{osf}.yaml":
content => "
---
message: [
'#{@msg1os}',
'#{@msg2os}',
]
includes: '#{@module_name}::mod_osfamily'
hash_value:
#{@k1}: '#{@hval1os}'
#{@k2}: '#{@hval2os}'
"
}
NEW_YAML
osfamily_yamls += new_yaml
end
environ = <<ENV
File {
ensure => file,
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
mode => "0644",
}
file {
[
"#{@coderoot}",
"#{envroot}",
"#{production}",
"#{production}/modules",
"#{production}/manifests",
"#{hieradir}",
"#{moduledir}",
"#{moduledir}/examples",
"#{moduledir}/manifests",
"#{moduledir}/templates",
] :
ensure => directory,
}
file { '#{production}/manifests/site.pp':
ensure => file,
content => "
node default {
\\$msgs = hiera_array('message')
notify {\\$msgs:}
class {'#{@module_name}':
result_dir => hiera('result_dir')[\\$facts['networking']['hostname']],
}
}
",
}
file {"#{@coderoot}/hiera.yaml":
content => "
---
:backends:
- yaml
:yaml:
:datadir: #{@coderoot}/hieradata
:hierarchy:
- \\"%{clientcert}\\"
- \\"%{environment}\\"
- \\"%{os.family}\\"
- \\"default\\"
"
}
file {"#{hieradir}/default.yaml":
content => "
---
message: '#{@msg_default}'
includes: '#{@module_name}::mod_default'
result_dir:
#{tmp_dirs}
"
}
#{osfamily_yamls}
file {"#{hieradir}/production.yaml":
content => "
---
message: '#{@msg_production}'
includes: '#{@module_name}::mod_production'
hash_value:
#{@k2}: '#{@hval2p}'
#{@k3}: '#{@hval3p}'
"
}
file {"#{hieradir}/#{$fqdn}.yaml":
content => "
---
message: '#{@msg_fqdn}'
includes: '#{@module_name}::mod_fqdn'
"
}
file {"#{moduledir}/examples/init.pp":
content => "
include #{@module_name}
"
}
file { "#{moduledir}/manifests/init.pp":
content => "
class #{@module_name} (
\\$result_dir,
) {
file { \\$result_dir:
ensure => directory,
mode => '0755',
}
file {\\\"\\\${result_dir}/#{@module_name}_results_epp\\\":
ensure => file,
mode => '0644',
content => epp('#{@module_name}/hieratest_results_epp.epp'),
}
file {\\\"\\\${result_dir}/#{@module_name}_results_erb\\\":
ensure => file,
mode => '0644',
content => template('#{@module_name}/hieratest_results_erb.erb'),
}
}
"
}
file { "#{moduledir}/manifests/mod_default.pp":
content => "
class #{@module_name}::mod_default {
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_default invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_default\\\":
ensure => 'file',
mode => '0644',
content => \\\"#{@mod_default_msg}\\\\n\\\",
}
}
"
}
file { "#{moduledir}/manifests/mod_osfamily.pp":
content => "
class #{@module_name}::mod_osfamily {
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_osfamily invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_osfamily\\\":
ensure => 'file',
mode => '0644',
content => \\\"#{@mod_osfamily_msg}\\\\n\\\",
}
}
"
}
file { "#{moduledir}/manifests/mod_production.pp":
content => "
class #{@module_name}::mod_production {
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_production invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_production\\\":
ensure => 'file',
mode => '0644',
content => '#{@mod_production_msg}',
}
}
"
}
file { "#{moduledir}/manifests/mod_fqdn.pp":
content => "
class #{@module_name}::mod_fqdn {
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_fqdn invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_fqdn\\\":
ensure => 'file',
mode => '0644',
content => \\\"#{@mod_fqdn_msg}\\\\n\\\",
}
}
"
}
file { "#{moduledir}/templates/hieratest_results_epp.epp":
content => "
hiera('message'): <%= hiera('message') %>
hiera('hash_value'): <%= hiera('hash_value') %>
hiera('includes'): <%= hiera('includes') %>
hiera_array('message'): <%= hiera_array('message') %>
hiera_array('includes'): <%= hiera_array('includes') %>
hiera_hash('hash_value'): <%= hiera_hash('hash_value') %>
hiera_include('includes'): <%= hiera_include('includes') %>
"
}
file { "#{moduledir}/templates/hieratest_results_erb.erb":
content => "
hiera('message'): <%= scope().call_function('hiera', ['message']) %>
hiera('hash_value'): <%= scope().call_function('hiera', ['hash_value']) %>
hiera('includes'): <%= scope().call_function('hiera', ['includes']) %>
hiera_array('message'): <%= scope().call_function('hiera_array', ['message']) %>
hiera_array('includes'): <%= scope().call_function('hiera_array', ['includes']) %>
hiera_hash('hash_value'): <%= scope().call_function('hiera_hash', ['hash_value']) %>
"
}
ENV
environ
end
def find_osfamilies
family_hash = {}
agents.each do |agent|
res = on(agent, facter("os.family"))
osf = res.stdout.chomp
family_hash[osf] = 1
end
family_hash.keys
end
def find_tmp_dirs
tmp_dirs = ""
host_to_result_dir = {}
agents.each do |agent|
h = on(agent, facter("networking.hostname")).stdout.chomp
t = agent.tmpdir("#{@module_name}_results")
tmp_dirs += " #{h}: '#{t}'\n"
host_to_result_dir[h] = t
end
result = {
'tmp_dirs' => tmp_dirs,
'host_to_result_dir' => host_to_result_dir
}
result
end
step 'Setup'
with_puppet_running_on master, @master_opts, @coderoot do
res = find_tmp_dirs
tmp_dirs = res['tmp_dirs']
host_to_result_dir = res['host_to_result_dir']
env_manifest = create_environment(find_osfamilies, tmp_dirs)
apply_manifest_on(master, env_manifest, :catch_failures => true)
agents.each do |agent|
resultdir = host_to_result_dir[on(agent, facter("networking.hostname")).stdout.chomp]
step "Applying catalog to agent: #{agent}. result files in #{resultdir}"
on(
agent,
puppet('agent', "-t"),
:acceptable_exit_codes => [2]
)
step "####### Verifying hiera calls from erb template #######"
r1 = on(agent, "cat #{resultdir}/hieratest_results_erb")
result = r1.stdout
step "Verifying hiera() call #1."
assert_match(
/#{@h_m_call}: #{@msg_production}/,
result,
"#{@h_m_call} failed. Expected: '#{@msg_production}'"
)
step "Verifying hiera() call #2."
assert_match(
/#{@h_h_call}.*\"#{@k3}\"=>\"#{@hval3p}\"/,
result,
"#{@h_h_call} failed. Expected: '\"#{@k3}\"=>\"#{@hval3p}\"'"
)
step "Verifying hiera() call #3."
assert_match(
/#{@h_h_call}.*\"#{@k2}\"=>\"#{@hval2p}\"/,
result,
"#{@h_h_call} failed. Expected: '\"#{@k2}\"=>\"#{@hval2p}\"'"
)
step "Verifying hiera() call #4."
assert_match(
/#{@h_i_call}: #{@module_name}::mod_production/,
result,
"#{@h_i_call} failed. Expected:'#{@module_name}::mod_production'"
)
step "Verifying hiera_array() call. #1"
assert_match(
/#{@ha_m_call}: \[\"#{@msg_production}\", \"#{@msg1os}\", \"#{@msg2os}\", \"#{@msg_default}\"\]/,
result,
"#{@ha_m_call} failed. Expected: '[\"#{@msg_production}\", \"#{@msg1os}\", \"#{@msg2os}\", \"#{@msg_default}\"]'"
)
step "Verifying hiera_array() call. #2"
assert_match(
/#{@ha_i_call}: \[\"#{@module_name}::mod_production\", \"#{@module_name}::mod_osfamily\", \"#{@module_name}::mod_default\"\]/,
result,
"#{@ha_i_call} failed. Expected: '[\"#{@module_name}::mod_production\", \"#{@module_name}::mod_osfamily\", \"#{@module_name}::mod_default\"]'"
)
step "Verifying hiera_hash() call. #1"
assert_match(
/#{@hh_h_call}:.*\"#{@k3}\"=>\"#{@hval3p}\"/,
result,
"#{@hh_h_call} failed. Expected: '\"#{@k3}\"=>\"#{@hval3p}\"'"
)
step "Verifying hiera_hash() call. #2"
assert_match(
/#{@hh_h_call}:.*\"#{@k2}\"=>\"#{@hval2p}\"/,
result,
"#{@hh_h_call} failed. Expected: '\"#{@k2}\"=>\"#{@hval2p}\"'"
)
step "Verifying hiera_hash() call. #3"
assert_match(
/#{@hh_h_call}:.*\"#{@k1}\"=>\"#{@hval1os}\"/,
result,
"#{@hh_h_call} failed. Expected: '\"#{@k1}\"=>\"#{@hval1os}\"'"
)
r2 = on(agent, "cat #{resultdir}/mod_default")
result = r2.stdout
step "Verifying hiera_include() call. #1"
assert_match(
"#{@mod_default_msg}",
result,
"#{@hi_i_call} failed. Expected: '#{@mod_default_msg}'"
)
r3 = on(agent, "cat #{resultdir}/mod_osfamily")
result = r3.stdout
step "Verifying hiera_include() call. #2"
assert_match(
"#{@mod_osfamily_msg}",
result,
"#{@hi_i_call} failed. Expected: '#{@mod_osfamily_msg}'"
)
r4 = on(agent, "cat #{resultdir}/mod_production")
result = r4.stdout
step "Verifying hiera_include() call. #3"
assert_match(
"#{@mod_production_msg}",
result,
"#{@hi_i_call} failed. Expected: '#{@mod_production_msg}'"
)
step "####### Verifying hiera calls from epp template #######"
r5 = on(agent, "cat #{resultdir}/hieratest_results_epp")
result = r5.stdout
step "Verifying hiery() call #1."
assert_match(
/#{@h_m_call}: #{@msg_production}/,
result,
"#{@hi_m_call} failed. Expected '#{@msg_production}'"
)
step "Verifying hiera() call #2."
assert_match(
/#{@h_h_call}.*#{@k3} => #{@hval3p}/,
result,
"#{@h_h_call} failed. Expected '#{@k3} => #{@hval3p}'"
)
step "Verifying hiera() call #3."
assert_match(/#{@h_h_call}.*#{@k2} => #{@hval2p}/,
result,
"#{@h_h_call} failed. Expected '#{@k2} => #{@hval2p}'"
)
step "Verifying hiera() call #4."
assert_match(
/#{@h_i_call}: #{@module_name}::mod_production/,
result,
"#{@h_i_call} failed. Expected: '#{@module_name}::mod_production'"
)
step "Verifying hiera_array() call. #1"
assert_match(
/#{@ha_m_call}: \[#{@msg_production}, #{@msg1os}, #{@msg2os}, #{@msg_default}\]/,
result,
"#{@ha_m_call} failed. Expected: '[#{@msg_production}, #{@msg1os}, #{@msg2os}, #{@msg_default}]'"
)
step "Verifying hiera_array() call. #2"
assert_match(
/#{@ha_i_call}: \[#{@module_name}::mod_production, #{@module_name}::mod_osfamily, #{@module_name}::mod_default\]/,
result,
"#{@ha_i_call} failed. Expected: '[#{@module_name}::mod_production, #{@module_name}::mod_osfamily, #{@module_name}::mod_default'"
)
step "Verifying hiera_hash() call. #1"
assert_match(
/#{@hh_h_call}:.*#{@k3} => #{@hval3p}/,
result,
"#{@hh_h_call} failed. Expected: '{@k3} => #{@hval3p}'"
)
step "Verifying hiera_hash() call. #2"
assert_match(
/#{@hh_h_call}:.*#{@k2} => #{@hval2p}/,
result,
"#{@hh_h_call} failed. Expected '#{@k2} => #{@hval2p}'",
)
step "Verifying hiera_hash() call. #3"
assert_match(
/#{@hh_h_call}:.*#{@k1} => #{@hval1os}/,
result,
"#{@hh_h_call}: failed. Expected: '#{@k1} => #{@hval1os}'"
)
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/parser_functions/no_exception_in_reduce_with_bignum.rb | acceptance/tests/parser_functions/no_exception_in_reduce_with_bignum.rb | test_name 'C97760: Integer in reduce() should not cause exception' do
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:unit'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
step 'On master, create site.pp with integer' do
create_sitepp(master, tmp_environment, <<-SITEPP)
$data = [
{
"certname"=>"xxxxxxxxx.some.domain",
"parameters"=>{
"admin_auth_keys"=>{
"keyname1"=>{
"key"=>"ABCDEF",
"options"=>["from=\\"10.0.0.0/8\\""]
},
"keyname2"=>{
"key"=>"ABCDEF",
},
"keyname3"=>{
"key"=>"ABCDEF",
"options"=>["from=\\"10.0.0.0/8\\""],
"type"=>"ssh-xxx"
},
"keyname4"=>{
"key"=>"ABCDEF",
"options"=>["from=\\"10.0.0.0/8\\""]
}
},
"admin_user"=>"ertxa",
"admin_hosts"=>["1.2.3.4",
"1.2.3.4",
"1.2.3.4"],
"admin_password"=>"ABCDEF",
"sshd_ports"=>[22,
22, 24],
"sudo_no_password_all"=>false,
"sudo_no_password_commands"=>[],
"sshd_config_template"=>"cfauth/sshd_config.epp",
"sudo_env_keep"=>[]
},
"exported"=>false},
]
$data_reduced = $data.reduce({}) |$m, $r|{
$cn = $r['certname']
notice({ $cn => $r['parameters'] })
}
SITEPP
end
with_puppet_running_on(master, {}) do
agents.each do |agent|
on(agent, puppet("agent -t --environment #{tmp_environment}"))
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/parser_functions/puppet_lookup_cmd.rb | acceptance/tests/parser_functions/puppet_lookup_cmd.rb | test_name "Puppet Lookup Command"
tag 'audit:high',
'audit:acceptance',
'audit:refactor' # Master is not required for this test. Replace with agents.each
# Wrap steps in blocks in accordance with Beaker style guide
# doc:
# https://puppet.com/docs/puppet/latest/hiera_automatic.html
@module_name = "puppet_lookup_command_test"
### @testroot = "/etc/puppetlabs"
@testroot = master.tmpdir("#{@module_name}")
@coderoot = "#{@testroot}/code"
@confdir = "#{@testroot}/puppet"
@node1 = 'node1.example.org'
@node2 = 'node2.example.org'
@master_opts = {
'main' => {
'environmentpath' => "#{@coderoot}/environments",
'hiera_config' => "#{@coderoot}/hiera.yaml",
},
}
@manifest = <<MANIFEST
File {
ensure => directory,
mode => "0755",
}
file {
'#{@confdir}':;
'#{@coderoot}':;
'#{@coderoot}/hieradata':;
'#{@coderoot}/environments':;
##### default environment, production
'#{@coderoot}/environments/production':;
'#{@coderoot}/environments/production/data':;
'#{@coderoot}/environments/production/functions':;
'#{@coderoot}/environments/production/functions/environment':;
'#{@coderoot}/environments/production/lib':;
'#{@coderoot}/environments/production/lib/puppet':;
'#{@coderoot}/environments/production/lib/puppet/functions':;
'#{@coderoot}/environments/production/lib/puppet/functions/environment':;
'#{@coderoot}/environments/production/manifests':;
'#{@coderoot}/environments/production/modules':;
# module mod1 hiera
'#{@coderoot}/environments/production/modules/mod1':;
'#{@coderoot}/environments/production/modules/mod1/manifests':;
'#{@coderoot}/environments/production/modules/mod1/data':;
'#{@coderoot}/environments/production/modules/mod1/functions':;
'#{@coderoot}/environments/production/modules/mod1/lib':;
'#{@coderoot}/environments/production/modules/mod1/lib/puppet':;
'#{@coderoot}/environments/production/modules/mod1/lib/puppet/functions':;
'#{@coderoot}/environments/production/modules/mod1/lib/puppet/functions/mod1':;
# module mod2 ruby function
'#{@coderoot}/environments/production/modules/mod2':;
'#{@coderoot}/environments/production/modules/mod2/manifests':;
'#{@coderoot}/environments/production/modules/mod2/data':;
'#{@coderoot}/environments/production/modules/mod2/functions':;
'#{@coderoot}/environments/production/modules/mod2/lib':;
'#{@coderoot}/environments/production/modules/mod2/lib/puppet':;
'#{@coderoot}/environments/production/modules/mod2/lib/puppet/functions':;
'#{@coderoot}/environments/production/modules/mod2/lib/puppet/functions/mod2':;
# module mod3 puppet function
'#{@coderoot}/environments/production/modules/mod3':;
'#{@coderoot}/environments/production/modules/mod3/manifests':;
'#{@coderoot}/environments/production/modules/mod3/data':;
'#{@coderoot}/environments/production/modules/mod3/functions':;
'#{@coderoot}/environments/production/modules/mod3/not-lib':;
'#{@coderoot}/environments/production/modules/mod3/not-lib/puppet':;
'#{@coderoot}/environments/production/modules/mod3/not-lib/puppet/functions':;
'#{@coderoot}/environments/production/modules/mod3/not-lib/puppet/functions/mod3':;
# module mod4 none
'#{@coderoot}/environments/production/modules/mod4':;
'#{@coderoot}/environments/production/modules/mod4/manifests':;
'#{@coderoot}/environments/production/modules/mod4/data':;
'#{@coderoot}/environments/production/modules/mod4/functions':;
'#{@coderoot}/environments/production/modules/mod4/lib':;
'#{@coderoot}/environments/production/modules/mod4/lib/puppet':;
'#{@coderoot}/environments/production/modules/mod4/lib/puppet/functions':;
'#{@coderoot}/environments/production/modules/mod4/lib/puppet/functions/mod4':;
##### env1 hiera
'#{@coderoot}/environments/env1':;
'#{@coderoot}/environments/env1/data':;
'#{@coderoot}/environments/env1/functions':;
'#{@coderoot}/environments/env1/functions/environment':;
'#{@coderoot}/environments/env1/lib':;
'#{@coderoot}/environments/env1/lib/puppet':;
'#{@coderoot}/environments/env1/lib/puppet/functions':;
'#{@coderoot}/environments/env1/lib/puppet/functions/environment':;
'#{@coderoot}/environments/env1/manifests':;
'#{@coderoot}/environments/env1/modules':;
# module mod1 hiera
'#{@coderoot}/environments/env1/modules/mod1':;
'#{@coderoot}/environments/env1/modules/mod1/manifests':;
'#{@coderoot}/environments/env1/modules/mod1/data':;
'#{@coderoot}/environments/env1/modules/mod1/functions':;
'#{@coderoot}/environments/env1/modules/mod1/lib':;
'#{@coderoot}/environments/env1/modules/mod1/lib/puppet':;
'#{@coderoot}/environments/env1/modules/mod1/lib/puppet/functions':;
'#{@coderoot}/environments/env1/modules/mod1/lib/puppet/functions/mod1':;
# module mod2 ruby function
'#{@coderoot}/environments/env1/modules/mod2':;
'#{@coderoot}/environments/env1/modules/mod2/manifests':;
'#{@coderoot}/environments/env1/modules/mod2/data':;
'#{@coderoot}/environments/env1/modules/mod2/functions':;
'#{@coderoot}/environments/env1/modules/mod2/lib':;
'#{@coderoot}/environments/env1/modules/mod2/lib/puppet':;
'#{@coderoot}/environments/env1/modules/mod2/lib/puppet/functions':;
'#{@coderoot}/environments/env1/modules/mod2/lib/puppet/functions/mod2':;
# module mod3 puppet function
'#{@coderoot}/environments/env1/modules/mod3':;
'#{@coderoot}/environments/env1/modules/mod3/manifests':;
'#{@coderoot}/environments/env1/modules/mod3/data':;
'#{@coderoot}/environments/env1/modules/mod3/functions':;
'#{@coderoot}/environments/env1/modules/mod3/not-lib':;
'#{@coderoot}/environments/env1/modules/mod3/not-lib/puppet':;
'#{@coderoot}/environments/env1/modules/mod3/not-lib/puppet/functions':;
'#{@coderoot}/environments/env1/modules/mod3/not-lib/puppet/functions/mod3':;
# module mod4 none
'#{@coderoot}/environments/env1/modules/mod4':;
'#{@coderoot}/environments/env1/modules/mod4/manifests':;
'#{@coderoot}/environments/env1/modules/mod4/data':;
'#{@coderoot}/environments/env1/modules/mod4/functions':;
'#{@coderoot}/environments/env1/modules/mod4/lib':;
'#{@coderoot}/environments/env1/modules/mod4/lib/puppet':;
'#{@coderoot}/environments/env1/modules/mod4/lib/puppet/functions':;
'#{@coderoot}/environments/env1/modules/mod4/lib/puppet/functions/mod4':;
##### env2 ruby function
'#{@coderoot}/environments/env2':;
'#{@coderoot}/environments/env2/data':;
'#{@coderoot}/environments/env2/functions':;
'#{@coderoot}/environments/env2/functions/environment':;
'#{@coderoot}/environments/env2/lib':;
'#{@coderoot}/environments/env2/lib/puppet':;
'#{@coderoot}/environments/env2/lib/puppet/functions':;
'#{@coderoot}/environments/env2/lib/puppet/functions/environment':;
'#{@coderoot}/environments/env2/manifests':;
'#{@coderoot}/environments/env2/modules':;
# module mod1 hiera
'#{@coderoot}/environments/env2/modules/mod1':;
'#{@coderoot}/environments/env2/modules/mod1/manifests':;
'#{@coderoot}/environments/env2/modules/mod1/data':;
'#{@coderoot}/environments/env2/modules/mod1/functions':;
'#{@coderoot}/environments/env2/modules/mod1/lib':;
'#{@coderoot}/environments/env2/modules/mod1/lib/puppet':;
'#{@coderoot}/environments/env2/modules/mod1/lib/puppet/functions':;
'#{@coderoot}/environments/env2/modules/mod1/lib/puppet/functions/mod1':;
# module mod2 ruby function
'#{@coderoot}/environments/env2/modules/mod2':;
'#{@coderoot}/environments/env2/modules/mod2/manifests':;
'#{@coderoot}/environments/env2/modules/mod2/data':;
'#{@coderoot}/environments/env2/modules/mod2/functions':;
'#{@coderoot}/environments/env2/modules/mod2/lib':;
'#{@coderoot}/environments/env2/modules/mod2/lib/puppet':;
'#{@coderoot}/environments/env2/modules/mod2/lib/puppet/functions':;
'#{@coderoot}/environments/env2/modules/mod2/lib/puppet/functions/mod2':;
# module mod3 puppet function
'#{@coderoot}/environments/env2/modules/mod3':;
'#{@coderoot}/environments/env2/modules/mod3/manifests':;
'#{@coderoot}/environments/env2/modules/mod3/data':;
'#{@coderoot}/environments/env2/modules/mod3/functions':;
'#{@coderoot}/environments/env2/modules/mod3/not-lib':;
'#{@coderoot}/environments/env2/modules/mod3/not-lib/puppet':;
'#{@coderoot}/environments/env2/modules/mod3/not-lib/puppet/functions':;
'#{@coderoot}/environments/env2/modules/mod3/not-lib/puppet/functions/mod3':;
# module mod4 none
'#{@coderoot}/environments/env2/modules/mod4':;
'#{@coderoot}/environments/env2/modules/mod4/manifests':;
'#{@coderoot}/environments/env2/modules/mod4/data':;
'#{@coderoot}/environments/env2/modules/mod4/functions':;
'#{@coderoot}/environments/env2/modules/mod4/lib':;
'#{@coderoot}/environments/env2/modules/mod4/lib/puppet':;
'#{@coderoot}/environments/env2/modules/mod4/lib/puppet/functions':;
'#{@coderoot}/environments/env2/modules/mod4/lib/puppet/functions/mod4':;
##### env3 puppet function
'#{@coderoot}/environments/env3':;
'#{@coderoot}/environments/env3/data':;
'#{@coderoot}/environments/env3/functions':;
'#{@coderoot}/environments/env3/functions/environment':;
'#{@coderoot}/environments/env3/not-lib':;
'#{@coderoot}/environments/env3/not-lib/puppet':;
'#{@coderoot}/environments/env3/not-lib/puppet/functions':;
'#{@coderoot}/environments/env3/not-lib/puppet/functions/environment':;
'#{@coderoot}/environments/env3/manifests':;
'#{@coderoot}/environments/env3/modules':;
# module mod1 hiera
'#{@coderoot}/environments/env3/modules/mod1':;
'#{@coderoot}/environments/env3/modules/mod1/manifests':;
'#{@coderoot}/environments/env3/modules/mod1/data':;
'#{@coderoot}/environments/env3/modules/mod1/functions':;
'#{@coderoot}/environments/env3/modules/mod1/lib':;
'#{@coderoot}/environments/env3/modules/mod1/lib/puppet':;
'#{@coderoot}/environments/env3/modules/mod1/lib/puppet/functions':;
'#{@coderoot}/environments/env3/modules/mod1/lib/puppet/functions/mod1':;
# module mod2 ruby function
'#{@coderoot}/environments/env3/modules/mod2':;
'#{@coderoot}/environments/env3/modules/mod2/manifests':;
'#{@coderoot}/environments/env3/modules/mod2/data':;
'#{@coderoot}/environments/env3/modules/mod2/functions':;
'#{@coderoot}/environments/env3/modules/mod2/lib':;
'#{@coderoot}/environments/env3/modules/mod2/lib/puppet':;
'#{@coderoot}/environments/env3/modules/mod2/lib/puppet/functions':;
'#{@coderoot}/environments/env3/modules/mod2/lib/puppet/functions/mod2':;
# module mod3 puppet function
'#{@coderoot}/environments/env3/modules/mod3':;
'#{@coderoot}/environments/env3/modules/mod3/manifests':;
'#{@coderoot}/environments/env3/modules/mod3/data':;
'#{@coderoot}/environments/env3/modules/mod3/functions':;
'#{@coderoot}/environments/env3/modules/mod3/not-lib':;
'#{@coderoot}/environments/env3/modules/mod3/not-lib/puppet':;
'#{@coderoot}/environments/env3/modules/mod3/not-lib/puppet/functions':;
'#{@coderoot}/environments/env3/modules/mod3/not-lib/puppet/functions/mod3':;
# module mod4 none
'#{@coderoot}/environments/env3/modules/mod4':;
'#{@coderoot}/environments/env3/modules/mod4/manifests':;
'#{@coderoot}/environments/env3/modules/mod4/data':;
'#{@coderoot}/environments/env3/modules/mod4/functions':;
'#{@coderoot}/environments/env3/modules/mod4/lib':;
'#{@coderoot}/environments/env3/modules/mod4/lib/puppet':;
'#{@coderoot}/environments/env3/modules/mod4/lib/puppet/functions':;
'#{@coderoot}/environments/env3/modules/mod4/lib/puppet/functions/mod4':;
##### env4 none
'#{@coderoot}/environments/env4':;
'#{@coderoot}/environments/env4/data':;
'#{@coderoot}/environments/env4/functions':;
'#{@coderoot}/environments/env4/functions/environment':;
'#{@coderoot}/environments/env4/lib':;
'#{@coderoot}/environments/env4/lib/puppet':;
'#{@coderoot}/environments/env4/lib/puppet/functions':;
'#{@coderoot}/environments/env4/lib/puppet/functions/environment':;
'#{@coderoot}/environments/env4/manifests':;
'#{@coderoot}/environments/env4/modules':;
# module mod1 hiera
'#{@coderoot}/environments/env4/modules/mod1':;
'#{@coderoot}/environments/env4/modules/mod1/manifests':;
'#{@coderoot}/environments/env4/modules/mod1/data':;
'#{@coderoot}/environments/env4/modules/mod1/functions':;
'#{@coderoot}/environments/env4/modules/mod1/lib':;
'#{@coderoot}/environments/env4/modules/mod1/lib/puppet':;
'#{@coderoot}/environments/env4/modules/mod1/lib/puppet/functions':;
'#{@coderoot}/environments/env4/modules/mod1/lib/puppet/functions/mod1':;
# module mod2 ruby function
'#{@coderoot}/environments/env4/modules/mod2':;
'#{@coderoot}/environments/env4/modules/mod2/manifests':;
'#{@coderoot}/environments/env4/modules/mod2/data':;
'#{@coderoot}/environments/env4/modules/mod2/functions':;
'#{@coderoot}/environments/env4/modules/mod2/lib':;
'#{@coderoot}/environments/env4/modules/mod2/lib/puppet':;
'#{@coderoot}/environments/env4/modules/mod2/lib/puppet/functions':;
'#{@coderoot}/environments/env4/modules/mod2/lib/puppet/functions/mod2':;
# module mod3 puppet function
'#{@coderoot}/environments/env4/modules/mod3':;
'#{@coderoot}/environments/env4/modules/mod3/manifests':;
'#{@coderoot}/environments/env4/modules/mod3/data':;
'#{@coderoot}/environments/env4/modules/mod3/functions':;
'#{@coderoot}/environments/env4/modules/mod3/not-lib':;
'#{@coderoot}/environments/env4/modules/mod3/not-lib/puppet':;
'#{@coderoot}/environments/env4/modules/mod3/not-lib/puppet/functions':;
'#{@coderoot}/environments/env4/modules/mod3/not-lib/puppet/functions/mod3':;
# module mod4 none
'#{@coderoot}/environments/env4/modules/mod4':;
'#{@coderoot}/environments/env4/modules/mod4/manifests':;
'#{@coderoot}/environments/env4/modules/mod4/data':;
'#{@coderoot}/environments/env4/modules/mod4/functions':;
'#{@coderoot}/environments/env4/modules/mod4/lib':;
'#{@coderoot}/environments/env4/modules/mod4/lib/puppet':;
'#{@coderoot}/environments/env4/modules/mod4/lib/puppet/functions':;
'#{@coderoot}/environments/env4/modules/mod4/lib/puppet/functions/mod4':;
}
## Global data provider config (hiera)
file { '#{@coderoot}/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
:backends:
- "yaml"
:logger: "console"
:hierarchy:
- "global"
:yaml:
:datadir: "#{@coderoot}/hieradata"
',
}
## facts file
file { '#{@coderoot}/facts.yaml':
ensure => file,
mode => "0644",
content => '---
my_data_key: "my_data_value"
',
}
file { '#{@coderoot}/hieradata/global.yaml':
ensure => file,
mode => "0644",
content => '---
global_key: "global-hiera provided value for key"
another_global_key: "global-hiera provided value for key"
mod1::global_key: "global-hiera provided value for key"
mod2::global_key: "global-hiera provided value for key"
mod3::global_key: "global-hiera provided value for key"
mod4::global_key: "global-hiera provided value for key"
',
}
## Evironment data provider configuration
file { '#{@coderoot}/environments/production/environment.conf':
ensure => file,
mode => "0644",
content => 'environment_timeout = 0
',
}
file { '#{@coderoot}/environments/env1/environment.conf':
ensure => file,
mode => "0644",
content => 'environment_timeout = 0
environment_data_provider = "hiera"
',
}
file { '#{@coderoot}/environments/env2/environment.conf':
ensure => file,
mode => "0644",
content => 'environment_timeout = 0
environment_data_provider = "function"
',
}
file { '#{@coderoot}/environments/env3/environment.conf':
ensure => file,
mode => "0644",
content => 'environment_timeout = 0
environment_data_provider = "function"
',
}
file { '#{@coderoot}/environments/env4/environment.conf':
ensure => file,
mode => "0644",
content => 'environment_timeout = 0
environment_data_provider = "none"
',
}
# Environment hiera data provider
file { '#{@coderoot}/environments/production/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/production/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
global_key: "env-production hiera provided value"
environment_key: "env-production hiera provided value"
',
}
file { '#{@coderoot}/environments/env1/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env1/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
global_key: "env-env1 hiera provided value"
environment_key: "env-env1 hiera provided value"
',
}
file { '#{@coderoot}/environments/env2/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env2/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
global_key: "env-env1 hiera provided value"
environment_key: "env-env1 hiera provided value"
',
}
file { '#{@coderoot}/environments/env3/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env3/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
global_key: "env-env1 hiera provided value"
environment_key: "env-env1 hiera provided value"
',
}
file { '#{@coderoot}/environments/env4/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env4/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
global_key: "env-env1 hiera provided value"
environment_key: "env-env1 hiera provided value"
',
}
# Environment ruby function data provider
file { '#{@coderoot}/environments/production/lib/puppet/functions/environment/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'environment::data') do
def data()
{
'environment_key': 'env-production-ruby-function data() provided value',
'global_key': 'env-production-ruby-function data () provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/env1/lib/puppet/functions/environment/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'environment::data') do
def data()
{
'environment_key' => 'env-env1-ruby-function data() provided value',
'global_key' => 'env-env1-ruby-function data () provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/env2/lib/puppet/functions/environment/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'environment::data') do
def data()
{
'environment_key' => 'env-env2-ruby-function data() provided value',
'global_key' => 'env-env2-ruby-function data () provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/env3/not-lib/puppet/functions/environment/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'environment::data') do
def data()
{
'environment_key' => 'env-env3-ruby-function data() provided value',
'global_key' => 'env-env3-ruby-function data () provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/env4/lib/puppet/functions/environment/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'environment::data') do
def data()
{
'environment_key' => 'env-env4-ruby-function data() provided value',
'global_key' => 'env-env4-ruby-function data () provided value',
}
end
end
",
}
# Environment puppet function data provider
file { '#{@coderoot}/environments/production/functions/environment/data.pp':
ensure => file,
mode => "0755",
content => 'function environment::data() {
{
"environment_key" => "env-production-puppet-function data() provided value",
"global_key" => "env-production-puppet-function data() provided value",
}
}
',
}
file { '#{@coderoot}/environments/env1/functions/environment/data.pp':
ensure => file,
mode => "0755",
content => 'function environment::data() {
{
"environment_key" => "env-env1-puppet-function data() provided value",
"global_key" => "env-env1-puppet-function data() provided value",
}
}
',
}
file { '#{@coderoot}/environments/env2/functions/environment/data.pp':
ensure => file,
mode => "0755",
content => 'function environment::data() {
{
"environment_key" => "env-env2-puppet-function data() provided value",
"global_key" => "env-env2-puppet-function data() provided value",
}
}
',
}
file { '#{@coderoot}/environments/env3/functions/environment/data.pp':
ensure => file,
mode => "0755",
content => 'function environment::data() {
{
"environment_key" => "env-env3-puppet-function data() provided value",
"global_key" => "env-env3-puppet-function data() provided value",
}
}
',
}
file { '#{@coderoot}/environments/env4/functions/environment/data.pp':
ensure => file,
mode => "0755",
content => 'function environment::data() {
{
"environment_key" => "env-env4-puppet-function data() provided value",
"global_key" => "env-env4-puppet-function data() provided value",
}
}
',
}
## Module data provider configuration
# Module hiera data provider
file { '#{@coderoot}/environments/production/modules/mod1/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/production/modules/mod1/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod1::module_key": "module-production-mod1-hiera provided value"
"mod1::global_key": "module-production-mod1-hiera provided value"
"environment_key": "module-production-mod1-hiera provided value"
"global_key": "module-production-mod1-hiera provided value"
',
}
file { '#{@coderoot}/environments/production/modules/mod2/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/production/modules/mod2/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod2::module_key": "module-production-mod2-hiera provided value"
"mod2::global_key": "module-production-mod2-hiera provided value"
"environment_key": "module-production-mod2-hiera provided value"
"global_key": "module-production-mod2-hiera provided value"
',
}
file { '#{@coderoot}/environments/production/modules/mod3/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/production/modules/mod3/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod3::module_key": "module-production-mod3-hiera provided value"
"mod3::global_key": "module-production-mod3-hiera provided value"
"environment_key": "module-production-mod3-hiera provided value"
"global_key" => "module-production-mod3-hiera provided value"
',
}
file { '#{@coderoot}/environments/production/modules/mod4/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/production/modules/mod4/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod4::module_key": "module-production-mod4-hiera provided value"
"mod4::global_key": "module-production-mod4-hiera provided value"
"environment_key": "module-production-mod4-hiera provided value"
"global_key": "module-production-mod4-hiera provided value"
',
}
file { '#{@coderoot}/environments/env1/modules/mod1/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env1/modules/mod1/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod1::module_key": "module-env1-mod1-hiera provided value"
"global_key": "module-env1-mod1-hiera provided value"
"environment_key": "module-env1-mod1-hiera provided value"
',
}
file { '#{@coderoot}/environments/env1/modules/mod2/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env1/modules/mod2/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod2::module_key": "module-env1-mod2-hiera provided value"
"global_key": "module-env1-mod2-hiera provided value"
"environment_key": "module-env1-mod2-hiera provided value"
',
}
file { '#{@coderoot}/environments/env1/modules/mod3/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env1/modules/mod3/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod3::module_key": "module-env1-mod3-hiera provided value"
"global_key": "module-env1-mod3-hiera provided value"
"environment_key": "module-env1-mod3-hiera provided value"
',
}
file { '#{@coderoot}/environments/env1/modules/mod4/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env1/modules/mod4/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod4::module_key": "module-env1-mod4-hiera provided value"
"global_key": "module-env1-mod4-hiera provided value"
"environment_key": "module-env1-mod4-hiera provided value"
',
}
file { '#{@coderoot}/environments/env2/modules/mod1/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env2/modules/mod1/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod1::module_key": "module-env2-mod1-hiera provided value"
"global_key": "module-env2-mod1-hiera provided value"
"environment_key": "module-env2-mod1-hiera provided value"
',
}
file { '#{@coderoot}/environments/env2/modules/mod2/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env2/modules/mod2/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod2::module_key": "module-env2-mod2-hiera provided value"
"global_key": "module-env2-mod2-hiera provided value"
"environment_key": "module-env2-mod2-hiera provided value"
',
}
file { '#{@coderoot}/environments/env2/modules/mod3/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env2/modules/mod3/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod3::module_key": "module-env2-mod3-hiera provided value"
"global_key": "module-env2-mod3-hiera provided value"
"environment_key": "module-env2-mod3-hiera provided value"
',
}
file { '#{@coderoot}/environments/env2/modules/mod4/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env2/modules/mod4/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod4::module_key": "module-env2-mod4-hiera provided value"
"global_key": "module-env2-mod4-hiera provided value"
"environment_key": "module-env2-mod4-hiera provided value"
',
}
file { '#{@coderoot}/environments/env3/modules/mod1/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env3/modules/mod1/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod1::module_key": "module-env3-mod1-hiera provided value"
"global_key": "module-env3-mod1-hiera provided value"
"environment_key": "module-env3-mod1-hiera provided value"
',
}
file { '#{@coderoot}/environments/env3/modules/mod2/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env3/modules/mod2/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod2::module_key": "module-env3-mod2-hiera provided value"
"global_key": "module-env3-mod2-hiera provided value"
"environment_key": "module-env3-mod2-hiera provided value"
',
}
file { '#{@coderoot}/environments/env3/modules/mod3/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env3/modules/mod3/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod3::module_key": "module-env3-mod3-hiera provided value"
"global_key": "module-env3-mod3-hiera provided value"
"environment_key": "module-env3-mod3-hiera provided value"
',
}
file { '#{@coderoot}/environments/env3/modules/mod4/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env3/modules/mod4/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod4::module_key": "module-env3-mod4-hiera provided value"
"global_key": "module-env3-mod4-hiera provided value"
"environment_key": "module-env3-mod4-hiera provided value"
',
}
file { '#{@coderoot}/environments/env4/modules/mod1/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env4/modules/mod1/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod1::module_key": "module-env4-mod1-hiera provided value"
"global_key": "module-env4-mod1-hiera provided value"
"environment_key": "module-env4-mod1-hiera provided value"
',
}
file { '#{@coderoot}/environments/env4/modules/mod2/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env4/modules/mod2/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod2::module_key": "module-env4-mod2-hiera provided value"
"global_key": "module-env4-mod2-hiera provided value"
"environment_key": "module-env4-mod2-hiera provided value"
',
}
file { '#{@coderoot}/environments/env4/modules/mod3/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env4/modules/mod3/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod3::module_key": "module-env4-mod3-hiera provided value"
"global_key": "module-env4-mod3-hiera provided value"
"environment_key": "module-env4-mod3-hiera provided value"
',
}
file { '#{@coderoot}/environments/env4/modules/mod4/hiera.yaml':
ensure => file,
mode => "0644",
content => '---
version: 4
',
}
file { '#{@coderoot}/environments/env4/modules/mod4/data/common.yaml':
ensure => file,
mode => "0644",
content => '---
"mod4::module_key": "module-env4-mod4-hiera provided value"
"global_key": "module-env4-mod4-hiera provided value"
"environment_key": "module-env4-mod4-hiera provided value"
',
}
# Module ruby function data provider
file { '#{@coderoot}/environments/production/modules/mod1/lib/puppet/functions/mod1/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'mod1::data') do
def data()
{
'mod1::module_key' => 'module-production-mod1-ruby-function provided value',
'mod1::global_key' => 'module-production-mod1-ruby-function provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/production/modules/mod2/lib/puppet/functions/mod2/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'mod2::data') do
def data()
{
'mod2::module_key' => 'module-production-mod2-ruby-function provided value',
'mod2::global_key' => 'module-production-mod2-ruby-function provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/production/modules/mod3/not-lib/puppet/functions/mod3/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'mod3::data') do
def data()
{
'mod3::module_key' => 'module-production-mod3-ruby-function provided value',
'mod3::global_key' => 'module-production-mod3-ruby-function provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/production/modules/mod4/lib/puppet/functions/mod4/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'mod4::data') do
def data()
{
'mod4::module_key' => 'module-production-mod4-ruby-function provided value',
'mod4::global_key' => 'module-production-mod4-ruby-function provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/env1/modules/mod1/lib/puppet/functions/mod1/data.rb':
ensure => file,
mode => "0644",
content => "Puppet::Functions.create_function(:'mod1::data') do
def data()
{
'mod1::module_key' => 'module-env1-mod1-ruby-function provided value',
}
end
end
",
}
file { '#{@coderoot}/environments/env1/modules/mod2/lib/puppet/functions/mod2/data.rb':
ensure => file,
mode => "0644",
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | true |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/parser_functions/calling_all_functions.rb | acceptance/tests/parser_functions/calling_all_functions.rb | test_name 'Calling all functions.. test in progress!'
tag 'audit:high',
'audit:acceptance'
# create single manifest calling all functions
step 'Apply manifest containing all function calls'
def manifest_call_each_function_from_array(functions)
manifest = ''
# use index to work around puppet's immutable variables
# use variables so we can concatenate strings
functions.each_with_index do |function,index|
if function[:rvalue]
manifest << "$pre#{index} = \"sayeth #{function[:name].capitalize}: Scope(Class[main]): \" "
manifest << "$output#{index} = #{function[:name]}(#{function[:args]}) "
manifest << "#{function[:lambda]} notice \"${pre#{index}}${output#{index}}\"\n"
else
manifest << "$pre#{index} = \"sayeth #{function[:name].capitalize}: \" "
manifest << "notice \"${pre#{index}}\"\n"
manifest << "#{function[:name]}(#{function[:args]}) "
manifest << "#{function[:lambda]}\n"
end
end
manifest
end
agents.each do |agent|
testdir = agent.tmpdir('calling_all_functions')
# if agent["platform"] =~ /win/
# generator = {:args => '"c:/windows/system32/tasklist.exe"', :expected => /\nImage Name/}
# else
# generator = {:args => '"/bin/date"', :expected => /\w\w\w.*?\d\d:\d\d\:\d\d/}
# end
# create list of 3x functions and args
# notes: hiera functions are well tested elsewhere, included for completeness
# special cases: contain (call this from call_em_all)
# do fail last because it errors out
functions_3x = [
{:name => :alert, :args => '"consider yourself on alert"', :lambda => nil, :expected => 'consider yourself on alert', :rvalue => false},
{:name => :binary_file, :args => '"call_em_all/rickon.txt"', :lambda => nil, :expected => '', :rvalue => true},
#{:name => :break, :args => '', :lambda => nil, :expected => '', :rvalue => false},
# this is explicitly called from call_em_all module which is included below
#{:name => :contain, :args => 'call_em_all', :lambda => nil, :expected => '', :rvalue => true},
# below doens't instance the resource. no output
{:name => :create_resources, :args => 'notify, {"w"=>{message=>"winter is coming"}}', :lambda => nil, :expected => '', :rvalue => false},
{:name => :crit, :args => '"consider yourself critical"', :lambda => nil, :expected => 'consider yourself critical', :rvalue => false},
{:name => :debug, :args => '"consider yourself bugged"', :lambda => nil, :expected => '', :rvalue => false}, # no output expected unless run with debug
{:name => :defined, :args => 'File["/tmp"]', :lambda => nil, :expected => 'false', :rvalue => true},
{:name => :dig, :args => '[100]', :lambda => nil, :expected => '[100]', :rvalue => true},
# Expect sha256 hash value for the digest
{:name => :digest, :args => '"Sansa"', :lambda => nil, :expected => '4ebf3a5527313f06c7965749d7764c15cba6fe86da11691ca9bd0ce448563979', :rvalue => true},
{:name => :emerg, :args => '"consider yourself emergent"', :lambda => nil, :expected => 'consider yourself emergent', :rvalue => false},
{:name => :err, :args => '"consider yourself in err"', :lambda => nil, :expected => 'consider yourself in err', :rvalue => false},
{:name => :file, :args => '"call_em_all/rickon.txt"', :lambda => nil, :expected => 'who?', :rvalue => true},
{:name => :fqdn_rand, :args => '100000', :lambda => nil, :expected => /Fqdn_rand: Scope\(Class\[main\]\): \d{1,5}/, :rvalue => true},
# generate requires a fully qualified exe; which requires specifics for windows vs posix
#{:name => :generate, :args => generator[:args], :lambda => nil, :expected => generator[:expected], :rvalue => true},
{:name => :hiera_array, :args => 'date,default_array', :lambda => nil, :expected => 'default_array', :rvalue => true},
{:name => :hiera_hash, :args => 'date,default_hash', :lambda => nil, :expected => 'default_hash', :rvalue => true},
{:name => :hiera_include, :args => 'date,call_em_all', :lambda => nil, :expected => '', :rvalue => false},
{:name => :hiera, :args => 'date,default_date', :lambda => nil, :expected => 'default_date', :rvalue => true},
{:name => :include, :args => 'call_em_all', :lambda => nil, :expected => '', :rvalue => false},
{:name => :info, :args => '"consider yourself informed"', :lambda => nil, :expected => '', :rvalue => false}, # no ouput unless in debug mode
{:name => :inline_template, :args => '\'empty<%= @x %>space\'', :lambda => nil, :expected => 'emptyspace', :rvalue => true},
# test the living life out of this thing in lookup.rb, and it doesn't allow for a default value
#{:name => :lookup, :args => 'date,lookup_date', :lambda => nil, :expected => '', :rvalue => true}, # well tested elsewhere
{:name => :sha256, :args => '"Bran"', :lambda => nil, :expected => '824264f7f73d6026550b52a671c50ad0c4452af66c24f3784e30f515353f2ce0', :rvalue => true},
# Integer.new
{:name => :Integer, :args => '"100"', :lambda => nil, :expected => '100', :rvalue => true},
{:name => :notice, :args => '"consider yourself under notice"', :lambda => nil, :expected => 'consider yourself under notice', :rvalue => false},
{:name => :realize, :args => 'User[arya]', :lambda => nil, :expected => '', :rvalue => false}, # TODO: create a virtual first
{:name => :regsubst, :args => '"Cersei","Cer(\\\\w)ei","Daenery\\\\1"',:lambda => nil, :expected => 'Daenerys', :rvalue => true},
# explicitly called in call_em_all; implicitly called by the include above
#{:name => :require, :args => '[4,5,6]', :lambda => nil, :expected => '', :rvalue => true},
# 4x output contains brackets around scanf output
{:name => :scanf, :args => '"Eddard Stark","%6s"', :lambda => nil, :expected => '[Eddard]', :rvalue => true},
{:name => :sha1, :args => '"Sansa"', :lambda => nil, :expected => '4337ce5e4095e565d51e0ef4c80df1fecf238b29', :rvalue => true},
{:name => :shellquote, :args => '["-1", "--two"]', :lambda => nil, :expected => '-1 --two', :rvalue => true},
# 4x output contains brackets around split output and commas btwn values
{:name => :split, :args => '"9,8,7",","', :lambda => nil, :expected => '[9, 8, 7]', :rvalue => true},
{:name => :sprintf, :args => '"%b","123"', :lambda => nil, :expected => '1111011', :rvalue => true},
{:name => :step, :args => '[100,99],1', :lambda => nil, :expected => 'Iterator[Integer]-Value', :rvalue => true},
# explicitly called in call_em_all
#{:name => :tag, :args => '[4,5,6]', :lambda => nil, :expected => '', :rvalue => true},
{:name => :tagged, :args => '"yer_it"', :lambda => nil, :expected => 'false', :rvalue => true},
{:name => :template, :args => '"call_em_all/template.erb"', :lambda => nil, :expected => 'no defaultsno space', :rvalue => true},
{:name => :type, :args => '42', :lambda => nil, :expected => 'Integer[42, 42]', :rvalue => true},
{:name => :versioncmp, :args => '"1","2"', :lambda => nil, :expected => '-1', :rvalue => true},
{:name => :warning, :args => '"consider yourself warned"', :lambda => nil, :expected => 'consider yourself warned', :rvalue => false},
# do this one last or it will not allow the others to run.
{:name => :fail, :args => '"Jon Snow"', :lambda => nil, :expected => /Error:.*Jon Snow/, :rvalue => false},
]
puppet_version = on(agent, puppet('--version')).stdout.chomp
functions_4x = [
{:name => :assert_type, :args => '"String[1]", "Valar morghulis"', :lambda => nil, :expected => 'Valar morghulis', :rvalue => true},
{:name => :each, :args => '[1,2,3]', :lambda => '|$x| {$x}', :expected => '[1, 2, 3]', :rvalue => true},
{:name => :epp, :args => '"call_em_all/template.epp",{x=>droid}', :lambda => nil, :expected => 'This is the droid you are looking for!', :rvalue => true},
{:name => :filter, :args => '[4,5,6]', :lambda => '|$x| {true}', :expected => '[4, 5, 6]', :rvalue => true},
# find_file() called by binary_file
#{:name => :find_file, :args => '[4,5,6]', :lambda => '|$x| {true}', :expected => '[4, 5, 6]', :rvalue => true},
{:name => :inline_epp, :args => '\'<%= $x %>\',{x=>10}', :lambda => nil, :expected => '10', :rvalue => true},
#{:name => :lest, :args => '100', :lambda => '"100"', :expected => '100', :rvalue => true},
{:name => :map, :args => '[7,8,9]', :lambda => '|$x| {$x * $x}', :expected => '[49, 64, 81]', :rvalue => true},
{:name => :match, :args => '"abc", /b/', :lambda => nil, :expected => '[b]', :rvalue => true},
#{:name => :next, :args => '100', :lambda => nil, :expected => '100', :rvalue => true},
{:name => :reduce, :args => '[4,5,6]', :lambda => '|$sum, $n| { $sum+$n }', :expected => '15', :rvalue => true},
#{:name => :return, :args => '100', :lambda => nil, :expected => '100', :rvalue => true},
{:name => :reverse_each, :args => '[100,99]', :lambda => nil, :expected => 'Iterator[Integer]-Value', :rvalue => true},
# :reuse,:recycle
{:name => :slice, :args => '[1,2,3,4,5,6], 2', :lambda => nil, :expected => '[[1, 2], [3, 4], [5, 6]]', :rvalue => true},
{:name => :strftime, :args => 'Timestamp("4216-09-23T13:14:15.123 UTC"), "%C"', :lambda => nil, :expected => '42', :rvalue => true},
{:name => :then, :args => '100', :lambda => '|$x| {$x}', :expected => '100', :rvalue => true},
{:name => :with, :args => '1, "Catelyn"', :lambda => '|$x, $y| {"$x, $y"}', :expected => '1, Catelyn', :rvalue => true},
]
module_manifest = <<PP
File {
ensure => directory,
}
file {
'#{testdir}':;
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/modules':;
'#{testdir}/environments/production/modules/tagged':;
'#{testdir}/environments/production/modules/tagged/manifests':;
'#{testdir}/environments/production/modules/contained':;
'#{testdir}/environments/production/modules/contained/manifests':;
'#{testdir}/environments/production/modules/required':;
'#{testdir}/environments/production/modules/required/manifests':;
'#{testdir}/environments/production/modules/call_em_all':;
'#{testdir}/environments/production/modules/call_em_all/manifests':;
'#{testdir}/environments/production/modules/call_em_all/templates':;
'#{testdir}/environments/production/modules/call_em_all/files':;
}
file { '#{testdir}/environments/production/modules/tagged/manifests/init.pp':
ensure => file,
content => 'class tagged {
notice tagged
tag yer_it
}',
}
file { '#{testdir}/environments/production/modules/required/manifests/init.pp':
ensure => file,
content => 'class required {
notice required
}',
}
file { '#{testdir}/environments/production/modules/contained/manifests/init.pp':
ensure => file,
content => 'class contained {
notice contained
}',
}
file { '#{testdir}/environments/production/modules/call_em_all/manifests/init.pp':
ensure => file,
content => 'class call_em_all {
notice call_em_all
contain contained
require required
tag yer_it
}',
}
file { '#{testdir}/environments/production/modules/call_em_all/files/rickon.txt':
ensure => file,
content => 'who?',
}
file { '#{testdir}/environments/production/modules/call_em_all/templates/template.epp':
ensure => file,
content => 'This is the <%= $x %> you are looking for!',
}
file { '#{testdir}/environments/production/modules/call_em_all/templates/template.erb':
ensure => file,
content => 'no defaults<%= @x %>no space',
}
PP
apply_manifest_on(agent, module_manifest, :catch_failures => true)
scope = 'Scope(Class[main]):'
# apply the 4x function manifest with future parser
puppet_apply_options = {:modulepath => "#{testdir}/environments/production/modules/",
:acceptable_exit_codes => 1}
puppet_apply_options[:future_parser] = true if puppet_version =~ /\A3\./
apply_manifest_on(agent, manifest_call_each_function_from_array(functions_4x), puppet_apply_options) do |result|
functions_4x.each do |function|
expected = "#{function[:name].capitalize}: #{scope} #{function[:expected]}"
unless agent['locale'] == 'ja'
assert_match(expected, result.output,
"#{function[:name]} output didn't match expected value")
end
end
end
file_path = agent.tmpfile('apply_manifest.pp')
create_remote_file(agent, file_path, manifest_call_each_function_from_array(functions_3x))
trusted_3x = puppet_version =~ /\A3\./ ? '--trusted_node_data ' : ''
on(agent, puppet("apply #{trusted_3x} --color=false --modulepath #{testdir}/environments/production/modules/ #{file_path}"),
:acceptable_exit_codes => 1 ) do |result|
functions_3x.each do |function|
# append the function name to the matcher so it's more expressive
if function[:expected].is_a?(String)
if function[:name] == :fail
expected = function[:expected]
elsif function[:name] == :crit
expected = "#{function[:name].capitalize}ical: #{scope} #{function[:expected]}"
elsif function[:name] == :emerg
expected = "#{function[:name].capitalize}ency: #{scope} #{function[:expected]}"
elsif function[:name] == :err
expected = "#{function[:name].capitalize}or: #{scope} #{function[:expected]}"
elsif function[:expected] == ''
expected = "#{function[:name].capitalize}: #{function[:expected]}"
else
expected = "#{function[:name].capitalize}: #{scope} #{function[:expected]}"
end
elsif function[:expected].is_a?(Regexp)
expected = function[:expected]
else
raise 'unhandled function expectation type (we allow String or Regexp)'
end
unless agent['locale'] == 'ja'
assert_match(expected, result.output, "#{function[:name]} output didn't match expected value")
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/parser_functions/hiera_hash/lookup_data.rb | acceptance/tests/parser_functions/hiera_hash/lookup_data.rb | test_name "Lookup data using the hiera_hash parser function"
tag 'audit:high',
'audit:acceptance',
'audit:refactor' # Master is not required for this test. Replace with agents.each
testdir = master.tmpdir('hiera')
step 'Setup'
apply_manifest_on(master, <<-PP, :catch_failures => true)
File {
ensure => directory,
mode => "0750",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}':;
'#{testdir}/hieradata':;
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/production/modules':;
}
file { '#{testdir}/hiera.yaml':
ensure => file,
content => '---
:backends:
- "yaml"
:logger: "console"
:hierarchy:
- "%{environment}"
- "global"
:yaml:
:datadir: "#{testdir}/hieradata"
',
mode => "0640";
}
file { '#{testdir}/hieradata/global.yaml':
ensure => file,
content => "---
database_user:
name: postgres
uid: 500
gid: 500
",
mode => "0640";
}
file { '#{testdir}/hieradata/production.yaml':
ensure => file,
content => "---
database_user:
shell: '/bin/bash'
",
mode => "0640";
}
file {
'#{testdir}/environments/production/modules/ntp/':;
'#{testdir}/environments/production/modules/ntp/manifests':;
}
file { '#{testdir}/environments/production/modules/ntp/manifests/init.pp':
ensure => file,
content => 'class ntp {
$database_user = hiera_hash("database_user")
notify { "the database user":
message => "name: ${database_user["name"]} shell: ${database_user["shell"]}"
}
}',
mode => "0640";
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
content => "
node default {
include ntp
}",
mode => "0640";
}
PP
step "Try to lookup hash data"
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
'hiera_config' => "#{testdir}/hiera.yaml",
},
}
with_puppet_running_on master, master_opts, testdir do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result|
assert_match("name: postgres shell: /bin/bash", result.stdout)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/parser_functions/hiera_array/lookup_data.rb | acceptance/tests/parser_functions/hiera_array/lookup_data.rb | test_name "Lookup data using the hiera_array parser function"
tag 'audit:high',
'audit:acceptance',
'audit:refactor' # Master is not required for this test. Replace with agents.each
testdir = master.tmpdir('hiera')
step 'Setup'
apply_manifest_on(master, <<-PP, :catch_failures => true)
File {
ensure => directory,
mode => "0750",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}':;
'#{testdir}/hieradata':;
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/production/modules':;
}
file { '#{testdir}/hiera.yaml':
ensure => file,
content => '---
:backends:
- "yaml"
:logger: "console"
:hierarchy:
- "%{environment}"
- "global"
:yaml:
:datadir: "#{testdir}/hieradata"
',
mode => "0640";
}
file { '#{testdir}/hieradata/global.yaml':
ensure => file,
content => "---
port: '8080'
ntpservers: ['global.ntp.puppetlabs.com']
",
mode => "0640";
}
file { '#{testdir}/hieradata/production.yaml':
ensure => file,
content => "---
ntpservers: ['production.ntp.puppetlabs.com']
",
mode => "0640";
}
file {
'#{testdir}/environments/production/modules/ntp':;
'#{testdir}/environments/production/modules/ntp/manifests':;
}
file { '#{testdir}/environments/production/modules/ntp/manifests/init.pp':
ensure => file,
content => '
class ntp {
$ntpservers = hiera_array("ntpservers")
define print {
$server = $name
notify { "ntpserver ${server}": }
}
ntp::print { $ntpservers: }
}',
mode => "0640";
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
content => "
node default {
include ntp
}",
mode => "0640";
}
PP
step "Try to lookup array data"
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
'hiera_config' => "#{testdir}/hiera.yaml",
},
}
with_puppet_running_on master, master_opts, testdir do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result|
assert_match('ntpserver global.ntp.puppetlabs.com', result.stdout)
assert_match('ntpserver production.ntp.puppetlabs.com', result.stdout)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/parser_functions/hiera/lookup_data.rb | acceptance/tests/parser_functions/hiera/lookup_data.rb | test_name "Lookup data using the hiera parser function"
tag 'audit:high',
'audit:acceptance',
'audit:refactor' # Master is not required for this test. Replace with agents.each
testdir = master.tmpdir('hiera')
step 'Setup'
apply_manifest_on(master, <<-PP, :catch_failures => true)
File {
ensure => directory,
mode => "0750",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}':;
'#{testdir}/hieradata':;
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/production/modules':;
}
file { '#{testdir}/hiera.yaml':
ensure => file,
content => '---
:backends:
- "yaml"
:logger: "console"
:hierarchy:
- "%{environment}"
- "global"
:yaml:
:datadir: "#{testdir}/hieradata"
',
mode => "0640",
}
file { '#{testdir}/hieradata/global.yaml':
ensure => file,
content => "---
port: 8080
",
mode => "0640",
}
file {
'#{testdir}/environments/production/modules/apache':;
'#{testdir}/environments/production/modules/apache/manifests':;
}
file { '#{testdir}/environments/production/modules/apache/manifests/init.pp':
ensure => file,
content => '
class apache {
$port = hiera("port")
notify { "port from hiera":
message => "apache server port: ${port}"
}
}',
mode => "0640",
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
content => "
node default {
include apache
}",
mode => "0640",
}
PP
step "Try to lookup string data"
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
'hiera_config' => "#{testdir}/hiera.yaml",
},
}
with_puppet_running_on master, master_opts, testdir do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result|
assert_match('apache server port: 8080', result.stdout)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/directory_environment_production_created_master.rb | acceptance/tests/environment/directory_environment_production_created_master.rb | test_name 'ensure production environment created by master if missing'
tag 'audit:high',
'audit:integration',
'server'
testdir = create_tmpdir_for_user master, 'prod-env-created'
step 'make environmentpath'
master_user = puppet_config(master, 'user', section: 'master')
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
owner => #{master_user},
group => #{master.puppet['group']},
mode => '0640',
}
file {
"#{testdir}":;
"#{testdir}/environments":;
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
}
}
step 'run master; ensure production environment created'
with_puppet_running_on(master, master_opts, testdir) do
on(master, "test -d '#{testdir}/environments/production'")
step 'ensure catalog returned from production env with no changes'
agents.each do |agent|
on(agent, puppet("agent -t --environment production --detailed-exitcodes")) do |result|
# detailed-exitcodes produces a 0 when no changes are made.
assert_equal(0, result.exit_code)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/use_enc_environment_for_pluginsync.rb | acceptance/tests/environment/use_enc_environment_for_pluginsync.rb | test_name "Agent should use environment given by ENC for pluginsync" do
tag 'audit:high',
'audit:integration',
'audit:refactor', # This test should be rolled into use_enc_environment
'server'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
testdir = create_tmpdir_for_user(master, 'respect_enc_test')
create_remote_file(master, "#{testdir}/enc.rb", <<END)
#!#{master['privatebindir']}/ruby
puts <<YAML
parameters:
environment: special
YAML
END
on(master, "chmod 755 #{testdir}/enc.rb")
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/special/':;
'#{testdir}/environments/special/modules':;
'#{testdir}/environments/special/modules/amod':;
'#{testdir}/environments/special/modules/amod/lib':;
'#{testdir}/environments/special/modules/amod/lib/puppet':;
}
file { '#{testdir}/environments/special/modules/amod/lib/puppet/foo.rb':
ensure => file,
mode => "0640",
content => "#special_version",
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
},
'master' => {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb"
},
}
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
agent_vardir = agent.puppet['vardir']
teardown do
on(agent, "rm -rf '#{agent_vardir}/lib'")
end
run_agent_on(agent, "-t --no-daemonize --onetime")
on(agent, "cat '#{agent_vardir}/lib/puppet/foo.rb'") do |result|
assert_match(/#special_version/, result.stdout, "The plugin from environment 'special' was not synced")
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/custom_type_provider_from_same_environment.rb | acceptance/tests/environment/custom_type_provider_from_same_environment.rb | test_name 'C59122: ensure provider from same env as custom type' do
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'audit:integration', # This behavior is specific to the master to 'do the right thing'
'server'
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
file_correct = "#{tmp_environment}-correct.txt"
file_wrong = "#{tmp_environment}-wrong.txt"
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
fq_prod_environmentpath = "#{environmentpath}/production"
teardown do
step 'clean out production env' do
on(master, "rm -rf #{fq_prod_environmentpath}/modules/*", :accept_all_exit_codes => true)
on(master, "rm #{fq_prod_environmentpath}/manifests/site.pp", :accept_all_exit_codes => true)
end
step 'clean out file resources' do
on(hosts, "rm #{file_correct} #{file_wrong}", :accept_all_exit_codes => true)
end
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create a custom type and provider in each of production and #{tmp_environment}" do
type_name = 'test_custom_type'
provider_name = 'universal'
type_content = <<TYPE
Puppet::Type.newtype(:#{type_name}) do
@doc = "Manage a file (the simple version)."
ensurable
newparam(:name) do
desc "The full path to the file."
end
end
TYPE
def provider_content(file_file_content, type_name, provider_name)
return <<PROVIDER
Puppet::Type.type(:#{type_name}).provide(:#{provider_name}) do
desc "#{provider_name} file mgmt, yo"
def create
File.open(@resource[:name], "w") { |f| f.puts "#{file_file_content}!" }
end
def destroy
File.unlink(@resource[:name])
end
def exists?
File.exist?(@resource[:name])
end
end
PROVIDER
end
manifest = <<MANIFEST
File { ensure => directory }
file {
'#{fq_tmp_environmentpath}/modules/simple_type':;
'#{fq_tmp_environmentpath}/modules/simple_type/lib':;
'#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet':;
'#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/type/':;
'#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/provider/':;
'#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/provider/#{type_name}':;
'#{fq_prod_environmentpath}/modules':;
'#{fq_prod_environmentpath}/modules/simple_type':;
'#{fq_prod_environmentpath}/modules/simple_type/lib':;
'#{fq_prod_environmentpath}/modules/simple_type/lib/puppet':;
'#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/type/':;
'#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/provider/':;
'#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/provider/#{type_name}':;
}
file { '#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/type/#{type_name}.rb':
ensure => file,
content => '#{type_content}',
}
file { '#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/type/#{type_name}.rb':
ensure => file,
content => '#{type_content}',
}
file { '#{fq_tmp_environmentpath}/modules/simple_type/lib/puppet/provider/#{type_name}/#{provider_name}.rb':
ensure => file,
content => '#{provider_content('correct', type_name, provider_name)}',
}
file { '#{fq_prod_environmentpath}/modules/simple_type/lib/puppet/provider/#{type_name}/#{provider_name}.rb':
ensure => file,
content => '#{provider_content('wrong', type_name, provider_name)}',
}
file { '#{fq_tmp_environmentpath}/manifests/site.pp':
ensure => file,
content => 'node default { #{type_name}{"#{file_correct}": ensure=>present} }',
}
file { '#{fq_prod_environmentpath}/manifests': }
file { '#{fq_prod_environmentpath}/manifests/site.pp':
ensure => file,
content => 'node default { #{type_name}{"#{file_wrong}": ensure=>present} }',
}
MANIFEST
apply_manifest_on(master, manifest, :catch_failures => true)
end
step "run agent in #{tmp_environment}, ensure it finds the correct provider" do
with_puppet_running_on(master,{}) do
agents.each do |agent|
on(agent, puppet("agent -t --environment #{tmp_environment}"),
:accept_all_exit_codes => true) do |result|
assert_equal(2, result.exit_code, 'agent did not exit with the correct code of 2')
assert_match(/#{file_correct}/, result.stdout, 'agent did not ensure the correct file')
assert(agent.file_exist?(file_correct), 'puppet did not create the file')
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/broken_unassigned_environment_handled_gracefully.rb | acceptance/tests/environment/broken_unassigned_environment_handled_gracefully.rb | test_name 'PUP-3755 Test an un-assigned broken environment'
tag 'audit:high',
'audit:integration',
'audit:refactor', # Use mk_tmp_environment_with_teardown helper
'server'
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step 'setup environments'
testdir = create_tmpdir_for_user(master, 'confdir')
environment = 'debug'
manifest = <<-MANIFEST
File {
ensure => directory,
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
mode => "0750",
}
file { "#{testdir}":;
"#{testdir}/environments":;
"#{testdir}/environments/production":;
"#{testdir}/environments/production/manifests":;
"#{testdir}/environments/production/modules":;
"#{testdir}/environments/#{environment}":;
"#{testdir}/environments/#{environment}/manifests":;
"#{testdir}/environments/#{environment}/modules":;
}
# broken envioronment
file { "#{testdir}/environments/production/manifests/site.pp":
ensure => file,
content => 'import "/tmp/bogus/*.pp"'
}
file { "#{testdir}/environments/#{environment}/manifests/site.pp":
ensure => file,
content => 'node default{\nnotify{"you win":}\n}'
}
MANIFEST
apply_manifest_on(master, manifest, :catch_failures => true)
step 'run agents, ensure no one complains about the other environment'
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments"
}
}
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
on(agent, puppet('agent',
"--test --environment #{environment}"),
:acceptable_exit_codes => (0..255)) do |result|
assert_match(/you win/, result.stdout, 'agent did not pickup newly classified environment.')
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/use_enc_environment_for_files.rb | acceptance/tests/environment/use_enc_environment_for_files.rb | test_name "Agent should use environment given by ENC for fetching remote files" do
tag 'audit:high',
'audit:integration',
'audit:refactor', # This test should be rolled into use_enc_environment
'server'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
testdir = create_tmpdir_for_user(master, 'respect_enc_test')
create_remote_file(master, "#{testdir}/enc.rb", <<END)
#!#{master['privatebindir']}/ruby
puts <<YAML
parameters:
environment: special
YAML
END
on(master, "chmod 755 '#{testdir}/enc.rb'")
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/special/':;
'#{testdir}/environments/special/manifests':;
'#{testdir}/environments/special/modules':;
'#{testdir}/environments/special/modules/amod':;
'#{testdir}/environments/special/modules/amod/files':;
}
file { '#{testdir}/environments/special/modules/amod/files/testy':
ensure => file,
mode => "0640",
content => 'special_environment',
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
'environment_timeout' => 0,
},
'master' => {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
},
}
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
atmp = agent.tmpdir('respect_enc_test')
teardown do
on(agent, "rm -rf '#{atmp}'")
end
logger.debug "agent: #{agent} \tagent.tmpdir => #{atmp}"
create_remote_file(master, "#{testdir}/environments/special/manifests/different.pp", <<END)
file { "#{atmp}/special_testy":
source => "puppet:///modules/amod/testy",
}
END
on(master, "chmod 644 '#{testdir}/environments/special/manifests/different.pp'")
run_agent_on(agent, "--no-daemonize --onetime --verbose --trace")
on(agent, "cat '#{atmp}/special_testy'") do |result|
assert_match(/special_environment/,
result.stdout,
"The file from environment 'special' was not found")
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/use_last_server_specified_environment.rb | acceptance/tests/environment/use_last_server_specified_environment.rb | test_name "Agent should use the last server-specified environment if server is authoritative" do
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'server'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
testdir = create_tmpdir_for_user(master, 'use_enc_env')
create_remote_file(master, "#{testdir}/enc.rb", <<END)
#!#{master['privatebindir'] || '/opt/puppetlabs/puppet/bin'}/ruby
puts <<YAML
parameters:
environment: special
YAML
END
on(master, "chmod 755 '#{testdir}/enc.rb'")
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/special/':;
'#{testdir}/environments/special/manifests':;
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
mode => "0640",
content => 'notify { "production environment": }',
}
file { '#{testdir}/environments/special/manifests/different.pp':
ensure => file,
mode => "0640",
content => 'notify { "special environment": }',
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
},
}
master_opts['master'] = {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
} if !master.is_pe?
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
step 'ensure the lastrunfile is absent for the first run' do
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
step 'first run: agent makes a node request to get the environment' do
run_agent_on(agent, '--no-daemonize --onetime --debug') do |result|
assert_match(/Local environment: 'production' doesn't match server specified node environment 'special', switching agent to 'special'/, result.stdout)
assert_match(/Debug: HTTP GET .*\/puppet\/v3\/node/, result.stdout)
assert_match(/Notice: special environment/, result.stdout)
end
end
step 'second run: agent uses the environment from lastrunfile' do
run_agent_on(agent, '--no-daemonize --onetime --debug') do |result|
assert_match(/Debug: Successfully loaded last environment from the lastrunfile/, result.stdout)
assert_match(/Notice: special environment/, result.stdout)
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/environment_scenario-bad.rb | acceptance/tests/environment/environment_scenario-bad.rb | test_name 'Test behavior of directory environments when environmentpath is set to a non-existent directory' do
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/classifier_utils'
extend Puppet::Acceptance::ClassifierUtils
tag 'audit:high',
'audit:unit', # The error responses for the agent should be covered by Ruby unit tests.
# The server 404/400 response should be covered by server integration tests.
'server'
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
classify_nodes_as_agent_specified_if_classifer_present
step 'setup environments'
testdir = create_tmpdir_for_user(master, 'confdir')
puppet_conf_backup_dir = create_tmpdir_for_user(master, "puppet-conf-backup-dir")
apply_manifest_on(master, environment_manifest(testdir), :catch_failures => true)
step 'Test' do
env_path = '/doesnotexist'
master_opts = {
'main' => {
'environmentpath' => "#{env_path}",
}
}
env = 'testing'
results = use_an_environment(env, 'bad environmentpath', master_opts, testdir, puppet_conf_backup_dir, :directory_environments => true)
expectations = {
:puppet_config => {
:exit_code => 0,
:matches => [%r{basemodulepath = /etc/puppetlabs/code/modules:/opt/puppetlabs/puppet/modules},
%r{modulepath =},
%r{manifest =},
%r{config_version =}],
},
:puppet_apply => {
:exit_code => 1,
:matches => [%r{Could not find a directory environment named '#{env}' anywhere in the path.*#{env_path}}],
},
:puppet_agent => {
:exit_code => 0,
},
}
agents.each do |host|
unless host['locale'] == 'ja'
expectations[:puppet_agent][:matches] = [%r{Environment '#{env}' not found on server, skipping initial pluginsync.},
%r{Local environment: '#{env}' doesn't match server specified environment 'production', restarting agent run with environment 'production'}]
end
end
assert_review(review_results(results, expectations))
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/can_enumerate_environments.rb | acceptance/tests/environment/can_enumerate_environments.rb | test_name "Can enumerate environments via an HTTP endpoint"
tag 'audit:high',
'audit:integration',
'server'
confine :except, :platform => /osx/ # see PUP-4820
def server_port(agent)
setting_on(agent, "agent", "serverport")
end
def setting_on(host, section, name)
on(host, puppet("config", "print", name, "--section", section)).stdout.chomp
end
def full_path(host, path)
if host['platform'] =~ /win/
on(host, "cygpath '#{path}'").stdout.chomp
else
path
end
end
def curl_master_from(agent, path, headers = '', &block)
url = "https://#{master}:#{server_port(agent)}#{path}"
cert_path = full_path(agent, setting_on(agent, "agent", "hostcert"))
key_path = full_path(agent, setting_on(agent, "agent", "hostprivkey"))
curl_base = "curl --tlsv1 -sg --cert \"#{cert_path}\" --key \"#{key_path}\" -k -H '#{headers}'"
on agent, "#{curl_base} '#{url}'", &block
end
master_user = puppet_config(master, 'user', section: 'master')
environments_dir = create_tmpdir_for_user master, "environments"
apply_manifest_on(master, <<-MANIFEST)
File {
ensure => directory,
owner => #{master_user},
group => #{master.puppet['group']},
mode => "0770",
}
file {
"#{environments_dir}":;
"#{environments_dir}/env1":;
"#{environments_dir}/env2":;
}
MANIFEST
master_opts = {
:master => {
:environmentpath => environments_dir
}
}
if master.is_pe?
master_opts[:master][:basemodulepath] = master['sitemoduledir']
end
with_puppet_running_on(master, master_opts) do
step "Ensure that an unauthenticated client cannot access the environments list" do
on(master, "curl --tlsv1 -ksv https://#{master}:#{server_port(master)}/puppet/v3/environments", :acceptable_exit_codes => [0,7]) do |result|
assert_match(/< HTTP\/1\.\d 403/, result.stderr)
end
end
step "Ensure that an authenticated client can retrieve the list of environments" do
curl_master_from(master, '/puppet/v3/environments') do |result|
data = JSON.parse(result.stdout)
assert_equal(["env1", "env2", "production"], data["environments"].keys.sort)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/enc_nonexistent_directory_environment.rb | acceptance/tests/environment/enc_nonexistent_directory_environment.rb | test_name "Master should produce error if enc specifies a nonexistent environment" do
require 'puppet/acceptance/classifier_utils.rb'
extend Puppet::Acceptance::ClassifierUtils
tag 'audit:high',
'audit:unit',
'server'
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
testdir = create_tmpdir_for_user(master, 'nonexistent_env')
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
mode => '0755',
}
file {
"#{testdir}":;
"#{testdir}/environments":;
"#{testdir}/environments/production":;
"#{testdir}/environments/production/manifests":;
"#{testdir}/environments/production/manifests/site.pp":
ensure => file,
mode => '0644',
content => 'notify { "In the production environment": }';
}
MANIFEST
if master.is_pe?
group = {
'name' => 'Environment Does Not Exist',
'description' => 'Classify our test agent nodes in an environment that does not exist.',
'environment' => 'doesnotexist',
'environment_trumps' => true,
}
create_group_for_nodes(agents, group)
else
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
file { "#{testdir}/enc.rb":
ensure => file,
mode => '0775',
content => '#!#{master['privatebindir']}/ruby
puts "environment: doesnotexist"
';
}
MANIFEST
end
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
}
}
master_opts['master'] = {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
} if !master.is_pe?
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
on(agent, puppet("agent -t --verbose"), :acceptable_exit_codes => [1]) do |result|
unless agent['locale'] == 'ja'
assert_match(/Could not find a directory environment named 'doesnotexist'/, result.stderr, "Errors when nonexistent environment is specified")
end
refute_match(/In the production environment/, result.stdout, "Executed manifest from production environment")
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/use_agent_environment_when_enc_doesnt_specify.rb | acceptance/tests/environment/use_agent_environment_when_enc_doesnt_specify.rb | test_name "Agent should use agent environment if there is an enc that does not specify the environment" do
require 'puppet/acceptance/classifier_utils'
extend Puppet::Acceptance::ClassifierUtils
tag 'audit:high',
'audit:integration',
'server'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
classify_nodes_as_agent_specified_if_classifer_present
testdir = create_tmpdir_for_user(master, 'use_agent_env')
create_remote_file(master, "#{testdir}/enc.rb", <<END)
#!#{master['privatebindir']}/ruby
puts <<YAML
parameters:
YAML
END
on(master, "chmod 755 '#{testdir}/enc.rb'")
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/more_different/':;
'#{testdir}/environments/more_different/manifests':;
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
mode => "0640",
content => 'notify { "production environment": }',
}
file { '#{testdir}/environments/more_different/manifests/more_different.pp':
ensure => file,
mode => "0640",
content => 'notify { "more_different_string": }',
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
},
}
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
run_agent_on(agent, "--no-daemonize --onetime --verbose --environment more_different") do |result|
assert_match(/more_different_string/, result.stdout, "Did not find more_different_string from \"more_different\" environment")
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/use_enc_environment.rb | acceptance/tests/environment/use_enc_environment.rb | test_name 'Agent should use environment given by ENC and only compile a catalog once' do
require 'puppet/acceptance/classifier_utils.rb'
extend Puppet::Acceptance::ClassifierUtils
tag 'audit:high',
'audit:integration',
'server'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
testdir = create_tmpdir_for_user(master, 'use_enc_env')
if master.is_pe?
group = {
'name' => 'Special Environment',
'description' => 'Classify our test agent nodes in the special environment.',
'environment' => 'special',
'environment_trumps' => true,
}
create_group_for_nodes(agents, group)
else
create_remote_file(master, "#{testdir}/enc.rb", <<END)
#!#{master['privatebindir']}/ruby
puts <<YAML
parameters:
environment: special
YAML
END
on(master, "chmod 755 '#{testdir}/enc.rb'")
end
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/special/':;
'#{testdir}/environments/special/manifests':;
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
mode => "0640",
content => 'notify { "production environment": }',
}
file { '#{testdir}/environments/special/manifests/different.pp':
ensure => file,
mode => "0640",
content => 'notify { "expected_string": }',
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
},
}
master_opts['master'] = {
'node_terminus' => 'exec',
'external_nodes' => "#{testdir}/enc.rb",
} if !master.is_pe?
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
run_agent_on(agent, "--no-daemonize --onetime --verbose") do |result|
assert_match(/expected_string/, result.stdout, "Did not find expected_string from \"special\" environment")
caching_catalog_message_count = result.stdout.split(/Info: Caching catalog for/).length - 1
assert_equal(caching_catalog_message_count, 1, 'Should only compile and cache the catalog once during the run')
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/variables_refreshed_each_compilation.rb | acceptance/tests/environment/variables_refreshed_each_compilation.rb | test_name 'C98115 compilation should get new values in variables on each compilation' do
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
confine :except, :platform => /^(aix|osx|solaris)/
tag 'audit:high',
'audit:integration',
'server'
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
app_type = File.basename(__FILE__, '.*')
tmp_environment = mk_tmp_environment_with_teardown(master, app_type)
fq_tmp_environmentpath = "#{environmentpath}/#{tmp_environment}"
create_remote_file(master, "#{fq_tmp_environmentpath}/environment.conf", <<-CONF)
environment_timeout = unlimited
CONF
# the module function loading logic is different from inside a single manifest
# we exercise both here
on(master, "mkdir -p '#{fq_tmp_environmentpath}'/modules/custom_time/{manifests,functions,facts.d}")
create_remote_file(master, "#{fq_tmp_environmentpath}/modules/custom_time/manifests/init.pp", <<-FILE)
class custom_time {
$t = custom_time::my_system_time()
notify { 'custom time':
message => "module_${t}_module",
}
}
FILE
create_remote_file(master, "#{fq_tmp_environmentpath}/modules/custom_time/functions/my_system_time.pp", <<-FILE)
function custom_time::my_system_time() {
$facts['custom_time']
}
FILE
create_sitepp(master, tmp_environment, <<-SITE)
function bar() {
$facts['custom_time']
}
class foo::bar {
notify { "local_${bar()}_local": }
}
include foo::bar
include custom_time
SITE
create_remote_file(master, "#{fq_tmp_environmentpath}/modules/custom_time/facts.d/custom_time.sh", <<-FILE)
#!/bin/bash
if [[ `uname` == 'Darwin' ]]; then
echo -n "custom_time=$(date +%s)"
else
echo -n "custom_time=$(date +%s%N)"
fi
FILE
on(master, "chmod -R 0777 '#{fq_tmp_environmentpath}/'")
windows_fact_location = "#{fq_tmp_environmentpath}/modules/custom_time/facts.d/custom_time.ps1"
create_remote_file(master, windows_fact_location, <<-FILE)
echo "custom_time=$(get-date -format HHmmssffffff)"
FILE
on(master, "chmod -R 0666 '#{windows_fact_location}'")
step "run agent in #{tmp_environment}, ensure it increments the customtime with each run" do
with_puppet_running_on(master, {}) do
local_custom_time_pattern = 'local_(\d+)_local'
module_custom_time_pattern = 'module_(\d+)_module'
agents.each do |agent|
# ensure our custom facts have been synced
on(agent,
puppet("agent -t --environment '#{tmp_environment}'"),
:accept_all_exit_codes => true)
local_custom_time1 = module_custom_time1 = nil
local_custom_time2 = module_custom_time2 = nil
on(agent, puppet("agent -t --environment '#{tmp_environment}'"),
:accept_all_exit_codes => [2]) do |result|
assert_match(/Notice: #{local_custom_time_pattern}/, result.stdout, 'first custom time was not as expected')
assert_match(/Notice: #{module_custom_time_pattern}/, result.stdout, 'first module uptime was not as expected')
local_custom_time1 = result.stdout.match(/Notice: #{local_custom_time_pattern}/)[1].to_i
module_custom_time1 = result.stdout.match(/Notice: #{module_custom_time_pattern}/)[1].to_i
end
sleep 1
on(agent, puppet("agent -t --environment '#{tmp_environment}'"),
:accept_all_exit_codes => [2]) do |result|
assert_match(/Notice: #{local_custom_time_pattern}/, result.stdout, 'second custom time was not as expected')
assert_match(/Notice: #{module_custom_time_pattern}/, result.stdout, 'second module uptime was not as expected')
local_custom_time2 = result.stdout.match(/Notice: #{local_custom_time_pattern}/)[1].to_i
module_custom_time2 = result.stdout.match(/Notice: #{module_custom_time_pattern}/)[1].to_i
end
assert(local_custom_time2 > local_custom_time1, 'local custom time did not change as expected if at all')
assert(module_custom_time2 > module_custom_time1, 'module custom time did not change as expected if at all')
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/use_agent_environment_when_no_enc.rb | acceptance/tests/environment/use_agent_environment_when_no_enc.rb | test_name "Agent should use agent environment if there is no enc-specified environment" do
tag 'audit:high',
'audit:integration',
'audit:refactor', # This can be combined with use_agent_environment_when_enc_doesnt_specify test
'server'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
testdir = create_tmpdir_for_user(master, 'use_agent_env')
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{testdir}/environments':;
'#{testdir}/environments/production':;
'#{testdir}/environments/production/manifests':;
'#{testdir}/environments/more_different/':;
'#{testdir}/environments/more_different/manifests':;
}
file { '#{testdir}/environments/production/manifests/site.pp':
ensure => file,
mode => "0640",
content => 'notify { "production environment": }',
}
file { '#{testdir}/environments/more_different/manifests/more_different.pp':
ensure => file,
mode => "0640",
content => 'notify { "more_different_string": }',
}
MANIFEST
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
},
'master' => {
'node_terminus' => 'plain'
},
}
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
run_agent_on(agent, "--no-daemonize --onetime --verbose --environment more_different") do |result|
assert_match(/more_different_string/, result.stdout, "Did not find more_different_string from \"more_different\" environment")
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/use_environment_from_environmentpath.rb | acceptance/tests/environment/use_environment_from_environmentpath.rb | test_name "Use environments from the environmentpath" do
require 'puppet/acceptance/classifier_utils'
extend Puppet::Acceptance::ClassifierUtils
tag 'audit:high',
'audit:integration',
'server'
classify_nodes_as_agent_specified_if_classifer_present
testdir = create_tmpdir_for_user(master, 'use_environmentpath')
def generate_environment(path_to_env, environment)
<<-EOS
"#{path_to_env}/#{environment}":;
"#{path_to_env}/#{environment}/manifests":;
"#{path_to_env}/#{environment}/modules":;
EOS
end
def generate_module_content(module_name, options = {})
base_path = options[:base_path]
environment = options[:environment]
env_path = options[:env_path]
path_to_module = [base_path, env_path, environment, "modules"].compact.join("/")
module_info = "module-#{module_name}"
module_info << "-from-#{environment}" if environment
<<-EOS
"#{path_to_module}/#{module_name}":;
"#{path_to_module}/#{module_name}/manifests":;
"#{path_to_module}/#{module_name}/files":;
"#{path_to_module}/#{module_name}/templates":;
"#{path_to_module}/#{module_name}/lib":;
"#{path_to_module}/#{module_name}/lib/facter":;
"#{path_to_module}/#{module_name}/manifests/init.pp":
ensure => file,
mode => "0640",
content => 'class #{module_name} {
notify { "template-#{module_name}": message => template("#{module_name}/our_template.erb") }
file { "$agent_file_location/file-#{module_info}": source => "puppet:///modules/#{module_name}/data" }
}'
;
"#{path_to_module}/#{module_name}/lib/facter/environment_fact_#{module_name}.rb":
ensure => file,
mode => "0640",
content => "Facter.add(:environment_fact_#{module_name}) { setcode { 'environment fact from #{module_info}' } }"
;
"#{path_to_module}/#{module_name}/files/data":
ensure => file,
mode => "0640",
content => "data file from #{module_info}"
;
"#{path_to_module}/#{module_name}/templates/our_template.erb":
ensure => file,
mode => "0640",
content => "<%= @environment_fact_#{module_name} %>"
;
EOS
end
def generate_site_manifest(path_to_manifest, *modules_to_include)
<<-EOS
"#{path_to_manifest}/site.pp":
ensure => file,
mode => "0640",
content => "#{modules_to_include.map {|m| "include #{m}"}.join("\n")}"
;
EOS
end
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
mode => "0770",
}
file {
"#{testdir}":;
"#{testdir}/base":;
"#{testdir}/additional":;
"#{testdir}/modules":;
#{generate_environment("#{testdir}/base", "shadowed")}
#{generate_environment("#{testdir}/base", "onlybase")}
#{generate_environment("#{testdir}/additional", "shadowed")}
#{generate_module_content("atmp",
:base_path => testdir,
:env_path => 'base',
:environment => 'shadowed')}
#{generate_site_manifest("#{testdir}/base/shadowed/manifests", "atmp", "globalmod")}
#{generate_module_content("atmp",
:base_path => testdir,
:env_path => 'base',
:environment => 'onlybase')}
#{generate_site_manifest("#{testdir}/base/onlybase/manifests", "atmp", "globalmod")}
#{generate_module_content("atmp",
:base_path => testdir,
:env_path => 'additional',
:environment => 'shadowed')}
#{generate_site_manifest("#{testdir}/additional/shadowed/manifests", "atmp", "globalmod")}
# And one global module (--modulepath setting)
#{generate_module_content("globalmod", :base_path => testdir)}
"#{testdir}/additional/production":;
"#{testdir}/additional/production/manifests":;
#{generate_site_manifest("#{testdir}/additional/production/manifests", "globalmod")}
}
MANIFEST
def run_with_environment(agent, environment, options = {})
expected_exit_code = options[:expected_exit_code] || 2
step "running an agent in environment '#{environment}'"
atmp = agent.tmpdir("use_environmentpath_#{environment}")
teardown do
on(agent, "rm -rf '#{atmp}'")
end
agent_config = [
"-t"
]
agent_config << '--environment' << environment if environment
# This to test how the agent behaves when using the directory environment
# loaders (which will not load an environment if it does not exist)
agent_config << "--environmentpath='$confdir/environments'" if agent != master
agent_config << {
'ENV' => { "FACTER_agent_file_location" => atmp },
}
on(agent,
puppet("agent", *agent_config),
:acceptable_exit_codes => [expected_exit_code]) do |result|
yield atmp, result
end
end
master_opts = {
'master' => {
'environmentpath' => "#{testdir}/additional:#{testdir}/base",
'basemodulepath' => "#{testdir}/modules",
}
}
if master.is_pe?
master_opts['master']['basemodulepath'] << ":#{master['sitemoduledir']}"
end
with_puppet_running_on(master, master_opts, testdir) do
agents.each do |agent|
run_with_environment(agent, "shadowed") do |tmpdir, catalog_result|
["module-atmp-from-shadowed", "module-globalmod"].each do |expected|
assert_match(/environment fact from #{expected}/, catalog_result.stdout)
end
["module-atmp-from-shadowed", "module-globalmod"].each do |expected|
on(agent, "cat '#{tmpdir}/file-#{expected}'") do |file_result|
assert_match(/data file from #{expected}/, file_result.stdout)
end
end
end
run_with_environment(agent, "onlybase") do |tmpdir, catalog_result|
["module-atmp-from-onlybase", "module-globalmod"].each do |expected|
assert_match(/environment fact from #{expected}/, catalog_result.stdout)
end
["module-atmp-from-onlybase", "module-globalmod"].each do |expected|
on(agent, "cat '#{tmpdir}/file-#{expected}'") do |file_result|
assert_match(/data file from #{expected}/, file_result.stdout)
end
end
end
run_with_environment(agent, "production", :expected_exit_code => 2) do |tmpdir, catalog_result|
refute_match(/module-atmp/, catalog_result.stdout, "module-atmp was included despite the default environment being loaded")
assert_match(/environment fact from module-globalmod/, catalog_result.stdout)
on(agent, "cat '#{tmpdir}/file-module-globalmod'") do |file_result|
assert_match(/data file from module-globalmod/, file_result.stdout)
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/feature_branch_configured_environment.rb | acceptance/tests/environment/feature_branch_configured_environment.rb | test_name "Agent should use set environment after running with specified environment" do
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
tag 'audit:high',
'server'
# Remove all traces of the last used environment
teardown do
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
tmp_environment = mk_tmp_environment_with_teardown(master, 'special')
agents.each do |agent|
on(agent, puppet("agent -t --environment #{tmp_environment}")) do |result|
assert_match(/Info: Using environment 'special_\w+'/, result.stdout)
end
on(agent, puppet('agent -t')) do |result|
assert_match(/Info: Using environment 'production'/, result.stdout)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/environment/should_find_existing_production_environment.rb | acceptance/tests/environment/should_find_existing_production_environment.rb | test_name "should find existing production environment"
tag 'audit:medium'
require 'puppet/acceptance/i18ndemo_utils'
extend Puppet::Acceptance::I18nDemoUtils
agents.each do |agent|
path_separator = agent.platform_defaults[:pathseparator]
initial_environment = on(agent, puppet("config print environment")).stdout.chomp
initial_environment_paths = on(agent, puppet("config print environmentpath")).stdout.chomp.split(path_separator)
default_environment_path = ''
custom_environment_path = agent.tmpdir('custom_environment')
teardown do
step 'uninstall the module' do
uninstall_i18n_demo_module(master)
uninstall_i18n_demo_module(agent)
end
step 'Remove custom environment paths' do
environment_paths = on(agent, puppet("config print environmentpath")).stdout.chomp
environment_paths.split(path_separator).each do |path|
agent.rm_rf(path) unless initial_environment_paths.include?(path)
end
agent.rm_rf(custom_environment_path)
end
step 'Reset environment settings' do
on(agent, puppet("config set environmentpath #{initial_environment_paths.join(path_separator)}"))
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
if initial_environment == 'production'
on(agent, puppet("config delete environment"))
else
on(agent, puppet("config set environment #{initial_environment}"))
end
on(agent, puppet("agent -t"))
end
end
step 'Ensure a clean environment with default settings' do
step 'Remove the lastrunfile which contains the last used agent environment' do
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
step 'Change to the default environment setting' do
on(agent, puppet("config delete environment"))
on(agent, puppet("config print environment")) do |result|
assert_match('production', result.stdout, "Default environment is not 'production' as expected")
end
end
step 'Change to the default environmentpath setting and remove production folder' do
on(agent, puppet("config delete environmentpath"))
default_environment_path = on(agent, puppet("config print environmentpath")).stdout.chomp
agent.rm_rf("#{default_environment_path}/production")
end
step 'Apply changes and expect puppet to create the production folder back' do
on(agent, puppet("agent -t"))
on(agent, "ls #{default_environment_path}") do |result|
assert_match('production', result.stdout, "Default environment folder was not generated in last puppet run")
end
end
end
step 'Install a module' do
install_i18n_demo_module(master)
end
step 'Expect output from the custom fact of the module' do
on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Error:.*i18ndemo/, result.stderr)
end
end
step 'Add a custom environment path before the current one' do
current_environment_path = on(agent, puppet("config print environmentpath")).stdout.chomp
on(agent, puppet("config set environmentpath '#{custom_environment_path}#{path_separator}#{current_environment_path}'"))
end
step 'Expect the module to still be found' do
on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Error:.*i18ndemo/, result.stderr)
end
end
step 'Expect no production environment folder changes' do
on(agent, "ls #{custom_environment_path}") do |result|
refute_match(/production/, result.stdout)
end
on(agent, "ls #{default_environment_path}") do |result|
assert_match('production', result.stdout)
end
end
step 'Remove production folder' do
agent.rm_rf("#{default_environment_path}/production")
end
step 'Expect production environment folder to be recreated in the custom path' do
on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result|
step 'Expect the module to be gone on the server node' do
refute_match(/Error:.*i18ndemo/, result.stderr)
end if agent == master
step 'Expect the production environment, along with the module, to be synced back on the agent node' do
assert_match(/Error:.*i18ndemo/, result.stderr)
end if agent != master
end
on(agent, "ls #{custom_environment_path}") do |result|
assert_match('production', result.stdout, "Default environment folder was not generated in last puppet run")
end
on(agent, "ls #{default_environment_path}") do |result|
refute_match(/production/, result.stdout)
end
end
step 'Set back to just default environmentpath setting' do
on(agent, puppet("config delete environmentpath"))
end
step 'Expect production environment folder to be found in both paths but use the default one' do
on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result|
step 'Expect the module to be gone' do
refute_match(/Error:.*i18ndemo/, result.stderr)
end if agent == master
end
on(agent, "ls #{default_environment_path}") do |result|
assert_match('production', result.stdout, "Default environment folder was not generated in last puppet run")
end
on(agent, "ls #{custom_environment_path}") do |result|
assert_match('production', result.stdout)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/security/cve-2013-1640_facter_string.rb | acceptance/tests/security/cve-2013-1640_facter_string.rb | # Setting a custom fact to "string" will overwrite a local variable during
# template compilation on the master allowing remote code execution by
# any authenticated client.
test_name "CVE 2013-1640 Remote Code Execution" do
tag 'audit:high', # low risk, high (security) impact
'audit:integration'
confine :except, :platform => 'windows'
on agents, %q[ FACTER_string="<%= %x{ /bin/echo hax0rd } %>" ] +
%q[ puppet apply -e ] +
%q[ 'notice(inline_template("<%= \"I am Safe\" %>"))' ] do |test|
assert_match(/I am Safe/, test.stdout)
refute_match(/hax0rd/, test.stdout)
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/security/cve-2013-4761_injection_of_class_names_loading_code.rb | acceptance/tests/security/cve-2013-4761_injection_of_class_names_loading_code.rb | test_name "CVE 2013-4761 Injection of bad class names causing code loading" do
confine :except, :platform => 'windows'
tag 'audit:high', # low risk, high (security) impact
'audit:integration', # issue is completely on the master side
'server'
testdir = create_tmpdir_for_user master, 'class-names-injection'
exploit_path = "#{testdir}/exploit.rb"
exploited_path = "#{testdir}/exploited"
# @return [String] path to the manifest file
def create_exploit_manifest(path, exploit_path_expression)
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{path}/environments':;
'#{path}/environments/production':;
'#{path}/environments/production/manifests':;
'#{path}/environments/production/manifests/site.pp':
ensure => file,
content => '
$enc_data = "#{exploit_path_expression}"
include $enc_data
',
mode => "0640",
}
MANIFEST
end
def should_not_be_able_to_exploit(exploited_path)
agents.each do |agent|
next if agent['roles'].include?('master')
step "Request a catalog to trigger the exploit" do
on agent, puppet('agent', '-t'), :acceptable_exit_codes => [1]
end
step "Check that the exploit marker was not created" do
on master, "test ! -e #{exploited_path}"
end
end
end
step "Create exploit file" do
create_remote_file(master, exploit_path, <<-EXPLOIT)
::File.open('#{exploited_path}', 'w') { |f| f.puts("exploited") }
EXPLOIT
on(master, "chmod 777 #{exploit_path}")
end
master_opts = {
'main' => {
'environmentpath' => "#{testdir}/environments",
},
}
with_puppet_running_on(master, master_opts) do
step "Class name is not interpreted as an absolute path" do
create_exploit_manifest(testdir, 'tmp::exploit')
should_not_be_able_to_exploit(exploited_path)
end
step "Class name cannot be used for a directory traversal out of the module path" do
# This is just a guess about how far back we need to go...
traversal_exploit_expression = "#{'::..' * 20}#{exploit_path.gsub(File::SEPARATOR,'::')}"
create_exploit_manifest(testdir, traversal_exploit_expression)
should_not_be_able_to_exploit(exploited_path)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/security/cve-2013-1652_poison_other_node_cache.rb | acceptance/tests/security/cve-2013-1652_poison_other_node_cache.rb | test_name "CVE 2013-1652 Poison node cache" do
tag 'audit:high', # low risk, high (security) impact
'audit:integration', # master side only
'server'
step "Determine suitability of the test" do
skip_test( "This test will only run on Puppet 3.x" ) if
on(master, puppet('--version')).stdout =~ /\A2\./
end
with_puppet_running_on( master, {} ) do
# Ensure agent has a signed cert
on master, puppet('agent', '-t' )
certname = on(
master, puppet('agent', "--configprint certname")).stdout.chomp
cert_path = on(
master, puppet('agent', "--configprint hostcert")).stdout.chomp
key_path = on(
master, puppet('agent', "--configprint hostprivkey")).stdout.chomp
curl_base = "curl --tlsv1 -g --cert \"#{cert_path}\" " +
"--key \"#{key_path}\" -k -H 'Accept: application/json'"
step "Attempt to poison the master's node cache" do
yamldir = puppet_config(master, 'yamldir', section: 'master')
exploited = "#{yamldir}/node/you.lose.yaml"
on master, "rm -rf #{exploited}"
on master, "rm -rf #{yamldir}/node/*"
payload2 = "https://#{master}:8140/puppet/v3/node/#{certname}?environment=production" +
"&instance=---+%21ruby%2Fobject%3APuppet%3A%3ANode%0A+classes" +
"%3A%0A+-+foo%0A+name%3A+you.lose%0A+parameters" +
"%3A+%7B%7D%0A+time%3A+2013-02-28+15%3A12%3A30.367008+-08%3A00"
on master, "#{curl_base} '#{payload2}'"
fail_test( "Found exploit file #{exploited}" ) if
on( master, "[ ! -f #{exploited} ]",
:acceptable_exit_codes => [0,1] ).exit_code == 1
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/security/cve-2013-2275_report_acl.rb | acceptance/tests/security/cve-2013-2275_report_acl.rb | test_name "(#19531) report save access control"
tag 'audit:high', # low risk, high (security) impact
'audit:refactor', # Use block style `test_name`
'audit:integration', # issue completely on the server side
'server'
step "Verify puppet only allows saving reports from the node matching the certificate"
fake_report = <<-EOYAML
--- !ruby/object:Puppet::Transaction::Report
host: mccune
metrics: {}
logs: []
puppet_version: "2.7.20"
status: failed
report_format: 3
EOYAML
with_puppet_running_on(master, {}) do
submit_fake_report_cmd = [
"curl --tlsv1 -k -X PUT",
"--cacert \"$(puppet config print --section server cacert)\"",
"--cert \"$(puppet config print --section server hostcert)\"",
"--key \"$(puppet config print --section server hostprivkey)\"",
"-H 'Content-Type: text/yaml'",
"-d '#{fake_report}'",
"\"https://#{master}:8140/puppet/v3/report/mccune?environment=production\"",
].join(" ")
on(master, submit_fake_report_cmd, :acceptable_exit_codes => [0]) do |result|
msg = "(#19531) (CVE-2013-2275) Puppet Server accepted a report for a node that does not match the certname"
assert_match(/Forbidden request/, result.stdout, msg)
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/security/cve-2013-1652_improper_query_params.rb | acceptance/tests/security/cve-2013-1652_improper_query_params.rb | require 'json'
test_name "CVE 2013-1652 Improper query parameter validation" do
confine :except, :platform => 'windows'
confine :except, :platform => /osx/ # see PUP-4820
confine :except, :platform => /aix/
tag 'audit:high', # risk low, high (security) impact
'audit:integration',
'server'
with_puppet_running_on master, {} do
# Ensure each agent has a signed cert
on agents, puppet('agent', "-t")
agents.each do |agent|
next if agent['roles'].include?( 'master' )
certname = on(agent, puppet('agent', "--configprint certname")).stdout.chomp
payload = "https://#{master}:8140/puppet/v3/catalog/#{certname}" +
"?environment=production&use_node=" +
"---%20!ruby/object:Puppet::Node%0A%20%20" +
"name:%20#{master}%0A%20%20classes:%20\[\]%0A%20%20" +
"parameters:%20%7B%7D%0A%20%20facts:%20%7B%7D"
cert_path = on(agent, puppet('agent', "--configprint hostcert")).stdout.chomp
key_path = on(agent, puppet('agent', "--configprint hostprivkey")).stdout.chomp
curl_base = "curl --tlsv1 -g --cert \"#{cert_path}\" --key \"#{key_path}\" -k -H 'Accept: application/json'"
curl_call = "#{curl_base} '#{payload}'"
step "Attempt to retrieve another nodes catalog" do
on agent, curl_call do |test|
begin
res = JSON.parse( test.stdout )
fail_test( "Retrieved catalog for #{master} from #{agent}" ) if
res['data'] && res['data']['name'] == master.name
rescue JSON::ParserError
# good, continue
end
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/ssl/autosign_command.rb | acceptance/tests/ssl/autosign_command.rb | test_name "autosign command and csr attributes behavior (#7243,#7244)" do
skip_test "Test requires at least one non-master agent" if hosts.length == 1
tag 'audit:high', # cert/ca core behavior
'audit:integration',
'server' # Ruby implementation is deprecated
def assert_key_generated(name, stdout)
assert_match(/Creating a new RSA SSL key for #{name}/, stdout, "Expected agent to create a new SSL key for autosigning")
end
testdirs = {}
test_certnames = []
step "Generate tmp dirs on all hosts" do
hosts.each do |host|
testdirs[host] = host.tmpdir('autosign_command')
on(host, "chmod 755 #{testdirs[host]}")
end
end
hostname = master.execute('facter hostname')
fqdn = master.execute('facter fqdn')
teardown do
step "clear test certs"
master_opts = {
'main' => { 'server' => fqdn },
'master' => { 'dns_alt_names' => "puppet,#{hostname},#{fqdn}" }
}
with_puppet_running_on(master, master_opts) do
on(master,
"puppetserver ca clean --certname #{test_certnames.join(',')}",
:acceptable_exit_codes => [0,24])
end
end
step "Step 1: ensure autosign command can approve CSRs" do
# Our script needs to consume stdin (SERVER-1116)
# We should revert back to /bin/true once resolved
autosign_true_script = <<-EOF
!#/bin/bash
while read line
do
: # noop command
done
exit 0
EOF
autosign_true_script_path = "#{testdirs[master]}/mytrue"
create_remote_file(master, autosign_true_script_path, autosign_true_script)
on(master, "chmod 777 #{autosign_true_script_path}")
master_opts = {
'master' => {
'autosign' => autosign_true_script_path,
'dns_alt_names' => "puppet,#{hostname},#{fqdn}"
}
}
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
next if agent == master
test_certnames << (certname = "#{agent}-autosign")
on(agent, puppet("agent --test",
"--waitforcert 0",
"--ssldir", "'#{testdirs[agent]}/ssldir-autosign'",
"--certname #{certname}"), :acceptable_exit_codes => [0,2]) do |result|
unless agent['locale'] == 'ja'
assert_key_generated(agent, result.stdout)
assert_match(/Downloaded certificate for #{agent}/, result.stdout, "Expected certificate to be autosigned")
end
end
end
end
end
step "Step 2: ensure autosign command can reject CSRs" do
# Our script needs to consume stdin (SERVER-1116)
# We should revert back to /bin/false once resolved
autosign_false_script = <<-EOF
!#/bin/bash
while read line
do
: # noop command
done
exit 1
EOF
autosign_false_script_path = "#{testdirs[master]}/myfalse"
create_remote_file(master, autosign_false_script_path, autosign_false_script)
on(master, "chmod 777 #{autosign_false_script_path}")
master_opts = {
'master' => {
'autosign' => autosign_false_script_path,
'dns_alt_names' => "puppet,#{hostname},#{fqdn}"
}
}
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
next if agent == master
test_certnames << (certname = "#{agent}-reject")
on(agent, puppet("agent --test",
"--waitforcert 0",
"--ssldir", "'#{testdirs[agent]}/ssldir-reject'",
"--certname #{certname}"), :acceptable_exit_codes => [1]) do |result|
unless agent['locale'] == 'ja'
assert_key_generated(agent, result.stdout)
assert_match(/Certificate for #{agent}-reject has not been signed yet/, result.stdout, "Expected certificate to not be autosigned")
end
end
end
end
end
autosign_inspect_csr_path = "#{testdirs[master]}/autosign_inspect_csr.rb"
step "Step 3: setup an autosign command that inspects CSR attributes" do
autosign_inspect_csr = <<-END
#!/usr/bin/env ruby
require 'openssl'
def unwrap_attr(attr)
set = attr.value
str = set.value.first
str.value
end
csr_text = STDIN.read
csr = OpenSSL::X509::Request.new(csr_text)
passphrase = csr.attributes.find { |a| a.oid == '1.3.6.1.4.1.34380.2.1' }
# And here we jump hoops to unwrap ASN1's Attr Set Str
if unwrap_attr(passphrase) == 'my passphrase'
exit 0
end
exit 1
END
create_remote_file(master, autosign_inspect_csr_path, autosign_inspect_csr)
on master, "chmod 777 #{testdirs[master]}"
on master, "chmod 777 #{autosign_inspect_csr_path}"
end
agent_csr_attributes = {}
step "Step 4: create attributes for inclusion on csr on agents" do
csr_attributes = <<-END
custom_attributes:
1.3.6.1.4.1.34380.2.0: hostname.domain.com
1.3.6.1.4.1.34380.2.1: my passphrase
1.3.6.1.4.1.34380.2.2: # system IPs in hex
- 0xC0A80001 # 192.168.0.1
- 0xC0A80101 # 192.168.1.1
END
agents.each do |agent|
agent_csr_attributes[agent] = "#{testdirs[agent]}/csr_attributes.yaml"
create_remote_file(agent, agent_csr_attributes[agent], csr_attributes)
end
end
step "Step 5: successfully obtain a cert" do
master_opts = {
'master' => {
'autosign' => autosign_inspect_csr_path,
'dns_alt_names' => "puppet,#{hostname},#{fqdn}"
},
}
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
next if agent == master
step "attempting to obtain cert for #{agent}"
test_certnames << (certname = "#{agent}-attrs")
on(agent, puppet("agent --test",
"--waitforcert 0",
"--ssldir", "'#{testdirs[agent]}/ssldir-attrs'",
"--csr_attributes '#{agent_csr_attributes[agent]}'",
"--certname #{certname}"), :acceptable_exit_codes => [0,2]) do |result|
assert_key_generated(agent, result.stdout) unless agent['locale'] == 'ja'
assert_match(/Downloaded certificate for #{agent}/, result.stdout, "Expected certificate to be autosigned")
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/ssl/certificate_extensions.rb | acceptance/tests/ssl/certificate_extensions.rb | require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
test_name "certificate extensions available as trusted data" do
skip_test "Test requires at least one non-master agent" if hosts.length == 1
tag 'audit:high', # ca/cert core functionality
'audit:integration',
'server' # Ruby implementation is deprecated
initialize_temp_dirs
agent_certnames = []
hostname = master.execute('facter networking.hostname')
fqdn = master.execute('facter networking.fqdn')
teardown do
step "Cleanup the test agent certs"
master_config = {
'main' => { 'server' => fqdn },
'master' => { 'dns_alt_names' => "puppet,#{hostname},#{fqdn}" }
}
with_puppet_running_on(master, master_config) do
on(master,
"puppetserver ca clean --certname #{agent_certnames.join(',')}",
:acceptable_exit_codes => [0,24])
end
end
environments_dir = get_test_file_path(master, "environments")
master_config = {
'main' => {
'environmentpath' => environments_dir,
},
'master' => {
'autosign' => true,
'dns_alt_names' => "puppet,#{hostname},#{fqdn}",
}
}
csr_attributes = YAML.dump({
'extension_requests' => {
# registered puppet extensions
'pp_uuid' => 'b5e63090-5167-11e3-8f96-0800200c9a66',
'pp_instance_id' => 'i-3fkva',
# private (arbitrary) extensions
'1.3.6.1.4.1.34380.1.2.1' => 'db-server', # node role
'1.3.6.1.4.1.34380.1.2.2' => 'webops' # node group
}
})
step "Generate a production environment manifest to dump trusted data"
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
mode => "0770",
owner => #{master.puppet['user']},
group => #{master.puppet['group']},
}
file {
'#{environments_dir}':;
'#{environments_dir}/production':;
'#{environments_dir}/production/manifests':;
'#{environments_dir}/production/manifests/site.pp':
ensure => file,
content => '
file { "$test_dir/trusted.yaml":
ensure => file,
content => inline_template("<%= YAML.dump(@trusted) %>")
}
',
mode => "0640",
}
MANIFEST
with_puppet_running_on(master, master_config) do
agents.each do |agent|
next if agent == master
step "Create agent csr_attributes.yaml on #{agent}"
agent_csr_attributes = get_test_file_path(agent, "csr_attributes.yaml")
agent_ssldir = get_test_file_path(agent, "ssldir")
create_remote_file(agent, agent_csr_attributes, csr_attributes)
agent_certname = "#{agent}-extensions"
agent_certnames << agent_certname
step "Check in as #{agent_certname}"
on(agent, puppet("agent", "--test",
"--waitforcert", 0,
"--csr_attributes", agent_csr_attributes,
"--certname", agent_certname,
"--ssldir", agent_ssldir,
'ENV' => { "FACTER_test_dir" => get_test_file_path(agent, "") }),
:acceptable_exit_codes => [0, 2])
trusted_data = YAML.load(on(agent, "cat #{get_test_file_path(agent, 'trusted.yaml')}").stdout)
agent_hostname, agent_domain = agent_certname.split('.', 2)
step "Verify trusted data"
assert_equal({
'authenticated' => 'remote',
'certname' => agent_certname,
'extensions' => {
'pp_uuid' => 'b5e63090-5167-11e3-8f96-0800200c9a66',
'pp_instance_id' => 'i-3fkva',
'1.3.6.1.4.1.34380.1.2.1' => 'db-server',
'1.3.6.1.4.1.34380.1.2.2' => 'webops'
},
'hostname' => agent_hostname,
'domain' => agent_domain,
'external' => {}
},
trusted_data)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/ssl/trusted_external_facts.rb | acceptance/tests/ssl/trusted_external_facts.rb | test_name "trusted external fact test" do
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
### HELPERS ###
SEPARATOR="<TRUSTED_JSON>"
def parse_trusted_json(puppet_output)
trusted_json = puppet_output.split(SEPARATOR)[1]
if trusted_json.nil?
raise "Puppet output does not contain the expected '#{SEPARATOR}<trusted_json>#{SEPARATOR}' output"
end
JSON.parse(trusted_json)
rescue => e
raise "Failed to parse the trusted JSON: #{e}"
end
### END HELPERS ###
tag 'audit:high', # external facts
'server'
skip_test 'requires a master for serving module content' if master.nil?
testdir = master.tmpdir('trusted_external_facts')
on(master, "chmod 755 #{testdir}")
tmp_environment = mk_tmp_environment_with_teardown(master, File.basename(__FILE__, '.*'))
teardown do
on(master, "rm -r '#{testdir}'", :accept_all_exit_codes => true)
# Remove all traces of the last used environment
agents.each do |agent|
on(agent, puppet('config print lastrunfile')) do |command_result|
agent.rm_rf(command_result.stdout)
end
end
end
step "create 'external' module referencing trusted hash" do
on(master, "mkdir -p #{environmentpath}/#{tmp_environment}/modules/external/manifests")
master_module_manifest = "#{environmentpath}/#{tmp_environment}/modules/external/manifests/init.pp"
manifest = <<MANIFEST
class external {
$trusted_json = inline_template('<%= @trusted.to_json %>')
notify { 'trusted facts':
message => "#{SEPARATOR}${trusted_json}#{SEPARATOR}"
}
}
MANIFEST
create_remote_file(master, master_module_manifest, manifest)
on(master, "chmod 644 '#{master_module_manifest}'")
end
step "create site.pp to classify nodes to include module" do
site_pp_file = "#{environmentpath}/#{tmp_environment}/manifests/site.pp"
site_pp = <<-SITE_PP
node default {
include external
}
SITE_PP
create_remote_file(master, site_pp_file, site_pp)
on(master, "chmod 644 '#{site_pp_file}'")
end
step "when trusted_external_command is a file" do
external_trusted_fact_script_path = "#{testdir}/external_facts.sh"
step "create the file" do
external_trusted_fact_script = <<EOF
#!/bin/bash
CERTNAME=$1
printf '{"doot":"%s"}\n' "$CERTNAME"
EOF
create_remote_file(master, external_trusted_fact_script_path, external_trusted_fact_script)
on(master, "chmod 777 #{external_trusted_fact_script_path}")
end
step "start the master and perform the test" do
master_opts = {
'main' => {
'trusted_external_command' => external_trusted_fact_script_path
}
}
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
on(agent, puppet("agent", "-t", "--environment", tmp_environment), :acceptable_exit_codes => [0,2]) do |res|
trusted_hash = parse_trusted_json(res.stdout)
assert_includes(trusted_hash, 'external', "Trusted fact hash contains external key")
assert_equal(agent.to_s, trusted_hash['external']['doot'], "trusted facts contains certname")
end
end
end
end
end
step "when trusted_external_command is a directory" do
dir_path = "#{testdir}/commands"
executable_files = {
'no_extension' => <<EOF,
#!/bin/bash
CERTNAME=$1
printf '{"no_extension_key":"%s"}\n' "$CERTNAME"
EOF
'shell.sh' => <<EOF,
#!/bin/bash
CERTNAME=$1
printf '{"shell_key":"%s"}\n' "$CERTNAME"
EOF
'ruby.rb' => <<EOF,
#!#{master[:privatebindir]}/ruby
require 'json'
CERTNAME=ARGV[0]
data = { "ruby_key" => CERTNAME }
print data.to_json
EOF
}
step "create the directory" do
on(master, "mkdir #{dir_path}")
on(master, "chmod 755 #{dir_path}")
executable_files.each do |filename, content|
filepath = "#{dir_path}/#{filename}"
create_remote_file(master, filepath, content)
on(master, "chmod 777 #{filepath}")
end
# Create a non-executable file and an executable child-directory
# to ensure that these cases are skipped during external data
# retrieval
create_remote_file(master, "#{dir_path}/non_executable_file", "foo")
executable_child_dir = "#{dir_path}/child_dir"
on(master, "mkdir #{executable_child_dir}")
on(master, "chmod 777 #{executable_child_dir}")
end
master_opts = {
'main' => {
'trusted_external_command' => dir_path
}
}
step "start the master and perform the test" do
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
on(agent, puppet("agent", "-t", "--environment", tmp_environment), :acceptable_exit_codes => [0,2]) do |res|
trusted_hash = parse_trusted_json(res.stdout)
assert_includes(trusted_hash, 'external', "Trusted fact hash contains external key")
external_keys = [
'no_extension',
'shell',
'ruby'
]
assert_equal(external_keys.sort, trusted_hash['external'].keys.sort, "trusted['external'] does not contain <basename> keys of all executable files")
external_keys.each do |key|
expected_data = { "#{key}_key" => agent.to_s }
data = trusted_hash['external'][key]
assert_equal(expected_data, data, "trusted['external'][#{key}] does not contain #{key}'s data")
end
end
end
end
end
step "when there's more than executable <basename> script" do
step "create the conflicting file" do
filepath = "#{dir_path}/shell.rb"
create_remote_file(master, filepath, executable_files['shell.sh'])
on(master, "chmod 777 #{filepath}")
end
step "start the master and perform the test" do
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
on(agent, puppet("agent", "-t", "--environment", tmp_environment), :acceptable_exit_codes => [1]) do |res|
assert_match(/.*shell.*#{Regexp.escape(dir_path)}/, res.stderr)
end
end
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/windows/PUP-9719_windows_system_first_pa_run.rb | acceptance/tests/windows/PUP-9719_windows_system_first_pa_run.rb | # frozen_string_literal: true
test_name 'PUP-9719 Windows First Agent run as SYSTEM sets cache file permissions correctly' do
tag 'risk:high',
'audit:high',
'audit:integration'
confine :to, platform: 'windows'
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
agents.each do |agent|
publicdir = on(agent, puppet('config print publicdir')).stdout.chomp
client_datadir = on(agent, puppet('config print client_datadir')).stdout.chomp
teardown do
on agent, 'schtasks /delete /tn PuppetSystemRun /F'
on agent, "rm -rf #{publicdir}/*" unless publicdir.empty?
on agent, "rm -rf #{client_datadir}/catalog/*" unless client_datadir.empty?
end
step 'Clean the public and catalog directories first' do
fail_test("The publicdir config is not set!") if publicdir.empty?
fail_test("The client_datadir config is not set!") if client_datadir.empty?
on agent, "rm -rf #{publicdir}/*"
on agent, "rm -rf #{client_datadir}/catalog/*"
end
step 'Create and run a scheduled task on System Account.' do
date_format = if agent['locale'] == 'ja'
'%Y/%m/%d'
else
'%m/%d/%Y'
end
on agent, %Q(
schtasks /create /tn PuppetSystemRun /RL HIGHEST /RU SYSTEM /F /SC ONCE /SD \
#{(Date.today + 1).strftime(date_format)} /ST 23:59 /TR \
'cmd /c \"%ProgramFiles%\\Puppet Labs\\Puppet\\bin\\puppet.bat\" agent -t'
)
on agent, 'schtasks /run /tn PuppetSystemRun'
end
step 'Wait for Puppet Agent run to complete' do
last_puppet_run = File.join(publicdir, 'last_run_summary.yaml')
trymax = 10
try = 1
last_wait = 2
wait = 3
file_found = false
while try <= trymax
if file_exists?(agent, last_puppet_run)
logger.info('Puppet run has completed')
file_found = true
break
end
@logger.warn "Wait for Puppet (SYSTEM) run to complete, Try #{try}, Trying again in #{wait} seconds"
sleep wait
(last_wait, wait) = wait, last_wait + wait
try += 1
end
fail_test("Puppet Run (SYSTEM) didn't complete") unless file_found
end
step "Test that normal PA run under Administrator doesn't fail." do
on agent, 'cmd /c puppet agent -t --detailed-exitcodes', acceptable_exit_codes: [0]
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/windows/QA-760_win_dash_dot_file_test.rb | acceptance/tests/windows/QA-760_win_dash_dot_file_test.rb | test_name "QA-760 - Windows Files Containing '-' and '.'"
tag 'risk:high',
'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:integration'
confine(:to, :platform => 'windows')
temp_folder = <<-MANIFEST
file { 'c:/temp':
ensure => directory
}
MANIFEST
dash_dot_file = <<-MANIFEST
file { 'c:/temp/dash-dot-%s.file':
ensure => file,
content => "The file has new content: %s!",
}
MANIFEST
step "Generate Manifest"
first_run_manifest = ""
second_run_manifest = ""
for i in 1..100
first_run_manifest += "#{dash_dot_file}\n" % [i,i]
second_run_manifest += "#{dash_dot_file}\n" % [i,-i]
end
step "Create Temp Folder"
agents.each do |agent|
on(agent, puppet('apply', '--debug'), :stdin => temp_folder)
end
step "Create Dash Dot File 100 Times"
agents.each do |agent|
on(agent, puppet('apply', '--debug'), :stdin => first_run_manifest)
end
step "Update Dash Dot File 100 Times"
agents.each do |agent|
on(agent, puppet('apply', '--debug'), :stdin => second_run_manifest)
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/windows/QA-506_windows_exit_codes_test.rb | acceptance/tests/windows/QA-506_windows_exit_codes_test.rb | test_name "Windows Exec `exit_code` Parameter Acceptance Test"
tag 'risk:high',
'audit:high',
'audit:refactor', # Use block style `test_name`
'audit:integration' # exec resource succeeds when the `exit_code` parameter
# is given a windows specific exit code and a exec
# returns that exit code, ie. it either correctly matches
# exit_code parameter to returned exit code, or ignores both (;
confine :to, :platform => 'windows'
pass_exitcode_manifest = <<-MANIFEST
winexitcode::execute { '0':
exit_code => 0
}
MANIFEST
upper_8bit_boundary_manifest = <<-MANIFEST
winexitcode::execute { '255':
exit_code => 255
}
MANIFEST
cross_8bit_boundary_manifest = <<-MANIFEST
winexitcode::execute { '256':
exit_code => 256
}
MANIFEST
upper_32bit_boundary_manifest = <<-MANIFEST
winexitcode::execute { '4294967295':
exit_code => 4294967295
}
MANIFEST
cross_32bit_boundary_manifest = <<-MANIFEST
winexitcode::execute { '4294967296':
exit_code => 0
}
MANIFEST
negative_boundary_manifest = <<-MANIFEST
winexitcode::execute { '-1':
exit_code => 4294967295
}
MANIFEST
step "Install Custom Module for Testing"
agents.each do |agent|
if (on(agent, puppet("--version")).stdout.split('.')[0].to_i < 4)
module_path_config_property = "confdir"
else
module_path_config_property = "codedir"
end
native_modules_path = on(agent, puppet("config print #{module_path_config_property}")).stdout.gsub('C:', '/cygdrive/c').strip
#Check to see if we are running on Windows 2003. Do a crazy hack to get around SCP issues.
if (on(agent, facter("os.release.major")).stdout =~ /2003/)
on(agent, "ln -s #{native_modules_path.gsub(/ /, '\ ')} /tmp/puppet_etc")
modules_path = '/tmp/puppet_etc'
else
modules_path = native_modules_path
end
#Create the modules directory if it doesn't exist
if on(agent, "test ! -d #{modules_path}/modules", :acceptable_exit_codes => [0,1]).exit_code == 0
on(agent, "mkdir -p #{modules_path}/modules")
end
# copy custom module.
scp_to(agent, File.expand_path(File.join(File.dirname(__FILE__), "winexitcode")), "#{modules_path}/modules")
end
agents.each do |agent|
step "Verify '0' is a Valid Exit Code"
#Apply the manifest and verify Puppet returns success.
on(agent, puppet('apply', '--debug'), :stdin => pass_exitcode_manifest)
step "Verify Unsigned 8bit Upper Boundary"
#Apply the manifest and verify Puppet returns success.
on(agent, puppet('apply', '--debug'), :stdin => upper_8bit_boundary_manifest)
step "Verify Unsigned 8bit Cross Boundary"
#Apply the manifest and verify Puppet returns success.
on(agent, puppet('apply', '--debug'), :stdin => cross_8bit_boundary_manifest)
step "Verify Unsigned 32bit Upper Boundary"
#Apply the manifest and verify Puppet returns success.
on(agent, puppet('apply', '--debug'), :stdin => upper_32bit_boundary_manifest)
step "Verify Unsigned 32bit Cross Boundary"
#Apply the manifest and verify Puppet returns success.
on(agent, puppet('apply', '--debug'), :stdin => cross_32bit_boundary_manifest)
step "Verify Negative Exit Code Rollover Boundary"
#Apply the manifest and verify Puppet returns success.
on(agent, puppet('apply', '--debug'), :stdin => negative_boundary_manifest)
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/windows/enable_password_changes_special_users.rb | acceptance/tests/windows/enable_password_changes_special_users.rb | test_name 'Puppet should change passwords for disabled, expired, or locked out Windows user accounts' do
tag 'audit:high',
'audit:acceptance'
require 'date'
require 'puppet/acceptance/windows_utils'
extend Puppet::Acceptance::WindowsUtils
confine :to, platform: 'windows'
def random_username
"pl#{rand(999999).to_i}"
end
def change_password_manifest(username)
return <<-MANIFEST
user { '#{username}':
ensure => 'present',
password => '#{NEW_PASSWORD}'
}
MANIFEST
end
INITIAL_PASSWORD='iP@ssword'
NEW_PASSWORD="Password-#{rand(999999).to_i}"
agents.each do |host|
disabled_username = random_username
step "Create a disabled user account" do
on(host, "cmd.exe /c net user #{disabled_username} #{INITIAL_PASSWORD} /active:no /add")
end
step "Change the disabled user account's password with puppet" do
apply_manifest_on(host, change_password_manifest(disabled_username))
end
step "Enabling the user account as the AccountManagement context can't verify disabled users" do
on(host, "cmd.exe /c net user #{disabled_username} /active:yes")
end
step "Ensure the password was changed" do
assert_password_matches_on(host, disabled_username, NEW_PASSWORD, "Expected the disabled user account's password to be changed")
end
expired_username = random_username
step "Create an expired user account" do
date_format = host["locale"] == "ja" ? "%y/%m/%d" : "%m/%d/%y"
on(host, "cmd.exe /c net user #{expired_username} #{INITIAL_PASSWORD} /expires:#{(Date.today - 1).strftime(date_format)} /add")
end
step "Change the expired user's password with puppet" do
apply_manifest_on(host, change_password_manifest(expired_username))
end
step "Make expired user valid, as AccountManagement context can't verify expired user credentials" do
date_format = host["locale"] == "ja" ? "%y/%m/%d" : "%m/%d/%y"
on(host, "cmd.exe /c net user #{expired_username} /expires:#{(Date.today + 1).strftime(date_format)}")
on(host, "cmd.exe /c net user #{expired_username} /active:yes")
end
step "Ensure the password was changed" do
assert_password_matches_on(host, expired_username, NEW_PASSWORD, "Expected the expired user account's password to be changed")
end
locked_username = random_username
step "Create a user account, lower the account lockout threshold, and lock the new account by using the wrong password" do
on(host, "cmd.exe /c net user #{locked_username} #{INITIAL_PASSWORD} /add")
on(host, "cmd.exe /c net accounts /lockoutthreshold:1")
on(host, "cmd.exe /c runas /user:#{locked_username} hostname.exe", accept_all_exit_codes: true)
end
step "Change the locked account's password with puppet" do
apply_manifest_on(host, change_password_manifest(locked_username))
end
step "Unlock the account(set it as active) as AccountManagement context can't verify credentials of locked out accounts" do
on(host, "cmd.exe /c net user #{locked_username} /active:yes")
end
step "Ensure the password was changed" do
assert_password_matches_on(host, locked_username, NEW_PASSWORD, "Expected the locked out user account's password to be changed")
end
teardown do
on(host, "cmd.exe /c net accounts /lockoutthreshold:0")
host.user_absent(disabled_username)
host.user_absent(expired_username)
host.user_absent(locked_username)
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/windows/service_manager_integration.rb | acceptance/tests/windows/service_manager_integration.rb | test_name 'Test agent state via service control manager' do
tag 'audit:integration'
confine :to, platform: 'windows'
teardown do
agents.each do |agent|
state = query_agent_state(agent)
if state != "STOPPED"
stop_puppet_windows_daemon(agent)
ensure_agent_state(agent, "STOPPED")
end
end
end
def query_agent_state(host)
on(host, 'sc query puppet').stdout.match(/STATE.+\s{1}(\w+)/)[1]
end
def start_puppet_windows_daemon(host)
on(host, 'sc start puppet')
end
def stop_puppet_windows_daemon(host)
on(host, 'sc stop puppet')
end
def ensure_agent_state(host, state)
retry_attempts = 0
while retry_attempts < 5
return if state == query_agent_state(host)
retry_attempts += 1
sleep 1
end
fail_test "State not #{state} after 5 tries"
end
step 'store initial state' do
agents.each do |agent|
initial_state = query_agent_state(agent)
assert_match("STOPPED", initial_state, "agent daemon should initially be stopped")
start_puppet_windows_daemon(agent)
ensure_agent_state(agent, "RUNNING")
stop_puppet_windows_daemon(agent)
ensure_agent_state(agent, "STOPPED")
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/windows/PA-2191_windows_nocodepage_utf8_fallback.rb | acceptance/tests/windows/PA-2191_windows_nocodepage_utf8_fallback.rb | test_name 'PA-2191 - winruby fallsback to UTF8 for invalid CodePage' do
confine :to, platform: 'windows'
tag 'audit:high',
'audit:acceptance'
agents.each do |host|
initial_chcp_code = on(host, 'cmd.exe /c chcp').stdout.delete('^0-9')
teardown do
on(host, "cmd.exe /c chcp #{initial_chcp_code}")
end
step 'set an invalid Code Page and check if puppet can run' do
on(host, 'cmd.exe /c chcp 720')
begin
on(host, puppet('--version'), acceptable_exit_codes: [0])
rescue StandardError
fail_test('Code Page 720 is invalid')
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/agent/last_run_summary_report.rb | acceptance/tests/agent/last_run_summary_report.rb | test_name "The 'last_run_summary.yaml' report has the right location and permissions" do
tag 'audit:high'
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
agents.each do |agent|
skip_test('This test does not work on Windows in japanese') if agent['platform'] =~ /windows/ && agent['locale'] == 'ja'
custom_publicdir = agent.tmpdir('custom_public_dir')
statedir = on(agent, puppet('config print statedir')).stdout.chomp
fail_test("The 'statedir' config is not set!") if statedir.empty?
publicdir = on(agent, puppet('config print publicdir')).stdout.chomp
fail_test("The 'publicdir' config is not set!") if publicdir.empty?
teardown do
agent.rm_rf(custom_publicdir)
agent.rm_rf("#{publicdir}/*") unless publicdir.empty?
on(agent, puppet("config set publicdir #{publicdir}"))
end
step "Check if '#{publicdir}' was created during puppet installation" do
on(agent, "ls #{publicdir}", :acceptable_exit_codes => [0])
end
step "Check if '#{publicdir}' has '0755' permissions" do
if agent['platform'] =~ /windows/
on(agent, "icacls #{publicdir}") do |result|
# Linux 'Owner' permissions class equivalent
assert_match(/BUILTIN\\Administrators:.*\(F\)/, result.stdout)
# Known issue on Windows: 'C:\ProgramData\PuppetLabs\puppet' permissions are inherited
# by its subfolders and it does not have any permissions for 'Everyone' (see 'PuppetAppDir'
# in 'puppet-agent/resources/windows/wix/appdatafiles.wxs')
# Below line should be added when solution is found:
# assert_match(/Everyone:.*\(RX\)/, result.stdout)
end
else
on(agent, "ls -al #{publicdir}") do |result|
assert_match(/rwxr-xr-x.+\.$/, result.stdout)
end
end
end
step "Create the 'last_run_summary.yaml' report file by applying catalog" do
on(agent, puppet('agent -t')) do |result|
assert_match('Applied catalog', result.stdout)
end
end
step "Check if the 'last_run_summary.yaml' report file created has '0640' permissions" do
if agent['platform'] =~ /windows/
on(agent, "icacls #{File.join(publicdir, 'last_run_summary.yaml')}") do |result|
# Linux 'Owner' premissions class equivalent
assert_match('Administrator:(R,W', result.stdout)
# Linux 'Group' permissions class equivalent
assert_match('None:(R)', result.stdout)
# Linux 'Public' permissions class equivalent
assert_match('Everyone:(Rc,S,RA)', result.stdout)
# According to icacls docs:
# Rc = Read control
# S = Synchronize
# RA = Read attributes
# More at https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/icacls
end
else
on(agent, "ls -al #{publicdir}") do |result|
assert_match(/rw-r-----.+last_run_summary\.yaml$/, result.stdout)
end
end
end
step "Check that '#{statedir}' exists and has no 'last_run_summary.yaml' file" do
on(agent, "ls #{statedir}",:acceptable_exit_codes => [0]) do |result|
refute_match(/last_run_summary.yaml/, result.stdout)
end
end
step "Check that 'publicdir' can be reconfigured" do
on(agent, puppet("config set publicdir #{custom_publicdir}"))
on(agent, puppet('config print publicdir')) do |result|
assert_match(custom_publicdir, result.stdout)
end
end
step "Create a new 'last_run_summary.yaml' report file by applying catalog" do
on(agent, puppet('agent -t')) do |result|
assert_match('Applied catalog', result.stdout)
end
end
step "Check if the 'last_run_summary.yaml' report file was created in the new location and still has '0640' permissions" do
if agent['platform'] =~ /windows/
on(agent, "icacls #{File.join(custom_publicdir, 'last_run_summary.yaml')}") do |result|
# Linux 'Owner' premissions class equivalent
assert_match('Administrator:(R,W', result.stdout)
# Linux 'Group' permissions class equivalent
assert_match('None:(R)', result.stdout)
# Linux 'Public' permissions class equivalent
assert_match('Everyone:(Rc,S,RA)', result.stdout)
# According to icacls docs:
# Rc = Read control
# S = Synchronize
# RA = Read attributes
# More at https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/icacls
end
else
on(agent, "ls -al #{custom_publicdir}") do |result|
assert_match(/rw-r-----.+last_run_summary\.yaml$/, result.stdout)
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/agent/agent_disable_lockfile.rb | acceptance/tests/agent/agent_disable_lockfile.rb | test_name "C4553 - agent --disable/--enable functionality should manage the agent lockfile properly"
tag 'audit:integration', # lockfile uses the standard `vardir` location to store/query lockfile.
# The validation of the `vardir` at the OS level
# should be accomplished in another test.
'audit:high',
'audit:refactor' # This test should not require a master. Remove the use of `with_puppet_running_on`.
#
# This test is intended to ensure that puppet agent --enable/--disable
# work properly, both in terms of complying with our public "API" around
# lockfile semantics ( http://links.puppet.com/agent_lockfiles ), and
# in terms of actually restricting or allowing new agent runs to begin.
#
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
initialize_temp_dirs()
@all_tests_passed = false
###############################################################################
# BEGIN TEST LOGIC
###############################################################################
teardown do
if @all_tests_passed then
remove_temp_dirs()
end
agents.each do |agent|
on(agent, puppet('agent', "--enable"))
end
end
tuples = [
["reason not specified", false],
["I'm busy; go away.'", true]
]
with_puppet_running_on(master, {}) do
tuples.each do |expected_message, explicitly_specify_message|
step "disable the agent; specify message? '#{explicitly_specify_message}', message: '#{expected_message}'" do
agents.each do |agent|
if (explicitly_specify_message)
on(agent, puppet('agent', "--disable \"#{expected_message}\""))
else
on(agent, puppet('agent', "--disable"))
end
agent_disabled_lockfile = "#{agent.puppet['vardir']}/state/agent_disabled.lock"
unless file_exists?(agent, agent_disabled_lockfile) then
fail_test("Failed to create disabled lock file '#{agent_disabled_lockfile}' on agent '#{agent}'")
end
lock_file_content = file_contents(agent, agent_disabled_lockfile)
# This is a hack; we should parse the JSON into a hash, but I don't
# think I have a library available from the acceptance test framework
# that I can use to do that. So I'm falling back to <gasp> regex.
lock_file_content_regex = /"disabled_message"\s*:\s*"#{expected_message}"/
unless lock_file_content =~ lock_file_content_regex
fail_test("Disabled lock file contents invalid; expected to match '#{lock_file_content_regex}', got '#{lock_file_content}' on agent '#{agent}'")
end
end
end
step "attempt to run the agent (message: '#{expected_message}')" do
agents.each do |agent|
on(agent, puppet('agent', "--test"), :acceptable_exit_codes => [1]) do |result|
disabled_regex = /administratively disabled.*'#{expected_message}'/
unless result.stdout =~ disabled_regex
fail_test("Unexpected output from attempt to run agent disabled; expecting to match '#{disabled_regex}', got '#{result.stdout}' on agent '#{agent}'") unless agent['locale'] == 'ja'
end
end
end
end
step "enable the agent (message: '#{expected_message}')" do
agents.each do |agent|
agent_disabled_lockfile = "#{agent.puppet['vardir']}/state/agent_disabled.lock"
on(agent, puppet('agent', "--enable"))
if file_exists?(agent, agent_disabled_lockfile) then
fail_test("Failed to remove disabled lock file '#{agent_disabled_lockfile}' on agent '#{agent}'")
end
end
end
step "verify that we can run the agent (message: '#{expected_message}')" do
agents.each do |agent|
on(agent, puppet('agent', "--test"))
end
end
end # tuples block
end # with_puppet_running_on block
@all_tests_passed = true
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
puppetlabs/puppet | https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/acceptance/tests/agent/agent_fails_with_unknown_resource.rb | acceptance/tests/agent/agent_fails_with_unknown_resource.rb | test_name "agent run should fail if it finds an unknown resource type" do
tag 'audit:high',
'audit:integration'
require 'puppet/acceptance/common_utils'
require 'puppet/acceptance/environment_utils'
extend Puppet::Acceptance::EnvironmentUtils
require 'puppet/acceptance/temp_file_utils'
extend Puppet::Acceptance::TempFileUtils
step "agent should fail when it can't find a resource" do
vendor_modules_path = master.tmpdir('vendor_modules')
tmp_environment = mk_tmp_environment_with_teardown(master, 'tmp')
site_pp_content = <<-SITEPP
define foocreateresource($one) {
$msg = 'hello'
notify { $name: message => $msg }
}
class example($x) {
if $x == undef or $x == [] or $x == '' {
notice 'foo'
return()
}
notice 'bar'
}
node default {
class { example: x => [] }
create_resources('foocreateresource', {'blah'=>{'one'=>'two'}})
mycustomtype{'foobar':}
}
SITEPP
manifests_path = "/tmp/#{tmp_environment}/manifests"
on(master, "mkdir -p '#{manifests_path}'")
create_remote_file(master, "#{manifests_path}/site.pp", site_pp_content)
custom_type_content = <<-CUSTOMTYPE
Puppet::Type.newtype(:mycustomtype) do
@doc = "Create a new mycustomtype thing."
newparam(:name, :namevar => true) do
desc "Name of mycustomtype instance"
end
def refresh
end
end
CUSTOMTYPE
type_path = "#{vendor_modules_path}/foo/lib/puppet/type"
on(master, "mkdir -p '#{type_path}'")
create_remote_file(master, "#{type_path}/mycustomtype.rb", custom_type_content)
on(master, "chmod -R 750 '#{vendor_modules_path}' '/tmp/#{tmp_environment}'")
on(master, "chown -R #{master.puppet['user']}:#{master.puppet['group']} '#{vendor_modules_path}' '/tmp/#{tmp_environment}'")
master_opts = {
'main' => {
'environment' => tmp_environment,
'vendormoduledir' => vendor_modules_path
}
}
with_puppet_running_on(master, master_opts) do
agents.each do |agent|
teardown do
agent.rm_rf(vendor_modules_path)
end
# override vendormoduledir in case agent and server are on the same host
agent_dir = get_test_file_path(agent, 'vendormodulepath')
on(agent, puppet('agent', '-t', '--environment', tmp_environment, '--vendormoduledir', agent_dir), acceptable_exit_codes: [1]) do |result|
assert_match(/Error: Failed to apply catalog: Resource type 'Mycustomtype' was not found/, result.stderr)
end
end
end
end
end
| ruby | Apache-2.0 | e227c27540975c25aa22d533a52424a9d2fc886a | 2026-01-04T15:39:26.576514Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.