From patchwork Fri Dec 20 11:26:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 54452 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89844E77197 for ; Fri, 20 Dec 2024 11:26:41 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.118]) by mx.groups.io with SMTP id smtpd.web11.149744.1734693993154756588 for ; Fri, 20 Dec 2024 03:26:37 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="dkim: body hash did not verify" header.i=@weidmueller.com header.s=selector2 header.b=KMKEckgy; spf=pass (domain: weidmueller.com, ip: 40.107.20.118, mailfrom: stefan.herbrechtsmeier-oss@weidmueller.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j3Dnl7DmzD8vGawq0EKZ09r8xqNZ7vm5GJzoyQidkl4iqYW4txRCE4+3NBNyRRCjJEQUDPkPsfpXcoNfXYn8/UtDRwkza78wj3vmTKCRZdjohjLrie7vb6X/wFWBLGNetwe4gEhwmiDe970zgCqUXMYBZ8oZ2hFDctvzZ6MvzaFWIddXWMFpwolwekiagfuEsdiv4mJhcv/cK3dOxArgsKY3JNXHxKu51htTN7APoSE9ut6LTX9xTTiUzvr1N93xIAs2xPjD+LgweoPlq+0Lg3fi1uMdJaU/RTjIhlVxzZJc85wK1ofS1PEogMXBkBSnJ5i2NM20F0NA2jr3nh5nWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9i3bNDHqF84Ldo1B37JTzHr5cWaUGE5wPJDTGQw9/m8=; b=Rl3KFA4iLFte/pSJdIzgt+A+vFSjv2lYs9emXPRZU5ar83+cchRLgXEELs5Epb29JEtQaD9udrUxY5vHge9N1Th7IfcmGtQsrCqigI5MoXbo2s7/LMnOC3vfF+o5aad1BT2UX2YhmKvZ8OFc49lYxYSrzhR4BHJaBy8IfwOaAldbynW5CAtjfiUiUrdeei9176Rga9bKygZ2oOgGH4MHhwbiYnk0pb1/8drSPsY0SkVlsE4tXhrfBa61nkNFevDVSh6cFPKhlsUYOnIrEcC+sWnP4hCcfMA/CiaKazo7nc0jmThgyX6kF0QpnPg671eYWQISZtSXOUGZMhMQAHoPYg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=weidmueller.com; dmarc=pass action=none header.from=weidmueller.com; dkim=pass header.d=weidmueller.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=weidmueller.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9i3bNDHqF84Ldo1B37JTzHr5cWaUGE5wPJDTGQw9/m8=; b=KMKEckgyuxsxA+v4QCLE5n4oArpZ9+shb4g3szld+Yu1d+oreYWtzUojNeAM2MIirf6erxugtlCxPTz5ki2I3XP/ZBpO/DZg6sFYpYk0h7soufhLD9TxNq3EEk9NWTMmyOWHXGwIq5e3G+eBMetv94ZgUHACoc6dD6Sfk9n6yhQTPKQnx+2vF096VI+kGkN1y9Osh6BphLWncsovL65yrZI8R22KR9fpeP2SNYFd5zogfj/dq9mRlz7Pom4g84x2jZZjhBUiAL1iTgRtMBZPS0dM9pjRqOjeJnjIQZ730O+rkOMlwarK04nJ/nxNz97ZCKLnn9kxgV7IPGD7WkQnJA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=weidmueller.com; Received: from PAXPR08MB6969.eurprd08.prod.outlook.com (2603:10a6:102:1d8::23) by DU0PR08MB8256.eurprd08.prod.outlook.com (2603:10a6:10:410::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8272.14; Fri, 20 Dec 2024 11:26:29 +0000 Received: from PAXPR08MB6969.eurprd08.prod.outlook.com ([fe80::3b1:b329:1ed9:dad4]) by PAXPR08MB6969.eurprd08.prod.outlook.com ([fe80::3b1:b329:1ed9:dad4%3]) with mapi id 15.20.8272.013; Fri, 20 Dec 2024 11:26:29 +0000 From: Stefan Herbrechtsmeier To: bitbake-devel@lists.openembedded.org CC: Stefan Herbrechtsmeier Subject: [RFC PATCH 13/21] tests: fetch: adapt npm test cases Date: Fri, 20 Dec 2024 12:26:04 +0100 Message-ID: <20241220112613.22647-14-stefan.herbrechtsmeier-oss@weidmueller.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241220112613.22647-1-stefan.herbrechtsmeier-oss@weidmueller.com> References: <20241220112613.22647-1-stefan.herbrechtsmeier-oss@weidmueller.com> X-ClientProxiedBy: FR0P281CA0106.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a8::7) To PAXPR08MB6969.eurprd08.prod.outlook.com (2603:10a6:102:1d8::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR08MB6969:EE_|DU0PR08MB8256:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f0e3a87-07cc-4bf8-c2b6-08dd20e92561 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|52116014|1800799024|376014|38350700014; X-Microsoft-Antispam-Message-Info: ip+DCzS7HG1sxQkO3gA0IZ2fz22QtNnhW8uzzVzqbGqZc4R0k3HNi+UjFUkHW7E3V/UkmAU+zOWW4LmXVS4lvQudQT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7INi4k6LtyT7r8iFx0CHpW32vqWDHM47fd+hcZo+yYGuZCLwpGV6dHRnWnbYmJNNXJgULZFx4Oo9zfJ5IEYIsZM2VPixFwHxuc5SNA+4qtaJF1bMKtLOBEX+RTOUGLQ2Z4XFq2ElgfJVWs5dbknx2i8xUaKDBOc96KaZSaJ2w7x3pEYoEkDSSCehZXqDPGuwLYmx4BexT+Bb6U3HMhu7ImzvXr/ZPLfPLkHUPdtVmM38j8sBUmaN4iVtT4G5PXCygxZxznkoI749iIA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR08MB6969.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(52116014)(1800799024)(376014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 46CSJ1QWhVC7DfdTkWOuJpDdh6Vrll6E4fi9NYP6XIIZ5gLf0rQ7hCw1WAWOEdnj5z3QNBMUE9v9zgaa0pz3jku6Z6Cis4ziifsoVQdywJZ7gMIJGfmVatfTEvIJxnefPdjIOxI5E8I2ixgCjeWLD1GO0kK5/Jos8sPFjcs8zGhQ0IPtKAFB1ZVAaVQ8Pg0OLj7jmTYNKh6F6cwSovbR4t6M6Gmw+a8i9WlLLZne4RlJzr1aiSKxZOgRxHdJg6uR2xzJefWgyrW3JZlYoc2heSww3pWNV8NYM/MkW7Zqji/PrkAXAYDp8WLv3cVRbsuMvUkKcz/WlPNaILzng3yNyvSgLF4rudiouWsh5zWf9oYjLveE4cTze71gUVtpwwcQ+HLclijuopgUNlqBWY/tZqNeL16VXOHu1FTES6vSbZqvSN2cmujoOw7/2hv+C8dIMzsEAS7UEubUFi1MNyiX/MF+iuMkRNaGZHvAZON39AntmybbIXihblnXW7PjN64iP9dPMbX/pbhDyhTci4GuFHeSqbdx5ja7ZyFMvKyELJrbs4LVlOScYMMI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rg: weidmueller.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f0e3a87-07cc-4bf8-c2b6-08dd20e92561 X-MS-Exchange-CrossTenant-AuthSource: PAXPR08MB6969.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2024 11:26:28.4098 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e4289438-1c5f-4c95-a51a-ee553b8b18ec X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vRwRHHX0n6DStVWTBc5MumiFBdYfvspvR+N60X6fptIGhNZoos6BHijCdareD8Co5sGUro93oulnayJ50f1RPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8256 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Fri, 20 Dec 2024 11:26:41 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/bitbake-devel/message/16937 From: Stefan Herbrechtsmeier Adapt the npm test cases to the reworked npm fetcher: * Add test case for latest version check * Remove decorator for npm binary check * Use common npm package for test cases * Define excepted file names * Remove test cases for (pre)mirrors, network and invalid urls because the reworked class is based on the wget fetcher. Signed-off-by: Stefan Herbrechtsmeier --- lib/bb/tests/fetch.py | 221 +++++++----------------------------------- 1 file changed, 36 insertions(+), 185 deletions(-) diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py index 3fd4c82cd..09f493f8a 100644 --- a/lib/bb/tests/fetch.py +++ b/lib/bb/tests/fetch.py @@ -1507,6 +1507,14 @@ class FetchLatestVersionTest(FetcherTest): : "0.9.29" } + test_npm_uris = { + # basic example; version pattern "A.B.C" + ( + "types-node", + "npm://registry.npmjs.org;package=@types/node;version=16.0.0" + ) : "22.10.2" + } + @skipIfNoNetwork() def test_git_latest_versionstring(self): for k, v in self.test_git_uris.items(): @@ -1557,6 +1565,17 @@ class FetchLatestVersionTest(FetcherTest): r = bb.utils.vercmp_string(v, verstring) self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) + @skipIfNoNetwork() + def test_npm_latest_versionstring(self): + for k, v in self.test_npm_uris.items(): + self.d.setVar("PN", k[0]) + ud = bb.fetch2.FetchData(k[1], self.d) + pupver = ud.method.latest_versionstring(ud, self.d) + verstring = pupver[0] + self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0]) + r = bb.utils.vercmp_string(v, verstring) + self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) + class FetchCheckStatusTest(FetcherTest): test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz", "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz", @@ -2618,216 +2637,48 @@ class CrateTest(FetcherTest): fetcher.download() class NPMTest(FetcherTest): - def skipIfNoNpm(): - import shutil - if not shutil.which("npm"): - return unittest.skip("npm not installed") - return lambda f: f - - @skipIfNoNpm() @skipIfNoNetwork() def test_npm(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"] + urls = [ + "npm://registry.npmjs.org;package=@types/node;version=22.10.2;" + "sha256sum=9dad888e5280e9969393d7410e26d4edf726a828ee4762318c8ddf6fcfee793e" + ] fetcher = bb.fetch.Fetch(urls, self.d) ud = fetcher.ud[fetcher.urls[0]] fetcher.download() - self.assertTrue(os.path.exists(ud.localpath)) - self.assertTrue(os.path.exists(ud.localpath + ".done")) - self.assertTrue(os.path.exists(ud.resolvefile)) + self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/@types-node-22.10.2.tgz"))) + self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/@types-node-22.10.2.tgz.done"))) fetcher.unpack(self.unpackdir) - unpackdir = os.path.join(self.unpackdir, "npm") - self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json"))) - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_bad_checksum(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"] - # Fetch once to get a tarball - fetcher = bb.fetch.Fetch(urls, self.d) - ud = fetcher.ud[fetcher.urls[0]] - fetcher.download() - self.assertTrue(os.path.exists(ud.localpath)) - # Modify the tarball - bad = b"bad checksum" - with open(ud.localpath, "wb") as f: - f.write(bad) - # Verify that the tarball is fetched again - fetcher.download() - badsum = hashlib.sha512(bad).hexdigest() - self.assertTrue(os.path.exists(ud.localpath + "_bad-checksum_" + badsum)) - self.assertTrue(os.path.exists(ud.localpath)) - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_premirrors(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"] - # Fetch once to get a tarball - fetcher = bb.fetch.Fetch(urls, self.d) - ud = fetcher.ud[fetcher.urls[0]] - fetcher.download() - self.assertTrue(os.path.exists(ud.localpath)) - - # Setup the mirror by renaming the download directory - mirrordir = os.path.join(self.tempdir, "mirror") - bb.utils.rename(self.dldir, mirrordir) - os.mkdir(self.dldir) - - # Configure the premirror to be used - self.d.setVar("PREMIRRORS", "https?$://.*/.* file://%s/npm2" % mirrordir) - self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") - - # Fetch again - self.assertFalse(os.path.exists(ud.localpath)) - # The npm fetcher doesn"t handle that the .resolved file disappears - # while the fetcher object exists, which it does when we rename the - # download directory to "mirror" above. Thus we need a new fetcher to go - # with the now empty download directory. - fetcher = bb.fetch.Fetch(urls, self.d) - ud = fetcher.ud[fetcher.urls[0]] - fetcher.download() - self.assertTrue(os.path.exists(ud.localpath)) - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_premirrors_with_specified_filename(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"] - # Fetch once to get a tarball - fetcher = bb.fetch.Fetch(urls, self.d) - ud = fetcher.ud[fetcher.urls[0]] - fetcher.download() - self.assertTrue(os.path.exists(ud.localpath)) - # Setup the mirror - mirrordir = os.path.join(self.tempdir, "mirror") - bb.utils.mkdirhier(mirrordir) - mirrorfilename = os.path.join(mirrordir, os.path.basename(ud.localpath)) - os.replace(ud.localpath, mirrorfilename) - self.d.setVar("PREMIRRORS", "https?$://.*/.* file://%s" % mirrorfilename) - self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") - # Fetch again - self.assertFalse(os.path.exists(ud.localpath)) - fetcher.download() - self.assertTrue(os.path.exists(ud.localpath)) - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_mirrors(self): - # Fetch once to get a tarball - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"] - fetcher = bb.fetch.Fetch(urls, self.d) - ud = fetcher.ud[fetcher.urls[0]] - fetcher.download() - self.assertTrue(os.path.exists(ud.localpath)) - # Setup the mirror - mirrordir = os.path.join(self.tempdir, "mirror") - bb.utils.mkdirhier(mirrordir) - os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath))) - self.d.setVar("MIRRORS", "https?$://.*/.* file://%s/" % mirrordir) - # Update the resolved url to an invalid url - with open(ud.resolvefile, "r") as f: - url = f.read() - uri = URI(url) - uri.path = "/invalid" - with open(ud.resolvefile, "w") as f: - f.write(str(uri)) - # Fetch again - self.assertFalse(os.path.exists(ud.localpath)) - fetcher.download() - self.assertTrue(os.path.exists(ud.localpath)) + self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm/package.json'))) - @skipIfNoNpm() @skipIfNoNetwork() def test_npm_destsuffix_downloadfilename(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz"] + urls = [ + "npm://registry.npmjs.org;package=@types/node;version=22.10.2;" + "destsuffix=foo/bar;downloadfilename=npm2/foo-bar.tgz;" + "sha256sum=9dad888e5280e9969393d7410e26d4edf726a828ee4762318c8ddf6fcfee793e" + ] fetcher = bb.fetch.Fetch(urls, self.d) fetcher.download() self.assertTrue(os.path.exists(os.path.join(self.dldir, "npm2/foo-bar.tgz"))) fetcher.unpack(self.unpackdir) - unpackdir = os.path.join(self.unpackdir, "foo", "bar") - self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json"))) - - def test_npm_no_network_no_tarball(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"] - self.d.setVar("BB_NO_NETWORK", "1") - fetcher = bb.fetch.Fetch(urls, self.d) - with self.assertRaises(bb.fetch2.NetworkAccess): - fetcher.download() - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_no_network_with_tarball(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0"] - # Fetch once to get a tarball - fetcher = bb.fetch.Fetch(urls, self.d) - fetcher.download() - # Disable network access - self.d.setVar("BB_NO_NETWORK", "1") - # Fetch again - fetcher.download() - fetcher.unpack(self.unpackdir) - unpackdir = os.path.join(self.unpackdir, "npm") - self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json"))) + self.assertTrue(os.path.exists(os.path.join(self.unpackdir, "foo/bar/package.json"))) - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_registry_alternate(self): - urls = ["npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0"] - fetcher = bb.fetch.Fetch(urls, self.d) - fetcher.download() - fetcher.unpack(self.unpackdir) - unpackdir = os.path.join(self.unpackdir, "npm") - self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json"))) - - @skipIfNoNpm() @skipIfNoNetwork() def test_npm_version_latest(self): - url = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest"] - fetcher = bb.fetch.Fetch(urls, self.d) - fetcher.download() - fetcher.unpack(self.unpackdir) - unpackdir = os.path.join(self.unpackdir, "npm") - self.assertTrue(os.path.exists(os.path.join(unpackdir, "package.json"))) - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_registry_invalid(self): - urls = ["npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0"] - fetcher = bb.fetch.Fetch(urls, self.d) - with self.assertRaises(bb.fetch2.FetchError): - fetcher.download() - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_package_invalid(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0"] - fetcher = bb.fetch.Fetch(urls, self.d) - with self.assertRaises(bb.fetch2.FetchError): - fetcher.download() - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_version_invalid(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid"] + urls = ["npm://registry.npmjs.org;package=@types/node;version=latest"] with self.assertRaises(bb.fetch2.ParameterError): - fetcher = bb.fetch.Fetch(urls, self.d) - - @skipIfNoNpm() - @skipIfNoNetwork() - def test_npm_registry_none(self): - urls = ["npm://;package=@savoirfairelinux/node-server-example;version=1.0.0"] - with self.assertRaises(bb.fetch2.MalformedUrl): - fetcher = bb.fetch.Fetch(urls, self.d) + bb.fetch.Fetch(urls, self.d) - @skipIfNoNpm() @skipIfNoNetwork() def test_npm_package_none(self): - urls = ["npm://registry.npmjs.org;version=1.0.0"] + urls = ["npm://registry.npmjs.org;version=22.10.2"] with self.assertRaises(bb.fetch2.MissingParameterError): fetcher = bb.fetch.Fetch(urls, self.d) - @skipIfNoNpm() @skipIfNoNetwork() def test_npm_version_none(self): - urls = ["npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example"] + urls = ["npm://registry.npmjs.org;package=@types/node"] with self.assertRaises(bb.fetch2.MissingParameterError): fetcher = bb.fetch.Fetch(urls, self.d)