oscerd commented on code in PR #28104: URL: https://github.com/apache/camel/pull/28104#discussion_r4314492490
########## components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCOperationHeaderOverrideTest.java: ########## @@ -0,0 +1,120 @@ +/* + * 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 java.security.Security; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.EndpointInject; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * The documented CamelPQCOperation header may only select an operation the endpoint actually holds resources for. + * Crossing from the signature family to the key encapsulation family used to dereference a null KeyGenerator. + */ +public class PQCOperationHeaderOverrideTest extends CamelTestSupport { + + @EndpointInject("mock:out") + protected MockEndpoint result; + + @Produce("direct:sign") + protected ProducerTemplate template; + + @BeforeEach + void addProviders() { + if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { + Security.addProvider(new BouncyCastleProvider()); + } + if (Security.getProvider(BouncyCastlePQCProvider.PROVIDER_NAME) == null) { + Security.addProvider(new BouncyCastlePQCProvider()); + } + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:sign") + .to("pqc:sign?operation=sign&signatureAlgorithm=MLDSA") + .to("mock:out"); + } + }; + } + + @Test + void anOverrideCrossingToTheKemFamilyIsRejectedWithAClearMessage() { + CamelExecutionException e = assertThrows(CamelExecutionException.class, + () -> template.sendBodyAndHeader("direct:sign", "Hello", + PQCConstants.OPERATION, PQCOperations.generateSecretKeyEncapsulation)); + + Throwable cause = e.getCause(); + assertInstanceOf(IllegalArgumentException.class, cause, + "expected a configuration error, not a NullPointerException: " + cause); + + String message = cause.getMessage(); + assertTrue(message.contains("generateSecretKeyEncapsulation"), "must name the requested operation: " + message); + assertTrue(message.contains("sign"), "must name the configured operation: " + message); Review Comment: Fixed in b0b5fb7 — the assertion is now `contains("configured for 'sign'")`. Also rebased onto @gnodet's `Regen` commit rather than force-pushing over it. That regen was mine to do: the `javaType` change is mirrored into the endpoint DSL as well as `pqc.json` and the catalog, and I had only done the latter two. Thanks for picking it up. _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]
