Release prep v9.1.0
[puppet-modules/puppetlabs-apt.git] / spec / unit / puppet / provider / apt_key_spec.rb
index 668a953bff76719b5333bf5c2013d8946ad821d4..772db666811eecfacb2caea3886ef666f6737059 100644 (file)
@@ -15,7 +15,7 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
     end
   end
 
-  context 'self.instances no key' do
+  context 'with self.instances no key' do
     before :each do
       # Unable to remove `master` from below terminology as it relies on outside code
       allow(described_class).to receive(:apt_key).with(
@@ -28,7 +28,7 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
     end
   end
 
-  context 'self.instances multiple keys' do
+  context 'with self.instances multiple keys' do
     before :each do
       command_output = <<~OUTPUT
         Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --homedir /tmp/tmp.DU0GdRxjmE --no-auto-check-trustdb --trust-model always --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyring /etc/apt/trusted.gpg.d/puppetlabs-pc1-keyring.gpg --no-tty --list-keys --with-colons --fingerprint --fixed-list-mode
@@ -49,16 +49,42 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
       expect(described_class.instances.size).to eq(2)
       expect(described_class.instances[0].name).to eq('630239CC130E1A7FD81A27B140976EAF437D05B5')
       expect(described_class.instances[0].id).to eq('40976EAF437D05B5')
+      expect(described_class.instances[0].expired).to be_falsey
       expect(described_class.instances[1].name).to eq('C5986B4F1257FFA86632CBA746181433FBB75451')
       expect(described_class.instances[1].id).to eq('46181433FBB75451')
+      expect(described_class.instances[1].expired).to be_falsey
     end
   end
 
-  context 'create apt_key resource' do
+  context 'with self.instances expired subkeys' do
+    before :each do
+      command_output = <<~OUTPUT
+        Executing: /tmp/apt-key-gpghome.0lru3TZOtF/gpg.1.sh --list-keys --with-colons --fingerprint 0x7721F63BD38B4796
+        tru:t:1:1682141947:0:3:1:5
+        pub:-:4096:1:7721F63BD38B4796:1460440275:::-:::scSC::::::23::0:
+        fpr:::::::::EB4C1BFD4F042F6DDDCCEC917721F63BD38B4796:
+        uid:-::::1460440275::7830FE2652F718E78EEE5881B7FA2CE8E3533BE4::Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>::::::::::0:
+        sub:e:4096:1:1397BC53640DB551:1460440520:1555048520:::::s::::::23:
+        fpr:::::::::3B068FB4789ABE4AEFA3BB491397BC53640DB551:
+        sub:e:4096:1:6494C6D6997C215E:1485225932:1579833932:::::s::::::23:
+        fpr:::::::::3E50F6D3EC278FDEB655C8CA6494C6D6997C215E:
+      OUTPUT
+      allow(described_class).to receive(:apt_key).with(
+        ['adv', '--no-tty', '--list-keys', '--with-colons', '--fingerprint', '--fixed-list-mode'],
+      ).and_return(command_output)
+    end
+
+    it 'returns 1 expired resource' do
+      expect(described_class.instances.size).to eq(1)
+      expect(described_class.instances[0].expired).to be_truthy
+    end
+  end
+
+  context 'with create apt_key resource' do
     it 'apt_key with content set and source nil' do
       expect(described_class).to receive(:apt_key).with(['adv', '--no-tty',
                                                          '--keyserver',
-                                                         :"keyserver.ubuntu.com",
+                                                         :'keyserver.ubuntu.com',
                                                          '--recv-keys',
                                                          'C105B9DE'])
       resource = Puppet::Type::Apt_key.new(name: 'source and content nil',
@@ -74,7 +100,7 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
     it 'apt_key content and source nil, options set' do
       expect(described_class).to receive(:apt_key).with(['adv', '--no-tty',
                                                          '--keyserver',
-                                                         :"keyserver.ubuntu.com",
+                                                         :'keyserver.ubuntu.com',
                                                          '--keyserver-options',
                                                          'jimno',
                                                          '--recv-keys',
@@ -143,13 +169,13 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
         '160bit key fingerprint lowercase' => '6F6B15509CF8E59E6E469F327F438280EF8D349F'.downcase,
         '32bit key id 0x formatted' => '0xEF8D349F',
         '64bit key id 0x formatted' => '0x7F438280EF8D349F',
-        '160bit key fingerprint 0x formatted' => '0x6F6B15509CF8E59E6E469F327F438280EF8D349F',
+        '160bit key fingerprint 0x formatted' => '0x6F6B15509CF8E59E6E469F327F438280EF8D349F'
       }
       hash_of_keys.each do |key_type, value|
         it "#{key_type} #{value} is valid" do
           expect(described_class).to receive(:apt_key).with(array_including('adv', '--no-tty',
                                                                             '--keyserver',
-                                                                            :"keyserver.ubuntu.com",
+                                                                            :'keyserver.ubuntu.com',
                                                                             '--recv-keys'))
           resource = Puppet::Type::Apt_key.new(name: 'source and content nil',
                                                id: value,
@@ -172,9 +198,9 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
     end
   end
 
-  context 'key_line_hash function' do
+  context 'with key_line_hash function' do
     it 'matches rsa' do
-      expect(described_class.key_line_hash('pub:-:1024:1:40976EAF437D05B5:1095016255:::-:::scESC:', 'fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:')).to include(
+      expect(described_class.key_line_hash('pub:-:1024:1:40976EAF437D05B5:1095016255:::-:::scESC:', ['fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:'])).to include(
         key_expiry: nil,
         key_fingerprint: '630239CC130E1A7FD81A27B140976EAF437D05B5',
         key_long: '40976EAF437D05B5',
@@ -185,7 +211,7 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
     end
 
     it 'matches dsa' do
-      expect(described_class.key_line_hash('pub:-:1024:17:40976EAF437D05B5:1095016255:::-:::scESC:', 'fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:')).to include(
+      expect(described_class.key_line_hash('pub:-:1024:17:40976EAF437D05B5:1095016255:::-:::scESC:', ['fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:'])).to include(
         key_expiry: nil,
         key_fingerprint: '630239CC130E1A7FD81A27B140976EAF437D05B5',
         key_long: '40976EAF437D05B5',
@@ -196,7 +222,7 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
     end
 
     it 'matches ecc' do
-      expect(described_class.key_line_hash('pub:-:1024:18:40976EAF437D05B5:1095016255:::-:::scESC:', 'fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:')).to include(
+      expect(described_class.key_line_hash('pub:-:1024:18:40976EAF437D05B5:1095016255:::-:::scESC:', ['fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:'])).to include(
         key_expiry: nil,
         key_fingerprint: '630239CC130E1A7FD81A27B140976EAF437D05B5',
         key_long: '40976EAF437D05B5',
@@ -207,7 +233,7 @@ describe Puppet::Type.type(:apt_key).provider(:apt_key) do
     end
 
     it 'matches ecdsa' do
-      expect(described_class.key_line_hash('pub:-:1024:19:40976EAF437D05B5:1095016255:::-:::scESC:', 'fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:')).to include(
+      expect(described_class.key_line_hash('pub:-:1024:19:40976EAF437D05B5:1095016255:::-:::scESC:', ['fpr:::::::::630239CC130E1A7FD81A27B140976EAF437D05B5:'])).to include(
         key_expiry: nil,
         key_fingerprint: '630239CC130E1A7FD81A27B140976EAF437D05B5',
         key_long: '40976EAF437D05B5',