-
Notifications
You must be signed in to change notification settings - Fork 12
Configure JaCoCo and CodeCov #402
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
Open
IshikaDawda
wants to merge
19
commits into
main
Choose a base branch
from
ut/nr-security-agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
47f6771
Unit test for newrelic-security-api module
IshikaDawda 28c0dd2
Unit test for newrelic-security-agent module
IshikaDawda 9a375eb
add more unit test for newrelic-security-api
IshikaDawda 64c496c
added more unit test for Dispatcher
IshikaDawda e61c7ad
added more test cases for newrelic-security-agent
IshikaDawda 0ea022e
updated the unit tests name
IshikaDawda 174d93d
Merge branch 'refs/heads/ut/newrelic-security-api' into ut/nr-securit…
IshikaDawda 82acc2b
Merge branch 'refs/heads/main' into ut/nr-security-agent
IshikaDawda d789020
setup jacoco for unit tests coverage
IshikaDawda de41a39
Add more unit tests for newrelic-security-api
IshikaDawda ea0acd9
Configure codecov GitHub action
IshikaDawda 244c259
Pass codecov token to unit tests action
IshikaDawda c7cb20e
upgrade upload-artifact GitHub action to v4 as v3 is marked as deprec…
IshikaDawda 9046dfa
configure jacoco and add unit tests for newrelic-security-agent
IshikaDawda 4f5e5e4
add AgentConfig and AgentInfo to jacoco exclude
IshikaDawda 2c6623e
Add more unit tests for newrelic-security-agent
IshikaDawda 6bfd2fb
Add more unit tests for newrelic-security-agent
IshikaDawda a2a3e90
Update README for jacoco and Codecov
IshikaDawda 4a8d367
remove debug print out
IshikaDawda 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
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,2 @@ | ||
| codecov: | ||
| max_report_age: off |
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
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
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,73 @@ | ||
| apply plugin: 'java' | ||
| apply plugin: 'jacoco' | ||
|
|
||
| jacoco { | ||
| toolVersion = "0.8.11" | ||
| } | ||
|
|
||
| test { | ||
| jacoco { | ||
| enabled = true | ||
| destinationFile = layout.buildDirectory.file('jacoco/test.exec').get().asFile | ||
| classDumpDir = layout.buildDirectory.dir('jacoco/classpathdumps').get().asFile | ||
| destinationFile = layout.buildDirectory.file("jacoco/${name}.exec").get().asFile | ||
|
|
||
| } | ||
| finalizedBy jacocoTestReport // report is always generated after tests run | ||
| } | ||
|
|
||
| jacocoTestReport { | ||
|
|
||
| dependsOn test | ||
| afterEvaluate { | ||
| classDirectories.setFrom(files(classDirectories.files.collect { | ||
| fileTree(dir: it, | ||
| exclude: ['**/*NoOp*.class', | ||
| '**/SecurityAgent.class', | ||
| '**/*Exception.class', | ||
| '**/*Error.class', | ||
| '**/*Constant*.class', | ||
| '**/*Pool*.class', | ||
| 'com/newrelic/agent/security/intcodeagent/utils/TTLMap.class', | ||
| 'com/newrelic/agent/security/intcodeagent/utils/ResourceUtils.class', | ||
| 'com/newrelic/agent/security/intcodeagent/models/**', | ||
| 'com/newrelic/agent/security/util/*.class', | ||
| 'com/newrelic/agent/security/intcodeagent/properties/*.class', | ||
| 'com/newrelic/agent/security/intcodeagent/*logging/*', | ||
| 'com/newrelic/agent/security/intcodeagent/serializers/*', | ||
| 'com/newrelic/agent/security/intcodeagent/schedulers/*', | ||
| 'com/newrelic/agent/security/intcodeagent/controlcommand/*', | ||
| 'com/newrelic/agent/security/intcodeagent/websocket/*', | ||
| 'com/newrelic/agent/security/intcodeagent/executor/*', | ||
| 'com/newrelic/agent/security/intcodeagent/constants/*.class', | ||
| 'com/newrelic/agent/security/instrumentator/utils/AgentUtils.class', | ||
| 'com/newrelic/agent/security/instrumentator/utils/ApplicationInfoUtils.class', | ||
| 'com/newrelic/agent/security/instrumentator/utils/EnvLogUtils*.class', | ||
| 'com/newrelic/agent/security/instrumentator/utils/HashGenerator.class', | ||
| 'com/newrelic/agent/security/instrumentator/utils/InstrumentationUtils.class', | ||
| 'com/newrelic/agent/security/instrumentator/utils/INRSettingsKey.class', | ||
| 'com/newrelic/agent/security/instrumentator/utils/NameFileFilter.class', | ||
| 'com/newrelic/agent/security/instrumentator/os/*', | ||
| 'com/newrelic/agent/security/instrumentator/httpclient/*.class', | ||
| 'com/newrelic/agent/security/instrumentator/*Hooks.class', | ||
| 'com/newrelic/agent/security/intcodeagent/websocket/WSUtils.class', | ||
| 'com/newrelic/agent/security/intcodeagent/websocket/CustomTrustStoreManagerUtils.class', | ||
| 'com/newrelic/agent/security/intcodeagent/apache/httpclient/*', | ||
| 'com/newrelic/api/agent/security/*.class', | ||
| 'com/newrelic/agent/security/*.class', | ||
| 'com/newrelic/api/agent/security/schema/*', | ||
| 'com/newrelic/api/agent/security/NewRelicSecurity.class', | ||
| 'com/newrelic/api/agent/security/instrumentation/helpers/VertxApiEndpointUtils*', | ||
| 'com/newrelic/api/agent/security/utils/UserDataTranslationHelper.class', | ||
| 'com/newrelic/api/agent/security/utils/logging/LogLevel.class', | ||
| 'com/newrelic/api/agent/security/instrumentation/helpers/GrpcClientRequestReplayHelper*', | ||
| 'com/newrelic/api/agent/security/instrumentation/helpers/AppServerInfoHelper.class', | ||
| ]) | ||
| })) | ||
| } | ||
| reports { | ||
| xml.required = true | ||
| html.outputLocation = layout.buildDirectory.dir('reports/jacoco') | ||
| } | ||
|
|
||
| } |
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
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
63 changes: 63 additions & 0 deletions
63
newrelic-security-agent/src/test/java/com/newrelic/agent/security/AgentConfigTest.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,63 @@ | ||
| package com.newrelic.agent.security; | ||
|
|
||
| import com.newrelic.agent.security.intcodeagent.exceptions.RestrictionModeException; | ||
| import com.newrelic.agent.security.util.IUtilConstants; | ||
| import com.newrelic.api.agent.NewRelic; | ||
| import org.apache.commons.io.FileUtils; | ||
| import org.junit.Assert; | ||
|
|
||
| import org.junit.Test; | ||
| import org.mockito.Answers; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
|
|
||
| public class AgentConfigTest { | ||
|
|
||
| @Test | ||
| public void applyRequiredGroup() throws RestrictionModeException { | ||
| AgentConfig.getInstance().instantiate(); | ||
| Assert.assertEquals("IAST", AgentConfig.getInstance().getGroupName()); | ||
| } | ||
| @Test | ||
|
|
||
| public void applyRequiredGroup1() throws RestrictionModeException{ | ||
| // try (MockedStatic<NewRelic> nrMock = Mockito.mockStatic(NewRelic.class, Answers.RETURNS_DEEP_STUBS)){ | ||
| // nrMock.when(NewRelic.getAgent().getConfig().getValue(IUtilConstants.SECURITY_MODE)).thenReturn("RASP"); | ||
| // nrMock.when(NewRelic.getAgent().getConfig().getValue(eq(IUtilConstants.NR_SECURITY_ENABLED), any())).thenReturn(false); | ||
| // AgentConfig.getInstance().instantiate(); | ||
| // Assert.assertEquals("RASP", AgentConfig.getInstance().getGroupName()); | ||
| // nrMock.reset(); | ||
| // nrMock.clearInvocations(); | ||
| // } | ||
| } | ||
| @Test | ||
| public void isNRSecurityEnabled() throws RestrictionModeException{ | ||
| AgentConfig.getInstance().instantiate(); | ||
| Assert.assertFalse(AgentConfig.getInstance().isNRSecurityEnabled()); | ||
| } | ||
| @Test | ||
| public void setK2HomePath() { | ||
| Assert.assertFalse(AgentConfig.getInstance().setSecurityHomePath()); | ||
| } | ||
| @Test | ||
| public void setK2HomePath1() throws IOException { | ||
| String AGENT_HOME = "/tmp/file_"+ UUID.randomUUID(); | ||
| try (MockedStatic<NewRelic> nrMock = Mockito.mockStatic(NewRelic.class, Answers.RETURNS_DEEP_STUBS)){ | ||
| nrMock.when(NewRelic.getAgent().getConfig().getValue("agent_home")).thenReturn(AGENT_HOME); | ||
|
|
||
| Assert.assertTrue(AgentConfig.getInstance().setSecurityHomePath()); | ||
| Assert.assertEquals(AGENT_HOME+"/nr-security-home", AgentConfig.getInstance().getSecurityHome()); | ||
| nrMock.reset(); | ||
| nrMock.clearInvocations(); | ||
| } finally { | ||
| FileUtils.forceDeleteOnExit(new File(AGENT_HOME)); | ||
| } | ||
| } | ||
| } |
105 changes: 105 additions & 0 deletions
105
newrelic-security-agent/src/test/java/com/newrelic/agent/security/AgentInfoTest.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,105 @@ | ||
| package com.newrelic.agent.security; | ||
|
|
||
| import com.newrelic.agent.security.instrumentator.utils.INRSettingsKey; | ||
| import com.newrelic.agent.security.intcodeagent.models.collectorconfig.CollectorConfig; | ||
| import com.newrelic.agent.security.intcodeagent.models.javaagent.ApplicationInfoBean; | ||
| import com.newrelic.agent.security.intcodeagent.models.javaagent.EventStats; | ||
| import com.newrelic.agent.security.intcodeagent.models.javaagent.Identifier; | ||
| import com.newrelic.agent.security.intcodeagent.models.javaagent.IdentifierEnvs; | ||
| import com.newrelic.agent.security.intcodeagent.models.javaagent.JAHealthCheck; | ||
| import com.newrelic.agent.security.util.IUtilConstants; | ||
| import com.newrelic.api.agent.NewRelic; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
|
|
||
| import org.junit.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Properties; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| public class AgentInfoTest { | ||
| @BeforeClass | ||
| public static void setUp() { | ||
| Identifier identifier = new Identifier(); | ||
| identifier.setKind(IdentifierEnvs.HOST); | ||
| AgentInfo.getInstance().setIdentifier(identifier); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
| public void generateAppInfo() { | ||
| // ApplicationInfoBean appInfoBean = AgentInfo.getInstance().generateAppInfo(Mockito.mock(CollectorConfig.class)); | ||
| // Assert.assertEquals(AgentInfo.getInstance().getApplicationUUID(), appInfoBean.getApplicationUUID()); | ||
| // Assert.assertEquals("STATIC", appInfoBean.getAgentAttachmentType()); | ||
| // Assert.assertEquals(AgentInfo.getInstance().getVMPID(), appInfoBean.getPid()); | ||
| // Assert.assertEquals("JAVA", appInfoBean.getCollectorType()); | ||
| // Assert.assertEquals("Java", appInfoBean.getLanguage()); | ||
| } | ||
|
|
||
| @Test | ||
| public void initializeHC() { | ||
| // AgentInfo.getInstance().generateAppInfo(Mockito.mock(CollectorConfig.class)); | ||
| // AgentInfo.getInstance().initialiseHC(); | ||
| // JAHealthCheck jaHealthCheck = AgentInfo.getInstance().getJaHealthCheck(); | ||
| Properties properties = new Properties(); | ||
| //default application_logging is true | ||
| properties.put("newrelic.config.application_logging.enabled", "false"); | ||
| System.setProperty("newrelic.config.security.scan_controllers.scan_instance_count", "1"); | ||
| System.out.println("config found ---" + NewRelic.getAgent().getConfig().getValue(IUtilConstants.IAST_SCAN_INSTANCE_COUNT)); | ||
| // assertion(jaHealthCheck, new AtomicInteger(0), new EventStats()); | ||
| } | ||
|
|
||
| @Test | ||
| public void isAgentActive() { | ||
| Assert.assertFalse(AgentInfo.getInstance().isAgentActive()); | ||
| } | ||
| // @Test | ||
| // public void initializeHC1() { | ||
| // AgentInfo.getInstance().generateAppInfo(Mockito.mock(CollectorConfig.class)); | ||
| // AgentInfo.getInstance().initialiseHC(); | ||
| // JAHealthCheck jaHealthCheck = AgentInfo.getInstance().getJaHealthCheck(); | ||
| // jaHealthCheck.incrementInvokedHookCount(); | ||
| // jaHealthCheck.incrementDropCount(); | ||
| // jaHealthCheck.incrementProcessedCount(); | ||
| // jaHealthCheck.incrementEventSentCount(); | ||
| // jaHealthCheck.incrementHttpRequestCount(); | ||
| // jaHealthCheck.incrementExitEventSentCount(); | ||
| // jaHealthCheck.incrementEventRejectionCount(); | ||
| // jaHealthCheck.incrementEventProcessingErrorCount(); | ||
| // jaHealthCheck.incrementEventSendRejectionCount(); | ||
| // jaHealthCheck.incrementEventSendErrorCount(); | ||
| // assertion(jaHealthCheck, new AtomicInteger(1), new EventStats()); | ||
| // | ||
| // // resetting the JAHealthCheck | ||
| // jaHealthCheck.reset(); | ||
| // assertion(jaHealthCheck, new AtomicInteger(0), new EventStats()); | ||
| // } | ||
|
|
||
| // private void assertion(JAHealthCheck jaHealthCheck, AtomicInteger atomicInteger, EventStats expectedEventStats) { | ||
| // Assert.assertEquals(AgentInfo.getInstance().getApplicationUUID(), jaHealthCheck.getApplicationUUID()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getInvokedHookCount()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getEventDropCount().intValue()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getEventProcessed().intValue()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getEventSentCount().get()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getHttpRequestCount().get()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getExitEventSentCount().get()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getEventRejectionCount().get()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getEventProcessingErrorCount().get()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getEventSendRejectionCount().get()); | ||
| // Assert.assertEquals(atomicInteger.get(), jaHealthCheck.getEventSendErrorCount().get()); | ||
| // | ||
| // assertEventStats(expectedEventStats, jaHealthCheck.getExitEventStats()); | ||
| // assertEventStats(expectedEventStats, jaHealthCheck.getIastEventStats()); | ||
| // assertEventStats(expectedEventStats, jaHealthCheck.getRaspEventStats()); | ||
| // Assert.assertEquals("HOST", jaHealthCheck.getKind().name()); | ||
| // } | ||
|
|
||
| // private void assertEventStats(EventStats expectedEventStats, EventStats actualEventStats) { | ||
| // Assert.assertSame(expectedEventStats.getErrorCount().get(), actualEventStats.getErrorCount().get()); | ||
| // Assert.assertSame(expectedEventStats.getProcessed().get(), actualEventStats.getProcessed().get()); | ||
| // Assert.assertSame(expectedEventStats.getSent().get(), actualEventStats.getSent().get()); | ||
| // Assert.assertSame(expectedEventStats.getRejected().get(), actualEventStats.getRejected().get()); | ||
| // } | ||
| } |
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.
any specific reason to add this?
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.
I have removed this, as I have added for debugging purpose.