mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
Add an extra check that gcert is installed on machine to make sure that the user is googler.
Bug: b/462556449 Change-Id: I2afff69ee202659e23d822c59dd4cc166a6a6964 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7201883 Reviewed-by: Junji Watanabe <jwata@google.com> Commit-Queue: Alex Ovsienko <ovsienko@google.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import argparse
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
@@ -64,6 +65,10 @@ class Config:
|
||||
def path(self):
|
||||
return self._config_path
|
||||
|
||||
@property
|
||||
def is_corp_machine(self):
|
||||
return shutil.which("gcert") is not None
|
||||
|
||||
@property
|
||||
def is_googler(self):
|
||||
return self.user.endswith("@google.com")
|
||||
@@ -93,7 +98,7 @@ class Config:
|
||||
self._config_path,
|
||||
file=sys.stderr)
|
||||
return False
|
||||
if not self.is_googler:
|
||||
if not self.is_googler or not self.is_corp_machine:
|
||||
return False
|
||||
if self._config.get("status") == "opt-out":
|
||||
return False
|
||||
|
||||
@@ -62,8 +62,10 @@ class BuildTelemetryTest(unittest.TestCase):
|
||||
# The cached result should be reused.
|
||||
check_auth.assert_called_once()
|
||||
|
||||
def test_enabled(self):
|
||||
@unittest.mock.patch('shutil.which')
|
||||
def test_enabled(self, mock_shutil):
|
||||
test_countdown = 2
|
||||
mock_shutil.return_value = "path"
|
||||
|
||||
# Googler auto opt-in.
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
@@ -138,6 +140,7 @@ class BuildTelemetryTest(unittest.TestCase):
|
||||
|
||||
# Non-Googler
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
mock_shutil.return_value = None
|
||||
cfg_path = os.path.join(tmpdir, "build_telemetry.cfg")
|
||||
with unittest.mock.patch(
|
||||
'build_telemetry.check_auth') as check_auth:
|
||||
|
||||
Reference in New Issue
Block a user