Skip to content

Commit

Permalink
Update invokes of HttpResponse methods
Browse files Browse the repository at this point in the history
  • Loading branch information
IshikaDawda committed Jan 15, 2025
1 parent c20e8bb commit 80edf6a
Show file tree
Hide file tree
Showing 34 changed files with 128 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public static void postProcessHttpRequest(Boolean isServletLockAcquired, StringB
if(!isServletLockAcquired || !NewRelicSecurity.isHookProcessingActive() || NewRelicSecurity.getAgent().getIastDetectionCategory().getRxssEnabled()){
return;
}
NewRelicSecurity.getAgent().getSecurityMetaData().getResponse().setResponseContentType(contentType);
NewRelicSecurity.getAgent().getSecurityMetaData().getResponse().setResponseBody(responseBody);
NewRelicSecurity.getAgent().getSecurityMetaData().getResponse().setContentType(contentType);
NewRelicSecurity.getAgent().getSecurityMetaData().getResponse().setBody(responseBody);
if (!contentType.equals(NO_MEDIA_CONTENT_TYPE)) {
NewRelicSecurity.getAgent().getSecurityMetaData().getResponse().setResponseCode(responseCode);
NewRelicSecurity.getAgent().getSecurityMetaData().getResponse().setStatusCode(responseCode);
}
ServletHelper.executeBeforeExitingTransaction();
// ServletHelper.executeBeforeExitingTransaction();
LowSeverityHelper.addRrequestUriToEventFilter(NewRelicSecurity.getAgent().getSecurityMetaData().getRequest());

if(!ServletHelper.isResponseContentTypeExcluded(NewRelicSecurity.getAgent().getSecurityMetaData().getResponse().getResponseContentType())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.junit.{Assert, FixMethodOrder, Test}
import java.net.ServerSocket
import java.util.UUID
import scala.concurrent.Await
import scala.concurrent.duration.{Duration, DurationInt}
import scala.concurrent.duration.DurationInt
import scala.jdk.CollectionConverters._
import scala.jdk.javaapi.FutureConverters

Expand Down Expand Up @@ -224,15 +224,15 @@ class PekkoHttpCoreTest {

Assert.assertFalse("response should not be empty", operation.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, operation.getResponse.getResponseContentType)
Assert.assertEquals("Invalid responseBody.", responseBody, operation.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid responseBody.", responseBody, operation.getResponse.getBody.toString)
}
private def assertMetaData(metaData: SecurityMetaData): Unit = {
Assert.assertFalse("response should not be empty", metaData.getRequest.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, metaData.getRequest.getContentType)
Assert.assertEquals("Invalid responseBody.", requestBody, metaData.getRequest.getBody.toString)
Assert.assertFalse("response should not be empty", metaData.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, metaData.getResponse.getResponseContentType)
Assert.assertEquals("Invalid responseBody.", responseBody, metaData.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid responseBody.", responseBody, metaData.getResponse.getBody.toString)
Assert.assertEquals("Invalid protocol.", metaData.getRequest.getProtocol, "http")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ object RequestProcessor {
try {
if (NewRelicSecurity.isHookProcessingActive && isLockAcquired && !NewRelicSecurity.getAgent.getIastDetectionCategory.getRxssEnabled) {
val securityResponse = NewRelicSecurity.getAgent.getSecurityMetaData.getResponse
securityResponse.setResponseCode(response.status.code)
securityResponse.setStatusCode(response.status.code)
processResponseHeaders(response.headers, securityResponse)
securityResponse.setResponseContentType(getContentType(securityResponse.getHeaders))
securityResponse.setContentType(getContentType(securityResponse.getHeaders))

securityResponse.getResponseBody.append(body)
securityResponse.getBody.append(body)

ServletHelper.executeBeforeExitingTransaction()
// ServletHelper.executeBeforeExitingTransaction()
if (!ServletHelper.isResponseContentTypeExcluded(NewRelicSecurity.getAgent.getSecurityMetaData.getResponse.getResponseContentType)) {
NewRelicSecurity.getAgent.getSecurityMetaData.getMetaData.setFromJumpRequiredInStackTrace(3)
val rxssOperation = new RXSSOperation(NewRelicSecurity.getAgent.getSecurityMetaData.getRequest, NewRelicSecurity.getAgent.getSecurityMetaData.getResponse, this.getClass.getName, METHOD_WITH_HTTP_APP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class EmberServerBuilderTest {
Assert.assertFalse("response should not be empty", operation.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, operation.getResponse.getResponseContentType)
Assert.assertFalse("Headers should not be empty", operation.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getStatusCode)
}

private def assertMetaData(metaData: SecurityMetaData): Unit = {
Expand All @@ -106,9 +106,9 @@ class EmberServerBuilderTest {

Assert.assertFalse("response should not be empty", metaData.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, metaData.getResponse.getResponseContentType)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getStatusCode)
Assert.assertFalse("Headers should not be empty", metaData.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getBody.toString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ object RequestProcessor {
try {
if (NewRelicSecurity.isHookProcessingActive && isLockAcquired && !NewRelicSecurity.getAgent.getIastDetectionCategory.getRxssEnabled) {
val securityResponse = NewRelicSecurity.getAgent.getSecurityMetaData.getResponse
securityResponse.setResponseCode(response.status.code)
securityResponse.setStatusCode(response.status.code)
processResponseHeaders(response.headers, securityResponse)
securityResponse.setResponseContentType(getContentType(securityResponse.getHeaders))
securityResponse.setContentType(getContentType(securityResponse.getHeaders))

securityResponse.getResponseBody.append(body)
securityResponse.getBody.append(body)

ServletHelper.executeBeforeExitingTransaction()
// ServletHelper.executeBeforeExitingTransaction()
if (!ServletHelper.isResponseContentTypeExcluded(NewRelicSecurity.getAgent.getSecurityMetaData.getResponse.getResponseContentType)) {
NewRelicSecurity.getAgent.getSecurityMetaData.getMetaData.setFromJumpRequiredInStackTrace(3)
val rxssOperation = new RXSSOperation(NewRelicSecurity.getAgent.getSecurityMetaData.getRequest, NewRelicSecurity.getAgent.getSecurityMetaData.getResponse, this.getClass.getName, METHOD_WITH_HTTP_APP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class EmberServerBuilderTest {
Assert.assertFalse("response should not be empty", operation.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, operation.getResponse.getResponseContentType)
Assert.assertFalse("Headers should not be empty", operation.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getStatusCode)
}

private def assertMetaData(metaData: SecurityMetaData): Unit = {
Expand All @@ -106,9 +106,9 @@ class EmberServerBuilderTest {

Assert.assertFalse("response should not be empty", metaData.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, metaData.getResponse.getResponseContentType)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getStatusCode)
Assert.assertFalse("Headers should not be empty", metaData.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getBody.toString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ object RequestProcessor {
try {
if (NewRelicSecurity.isHookProcessingActive && isLockAcquired && !NewRelicSecurity.getAgent.getIastDetectionCategory.getRxssEnabled) {
val securityResponse = NewRelicSecurity.getAgent.getSecurityMetaData.getResponse
securityResponse.setResponseCode(response.status.code)
securityResponse.setStatusCode(response.status.code)
processResponseHeaders(response.headers, securityResponse)
securityResponse.setResponseContentType(getContentType(securityResponse.getHeaders))
securityResponse.setContentType(getContentType(securityResponse.getHeaders))

securityResponse.getResponseBody.append(body)
securityResponse.getBody.append(body)

ServletHelper.executeBeforeExitingTransaction()
// ServletHelper.executeBeforeExitingTransaction()
if (!ServletHelper.isResponseContentTypeExcluded(NewRelicSecurity.getAgent.getSecurityMetaData.getResponse.getResponseContentType)) {
NewRelicSecurity.getAgent.getSecurityMetaData.getMetaData.setFromJumpRequiredInStackTrace(3)
val rxssOperation = new RXSSOperation(NewRelicSecurity.getAgent.getSecurityMetaData.getRequest, NewRelicSecurity.getAgent.getSecurityMetaData.getResponse, this.getClass.getName, METHOD_WITH_HTTP_APP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class EmberServerBuilderTest {
Assert.assertFalse("response should not be empty", operation.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, operation.getResponse.getResponseContentType)
Assert.assertFalse("Headers should not be empty", operation.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getStatusCode)
}

private def assertMetaData(metaData: SecurityMetaData): Unit = {
Expand All @@ -106,9 +106,9 @@ class EmberServerBuilderTest {

Assert.assertFalse("response should not be empty", metaData.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, metaData.getResponse.getResponseContentType)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getStatusCode)
Assert.assertFalse("Headers should not be empty", metaData.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getBody.toString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ object RequestProcessor {
try {
if (NewRelicSecurity.isHookProcessingActive && isLockAcquired && !NewRelicSecurity.getAgent.getIastDetectionCategory.getRxssEnabled) {
val securityResponse = NewRelicSecurity.getAgent.getSecurityMetaData.getResponse
securityResponse.setResponseCode(response.status.code)
securityResponse.setStatusCode(response.status.code)
processResponseHeaders(response.headers, securityResponse)
securityResponse.setResponseContentType(getContentType(securityResponse.getHeaders))
securityResponse.setContentType(getContentType(securityResponse.getHeaders))

securityResponse.getResponseBody.append(body)
securityResponse.getBody.append(body)

ServletHelper.executeBeforeExitingTransaction()
// ServletHelper.executeBeforeExitingTransaction()
if (!ServletHelper.isResponseContentTypeExcluded(NewRelicSecurity.getAgent.getSecurityMetaData.getResponse.getResponseContentType)) {
NewRelicSecurity.getAgent.getSecurityMetaData.getMetaData.setFromJumpRequiredInStackTrace(3)
val rxssOperation = new RXSSOperation(NewRelicSecurity.getAgent.getSecurityMetaData.getRequest, NewRelicSecurity.getAgent.getSecurityMetaData.getResponse, this.getClass.getName, METHOD_WITH_HTTP_APP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class EmberServerBuilderTest {
Assert.assertFalse("response should not be empty", operation.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, operation.getResponse.getResponseContentType)
Assert.assertFalse("Headers should not be empty", operation.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getStatusCode)
}

private def assertMetaData(metaData: SecurityMetaData): Unit = {
Expand All @@ -106,9 +106,9 @@ class EmberServerBuilderTest {

Assert.assertFalse("response should not be empty", metaData.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, metaData.getResponse.getResponseContentType)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getStatusCode)
Assert.assertFalse("Headers should not be empty", metaData.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getBody.toString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ object RequestProcessor {
try {
if (NewRelicSecurity.isHookProcessingActive && isLockAcquired && !NewRelicSecurity.getAgent.getIastDetectionCategory.getRxssEnabled) {
val securityResponse = NewRelicSecurity.getAgent.getSecurityMetaData.getResponse
securityResponse.setResponseCode(response.status.code)
securityResponse.setStatusCode(response.status.code)
processResponseHeaders(response.headers, securityResponse)
securityResponse.setResponseContentType(getContentType(securityResponse.getHeaders))
securityResponse.setContentType(getContentType(securityResponse.getHeaders))

securityResponse.getResponseBody.append(body)
securityResponse.getBody.append(body)

ServletHelper.executeBeforeExitingTransaction()
// ServletHelper.executeBeforeExitingTransaction()
if (!ServletHelper.isResponseContentTypeExcluded(NewRelicSecurity.getAgent.getSecurityMetaData.getResponse.getResponseContentType)) {
val rxssOperation = new RXSSOperation(NewRelicSecurity.getAgent.getSecurityMetaData.getRequest, NewRelicSecurity.getAgent.getSecurityMetaData.getResponse, this.getClass.getName, METHOD_WITH_HTTP_APP)
NewRelicSecurity.getAgent.getSecurityMetaData.getMetaData.setFromJumpRequiredInStackTrace(3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class EmberServerBuilderTest {
Assert.assertFalse("response should not be empty", operation.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, operation.getResponse.getResponseContentType)
Assert.assertFalse("Headers should not be empty", operation.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response body", "Hello, bob.", operation.getResponse.getBody.toString)
Assert.assertEquals("Invalid Response code", 200, operation.getResponse.getStatusCode)
}

private def assertMetaData(metaData: SecurityMetaData): Unit = {
Expand All @@ -106,9 +106,9 @@ class EmberServerBuilderTest {

Assert.assertFalse("response should not be empty", metaData.getResponse.isEmpty)
Assert.assertEquals("Invalid response content-type.", contentType, metaData.getResponse.getResponseContentType)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getResponseCode)
Assert.assertEquals("Invalid Response code", 200, metaData.getResponse.getStatusCode)
Assert.assertFalse("Headers should not be empty", metaData.getResponse.getHeaders.isEmpty)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getResponseBody.toString)
Assert.assertEquals("Invalid Response body", "Hello, bob.", metaData.getResponse.getBody.toString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ object RequestProcessor {
try {
if (NewRelicSecurity.isHookProcessingActive && isLockAcquired && !NewRelicSecurity.getAgent.getIastDetectionCategory.getRxssEnabled) {
val securityResponse = NewRelicSecurity.getAgent.getSecurityMetaData.getResponse
securityResponse.setResponseCode(response.status.code)
securityResponse.setStatusCode(response.status.code)
processResponseHeaders(response.headers, securityResponse)
securityResponse.setResponseContentType(getContentType(securityResponse.getHeaders))
securityResponse.setContentType(getContentType(securityResponse.getHeaders))

securityResponse.getResponseBody.append(body)
securityResponse.getBody.append(body)

ServletHelper.executeBeforeExitingTransaction()
// ServletHelper.executeBeforeExitingTransaction()
if (!ServletHelper.isResponseContentTypeExcluded(NewRelicSecurity.getAgent.getSecurityMetaData.getResponse.getResponseContentType)) {
NewRelicSecurity.getAgent.getSecurityMetaData.getMetaData.setFromJumpRequiredInStackTrace(3)
val rxssOperation = new RXSSOperation(NewRelicSecurity.getAgent.getSecurityMetaData.getRequest, NewRelicSecurity.getAgent.getSecurityMetaData.getResponse, this.getClass.getName, METHOD_WITH_HTTP_APP)
Expand Down
Loading

0 comments on commit 80edf6a

Please sign in to comment.