oscerd commented on code in PR #28106: URL: https://github.com/apache/camel/pull/28106#discussion_r4313368531
########## components/camel-pqc/src/test/java/org/apache/camel/component/pqc/PQCMaterialConsistencyTest.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.component.pqc; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Guards the consistency rules the sibling key material classes are meant to follow but drifted away from, so the next + * clone-and-tweak does not reintroduce the divergence. + */ +class PQCMaterialConsistencyTest { + + private static Path materialSourceRoot() throws URISyntaxException { + // the tests run from the module directory, so the sources sit at a fixed relative path + Path root = Paths.get("src/main/java/org/apache/camel/component/pqc/crypto"); + assertTrue(Files.isDirectory(root), "cannot locate the key material sources at " + root.toAbsolutePath()); + return root; + } + + private static List<Path> materialSources() throws Exception { + List<Path> sources = new ArrayList<>(); + try (Stream<Path> files = Files.walk(materialSourceRoot())) { + files.filter(p -> p.getFileName().toString().startsWith("PQCDefault")) + .filter(p -> p.getFileName().toString().endsWith("Material.java")) + .forEach(sources::add); + } + assertFalse(sources.isEmpty(), "no key material sources found"); + return sources; + } + + @Test + void everyKeyMaterialSeedsItsGeneratorWithSecureRandomHelper() throws Exception { + List<String> offenders = new ArrayList<>(); + for (Path source : materialSources()) { + String text = Files.readString(source, StandardCharsets.UTF_8); + if (!text.contains("SecureRandomHelper.getSecureRandom()")) { + offenders.add(source.getFileName().toString()); + } + } + + assertTrue(offenders.isEmpty(), + "these key material classes fall back to the provider default RNG instead of the shared" + + " SecureRandomHelper: " + offenders); + } + + @ParameterizedTest + @ValueSource(strings = { "MAYO", "SNOVA" }) + void mayoAndSnovaAcceptANamedParameterSet(String algorithm) { + assertTrue(PQCParameterSpecResolver.isSupported(algorithm), + algorithm + " has a name-addressable BouncyCastle parameter spec and must accept parameterSpec"); + } + + @Test + void mayoResolvesEveryDocumentedLevel() { + for (String name : new String[] { "mayo1", "mayo2", "mayo3", "mayo5" }) { + assertTrue(PQCParameterSpecResolver.resolve("MAYO", name).toString().toLowerCase().contains("mayo"), + "MAYO must resolve " + name); Review Comment: Both points were right — fixed in 996df4a. The assertion now checks non-null, the spec type, and the resolved level via `getName()`. One adjustment to the suggested snippet: `getName()` answers the canonical form rather than echoing the requested name, so `assertEquals(name, spec.getName())` fails with `expected: <mayo1> but was: <MAYO-1>`. The test is now a `@CsvSource` pinning each requested name to its canonical result (`mayo1,MAYO-1` and so on), which has the side benefit of verifying that the level requested is the level returned, not merely that something resolved. _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]
