gnodet-bot commented on code in PR #30561:
URL: https://github.com/apache/camel/pull/30561#discussion_r4652791195


##########
tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/CamelWebsiteContentTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.maven.packaging;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.http.HttpClient;
+import java.nio.charset.StandardCharsets;
+
+import com.sun.net.httpserver.HttpServer;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * CAMEL-27347: a sync with camel-website fails instead of writing a shorter 
list when GitHub does not answer, so a
+ * scheduled run never removes advisories or releases from the catalog.
+ */
+class CamelWebsiteContentTest {
+
+    private HttpServer server;
+    private String base;
+
+    @BeforeEach
+    void start() throws IOException {
+        server = HttpServer.create(new 
InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
+        reply("/security", 200, """
+                [{"name": "CVE-2026-1.md", "download_url": 
"%1$s/raw/CVE-2026-1.md"},
+                 {"name": "_index.md", "download_url": 
"%1$s/raw/_index.md"}]""");
+        reply("/empty", 200, "[]");
+        reply("/limited", 403, "{\"message\": \"API rate limit exceeded\"}");
+        reply("/raw/CVE-2026-1.md", 200, "---\ncve: CVE-2026-1\n---\n");
+        server.start();
+        base = "http://127.0.0.1:"; + server.getAddress().getPort();
+    }
+
+    @AfterEach
+    void stop() {
+        server.stop(0);
+    }
+
+    private void reply(String path, int status, String body) {
+        server.createContext(path, exchange -> {
+            byte[] bytes = 
body.formatted(base).getBytes(StandardCharsets.UTF_8);
+            exchange.sendResponseHeaders(status, bytes.length);
+            try (OutputStream out = exchange.getResponseBody()) {
+                out.write(bytes);
+            }
+        });
+    }
+
+    @Test
+    void listsTheMatchingFiles() throws Exception {
+        try (HttpClient client = HttpClient.newHttpClient()) {
+            assertThat(CamelWebsiteContent.downloadUrls(client, base + 
"/security", n -> n.startsWith("CVE-")))
+                    .containsExactly(base + "/raw/CVE-2026-1.md");
+            assertThat(CamelWebsiteContent.download(client, base + 
"/raw/CVE-2026-1.md")).contains("cve: CVE-2026-1");
+        }
+    }
+
+    @Test
+    void failsWhenRateLimited() {
+        try (HttpClient client = HttpClient.newHttpClient()) {
+            assertThatThrownBy(() -> CamelWebsiteContent.downloadUrls(client, 
base + "/limited", n -> true))
+                    
.isInstanceOf(IOException.class).hasMessageContaining("HTTP status 403")
+                    .hasMessageContaining("GITHUB_TOKEN");
+        }
+    }
+
+    @Test
+    void failsWhenNothingIsListed() {
+        try (HttpClient client = HttpClient.newHttpClient()) {
+            assertThatThrownBy(() -> CamelWebsiteContent.downloadUrls(client, 
base + "/empty", n -> true))
+                    .isInstanceOf(IOException.class).hasMessageContaining("No 
files found");
+            assertThatThrownBy(() -> CamelWebsiteContent.downloadUrls(client, 
base + "/security", n -> n.endsWith(".adoc")))
+                    .isInstanceOf(IOException.class).hasMessageContaining("No 
files found");
+        }
+    }
+
+    @Test
+    void failsWhenAFileCannotBeDownloaded() {
+        try (HttpClient client = HttpClient.newHttpClient()) {
+            assertThatThrownBy(() -> CamelWebsiteContent.download(client, base 
+ "/raw/missing.md"))
+                    
.isInstanceOf(IOException.class).hasMessageContaining("HTTP status 404");
+        }
+    }
+
+    @Test
+    void theTokenIsOnlyForTheGitHubApi() {
+        
assertThat(CamelWebsiteContent.request("https://raw.githubusercontent.com/apache/camel-website/main/x.md";)
+                .headers().firstValue("Authorization")).isEmpty();

Review Comment:
   💡 **Nit:** `theTokenIsOnlyForTheGitHubApi` only tests the negative case — 
that `raw.githubusercontent.com` does NOT receive an `Authorization` header. 
Consider adding a companion assertion for the positive case: that 
`api.github.com` URLs DO receive the token. Without the positive-case test, a 
regression that strips the token from GitHub API requests would not be caught 
here.
   
   The negative case alone is what the test name implies — just noting the gap.



##########
.github/workflows/sync-catalog-website.yml:
##########
@@ -0,0 +1,111 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+name: Sync catalog with camel-website
+
+# The catalog ships the Apache Camel security advisories and the known 
releases, generated from the
+# camel-website repository (content/security, content/releases) by the 
update-security-advisories and
+# update-camel-releases goals. This workflow runs them every week, and before 
a release on demand, and opens
+# a PR when something changed, so a release never ships stale lists 
(CAMEL-27347). Like generate-sbom.yml it
+# lives on main only and checks out each branch of the matrix in turn; the LTS 
branches have no advisories.
+on:
+  schedule:
+    # Every Monday at 06:00 UTC
+  - cron: '0 6 * * 1'
+  workflow_dispatch:
+
+permissions: {}
+jobs:
+  sync:
+    if: github.repository == 'apache/camel'
+    permissions:
+      contents: write
+      pull-requests: write # to create a PR (peter-evans/create-pull-request)
+
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+          - branch: 'main'
+            goals: 'camel-package:update-security-advisories 
camel-package:update-camel-releases'
+          - branch: 'camel-4.22.x'
+            goals: 'camel-package:update-camel-releases'
+          - branch: 'camel-4.18.x'
+            goals: 'camel-package:update-camel-releases'
+    steps:
+      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 
v7.0.1
+        with:
+          ref: ${{ matrix.branch }}
+          persist-credentials: false
+      - name: Set up JDK 21
+        uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # 
v6.3.0
+        with:
+          distribution: 'temurin'
+          java-version: '21'
+          cache: 'maven'
+      - name: Count the entries before the sync
+        run: |
+          for f in $(git ls-files 
'catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/advisories/*.json'
 
'catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/releases/*.json');
 do
+            echo "$f $(jq length "$f")"
+          done > "$RUNNER_TEMP/before.txt"

Review Comment:
   💡 **Edge case:** On a fresh branch that has never had the JSON files 
committed, `git ls-files '.../*.json'` produces no output, so `before.txt` is 
empty. The `while read` loop then exits immediately — the entry-count check 
passes vacuously and no error is raised even though the files are entirely 
missing. In practice this only matters for a brand-new branch. Worth noting; a 
simple guard could be:
   ```bash
   if [ ! -s "$RUNNER_TEMP/before.txt" ]; then
     echo "::warning::No existing catalog JSON files found — skipping 
entry-count check"
   fi
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to