Skip to content

Commit

Permalink
Compose Metadata Analyzer: Use v2 URL
Browse files Browse the repository at this point in the history
Signed-off-by: Valentijn Scholten <[email protected]>
  • Loading branch information
valentijnscholten committed Dec 18, 2024
1 parent 45982a2 commit 22b55f7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public class ComposerMetaAnalyzer extends AbstractMetaAnalyzer {
private static final String DEFAULT_BASE_URL = "https://repo.packagist.org";

/**
* @see <a href="https://packagist.org/apidoc#get-package-metadata-v1">Packagist's API doc for "Getting package data - Using the Composer v1 metadata (DEPRECATED)"</a>
* @see <a href="https://packagist.org/apidoc#get-package-data">Packagist's API doc for "Getting package data - Using the Composer v2 metadata"</a>
*/
private static final String API_URL = "/p/%s/%s.json";
private static final String API_URL = "/p2/%s/%s.json";

ComposerMetaAnalyzer() {
this.baseUrl = DEFAULT_BASE_URL;
Expand Down Expand Up @@ -98,7 +98,7 @@ public MetaModel analyze(final Component component) {
final JSONObject responsePackages = jsonObject
.getJSONObject("packages");
if (!responsePackages.has(expectedResponsePackage)) {
// the package no longer exists - like this one: https://repo.packagist.org/p/magento/adobe-ims.json
// the package no longer exists - for v2 there's no example (yet), v1 example https://repo.packagist.org/p/magento/adobe-ims.json
return meta;
}
final JSONObject composerPackage = responsePackages.getJSONObject(expectedResponsePackage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void testAnalyzerFindsVersionWithLeadingV() throws Exception {
.when(
request()
.withMethod("GET")
.withPath("/p/typo3/class-alias-loader.json")
.withPath("/p2/typo3/class-alias-loader.json")
)
.respond(
response()
Expand All @@ -96,6 +96,14 @@ public void testAnalyzerFindsVersionWithLeadingV() throws Exception {
);
}

/*
* This case no longer happens in the composer v2 repositories. It now returns a 404 for all examples from #2134
* - adobe-ims.json
* - adobe-stock-integration.json
* - composter-root-update-plugin.json
* - module-aws-s3.json
* Leaving it here in case we find a different package triggering this behaviour.
@Test
public void testAnalyzerGetsUnexpectedResponseContentCausingLatestVersionBeingNull() throws Exception {
Component component = new Component();
Expand All @@ -109,7 +117,7 @@ public void testAnalyzerGetsUnexpectedResponseContentCausingLatestVersionBeingNu
.when(
request()
.withMethod("GET")
.withPath("/p/magento/adobe-ims.json")
.withPath("/p2/magento/adobe-ims.json")
)
.respond(
response()
Expand All @@ -123,12 +131,41 @@ public void testAnalyzerGetsUnexpectedResponseContentCausingLatestVersionBeingNu
Assert.assertNull(metaModel.getLatestVersion());
}
*/

@Test
public void testAnalyzerGetsUnexpectedResponseContent404() throws Exception {
Component component = new Component();
ComposerMetaAnalyzer analyzer = new ComposerMetaAnalyzer();

component.setPurl(new PackageURL("pkg:composer/magento/[email protected]"));
final File packagistFile = getResourceFile("magento", "adobe-ims");

analyzer.setRepositoryBaseUrl(String.format("http://localhost:%d", mockServer.getPort()));
new MockServerClient("localhost", mockServer.getPort())
.when(
request()
.withMethod("GET")
.withPath("/p2/magento/adobe-ims.json")
)
.respond(
response()
.withStatusCode(404)
.withHeader(HttpHeaders.CONTENT_TYPE, "application/json")
);

analyzer.analyze(component);
MetaModel metaModel = analyzer.analyze(component);

Assert.assertNull(metaModel.getLatestVersion());
}


private static File getResourceFile(String namespace, String name) throws Exception{
return new File(
Thread.currentThread().getContextClassLoader()
.getResource(String.format(
"unit/tasks/repositories/https---repo.packagist.org-p-%s-%s.json",
"unit/tasks/repositories/https---repo.packagist.org-p2-%s-%s.json",
namespace,
name
))
Expand Down

This file was deleted.

Loading

0 comments on commit 22b55f7

Please sign in to comment.