epugh commented on code in PR #4264:
URL: https://github.com/apache/solr/pull/4264#discussion_r3106998197
##########
solr/core/src/test/org/apache/solr/handler/configsets/GetConfigSetFileAPITest.java:
##########
@@ -126,10 +135,70 @@ public void testEmptyFileReturnsEmptyContent() throws
Exception {
createConfigSetWithFile(configSetName, filePath, "");
final var api = new GetConfigSetFile(mockCoreContainer, null, null);
- final ConfigSetFileContentsResponse response =
api.getConfigSetFile(configSetName, filePath);
+ final StreamingOutput streamingOutput =
api.getConfigSetFile(configSetName, filePath);
+
+ assertNotNull(streamingOutput);
+
+ // Read the streamed bytes
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ streamingOutput.write(baos);
+
+ assertEquals(0, baos.size());
+ }
+
+ @Test
+ public void testBinaryFilePreservedWithStreamingOutput() throws Exception {
+ // This test demonstrates that binary files are now correctly handled
+ // by returning raw bytes via StreamingOutput instead of UTF-8 String.
+ final String configSetName = "binarytest";
+ final String filePath = "logo.png";
+
+ // Create a file with binary data simulating a small PNG image header
+ // PNG signature: 89 50 4E 47 0D 0A 1A 0A (first 8 bytes of any PNG)
+ // Plus some additional binary data that would corrupt as UTF-8
+ byte[] binaryData =
+ new byte[] {
+ (byte) 0x89,
+ 0x50,
+ 0x4E,
+ 0x47,
+ 0x0D,
+ 0x0A,
+ 0x1A,
+ 0x0A, // PNG signature
+ (byte) 0xFF,
+ (byte) 0xFE,
+ 0x00,
+ 0x01,
+ (byte) 0x80,
+ (byte) 0xDE,
+ (byte) 0xAD,
+ (byte) 0xBE,
+ (byte) 0xEF // Binary data
+ };
+
+ Path configDir = configSetBase.resolve(configSetName);
+ Files.createDirectories(configDir);
+ Files.write(configDir.resolve(filePath), binaryData);
+
+ final var api = new GetConfigSetFile(mockCoreContainer, null, null);
+ final StreamingOutput streamingOutput =
api.getConfigSetFile(configSetName, filePath);
+
+ assertNotNull(streamingOutput);
+
+ // Read the streamed bytes
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
Review Comment:
it actually is only used once in this exact way...
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]