Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 67dd216

Browse files
committed
Add tests for valid/invalid resource names
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.
1 parent 5a2e5c0 commit 67dd216

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

spec/defines/ppa_spec.rb

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,69 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = [])
4343
}
4444
end
4545

46+
[
47+
'ppa:foo/bar',
48+
'ppa:foo/bar1.0',
49+
'ppa:foo10/bar10',
50+
'ppa:foo-/bar_',
51+
].each do |value|
52+
describe 'valid resource names' do
53+
let :facts do
54+
{
55+
os: {
56+
family: 'Debian',
57+
name: 'Ubuntu',
58+
release: {
59+
major: '18',
60+
full: '18.04',
61+
},
62+
distro: {
63+
codename: 'trusty',
64+
id: 'Ubuntu',
65+
},
66+
},
67+
}
68+
end
69+
70+
let(:title) { value }
71+
72+
it { is_expected.not_to raise_error }
73+
it { is_expected.to contain_exec("add-apt-repository-#{value}") }
74+
end
75+
end
76+
77+
[
78+
'ppa:foo!/bar',
79+
'ppa:foo/bar!',
80+
'ppa:foo1.0/bar',
81+
'ppa:foo/bar/foobar',
82+
'|| ls -la ||',
83+
'|| touch /tmp/foo.txt ||',
84+
].each do |value|
85+
describe 'invalid resource names' do
86+
let :facts do
87+
{
88+
os: {
89+
family: 'Debian',
90+
name: 'Ubuntu',
91+
release: {
92+
major: '18',
93+
full: '18.04',
94+
},
95+
distro: {
96+
codename: 'trusty',
97+
id: 'Ubuntu',
98+
},
99+
},
100+
}
101+
end
102+
103+
let(:title) { value }
104+
105+
it { is_expected.to raise_error(Puppet::PreformattedError, %r{Invalid PPA name: #{value}}) }
106+
end
107+
end
108+
46109
describe 'Ubuntu 15.10 sources.list filename' do
47110
let :facts do
48111
{

0 commit comments

Comments
 (0)