Skip to content

Commit

Permalink
(CAT-1483) - Enhancement of validation for apt::source parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramesh7 committed Sep 28, 2023
1 parent 0a23900 commit 0d73bef
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -970,15 +970,15 @@ Default value: `present`

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

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

Specifies a distribution of the Apt repository.

Default value: `undef`

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

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

Specifies a component of the Apt repository.

Expand Down
28 changes: 14 additions & 14 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@
# Specifies whether to check if the package release date is valid. Defaults to `True`.
#
define apt::source (
Optional[String] $location = undef,
String $comment = $name,
String $ensure = present,
Optional[String] $release = undef,
String $repos = 'main',
Variant[Hash] $include = {},
Optional[Variant[String, Hash]] $key = undef,
Optional[Stdlib::AbsolutePath] $keyring = undef,
Optional[Variant[Hash, Numeric, String]] $pin = undef,
Optional[String] $architecture = undef,
Boolean $allow_unsigned = false,
Boolean $allow_insecure = false,
Boolean $notify_update = true,
Boolean $check_valid_until = true,
Optional[String] $location = undef,
String $comment = $name,
String $ensure = present,
Optional[Pattern[/\A[[:alnum:]\s-]+\z/]] $release = undef,
Pattern[/\A[[:alnum:]\s-]+\z/] $repos = 'main',
Variant[Hash] $include = {},
Optional[Variant[String, Hash]] $key = undef,
Optional[Stdlib::AbsolutePath] $keyring = undef,
Optional[Variant[Hash, Numeric, String]] $pin = undef,
Optional[String] $architecture = undef,
Boolean $allow_unsigned = false,
Boolean $allow_insecure = false,
Boolean $notify_update = true,
Boolean $check_valid_until = true,
) {
include apt

Expand Down
40 changes: 39 additions & 1 deletion spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@
}
end

context 'with invalid repos' do
let :params do
{
comment: 'foo',
location: 'http://debian.mirror.iweb.ca/debian/',
release: 'sid',
repos: '/test',
}
end

it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Pattern}) }
end

context 'with empty string for repos' do
let :params do
{
comment: 'foo',
location: 'http://debian.mirror.iweb.ca/debian/',
release: 'sid',
repos: '',
}
end

it { is_expected.to raise_error(Puppet::Error, %r{expects a match for Pattern}) }
end

context 'with simple key' do
let :params do
{
Expand Down Expand Up @@ -421,10 +447,22 @@
end
end

context 'with release is not empty string' do
let(:params) { { location: 'hello.there', release: 'test' } }

it { is_expected.to contain_apt__setting('list-my_source').with_content(%r{hello\.there test main}) }
end

context 'with release invalid string' do
let(:params) { { location: 'hello.there', release: '/' } }

it { is_expected.to raise_error(Puppet::Error, %r{value or a match for Pattern}) }
end

context 'with release is empty string' do
let(:params) { { location: 'hello.there', release: '' } }

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

context 'with invalid pin' do
Expand Down

0 comments on commit 0d73bef

Please sign in to comment.