From 5a2e5c099d8d9dcdca190342a0ab4adf1582f5ec Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Tue, 30 Aug 2022 12:56:32 +0100 Subject: [PATCH 1/2] (GH-1057) Regex fix to allow dotted resources Prior to this commit, one of our recent module updates introduced a regex validation step for the resource names in our ppa.pp manifest which would raise an issue if a valid resource name contained a dot (.). This commit aims to slightly adjust the regex validation so that it allows for dotted resource names. This PR should fix issue #1057. --- manifests/ppa.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/ppa.pp b/manifests/ppa.pp index e3c53e8e6d..7ea5c4ca1a 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -40,7 +40,7 @@ } # Validate the resource name - if $name !~ /^ppa:([a-zA-Z0-9\-_]+)\/([a-zA-z0-9\-_]+)$/ { + if $name !~ /^ppa:([a-zA-Z0-9\-_]+)\/([a-zA-z0-9\-_\.]+)$/ { fail("Invalid PPA name: ${name}") } From 67dd216cf8bc2a444c55892f3c7f3cf190e9414f Mon Sep 17 00:00:00 2001 From: Lukas Audzevicius Date: Wed, 31 Aug 2022 12:01:09 +0100 Subject: [PATCH 2/2] 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. --- spec/defines/ppa_spec.rb | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index c056b5ba3d..8d0c4f9263 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -43,6 +43,69 @@ def ppa_exec_params(user, repo, distro = 'trusty', environment = []) } end + [ + 'ppa:foo/bar', + 'ppa:foo/bar1.0', + 'ppa:foo10/bar10', + 'ppa:foo-/bar_', + ].each do |value| + describe 'valid resource names' do + let :facts do + { + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '18', + full: '18.04', + }, + distro: { + codename: 'trusty', + id: 'Ubuntu', + }, + }, + } + end + + let(:title) { value } + + it { is_expected.not_to raise_error } + it { is_expected.to contain_exec("add-apt-repository-#{value}") } + end + end + + [ + 'ppa:foo!/bar', + 'ppa:foo/bar!', + 'ppa:foo1.0/bar', + 'ppa:foo/bar/foobar', + '|| ls -la ||', + '|| touch /tmp/foo.txt ||', + ].each do |value| + describe 'invalid resource names' do + let :facts do + { + os: { + family: 'Debian', + name: 'Ubuntu', + release: { + major: '18', + full: '18.04', + }, + distro: { + codename: 'trusty', + id: 'Ubuntu', + }, + }, + } + end + + let(:title) { value } + + it { is_expected.to raise_error(Puppet::PreformattedError, %r{Invalid PPA name: #{value}}) } + end + end + describe 'Ubuntu 15.10 sources.list filename' do let :facts do {