Skip to content

remove dependency on servlet API (use case where not needed) #776

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

Merged
merged 2 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ public ServerInfoSupplier(String logName) {
public String get() {
// log server, port, app name, module name -- server:80/app/module
StringBuilder appInfo = new StringBuilder();
HttpServletRequest request = ESAPI.currentRequest();
if (request != null && logServerIP) {
appInfo.append(request.getLocalAddr()).append(":").append(request.getLocalPort());
if (logServerIP) {
HttpServletRequest request = ESAPI.currentRequest();
if (request != null) {
appInfo.append(request.getLocalAddr()).append(":").append(request.getLocalPort());
}
}
if (logAppName) {
appInfo.append("/").append(applicationName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class ServerInfoSupplierTest {
private HttpServletRequest request;

@Before
public void buildStaticMocks() throws Exception {
public void buildStaticMocks() {
request = mock(HttpServletRequest.class);
mockStatic(ESAPI.class);
when(ESAPI.class, "currentRequest").thenReturn(request);
}

@Test
public void verifyFullOutput() {
public void verifyFullOutput() throws Exception {
when(ESAPI.class, "currentRequest").thenReturn(request);
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
when(request.getLocalPort()).thenReturn(99999);

Expand All @@ -57,7 +57,8 @@ public void verifyOutputNullRequest() throws Exception {
}

@Test
public void verifyOutputNoAppName() {
public void verifyOutputNoAppName() throws Exception {
when(ESAPI.class, "currentRequest").thenReturn(request);
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
when(request.getLocalPort()).thenReturn(99999);

Expand All @@ -70,7 +71,8 @@ public void verifyOutputNoAppName() {
}

@Test
public void verifyOutputNullAppName() {
public void verifyOutputNullAppName() throws Exception {
when(ESAPI.class, "currentRequest").thenReturn(request);
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
when(request.getLocalPort()).thenReturn(99999);

Expand Down