diff --git a/manifests/source.pp b/manifests/source.pp index 7a44221497..dbc0ea46a0 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -310,10 +310,10 @@ $_release = $release } - # The deb822 format requires that if the Suite ($release) is a path (contains a /) that - # the Components field be absent. Check the original - $_releasefilter = $_release.any |$item| { $item.index('/') != undef } - if $_releasefilter { + # The deb822 format requires that if all Suite ($release) values end with a slash (/), + # the Components field must be omitted. Otherwise, Components is required. + $_all_suites_end_with_slash = $_release.all |$item| { $item =~ /\/$/ } + if $_all_suites_end_with_slash { $_repos = undef } elsif $repos !~ Array { warning("For deb822 sources, 'repos' must be specified as an array. Converting to array.") diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index db28d23f2d..8f029b0402 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -436,6 +436,66 @@ end describe 'deb822 sources' do + + context 'suite contains a slash but does not end with slash (should require Components)' do + let :params do + super().merge( + { + location: ['http://repo.mongodb.org/apt/debian'], + release: ['bookworm/mongodb-org/6.0'], + repos: ['main'], + keyring: '/etc/apt/keyrings/mongodb.gpg', + }, + ) + end + it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Suites: bookworm/mongodb-org/6.0}) } + it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Components: main}) } + end + + context 'suite ends with slash (should omit Components)' do + let :params do + super().merge( + { + location: ['https://pkg.jenkins.io/debian-stable'], + release: ['binary/'], + repos: [], + keyring: '/etc/apt/keyrings/jenkins-keyring.asc', + }, + ) + end + it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Suites: binary/}) } + it { is_expected.to contain_apt__setting("sources-#{title}").without_content(%r{Components:}) } + end + + context 'multiple suites, all end with slash (should omit Components)' do + let :params do + super().merge( + { + location: ['https://example.com/debian'], + release: ['foo/', 'bar/'], + repos: ['main'], + keyring: '/etc/apt/keyrings/example.gpg', + }, + ) + end + it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Suites: foo/ bar/}) } + it { is_expected.to contain_apt__setting("sources-#{title}").without_content(%r{Components:}) } + end + + context 'multiple suites, not all end with slash (should require Components)' do + let :params do + super().merge( + { + location: ['https://example.com/debian'], + release: ['foo/', 'bar'], + repos: ['main'], + keyring: '/etc/apt/keyrings/example.gpg', + }, + ) + end + it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Suites: foo/ bar}) } + it { is_expected.to contain_apt__setting("sources-#{title}").with_content(%r{Components: main}) } + end let :params do { source_format: 'sources',