Merge branch 'main' into avm99963-monorail

Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266

GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/tracker/test/field_helpers_test.py b/tracker/test/field_helpers_test.py
index f49a147..5d46586 100644
--- a/tracker/test/field_helpers_test.py
+++ b/tracker/test/field_helpers_test.py
@@ -1,7 +1,6 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file or at
-# https://developers.google.com/open-source/licenses/bsd
+# Copyright 2016 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
 
 """Unit tests for the field_helpers module."""
 from __future__ import print_function
@@ -15,8 +14,8 @@
 from framework import exceptions
 from framework import permissions
 from framework import template_helpers
-from proto import project_pb2
-from proto import tracker_pb2
+from mrproto import project_pb2
+from mrproto import tracker_pb2
 from services import service_manager
 from services import config_svc
 from testing import fake
@@ -1274,3 +1273,43 @@
     self.assertEqual(
         self.mr.errors.min_value, 'Minimum value must be less than maximum.')
     self.assertEqual(self.mr.errors.regex, 'Invalid regular expression.')
+
+  def testValidateLabels_NoLabels(self):
+    err_msg = field_helpers.ValidateLabels(
+        self.mr.cnxn,
+        self.services,
+        self.mr.project_id, [''],
+        ezt_errors=self.errors)
+    self.assertFalse(self.errors.AnyErrors())
+    self.assertEqual(err_msg, None)
+
+  def testValidateLabels_ExistingLabel(self):
+    err_msg = field_helpers.ValidateLabels(
+        self.mr.cnxn,
+        self.services,
+        self.mr.project_id, ['old_label'],
+        ezt_errors=self.errors)
+    self.assertFalse(self.errors.AnyErrors())
+    self.assertEqual(err_msg, None)
+
+  def testValidateLabels_AllowlistedLabel(self):
+    err_msg = field_helpers.ValidateLabels(
+        self.mr.cnxn,
+        self.services,
+        self.mr.project_id, ['old_label', 'CVE-test'],
+        ezt_errors=self.errors)
+    self.assertFalse(self.errors.AnyErrors())
+    self.assertEqual(err_msg, None)
+
+  def testValidateLabels_Error(self):
+    err_msg = field_helpers.ValidateLabels(
+        self.mr.cnxn,
+        self.services,
+        self.mr.project_id, ['freeze_new_label'],
+        ezt_errors=self.errors)
+    self.assertTrue(self.errors.AnyErrors())
+    self.assertEqual(
+        err_msg, (
+            'The creation of new labels is blocked for the Chromium project'
+            ' in Monorail. To continue with editing your issue, please'
+            ' remove: freeze_new_label label(s).'))