brizental pushed to branch tor-browser-140.2.0esr-15.0-1 at The Tor Project / Applications / Tor Browser

Commits:

5 changed files:

Changes:

  • .gitlab/ci/jobs/test/python-test.yml
    ... ... @@ -17,7 +17,7 @@ python-test:
    17 17
         - firefox
    
    18 18
       script:
    
    19 19
         - ./mach configure --with-base-browser-version=0.0.0
    
    20
    -    - .gitlab/ci/jobs/helpers.py --get-changed-files | xargs -0 --no-run-if-empty ./mach python-test -v
    
    20
    +    - ./mach python-test --subsuite base-browser
    
    21 21
       rules:
    
    22 22
         - if: $CI_PIPELINE_SOURCE == 'merge_request_event' || ($CI_COMMIT_BRANCH && $CI_COMMIT_REF_PROTECTED == 'true' && $CI_PIPELINE_SOURCE == 'push')
    
    23 23
           changes:
    

  • build/moz.configure/bootstrap.configure
    ... ... @@ -205,9 +205,7 @@ def bootstrap_path(path, **kwargs):
    205 205
                 if not target.tor_browser_build_alias:
    
    206 206
                     return False
    
    207 207
     
    
    208
    -            artifact = mozbuild.tbbutils.get_artifact_name(
    
    209
    -                path_parts[0], target, tasks.prefix
    
    210
    -            )
    
    208
    +            artifact = mozbuild.tbbutils.get_artifact_name(path_parts[0], tasks.prefix)
    
    211 209
                 if not artifact:
    
    212 210
                     log.info("%s is not mapped to a tbb artifact", path_parts[0])
    
    213 211
                     return False
    

  • python/mozbuild/mozbuild/tbbutils.py
    ... ... @@ -45,7 +45,7 @@ ARTIFACT_NAME_MAP = {
    45 45
     }
    
    46 46
     
    
    47 47
     
    
    48
    -def get_artifact_name(original_artifact_name, target, host):
    
    48
    +def get_artifact_name(original_artifact_name, host):
    
    49 49
         # These are not build artifacts, they are pre-built artifacts to be added to the final build,
    
    50 50
         # therefore this check can come before the host check.
    
    51 51
         if original_artifact_name in TOR_BROWSER_BUILD_ARTIFACTS:
    
    ... ... @@ -76,7 +76,7 @@ def get_artifact_path(url, artifact, target, prefix=""):
    76 76
         def filter_files(files, keyword):
    
    77 77
             return [file for file in files if keyword in file]
    
    78 78
     
    
    79
    -    artifact_files = filter_files(files, artifact)
    
    79
    +    artifact_files = [file for file in files if file.startswith(artifact)]
    
    80 80
     
    
    81 81
         if len(artifact_files) == 1:
    
    82 82
             return f"{url}/{path}/{artifact_files[0]}"
    
    ... ... @@ -84,8 +84,13 @@ def get_artifact_path(url, artifact, target, prefix=""):
    84 84
         files_per_os = filter_files(artifact_files, target.tor_browser_build_alias)
    
    85 85
     
    
    86 86
         # If there are files in the folder, but they don't have the OS in the name
    
    87
    -    # it means we can get any of them because they can be used to build for any OS.
    
    88
    -    # So let's just get the first one.
    
    87
    +    # it probably means we can get any of them because they can be used to build
    
    88
    +    # for any OS. So let's just get the first one.
    
    89
    +    #
    
    90
    +    # Note: It could be the case that the artifact _is_ OS dependant, but there
    
    91
    +    # just are no files for the OS we are looking for. In that case, this will
    
    92
    +    # return an incorrect artifact. This should not happen often though and is
    
    93
    +    # something we cannot address until artifact names are standardized on tbb.
    
    89 94
         if len(files_per_os) == 0:
    
    90 95
             return f"{url}/{artifact}/{artifact_files[0]}"
    
    91 96
     
    

  • python/mozbuild/mozbuild/test/python.toml
    ... ... @@ -111,6 +111,9 @@ subsuite = "mozbuild"
    111 111
     
    
    112 112
     ["test_rewrite_mozbuild.py"]
    
    113 113
     
    
    114
    +["test_tbbutils.py"]
    
    115
    +subsuite = "base-browser"
    
    116
    +
    
    114 117
     ["test_telemetry.py"]
    
    115 118
     
    
    116 119
     ["test_telemetry_settings.py"]
    

  • python/mozbuild/mozbuild/test/test_tbbutils.py
    1
    +import unittest
    
    2
    +from types import SimpleNamespace
    
    3
    +from unittest.mock import MagicMock, patch
    
    4
    +
    
    5
    +import mozunit
    
    6
    +
    
    7
    +from mozbuild.tbbutils import get_artifact_path, list_files_http
    
    8
    +
    
    9
    +
    
    10
    +class TestGetArtifactName(unittest.TestCase):
    
    11
    +    def setUp(self):
    
    12
    +        self.artifact = "artifact"
    
    13
    +        self.host = "linux64"
    
    14
    +
    
    15
    +    @patch("mozbuild.tbbutils.TOR_BROWSER_BUILD_ARTIFACTS", new=["artifact"])
    
    16
    +    def test_artifact_in_tbb_artifacts(self):
    
    17
    +        from mozbuild.tbbutils import get_artifact_name
    
    18
    +
    
    19
    +        result = get_artifact_name(self.artifact, self.host)
    
    20
    +        self.assertEqual(result, self.artifact)
    
    21
    +
    
    22
    +    @patch("mozbuild.tbbutils.ARTIFACT_NAME_MAP", new={"artifact": "tcafitra"})
    
    23
    +    def test_host_is_not_linux64(self):
    
    24
    +        from mozbuild.tbbutils import get_artifact_name
    
    25
    +
    
    26
    +        result = get_artifact_name(self.artifact, "linux64-aarch64")
    
    27
    +        self.assertIsNone(result)
    
    28
    +
    
    29
    +    @patch("mozbuild.tbbutils.ARTIFACT_NAME_MAP", new={"artifact": "tcafitra"})
    
    30
    +    def test_mapped_artifact(self):
    
    31
    +        from mozbuild.tbbutils import get_artifact_name
    
    32
    +
    
    33
    +        result = get_artifact_name(self.artifact, self.host)
    
    34
    +        self.assertEqual(result, self.artifact[::-1])
    
    35
    +
    
    36
    +
    
    37
    +class TestGetArtifactPath(unittest.TestCase):
    
    38
    +    def setUp(self):
    
    39
    +        self.url = "http://example.com"
    
    40
    +        self.artifact = "artifact"
    
    41
    +        # This is just an example target which is valid. But it doesn't make
    
    42
    +        # any difference and could be anything for these tests.
    
    43
    +        self.target = SimpleNamespace(tor_browser_build_alias="linux", cpu="x86_64")
    
    44
    +
    
    45
    +    @patch("mozbuild.tbbutils.list_files_http")
    
    46
    +    def test_no_files_returns_none(self, mock_list_files):
    
    47
    +        mock_list_files.return_value = []
    
    48
    +        result = get_artifact_path(self.url, self.artifact, self.target)
    
    49
    +        self.assertIsNone(result)
    
    50
    +
    
    51
    +    @patch("mozbuild.tbbutils.list_files_http")
    
    52
    +    def test_single_artifact_match(self, mock_list_files):
    
    53
    +        mock_list_files.return_value = ["artifact-1.zip"]
    
    54
    +        result = get_artifact_path(self.url, self.artifact, self.target)
    
    55
    +        self.assertEqual(result, f"{self.url}/{self.artifact}/artifact-1.zip")
    
    56
    +
    
    57
    +    @patch("mozbuild.tbbutils.list_files_http")
    
    58
    +    def test_artifact_without_os_returns_first(self, mock_list_files):
    
    59
    +        mock_list_files.return_value = ["artifact-1.zip", "artifact-2.zip"]
    
    60
    +        result = get_artifact_path(self.url, self.artifact, self.target)
    
    61
    +        self.assertTrue(result.startswith(f"{self.url}/{self.artifact}/"))
    
    62
    +        self.assertIn("artifact-", result)
    
    63
    +
    
    64
    +    @patch("mozbuild.tbbutils.list_files_http")
    
    65
    +    def test_artifact_with_os_match(self, mock_list_files):
    
    66
    +        mock_list_files.return_value = [
    
    67
    +            "artifact-windows.zip",
    
    68
    +            "artifact-linux.zip",
    
    69
    +        ]
    
    70
    +        result = get_artifact_path(self.url, self.artifact, self.target)
    
    71
    +        self.assertEqual(result, f"{self.url}/{self.artifact}/artifact-linux.zip")
    
    72
    +
    
    73
    +    @patch("mozbuild.tbbutils.list_files_http")
    
    74
    +    def test_artifact_with_cpu_match(self, mock_list_files):
    
    75
    +        mock_list_files.return_value = [
    
    76
    +            "artifact-linux-arm.zip",
    
    77
    +            "artifact-linux-x86_64.zip",
    
    78
    +        ]
    
    79
    +        result = get_artifact_path(self.url, self.artifact, self.target)
    
    80
    +        self.assertEqual(
    
    81
    +            result, f"{self.url}/{self.artifact}/artifact-linux-x86_64.zip"
    
    82
    +        )
    
    83
    +
    
    84
    +    @patch("mozbuild.tbbutils.list_files_http")
    
    85
    +    def test_artifact_with_prefix(self, mock_list_files):
    
    86
    +        mock_list_files.return_value = ["artifact-1.zip"]
    
    87
    +
    
    88
    +        prefix = "prefix"
    
    89
    +        result = get_artifact_path(self.url, self.artifact, self.target, prefix=prefix)
    
    90
    +        self.assertEqual(result, f"{self.url}/{prefix}/artifact-1.zip")
    
    91
    +        mock_list_files.assert_called_with(f"{self.url}/{prefix}?C=M;O=D")
    
    92
    +
    
    93
    +
    
    94
    +class TestListFilesHttp(unittest.TestCase):
    
    95
    +    def setUp(self):
    
    96
    +        self.url = "http://example.com"
    
    97
    +
    
    98
    +    @patch("mozbuild.tbbutils.urlopen")
    
    99
    +    def test_non_200_status_returns_empty(self, mock_urlopen):
    
    100
    +        mock_resp = MagicMock()
    
    101
    +        mock_resp.status = 404
    
    102
    +        mock_resp.read.return_value = b""
    
    103
    +        mock_urlopen.return_value.__enter__.return_value = mock_resp
    
    104
    +
    
    105
    +        result = list_files_http(self.url)
    
    106
    +        self.assertEqual(result, [])
    
    107
    +
    
    108
    +    @patch("mozbuild.tbbutils.urlopen")
    
    109
    +    def test_exception_returns_empty(self, mock_urlopen):
    
    110
    +        mock_urlopen.side_effect = Exception("network error")
    
    111
    +        result = list_files_http(self.url)
    
    112
    +        self.assertEqual(result, [])
    
    113
    +
    
    114
    +    @patch("mozbuild.tbbutils.urlopen")
    
    115
    +    def test_regular_links(self, mock_urlopen):
    
    116
    +        html = b"""
    
    117
    +        <html><body>
    
    118
    +        <a href="../">Parent</a>
    
    119
    +        <a href="file1.zip">file1</a>
    
    120
    +        <a href="file2.zip">file2</a>
    
    121
    +        </body></html>
    
    122
    +        """
    
    123
    +        mock_resp = MagicMock()
    
    124
    +        mock_resp.status = 200
    
    125
    +        mock_resp.read.return_value = html
    
    126
    +        mock_urlopen.return_value.__enter__.return_value = mock_resp
    
    127
    +
    
    128
    +        result = list_files_http(self.url)
    
    129
    +        self.assertEqual(result, ["file1.zip", "file2.zip"])
    
    130
    +
    
    131
    +    @patch("mozbuild.tbbutils.urlopen")
    
    132
    +    def test_tor_expert_bundle_rewrites(self, mock_urlopen):
    
    133
    +        html = """
    
    134
    +            <a href="tor-expert-bundle">bundle</a>
    
    135
    +        """
    
    136
    +        mock_resp = MagicMock()
    
    137
    +        mock_resp.status = 200
    
    138
    +        mock_resp.read.return_value = html.encode()
    
    139
    +        mock_urlopen.return_value.__enter__.return_value = mock_resp
    
    140
    +
    
    141
    +        result = list_files_http(self.url)
    
    142
    +        self.assertEqual(
    
    143
    +            result,
    
    144
    +            [
    
    145
    +                "tor-expert-bundle/tor-expert-bundle.tar.gz",
    
    146
    +            ],
    
    147
    +        )
    
    148
    +
    
    149
    +
    
    150
    +if __name__ == "__main__":
    
    151
    +    mozunit.main()