summaryrefslogtreecommitdiff
path: root/scripts/pushimage_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/pushimage_unittest.py')
-rw-r--r--scripts/pushimage_unittest.py117
1 files changed, 109 insertions, 8 deletions
diff --git a/scripts/pushimage_unittest.py b/scripts/pushimage_unittest.py
index ae6f6c861..a423143f8 100644
--- a/scripts/pushimage_unittest.py
+++ b/scripts/pushimage_unittest.py
@@ -62,8 +62,8 @@ class InputInsnsTest(cros_test_lib.MockTestCase):
def testOutputInsnsBasic(self):
"""Verify output instructions are sane"""
exp_content = """[insns]
-keyset = stumpy-mp-v3
channel = dev canary
+keyset = stumpy-mp-v3
chromeos_shell = false
ensure_no_password = true
firmware_update = true
@@ -74,8 +74,9 @@ create_nplusone = true
"""
insns = pushimage.InputInsns('test.board')
+ self.assertEqual(insns.GetAltInsnSets(), [None])
m = self.PatchObject(osutils, 'WriteFile')
- insns.OutputInsns('recovery', '/bogus', {}, {})
+ insns.OutputInsns('/bogus', {}, {})
self.assertTrue(m.called)
content = m.call_args_list[0][0][1]
self.assertEqual(content.rstrip(), exp_content.rstrip())
@@ -83,8 +84,8 @@ create_nplusone = true
def testOutputInsnsReplacements(self):
"""Verify output instructions can be updated"""
exp_content = """[insns]
-keyset = batman
channel = dev
+keyset = batman
chromeos_shell = false
ensure_no_password = true
firmware_update = true
@@ -106,11 +107,62 @@ config_board = test.board
insns = pushimage.InputInsns('test.board')
m = self.PatchObject(osutils, 'WriteFile')
- insns.OutputInsns('recovery', '/a/file', sect_insns, sect_general)
+ insns.OutputInsns('/a/file', sect_insns, sect_general)
self.assertTrue(m.called)
content = m.call_args_list[0][0][1]
self.assertEqual(content.rstrip(), exp_content.rstrip())
+ def testOutputInsnsMergeAlts(self):
+ """Verify handling of alternative insns.xxx sections"""
+ TEMPLATE_CONTENT = """[insns]
+channel = %(channel)s
+chromeos_shell = false
+ensure_no_password = true
+firmware_update = true
+security_checks = true
+create_nplusone = true
+override = sect_insns
+keyset = %(keyset)s
+%(extra)s
+[general]
+board = board
+config_board = test.board
+"""
+
+ exp_alts = ['insns.one', 'insns.two', 'insns.hotsoup']
+ exp_fields = {
+ 'one': {'channel': 'dev canary', 'keyset': 'OneKeyset', 'extra': ''},
+ 'two': {'channel': 'best', 'keyset': 'TwoKeyset', 'extra': ''},
+ 'hotsoup': {
+ 'channel': 'dev canary',
+ 'keyset': 'ColdKeyset',
+ 'extra': 'soup = cheddar\n',
+ },
+ }
+
+ # Make sure this overrides the insn sections.
+ sect_insns = {
+ 'override': 'sect_insns',
+ }
+ sect_insns_copy = sect_insns.copy()
+ sect_general = {
+ 'config_board': 'test.board',
+ 'board': 'board',
+ }
+
+ insns = pushimage.InputInsns('test.multi')
+ self.assertEqual(insns.GetAltInsnSets(), exp_alts)
+ m = self.PatchObject(osutils, 'WriteFile')
+
+ for alt in exp_alts:
+ m.reset_mock()
+ insns.OutputInsns('/a/file', sect_insns, sect_general, insns_merge=alt)
+ self.assertEqual(sect_insns, sect_insns_copy)
+ self.assertTrue(m.called)
+ content = m.call_args_list[0][0][1]
+ exp_content = TEMPLATE_CONTENT % exp_fields[alt[6:]]
+ self.assertEqual(content.rstrip(), exp_content.rstrip())
+
class MarkImageToBeSignedTest(gs_unittest.AbstractGSContextTest):
"""Tests for MarkImageToBeSigned()"""
@@ -233,7 +285,7 @@ class PushImageTests(gs_unittest.AbstractGSContextTest):
with mock.patch.object(gs.GSContext, 'Exists', return_value=True):
urls = pushimage.PushImage('/src', 'test.board', 'R34-5126.0.0',
sign_types=['recovery'])
- self.assertEqual(self.gs_mock.call_count, 22)
+ self.assertEqual(self.gs_mock.call_count, 26)
self.assertTrue(self.mark_mock.called)
self.assertEqual(urls, EXPECTED)
@@ -251,7 +303,7 @@ class PushImageTests(gs_unittest.AbstractGSContextTest):
with mock.patch.object(gs.GSContext, 'Exists', return_value=True):
urls = pushimage.PushImage('/src', 'test.board', 'R34-5126.0.0',
sign_types=['base'])
- self.assertEqual(self.gs_mock.call_count, 24)
+ self.assertEqual(self.gs_mock.call_count, 28)
self.assertTrue(self.mark_mock.called)
self.assertEqual(urls, EXPECTED)
@@ -259,7 +311,7 @@ class PushImageTests(gs_unittest.AbstractGSContextTest):
"""Verify nothing is signed when we request an unavailable type"""
urls = pushimage.PushImage('/src', 'test.board', 'R34-5126.0.0',
sign_types=['nononononono'])
- self.assertEqual(self.gs_mock.call_count, 20)
+ self.assertEqual(self.gs_mock.call_count, 24)
self.assertFalse(self.mark_mock.called)
self.assertEqual(urls, {})
@@ -271,6 +323,55 @@ class PushImageTests(gs_unittest.AbstractGSContextTest):
self.assertRaises(pushimage.PushError, pushimage.PushImage, '/src',
'test.board', 'R34-5126.0.0')
+ def testMultipleKeysets(self):
+ """Verify behavior when processing an insn w/multiple keysets"""
+ EXPECTED = {
+ 'canary': [
+ ('gs://chromeos-releases/canary-channel/test.board/5126.0.0/'
+ 'ChromeOS-recovery-R34-5126.0.0-test.board.instructions'),
+ ('gs://chromeos-releases/canary-channel/test.board/5126.0.0/'
+ 'ChromeOS-recovery-R34-5126.0.0-test.board-key2.instructions'),
+ ('gs://chromeos-releases/canary-channel/test.board/5126.0.0/'
+ 'ChromeOS-recovery-R34-5126.0.0-test.board-key3.instructions'),
+ ],
+ 'dev': [
+ ('gs://chromeos-releases/dev-channel/test.board/5126.0.0/'
+ 'ChromeOS-recovery-R34-5126.0.0-test.board.instructions'),
+ ('gs://chromeos-releases/dev-channel/test.board/5126.0.0/'
+ 'ChromeOS-recovery-R34-5126.0.0-test.board-key2.instructions'),
+ ('gs://chromeos-releases/dev-channel/test.board/5126.0.0/'
+ 'ChromeOS-recovery-R34-5126.0.0-test.board-key3.instructions'),
+ ],
+ }
+ with mock.patch.object(gs.GSContext, 'Exists', return_value=True):
+ urls = pushimage.PushImage('/src', 'test.board', 'R34-5126.0.0',
+ force_keysets=('key1', 'key2', 'key3'))
+ self.assertEqual(urls, EXPECTED)
+
+ def testMultipleAltInsns(self):
+ """Verify behavior when processing an insn w/multiple insn overlays"""
+ EXPECTED = {
+ 'canary': [
+ ('gs://chromeos-releases/canary-channel/test.multi/1.0.0/'
+ 'ChromeOS-recovery-R1-1.0.0-test.multi.instructions'),
+ ('gs://chromeos-releases/canary-channel/test.multi/1.0.0/'
+ 'ChromeOS-recovery-R1-1.0.0-test.multi-TwoKeyset.instructions'),
+ ('gs://chromeos-releases/canary-channel/test.multi/1.0.0/'
+ 'ChromeOS-recovery-R1-1.0.0-test.multi-ColdKeyset.instructions'),
+ ],
+ 'dev': [
+ ('gs://chromeos-releases/dev-channel/test.multi/1.0.0/'
+ 'ChromeOS-recovery-R1-1.0.0-test.multi.instructions'),
+ ('gs://chromeos-releases/dev-channel/test.multi/1.0.0/'
+ 'ChromeOS-recovery-R1-1.0.0-test.multi-TwoKeyset.instructions'),
+ ('gs://chromeos-releases/dev-channel/test.multi/1.0.0/'
+ 'ChromeOS-recovery-R1-1.0.0-test.multi-ColdKeyset.instructions'),
+ ],
+ }
+ with mock.patch.object(gs.GSContext, 'Exists', return_value=True):
+ urls = pushimage.PushImage('/src', 'test.multi', 'R1-1.0.0')
+ self.assertEqual(urls, EXPECTED)
+
class MainTests(cros_test_lib.MockTestCase):
"""Tests for main()"""
@@ -289,4 +390,4 @@ def main(_argv):
signing.INPUT_INSN_DIR = signing.TEST_INPUT_INSN_DIR
# Run the tests.
- cros_test_lib.main(level='info', module=__name__)
+ cros_test_lib.main(level='notice', module=__name__)