Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
530ef1b
API Endpoint Phase 2: Add Endpoint route in Servlet Framework
IshikaDawda Jun 7, 2024
b842390
API Endpoint Phase 2: Add Endpoint route in Servlet Framework
IshikaDawda Jun 7, 2024
0576b23
Add Unit tests for route detection for Servlet Framework
IshikaDawda Jun 7, 2024
b823e8d
Add Endpoint route in Servlet-3.0 Framework
IshikaDawda Jun 7, 2024
5f3301b
Add Unit tests for route detection for Servlet-3.0
IshikaDawda Jun 7, 2024
c40ee48
API Endpoint Phase 2: Add Endpoint route in Servlet Framework
IshikaDawda Jun 13, 2024
5ca6984
Fix for NR-280811
IshikaDawda Jun 14, 2024
a5cf4e8
Merge branch 'refs/heads/main' into feature/api-endpoint/Servlet-NR-2…
IshikaDawda Jul 16, 2024
7960d89
Consider corner cases for servlet route detection
IshikaDawda Jul 16, 2024
d1a2e22
Fix for NR-286896, where incorrect route calculated when empty route …
IshikaDawda Jul 25, 2024
a4bc3ce
Route detection support for servlet framework
IshikaDawda Sep 20, 2024
357624a
Merge branch 'refs/heads/main' into feature/api-endpoint/Servlet-NR-2…
IshikaDawda Sep 20, 2024
d1d5d8d
Merge branch 'refs/heads/main' into feature/api-endpoint/Servlet-NR-2…
IshikaDawda Sep 20, 2024
b69814b
Fix for extension based endpoints present in servlet
IshikaDawda Sep 20, 2024
22e5548
Merge branch 'refs/heads/main' into feature/api-endpoint/Servlet-NR-2…
IshikaDawda Nov 21, 2024
f2b3fb2
NR-338563: Fix for NR-282698 where route not detected for diff. mappi…
IshikaDawda Nov 21, 2024
b6443b7
Fix for NR-266822 where false APIs reported for servlet using applica…
IshikaDawda Nov 22, 2024
df473df
Fix for NR-266822 where false APIs reported for servlet using applica…
IshikaDawda Nov 22, 2024
28f88c1
Merge branch 'refs/heads/main' into feature/api-endpoint/Servlet-NR-2…
IshikaDawda Jan 20, 2025
951d002
Revert the Fix for NR-266822 as the mentioned endpoints are exposed
IshikaDawda Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Unit tests for route detection for Servlet-3.0
  • Loading branch information
IshikaDawda committed Jun 7, 2024
commit 5f3301b811ac96f75ebd94cbaa886f37ad862f4d
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import com.newrelic.agent.security.introspec.InstrumentationTestConfig;
import com.newrelic.agent.security.introspec.SecurityInstrumentationTestRunner;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import org.apache.catalina.servlets.DefaultServlet;
import com.newrelic.api.agent.security.schema.Framework;
import com.newrelic.api.agent.security.schema.SecurityMetaData;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Iterator;

@RunWith(SecurityInstrumentationTestRunner.class)
Expand All @@ -32,4 +38,21 @@ public void testURLMappings() {
ApplicationURLMapping mapping2 = mappings.next();
Assert.assertEquals("URL Mappings", new ApplicationURLMapping(method, "/test", handler), mapping2);
}

@Test
public void testRoute() throws IOException, URISyntaxException {
connect();
SecurityMetaData metaData = SecurityInstrumentationTestRunner.getIntrospector().getSecurityMetaData();
Assert.assertEquals( "Incorrect Route Detected","/test", metaData.getRequest().getRoute());
Assert.assertEquals("Incorrect Framework detected", Framework.SERVLET.name(), metaData.getMetaData().getFramework());
}

@Trace(dispatcher = true)
private void connect() throws IOException, URISyntaxException {
URL u = server.getEndPoint().toURL();
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setRequestProperty("content-type", "text/plain; charset=utf-8");
conn.connect();
conn.getResponseCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.servlets.DefaultServlet;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.apache.tomcat.util.http.fileupload.FileUtils;
Expand All @@ -19,6 +18,8 @@
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Set;

Expand Down Expand Up @@ -91,6 +92,10 @@ private void stop() {
}
}
}

public URI getEndPoint() throws URISyntaxException {
return new URI("http://localhost:" + port + "/test");
}
}
class MyServlet extends HttpServlet {
@Override
Expand Down