-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-14244: Add guard against accidental calls to halt JVM during testing #12666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
17729de
KAFKA-14244: Add guard against accidental calls to halt JVM during te…
C0urante 4d53013
Add license to service loader manifest file
C0urante 0d361d7
Add support for Java 18
C0urante 54b663d
Add tests
C0urante 91cd8bc
Remove custom SecurityManager
C0urante File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -424,6 +424,8 @@ subprojects { | |
| maxHeapSize = defaultMaxHeapSize | ||
| jvmArgs = defaultJvmArgs | ||
|
|
||
| systemProperty "junit.jupiter.extensions.autodetection.enabled", "true" | ||
|
|
||
| testLogging { | ||
| events = userTestLoggingEvents ?: testLoggingEvents | ||
| showStandardStreams = userShowStandardStreams ?: testShowStandardStreams | ||
|
|
@@ -456,6 +458,7 @@ subprojects { | |
| maxHeapSize = "2560m" | ||
| jvmArgs = defaultJvmArgs | ||
|
|
||
| systemProperty "junit.jupiter.extensions.autodetection.enabled", "true" | ||
|
|
||
| testLogging { | ||
| events = userTestLoggingEvents ?: testLoggingEvents | ||
|
|
@@ -472,7 +475,7 @@ subprojects { | |
| useJUnitPlatform { | ||
| includeTags "integration" | ||
| includeTags "org.apache.kafka.test.IntegrationTest" | ||
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | ||
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | ||
| // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. | ||
| includeEngines "junit-vintage", "junit-jupiter" | ||
| } | ||
|
|
@@ -505,6 +508,8 @@ subprojects { | |
| maxHeapSize = defaultMaxHeapSize | ||
| jvmArgs = defaultJvmArgs | ||
|
|
||
| systemProperty "junit.jupiter.extensions.autodetection.enabled", "true" | ||
|
|
||
| testLogging { | ||
| events = userTestLoggingEvents ?: testLoggingEvents | ||
| showStandardStreams = userShowStandardStreams ?: testShowStandardStreams | ||
|
|
@@ -520,7 +525,7 @@ subprojects { | |
| useJUnitPlatform { | ||
| excludeTags "integration" | ||
| excludeTags "org.apache.kafka.test.IntegrationTest" | ||
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | ||
| // Both engines are needed to run JUnit 4 tests alongside JUnit 5 tests. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated whitespace fix; this line was not aligned with others in my IDE. |
||
| // junit-vintage (JUnit 4) can be removed once the JUnit 4 migration is complete. | ||
| includeEngines "junit-vintage", "junit-jupiter" | ||
| } | ||
|
|
||
216 changes: 216 additions & 0 deletions
216
core/src/test/java/kafka/test/DelegatingSecurityManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| /* | ||
| * 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 kafka.test; | ||
|
|
||
| import java.io.FileDescriptor; | ||
| import java.net.InetAddress; | ||
| import java.security.Permission; | ||
|
|
||
| /** | ||
| * A {@link SecurityManager} implementation that accepts and wraps another {@link SecurityManager} instance. | ||
| * This class is not intended to be used directly, but as a superclass. Subclasses can selectively modify parts of the | ||
| * {@link SecurityManager} API without having to also implement boilerplate passthrough logic for the parts that | ||
| * they do not intend to modify. | ||
| */ | ||
| @SuppressWarnings({"deprecation", "removal"}) | ||
| public class DelegatingSecurityManager extends SecurityManager { | ||
| private final SecurityManager originalSecurityManager; | ||
|
|
||
| /** | ||
| * Create a new {@link DelegatingSecurityManager}, which delegates all calls to {@link SecurityManager} API methods | ||
| * to the provided {@link SecurityManager} instance. | ||
| * @param originalSecurityManager the {@link SecurityManager} to delegate to; may be null | ||
| */ | ||
| public DelegatingSecurityManager(SecurityManager originalSecurityManager) { | ||
| this.originalSecurityManager = originalSecurityManager; | ||
| } | ||
|
|
||
| @Override | ||
| public void checkExit(int status) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkExit(status); | ||
| } | ||
|
|
||
| @Override | ||
| public Object getSecurityContext() { | ||
| return (originalSecurityManager == null) ? super.getSecurityContext() | ||
| : originalSecurityManager.getSecurityContext(); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkPermission(Permission perm) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkPermission(perm); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkPermission(Permission perm, Object context) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkPermission(perm, context); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkCreateClassLoader() { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkCreateClassLoader(); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkAccess(Thread t) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkAccess(t); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkAccess(ThreadGroup g) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkAccess(g); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkExec(String cmd) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkExec(cmd); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkLink(String lib) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkLink(lib); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkRead(FileDescriptor fd) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkRead(fd); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkRead(String file) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkRead(file); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkRead(String file, Object context) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkRead(file, context); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkWrite(FileDescriptor fd) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkWrite(fd); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkWrite(String file) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkWrite(file); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkDelete(String file) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkDelete(file); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkConnect(String host, int port) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkConnect(host, port); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkConnect(String host, int port, Object context) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkConnect(host, port, context); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkListen(int port) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkListen(port); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkAccept(String host, int port) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkAccept(host, port); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkMulticast(InetAddress maddr) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkMulticast(maddr); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkMulticast(InetAddress maddr, byte ttl) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkMulticast(maddr, ttl); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkPropertiesAccess() { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkPropertiesAccess(); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkPropertyAccess(String key) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkPropertyAccess(key); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkPrintJobAccess() { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkPrintJobAccess(); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkPackageAccess(String pkg) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkPackageAccess(pkg); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkPackageDefinition(String pkg) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkPackageDefinition(pkg); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkSetFactory() { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkSetFactory(); | ||
| } | ||
|
|
||
| @Override | ||
| public void checkSecurityAccess(String target) { | ||
| if (originalSecurityManager != null) | ||
| originalSecurityManager.checkSecurityAccess(target); | ||
| } | ||
|
|
||
| @Override | ||
| public ThreadGroup getThreadGroup() { | ||
| return (originalSecurityManager == null) ? super.getThreadGroup() | ||
| : originalSecurityManager.getThreadGroup(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated whitespace fix; this line was not aligned with others in my IDE.