-
Notifications
You must be signed in to change notification settings - Fork 320
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
Add tests for Security Manager #2539
Merged
SylvainJuge
merged 12 commits into
elastic:main
from
SylvainJuge:test-security-manager-setup
Mar 6, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6a19f43
create container for simple test apps
SylvainJuge c5ab999
refactor ServiceIT + test security manager warn
SylvainJuge 82d298f
reproduce one issue with SecurityManager
SylvainJuge 3990393
wip : add remote debug + better tmp files
SylvainJuge 96ec236
Merge branch 'main' of github.com:elastic/apm-agent-java into test-se…
SylvainJuge 2189ca9
Merge branch 'main' of github.com:elastic/apm-agent-java into test-se…
SylvainJuge 932fbcc
make agent work better with security manager
SylvainJuge 11a06fe
Merge branch 'main' of github.com:elastic/apm-agent-java into test-se…
SylvainJuge ef0097e
Merge branch 'main' of github.com:elastic/apm-agent-java into test-se…
SylvainJuge 0dc61be
make test pass again
SylvainJuge 5b9037c
rename test
SylvainJuge b82d2bc
add convenient remote debug for JVM in containers
SylvainJuge File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
100 changes: 100 additions & 0 deletions
100
integration-tests/main-app-test/src/test/java/co/elastic/apm/test/AgentSetupIT.java
This file contains 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,100 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. 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 co.elastic.apm.test; | ||
|
||
import co.elastic.apm.agent.test.AgentFileAccessor; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.output.OutputFrame; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.containers.wait.strategy.WaitStrategy; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
import java.time.Duration; | ||
import java.util.Arrays; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class AgentSetupIT { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"openjdk:8", "openjdk:11", "openjdk:17"}) | ||
void testServiceNameAndVersionFromManifest(String image) { | ||
try (GenericContainer<TestAppContainer> app = testAppWithJavaAgent(image)) { | ||
|
||
app.waitingFor(Wait.forLogMessage(".* Starting Elastic APM .*", 1)) | ||
.start(); | ||
|
||
assertThat(app.getLogs()).contains(" as My Service Name (My Service Version) on "); | ||
} | ||
} | ||
|
||
@Test | ||
void testSecurityManagerWarning() { | ||
String expectedMsg = "Security manager without agent grant-all permission"; | ||
|
||
try (TestAppContainer app = testAppWithJavaAgent("openjdk:17")) { | ||
|
||
app.withSecurityManager() | ||
.waitingFor(Wait.forLogMessage(expectedMsg, 1)) | ||
// we expect startup to fail fast as JVM should not even properly start | ||
.withStartupTimeout(Duration.ofSeconds(1)); | ||
|
||
app.start(); | ||
|
||
assertThat(app.getLogs(OutputFrame.OutputType.STDERR)).contains(expectedMsg); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
void testSecurityManagerWithPolicy(@TempDir Path temp) throws IOException { | ||
Path tempPolicy = temp.resolve("security.policy"); | ||
|
||
// use a 'grant all' policy for now | ||
Files.write(tempPolicy, Arrays.asList( | ||
"grant codeBase \"file:///tmp/elastic-apm-agent.jar\" {", | ||
" permission java.security.AllPermission;", | ||
"};"), StandardOpenOption.CREATE | ||
); | ||
|
||
try (TestAppContainer app = testAppWithJavaAgent("openjdk:17")) { | ||
app.withSecurityManager(tempPolicy) | ||
.withStartupTimeout(Duration.ofSeconds(10)) | ||
.waitingFor(Wait.forLogMessage(".*Hello World!.*", 1)) | ||
.start(); | ||
} | ||
} | ||
|
||
private TestAppContainer testAppWithJavaAgent(String image) { | ||
return new TestAppContainer(image) | ||
.withAppJar(Path.of("target/main-app-test.jar")) | ||
.withArguments("wait") // make test app wait a bit so we can stop it | ||
.withJavaAgent(AgentFileAccessor.getPathToJavaagent()) | ||
// automatically enable remote debug | ||
.withRemoteDebug(); | ||
} | ||
|
||
} |
55 changes: 0 additions & 55 deletions
55
integration-tests/main-app-test/src/test/java/co/elastic/apm/test/ServiceIT.java
This file was deleted.
Oops, something went wrong.
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.
[for reviewer] this was actually tested previously within
ServiceTestIT