github-advanced-security[bot] commented on code in PR #19940:
URL: https://github.com/apache/druid/pull/19940#discussion_r3742648795
##########
processing/src/test/java/org/apache/druid/java/util/common/StringUtilsTest.java:
##########
@@ -150,165 +145,167 @@
final ByteBuffer bytes = bufferHolder.get();
bytes.put(new byte[]{'a', 'b', 'c', 'd'});
bytes.rewind();
- Assert.assertEquals("abcd", StringUtils.fromUtf8(bytes, 4));
+ Assertions.assertEquals("abcd", StringUtils.fromUtf8(bytes, 4));
bytes.rewind();
- Assert.assertEquals("abcd", StringUtils.fromUtf8(bytes));
+ Assertions.assertEquals("abcd", StringUtils.fromUtf8(bytes));
}
}
@SuppressWarnings("MalformedFormatString")
@Test
public void testNonStrictFormat()
{
- Assert.assertEquals("test%d; format",
StringUtils.nonStrictFormat("test%d", "format"));
- Assert.assertEquals("test%s%s; format",
StringUtils.nonStrictFormat("test%s%s", "format"));
+ Assertions.assertEquals("test%d; format",
StringUtils.nonStrictFormat("test%d", "format"));
+ Assertions.assertEquals("test%s%s; format",
StringUtils.nonStrictFormat("test%s%s", "format"));
Review Comment:
## CodeQL / Missing format argument
This format call refers to 2 argument(s) but only supplies 1 argument(s).
[Show more
details](https://github.com/apache/druid/security/code-scanning/11756)
##########
processing/src/test/java/org/apache/druid/java/util/common/CompressionUtilsTest.java:
##########
@@ -610,49 +610,49 @@
);
}
catch (ISE ise) {
- Assert.assertTrue(ise.getMessage().contains("does not start with
outDir"));
- Assert.assertFalse("Zip exploit triggered, /tmp/evil.txt was written.",
evilResult.exists());
+ Assertions.assertTrue(ise.getMessage().contains("does not start with
outDir"));
+ Assertions.assertFalse(evilResult.exists(), "Zip exploit triggered,
/tmp/evil.txt was written.");
return;
}
- Assert.fail("Exception was not thrown for malicious zip file");
+ Assertions.fail("Exception was not thrown for malicious zip file");
}
@Test
// Sanity check to make sure the test class works as expected
public void testZeroRemainingInputStream() throws IOException
{
try (OutputStream outputStream = new FileOutputStream(testFile)) {
- Assert.assertEquals(
+ Assertions.assertEquals(
GZ_BYTES.length,
ByteStreams.copy(
new ZeroRemainingInputStream(new ByteArrayInputStream(GZ_BYTES)),
outputStream
)
);
- Assert.assertEquals(
+ Assertions.assertEquals(
GZ_BYTES.length,
ByteStreams.copy(
new ZeroRemainingInputStream(new ByteArrayInputStream(GZ_BYTES)),
outputStream
)
);
- Assert.assertEquals(
+ Assertions.assertEquals(
GZ_BYTES.length,
ByteStreams.copy(
new ZeroRemainingInputStream(new ByteArrayInputStream(GZ_BYTES)),
outputStream
)
);
}
- Assert.assertEquals(GZ_BYTES.length * 3, testFile.length());
+ Assertions.assertEquals(GZ_BYTES.length * 3, testFile.length());
Review Comment:
## CodeQL / Result of multiplication cast to wider type
Potential overflow in [int multiplication](1) before it is converted to long
by use in an invocation context.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11757)
##########
processing/src/test/java/org/apache/druid/testing/junit/LoggerCaptureExtension.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.druid.testing.junit;
+
+import com.google.common.collect.ImmutableList;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * JUnit 5 extension that captures Log4j events emitted by a target class.
+ * Register it with {@code new LoggerCaptureExtension(TargetClass.class)} and
inspect {@link #getLogEvents()}.
+ */
+public class LoggerCaptureExtension implements BeforeEachCallback,
AfterEachCallback
+{
+ private final Class<?> targetClass;
+ private InMemoryAppender inMemoryAppender;
+ private LoggerConfig targetClassLoggerConfig;
+
+ public LoggerCaptureExtension(final Class<?> targetClass)
+ {
+ this.targetClass = targetClass;
+ }
+
+ @Override
+ public void beforeEach(final ExtensionContext context)
+ {
+ inMemoryAppender = new InMemoryAppender(targetClass);
+ final LoggerContext loggerContext = (LoggerContext)
LogManager.getContext(false);
+ final Configuration configuration = loggerContext.getConfiguration();
+ targetClassLoggerConfig =
configuration.getLoggerConfig(targetClass.getName());
+ targetClassLoggerConfig.addAppender(inMemoryAppender, Level.ALL, null);
+ }
+
+ @Override
+ public void afterEach(final ExtensionContext context)
+ {
+ clearLogEvents();
+ targetClassLoggerConfig.removeAppender(InMemoryAppender.NAME);
+ }
+
+ public List<LogEvent> getLogEvents()
+ {
+ return inMemoryAppender.getLogEvents();
+ }
+
+ public void clearLogEvents()
+ {
+ inMemoryAppender.clearLogEvents();
+ }
+
+ public void awaitLogEvents() throws InterruptedException
+ {
+ inMemoryAppender.awaitLogEvents();
+ }
+
+ private static class InMemoryAppender extends AbstractAppender
+ {
+ private static final String NAME = InMemoryAppender.class.getName();
+ private final String targetLoggerName;
+ @GuardedBy("logEvents")
+ private final List<LogEvent> logEvents = new ArrayList<>();
+
+ InMemoryAppender(final Class<?> targetClass)
+ {
+ super(NAME, null, null);
Review Comment:
## CodeQL / Deprecated method or constructor invocation
Invoking [AbstractAppender.AbstractAppender](1) should be avoided because it
has been deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11760)
##########
processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java:
##########
@@ -108,7 +109,7 @@
MatcherAssert.assertThat(e, CoreMatchers.instanceOf(IOException.class));
// Second exception
- Assert.assertEquals(1, e.getSuppressed().length);
+ Assertions.assertEquals(1, e.getSuppressed().length);
Review Comment:
## CodeQL / Dereferenced variable may be null
Variable [e](1) may be null at this access because of [this](2) assignment.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11759)
##########
processing/src/test/java/org/apache/druid/utils/CloseableUtilsTest.java:
##########
@@ -79,7 +80,7 @@
MatcherAssert.assertThat(e, CoreMatchers.instanceOf(IOException.class));
// Second exception
- Assert.assertEquals(1, e.getSuppressed().length);
+ Assertions.assertEquals(1, e.getSuppressed().length);
Review Comment:
## CodeQL / Dereferenced variable may be null
Variable [e](1) may be null at this access because of [this](2) assignment.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11758)
--
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]