Add tests for valid/invalid resource names issue-1057
authorLukas Audzevicius <laudzevicius24@hotmail.com>
Wed, 31 Aug 2022 11:01:09 +0000 (12:01 +0100)
committerLukas Audzevicius <laudzevicius24@hotmail.com>
Wed, 31 Aug 2022 15:36:56 +0000 (16:36 +0100)
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

index c056b5ba3df24bf30b8b2ba751df2ea910b2eb1f..8d0c4f926342a9a320f3ebca2429e966021f48b1 100644 (file)
@@ -43,6 +43,69 @@ describe 'apt::ppa' do
     }
   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
       {