diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index cd1bc6eb72..add040774c 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -18,6 +18,7 @@ Release with new features and bugfixes: * https://github.com/devonfw/IDEasy/issues/2607[#2607]: Align tool help for corepack * https://github.com/devonfw/IDEasy/issues/2322[#2322]: Use a consistent IDEasy icon across all operating systems * https://github.com/devonfw/IDEasy/issues/1209[#1209]: Improve confusing migration version message of `ide status` +* https://github.com/devonfw/IDEasy/issues/2714[#2714]: oc url-updater misses all versions since OpenShift 4.10 The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/51?closed=1[milestone 2026.10.001]. diff --git a/url-updater/src/main/java/com/devonfw/tools/ide/url/tool/oc/OcUrlUpdater.java b/url-updater/src/main/java/com/devonfw/tools/ide/url/tool/oc/OcUrlUpdater.java index a1479b196c..5849ac21b3 100644 --- a/url-updater/src/main/java/com/devonfw/tools/ide/url/tool/oc/OcUrlUpdater.java +++ b/url-updater/src/main/java/com/devonfw/tools/ide/url/tool/oc/OcUrlUpdater.java @@ -13,7 +13,8 @@ public class OcUrlUpdater extends WebsiteUrlUpdater { private static final String DOWNLOAD_BASE_URL = "https://mirror.openshift.com"; private static final String VERSION_BASE_URL = "https://mirror.openshift.com"; - private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d\\.\\d\\.\\d*)"); + // Match only exact version directories (e.g. 4.22.19), skipping -rc folders and partial version prefixes. + private static final Pattern VERSION_PATTERN = Pattern.compile("(?<=href=\")(\\d+\\.\\d+\\.\\d+)(?![\\w.-])"); /** * The Constructor. @@ -22,6 +23,16 @@ public OcUrlUpdater() { super(DOWNLOAD_BASE_URL, VERSION_BASE_URL); } + /** + * Package-private constructor used for testing {@link OcUrlUpdater}. + * + * @param downloadBaseUrl mock URL used as download base. + * @param versionBaseUrl mock URL used as version base. + */ + OcUrlUpdater(String downloadBaseUrl, String versionBaseUrl) { + super(downloadBaseUrl, versionBaseUrl); + } + @Override public String getTool() { diff --git a/url-updater/src/test/java/com/devonfw/tools/ide/url/tool/oc/OcUrlUpdaterTest.java b/url-updater/src/test/java/com/devonfw/tools/ide/url/tool/oc/OcUrlUpdaterTest.java new file mode 100644 index 0000000000..402f8e53ad --- /dev/null +++ b/url-updater/src/test/java/com/devonfw/tools/ide/url/tool/oc/OcUrlUpdaterTest.java @@ -0,0 +1,65 @@ +package com.devonfw.tools.ide.url.tool.oc; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.any; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; + +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import com.devonfw.tools.ide.url.model.folder.UrlRepository; +import com.devonfw.tools.ide.url.updater.AbstractUrlUpdaterTest; +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; + +/** + * Test of {@link OcUrlUpdater}. + */ +@WireMockTest +class OcUrlUpdaterTest extends AbstractUrlUpdaterTest { + + /** + * Tests that {@link OcUrlUpdater} picks up versions with a multi-digit minor version number (e.g. 4.10.0, released after OpenShift 4.10) and skips + * release-candidate folders (e.g. 5.0.0-rc.0). Regression test for #2714. + * + * @param tempDir path to a temporary directory. + * @param wmRuntimeInfo the {@link WireMockRuntimeInfo}. + */ + @Test + void testOcUrlUpdaterPicksUpMultiDigitMinorVersions(@TempDir Path tempDir, WireMockRuntimeInfo wmRuntimeInfo) { + + // arrange + stubFor(get(urlEqualTo("/pub/openshift-v4/clients/ocp/")) + .willReturn(aResponse() + .withStatus(200) + .withBody(readAndResolve( + PATH_INTEGRATION_TEST.resolve("OcUrlUpdater").resolve("ocp-index.html"), + wmRuntimeInfo)))); + + stubFor(any(urlMatching("/pub/openshift-v4/clients/ocp/[0-9.]+/openshift-client-.*")) + .willReturn(aResponse().withStatus(200).withBody(DOWNLOAD_CONTENT))); + + UrlRepository urlRepository = UrlRepository.load(tempDir); + OcUrlUpdater updater = new OcUrlUpdater( + wmRuntimeInfo.getHttpBaseUrl(), + wmRuntimeInfo.getHttpBaseUrl()); + + // act + update(updater, urlRepository); + + // assert + Path ocDir = tempDir.resolve("oc").resolve("oc"); + // single-digit minor version still works + assertUrlVersionOsX64(ocDir.resolve("4.9.59")); + // multi-digit minor versions (the regression, released after OpenShift 4.10) are now picked up + assertUrlVersionOsX64(ocDir.resolve("4.10.0")); + assertUrlVersionOsX64(ocDir.resolve("4.22.19")); + // release-candidate folders must not be extracted as a bogus stable version + assertThat(ocDir.resolve("5.0.0")).doesNotExist(); + } +} diff --git a/url-updater/src/test/resources/integrationtest/OcUrlUpdater/ocp-index.html b/url-updater/src/test/resources/integrationtest/OcUrlUpdater/ocp-index.html new file mode 100644 index 0000000000..0ebe26fb48 --- /dev/null +++ b/url-updater/src/test/resources/integrationtest/OcUrlUpdater/ocp-index.html @@ -0,0 +1,13 @@ + +
+../ +4.9.59/ +4.10.0/ +4.22.19/ +5.0.0-rc.0/ ++ +