api: field_handler: Prevent new "inside-chroot" APIs without Chroot
ChrootHandler is happy to skip over messages that unexpectedly are
missing a Chroot field, and in the primary entry path (handle_chroot()),
simply print a warning:
No chroot message found, falling back to defaults.
This hides the addition of malformed new APIs, since they can sometimes
get away with that due to technical debt in b/187787264.
Let's make it fatal instead.
BUG=b:187787264
TEST=./run_tests
Change-Id: Id81c49cec8a0d1fd287d5d5ad9412008dcfeb97b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4661997
Reviewed-by: Alex Klein <saklein@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Auto-Submit: Brian Norris <briannorris@chromium.org>
Commit-Queue: Brian Norris <briannorris@chromium.org>
diff --git a/api/field_handler_unittest.py b/api/field_handler_unittest.py
index 192a895..10620fd 100644
--- a/api/field_handler_unittest.py
+++ b/api/field_handler_unittest.py
@@ -77,6 +77,18 @@
self.assertEqual(empty_chroot, chroot)
+ def test_handle_no_chroot_message(self):
+ """Test handling of a message with no Chroot field."""
+ message = build_api_test_pb2.MultiFieldMessage()
+
+ # Double-check we didn't grow a Chroot field.
+ for descriptor in message.DESCRIPTOR.fields:
+ field = getattr(message, descriptor.name)
+ self.assertFalse(isinstance(field, common_pb2.Chroot))
+
+ with self.assertRaises(field_handler.MissingChrootMessage):
+ field_handler.handle_chroot(message, clear_field=False)
+
class HandleRemoteexec(cros_test_lib.TempDirTestCase):
"""Tests for handling remoteexec."""