summaryrefslogtreecommitdiff
path: root/tests/unittests/test_handler/test_handler_apt_source_v1.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/test_handler/test_handler_apt_source_v1.py')
-rw-r--r--tests/unittests/test_handler/test_handler_apt_source_v1.py75
1 files changed, 50 insertions, 25 deletions
diff --git a/tests/unittests/test_handler/test_handler_apt_source_v1.py b/tests/unittests/test_handler/test_handler_apt_source_v1.py
index 367971cb..2357d699 100644
--- a/tests/unittests/test_handler/test_handler_apt_source_v1.py
+++ b/tests/unittests/test_handler/test_handler_apt_source_v1.py
@@ -9,6 +9,7 @@ import os
import re
import shutil
import tempfile
+import pathlib
from unittest import mock
from unittest.mock import call
@@ -279,16 +280,16 @@ class TestAptSourceConfig(TestCase):
"""
cfg = self.wrapv1conf(cfg)
- with mock.patch.object(subp, 'subp',
- return_value=('fakekey 1234', '')) as mockobj:
+ with mock.patch.object(cc_apt_configure, 'add_apt_key') as mockobj:
cc_apt_configure.handle("test", cfg, self.fakecloud, None, None)
- # check if it added the right ammount of keys
+ # check if it added the right number of keys
calls = []
- for _ in range(keynum):
- calls.append(call(['apt-key', 'add', '-'],
- data=b'fakekey 1234',
- target=None))
+ sources = cfg['apt']['sources']
+ for src in sources:
+ print(sources[src])
+ calls.append(call(sources[src], None))
+
mockobj.assert_has_calls(calls, any_order=True)
self.assertTrue(os.path.isfile(filename))
@@ -364,11 +365,17 @@ class TestAptSourceConfig(TestCase):
"""
cfg = self.wrapv1conf([cfg])
- with mock.patch.object(subp, 'subp') as mockobj:
+ with mock.patch.object(cc_apt_configure, 'add_apt_key') as mockobj:
cc_apt_configure.handle("test", cfg, self.fakecloud, None, None)
- mockobj.assert_called_with(['apt-key', 'add', '-'],
- data=b'fakekey 4321', target=None)
+ # check if it added the right amount of keys
+ sources = cfg['apt']['sources']
+ calls = []
+ for src in sources:
+ print(sources[src])
+ calls.append(call(sources[src], None))
+
+ mockobj.assert_has_calls(calls, any_order=True)
self.assertTrue(os.path.isfile(filename))
@@ -405,12 +412,15 @@ class TestAptSourceConfig(TestCase):
cfg = {'key': "fakekey 4242",
'filename': self.aptlistfile}
cfg = self.wrapv1conf([cfg])
-
- with mock.patch.object(subp, 'subp') as mockobj:
+ with mock.patch.object(cc_apt_configure, 'apt_key') as mockobj:
cc_apt_configure.handle("test", cfg, self.fakecloud, None, None)
- mockobj.assert_called_once_with(['apt-key', 'add', '-'],
- data=b'fakekey 4242', target=None)
+ calls = (call(
+ 'add',
+ output_file=pathlib.Path(self.aptlistfile).stem,
+ data='fakekey 4242',
+ hardened=False),)
+ mockobj.assert_has_calls(calls, any_order=True)
# filename should be ignored on key only
self.assertFalse(os.path.isfile(self.aptlistfile))
@@ -422,16 +432,26 @@ class TestAptSourceConfig(TestCase):
cfg = self.wrapv1conf([cfg])
with mock.patch.object(subp, 'subp',
- return_value=('fakekey 1212', '')) as mockobj:
- cc_apt_configure.handle("test", cfg, self.fakecloud, None, None)
-
- mockobj.assert_called_with(['apt-key', 'add', '-'],
- data=b'fakekey 1212', target=None)
+ return_value=('fakekey 1212', '')):
+ with mock.patch.object(cc_apt_configure, 'apt_key') as mockobj:
+ cc_apt_configure.handle(
+ "test",
+ cfg,
+ self.fakecloud,
+ None,
+ None)
+
+ calls = (call(
+ 'add',
+ output_file=pathlib.Path(self.aptlistfile).stem,
+ data='fakekey 1212',
+ hardened=False),)
+ mockobj.assert_has_calls(calls, any_order=True)
# filename should be ignored on key only
self.assertFalse(os.path.isfile(self.aptlistfile))
- def apt_src_keyid_real(self, cfg, expectedkey):
+ def apt_src_keyid_real(self, cfg, expectedkey, is_hardened=None):
"""apt_src_keyid_real
Test specification of a keyid without source including
up to addition of the key (add_apt_key_raw mocked to keep the
@@ -446,9 +466,14 @@ class TestAptSourceConfig(TestCase):
return_value=expectedkey) as mockgetkey:
cc_apt_configure.handle("test", cfg, self.fakecloud,
None, None)
-
+ if is_hardened is not None:
+ mockkey.assert_called_with(
+ expectedkey,
+ self.aptlistfile,
+ hardened=is_hardened)
+ else:
+ mockkey.assert_called_with(expectedkey, self.aptlistfile)
mockgetkey.assert_called_with(key, keyserver)
- mockkey.assert_called_with(expectedkey, None)
# filename should be ignored on key only
self.assertFalse(os.path.isfile(self.aptlistfile))
@@ -459,7 +484,7 @@ class TestAptSourceConfig(TestCase):
cfg = {'keyid': keyid,
'filename': self.aptlistfile}
- self.apt_src_keyid_real(cfg, EXPECTEDKEY)
+ self.apt_src_keyid_real(cfg, EXPECTEDKEY, is_hardened=False)
def test_apt_src_longkeyid_real(self):
"""test_apt_src_longkeyid_real - Test long keyid including key add"""
@@ -467,7 +492,7 @@ class TestAptSourceConfig(TestCase):
cfg = {'keyid': keyid,
'filename': self.aptlistfile}
- self.apt_src_keyid_real(cfg, EXPECTEDKEY)
+ self.apt_src_keyid_real(cfg, EXPECTEDKEY, is_hardened=False)
def test_apt_src_longkeyid_ks_real(self):
"""test_apt_src_longkeyid_ks_real - Test long keyid from other ks"""
@@ -476,7 +501,7 @@ class TestAptSourceConfig(TestCase):
'keyserver': 'keys.gnupg.net',
'filename': self.aptlistfile}
- self.apt_src_keyid_real(cfg, EXPECTEDKEY)
+ self.apt_src_keyid_real(cfg, EXPECTEDKEY, is_hardened=False)
def test_apt_src_ppa(self):
"""Test adding a ppa"""