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 27, 2023
1 parent 0a23900 commit 1e9311a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -978,9 +978,9 @@ Default value: `undef`

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

Data type: `String`
Data type: `String[1]`

Specifies a component of the Apt repository.
Specifies a component of the Apt repository. Default 'main'.

Default value: `'main'`

Expand Down
12 changes: 9 additions & 3 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Specifies a distribution of the Apt repository.
#
# @param repos
# Specifies a component of the Apt repository.
# Specifies a component of the Apt repository. Default 'main'.
#
# @param include
# Configures include options. Valid options: a hash of available keys.
Expand Down Expand Up @@ -68,8 +68,8 @@
Optional[String] $location = undef,
String $comment = $name,
String $ensure = present,
Optional[String] $release = undef,
String $repos = 'main',
Optional[String[1]] $release = undef,
String[1] $repos = 'main',
Variant[Hash] $include = {},
Optional[Variant[String, Hash]] $key = undef,
Optional[Stdlib::AbsolutePath] $keyring = undef,
Expand Down Expand Up @@ -131,6 +131,12 @@
}
}

$repos.split(' ').each | $repo | {
if $repo !~ Regexp(/^(main|contrib|non-free|universe|multiverse|restricted)$/) {
fail('repos parameter must be set to a valid component name, or a comma-separated list of valid component names')
}
}

$header = epp('apt/_header.epp')

if $architecture {
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/source_compat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'comment' => 'foo',
'location' => 'http://debian.mirror.iweb.ca/debian/',
'release' => 'sid',
'repos' => 'testing',
'repos' => 'main',
'include' => { 'src' => false },
'key' => id,
'pin' => '10',
Expand All @@ -51,7 +51,7 @@
end

it {
expect(subject).to contain_apt__setting('list-my_source').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
expect(subject).to contain_apt__setting('list-my_source').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid main\n})
.without_content(%r{deb-src})
}

Expand Down
16 changes: 11 additions & 5 deletions spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
comment: 'foo',
location: 'http://debian.mirror.iweb.ca/debian/',
release: 'sid',
repos: 'testing',
repos: 'main',
key: id,
pin: '10',
architecture: 'x86_64',
Expand All @@ -80,7 +80,7 @@
end

it {
expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid main\n})
.without_content(%r{deb-src})
}

Expand All @@ -102,7 +102,7 @@
comment: 'foo',
location: 'http://debian.mirror.iweb.ca/debian/',
release: 'sid',
repos: 'testing',
repos: 'main',
key: {
'ensure' => 'refreshed',
'id' => id,
Expand All @@ -118,7 +118,7 @@
end

it {
expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid testing\n})
expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').with_content(%r{# foo\ndeb \[arch=x86_64 trusted=yes\] http://debian.mirror.iweb.ca/debian/ sid main\n})
.without_content(%r{deb-src})
}

Expand Down Expand Up @@ -421,10 +421,16 @@
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 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 }
end

context 'with invalid pin' do
Expand Down

0 comments on commit 1e9311a

Please sign in to comment.