metadata: treats CPEPrefix "unknown" as None

This CL changes CPEPrefix field to return None for the validate field
accessor.

There's little reason to return a special "unknown" string in property
accessor (which is used for tooling automation).

We still allow specifying "unknown" in that field.

Bug: b/321154076
Change-Id: Ib4cbc017d6b6df179ccfb008bd5ec9477913764b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5465016
Reviewed-by: Anne Redulla <aredulla@google.com>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
changes/16/5465016/2
Jiewei Qian 1 year ago committed by LUCI CQ
parent e4dca3ff60
commit bba165a25c

@ -93,6 +93,9 @@ class CPEPrefixField(field_types.SingleLineTextField):
if not self._is_valid(value):
return None
if util.is_unknown(value):
return None
# CPE names are case-insensitive, we normalize to lowercase.
# See https://cpe.mitre.org/specification/.
value = value.lower()

@ -141,7 +141,8 @@ class FieldValidationTest(unittest.TestCase):
def test_cpe_prefix(self):
expect = self._test_on_field(fields.CPE_PREFIX)
expect("unknown", "unknown", "understand unknown")
expect("unknown", None, "treat unknown as None")
expect("Unknown", None, "treat unknown as None")
expect("bad_cpe_format", None, "rejects invalid value")
expect("cpe:/a:d3", "cpe:/a:d3", "accept a valid cpe prefix")
expect("cpe:/a:D3", "cpe:/a:d3", "normalize to lowercase")

Loading…
Cancel
Save