Skip to content

Commit 2fbb2a5

Browse files
committed
(CAT-1483) - Enhancement of validation for apt::source parameters
1 parent 0326833 commit 2fbb2a5

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

REFERENCE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,15 +970,15 @@ Default value: `present`
970970

971971
##### <a name="-apt--source--release"></a>`release`
972972

973-
Data type: `Optional[String]`
973+
Data type: `Optional[Pattern[/\A[[:alnum:]\s-]+\z/]]`
974974

975975
Specifies a distribution of the Apt repository.
976976

977977
Default value: `undef`
978978

979979
##### <a name="-apt--source--repos"></a>`repos`
980980

981-
Data type: `String`
981+
Data type: `Pattern[/\A[[:alnum:]\s-]+\z/]`
982982

983983
Specifies a component of the Apt repository.
984984

manifests/source.pp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@
6565
# Specifies whether to check if the package release date is valid. Defaults to `True`.
6666
#
6767
define apt::source (
68-
Optional[String] $location = undef,
69-
String $comment = $name,
70-
String $ensure = present,
71-
Optional[String] $release = undef,
72-
String $repos = 'main',
73-
Variant[Hash] $include = {},
74-
Optional[Variant[String, Hash]] $key = undef,
75-
Optional[Stdlib::AbsolutePath] $keyring = undef,
76-
Optional[Variant[Hash, Numeric, String]] $pin = undef,
77-
Optional[String] $architecture = undef,
78-
Boolean $allow_unsigned = false,
79-
Boolean $allow_insecure = false,
80-
Boolean $notify_update = true,
81-
Boolean $check_valid_until = true,
68+
Optional[String] $location = undef,
69+
String $comment = $name,
70+
String $ensure = present,
71+
Optional[Pattern[/\A[[:alnum:]\s-]+\z/]] $release = undef,
72+
Pattern[/\A[[:alnum:]\s-]+\z/] $repos = 'main',
73+
Variant[Hash] $include = {},
74+
Optional[Variant[String, Hash]] $key = undef,
75+
Optional[Stdlib::AbsolutePath] $keyring = undef,
76+
Optional[Variant[Hash, Numeric, String]] $pin = undef,
77+
Optional[String] $architecture = undef,
78+
Boolean $allow_unsigned = false,
79+
Boolean $allow_insecure = false,
80+
Boolean $notify_update = true,
81+
Boolean $check_valid_until = true,
8282
) {
8383
include apt
8484

spec/defines/source_spec.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@
6565
}
6666
end
6767

68+
context 'with invalid repos' do
69+
let :params do
70+
{
71+
comment: 'foo',
72+
location: 'http://debian.mirror.iweb.ca/debian/',
73+
release: 'sid',
74+
repos: '/test',
75+
}
76+
end
77+
78+
it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Pattern}) }
79+
end
80+
81+
context 'with empty string for repos' do
82+
let :params do
83+
{
84+
comment: 'foo',
85+
location: 'http://debian.mirror.iweb.ca/debian/',
86+
release: 'sid',
87+
repos: '',
88+
}
89+
end
90+
91+
it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Pattern}) }
92+
end
93+
6894
context 'with simple key' do
6995
let :params do
7096
{
@@ -421,10 +447,22 @@
421447
end
422448
end
423449

450+
context 'with release is not empty string' do
451+
let(:params) { { location: 'hello.there', release: 'test' } }
452+
453+
it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there test main}) }
454+
end
455+
456+
context 'with release invalid string' do
457+
let(:params) { { location: 'hello.there', release: '/' } }
458+
459+
it { is_expected.to raise_error(Puppet::Error, %r{value or a match for Pattern}) }
460+
end
461+
424462
context 'with release is empty string' do
425463
let(:params) { { location: 'hello.there', release: '' } }
426464

427-
it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there main}) }
465+
it { is_expected.to raise_error(Puppet::Error, %r{value or a match for Pattern}) }
428466
end
429467

430468
context 'with invalid pin' do

0 commit comments

Comments
 (0)