allthingssecurity commented on code in PR #27125: URL: https://github.com/apache/camel/pull/27125#discussion_r4150428189
########## components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatLargePayloadTest.java: ########## @@ -0,0 +1,87 @@ +/* + * 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.converter.crypto; + +import javax.crypto.KeyGenerator; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +/** + * The HMAC (appended by default) is split off in a circular buffer on unmarshal. The buffer must wrap around for any + * message larger than the buffer size (4096 bytes by default). + */ +public class CryptoDataFormatLargePayloadTest extends CamelTestSupport { + + @Test + void testRoundTripSmallerThanBuffer() throws Exception { + doRoundTrip(100); + } + + @Test + void testRoundTripBufferSize() throws Exception { + doRoundTrip(4096); + } + + @Test + void testRoundTripLargerThanBuffer() throws Exception { + doRoundTrip(5000); + } + + @Test + void testRoundTripLarge() throws Exception { + doRoundTrip(100_000); + } + + private void doRoundTrip(int size) throws Exception { Review Comment: Good idea, added in 4eb4c77f48e0: `testTamperedCiphertextLargerThanBufferFailsAuthentication` (one ciphertext byte of a 5000 byte message flipped) and `testTruncatedCiphertextLargerThanBufferFailsAuthentication` (last cipher block dropped) both assert an `IllegalStateException` with `HMACAccumulator.AUTHENTICATION_FAILED`. camel-crypto tests pass. _Claude Code on behalf of allthingssecurity_ ########## components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HMACAccumulator.java: ########## @@ -133,13 +133,10 @@ static class CircularBuffer { public void write(byte[] data, int pos, int len) { if (available >= len) { Review Comment: Done in 4eb4c77f48e0: `write` now throws an `IllegalStateException` when the data does not fit. The existing `HMACAccumulatorTest.testBufferAdd` asserted the silent drop for a write to a full buffer, so it now expects the exception there. _Claude Code on behalf of allthingssecurity_ -- 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]
