oscerd commented on code in PR #28089: URL: https://github.com/apache/camel/pull/28089#discussion_r4313362804
########## components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCEndpointProviderLifecycleTest.java: ########## @@ -0,0 +1,80 @@ +/* + * 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.component.pqc; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.junit.jupiter.api.Test; + +import static java.security.Security.getProvider; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * The BouncyCastle providers live in the JVM-global {@link java.security.Security} registry, so a PQC endpoint must + * never remove them on stop - other endpoints, other CamelContexts and unrelated code in the same JVM rely on them. + */ +public class PQCEndpointProviderLifecycleTest { + + @Test + void stoppingTheContextKeepsTheProvidersRegistered() throws Exception { + try (CamelContext context = new DefaultCamelContext()) { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:sign").to("pqc:sign?operation=sign&signatureAlgorithm=MLDSA"); + } + }); + context.start(); + + assertNotNull(getProvider(BouncyCastleProvider.PROVIDER_NAME), "BC must be registered while running"); + assertNotNull(getProvider(BouncyCastlePQCProvider.PROVIDER_NAME), "BCPQC must be registered while running"); + + context.stop(); + + assertNotNull(getProvider(BouncyCastleProvider.PROVIDER_NAME), + "stopping a PQC endpoint must not de-register the JVM-global BC provider"); + assertNotNull(getProvider(BouncyCastlePQCProvider.PROVIDER_NAME), + "stopping a PQC endpoint must not de-register the JVM-global BCPQC provider"); + } + } + + @Test + void stoppingOneEndpointLeavesTheOtherUsable() throws Exception { + try (CamelContext context = new DefaultCamelContext()) { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() { + from("direct:a").to("pqc:a?operation=sign&signatureAlgorithm=MLDSA"); Review Comment: Applied in af0e5c5. Both routes now carry explicit ids (`a` and `b`) and `stopRoute("a")` reads directly. Agreed the implicit `route1` was a latent trap. _Claude Code on behalf of @oscerd_ -- 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]
