Skip to content

Commit

Permalink
Add tests for valid/invalid resource names
Browse files Browse the repository at this point in the history
Prior to this commit, ppa_spec.rb did not test the recently implemented
validation for resource names.

This commit aims to implement some test cases to make sure that valid
resource names are allowed while invalid or malicious resource names do
not work.
  • Loading branch information
LukasAud committed Aug 31, 2022
1 parent 5a2e5c0 commit 67dd216
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions spec/defines/ppa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,69 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = [])
}
end

[
'ppa:foo/bar',
'ppa:foo/bar1.0',
'ppa:foo10/bar10',
'ppa:foo-/bar_',
].each do |value|
describe 'valid resource names' do
let :facts do
{
os: {
family: 'Debian',
name: 'Ubuntu',
release: {
major: '18',
full: '18.04',
},
distro: {
codename: 'trusty',
id: 'Ubuntu',
},
},
}
end

let(:title) { value }

it { is_expected.not_to raise_error }
it { is_expected.to contain_exec("add-apt-repository-#{value}") }
end
end

[
'ppa:foo!/bar',
'ppa:foo/bar!',
'ppa:foo1.0/bar',
'ppa:foo/bar/foobar',
'|| ls -la ||',
'|| touch /tmp/foo.txt ||',
].each do |value|
describe 'invalid resource names' do
let :facts do
{
os: {
family: 'Debian',
name: 'Ubuntu',
release: {
major: '18',
full: '18.04',
},
distro: {
codename: 'trusty',
id: 'Ubuntu',
},
},
}
end

let(:title) { value }

it { is_expected.to raise_error(Puppet::PreformattedError, %r{Invalid PPA name: #{value}}) }
end
end

describe 'Ubuntu 15.10 sources.list filename' do
let :facts do
{
Expand Down

0 comments on commit 67dd216

Please sign in to comment.