Skip to content

Commit 3298247

Browse files
remove dependency on servlet API (use case where not needed) (#776)
* remove dependency on servlet API for a specif use case where not needed * fix typo in unit test
1 parent adf88c7 commit 3298247

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/main/java/org/owasp/esapi/logging/appender/ServerInfoSupplier.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ public ServerInfoSupplier(String logName) {
5151
public String get() {
5252
// log server, port, app name, module name -- server:80/app/module
5353
StringBuilder appInfo = new StringBuilder();
54-
HttpServletRequest request = ESAPI.currentRequest();
55-
if (request != null && logServerIP) {
56-
appInfo.append(request.getLocalAddr()).append(":").append(request.getLocalPort());
54+
if (logServerIP) {
55+
HttpServletRequest request = ESAPI.currentRequest();
56+
if (request != null) {
57+
appInfo.append(request.getLocalAddr()).append(":").append(request.getLocalPort());
58+
}
5759
}
5860
if (logAppName) {
5961
appInfo.append("/").append(applicationName);

src/test/java/org/owasp/esapi/logging/appender/ServerInfoSupplierTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public class ServerInfoSupplierTest {
2525
private HttpServletRequest request;
2626

2727
@Before
28-
public void buildStaticMocks() throws Exception {
28+
public void buildStaticMocks() {
2929
request = mock(HttpServletRequest.class);
3030
mockStatic(ESAPI.class);
31-
when(ESAPI.class, "currentRequest").thenReturn(request);
3231
}
3332

3433
@Test
35-
public void verifyFullOutput() {
34+
public void verifyFullOutput() throws Exception {
35+
when(ESAPI.class, "currentRequest").thenReturn(request);
3636
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
3737
when(request.getLocalPort()).thenReturn(99999);
3838

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

5959
@Test
60-
public void verifyOutputNoAppName() {
60+
public void verifyOutputNoAppName() throws Exception {
61+
when(ESAPI.class, "currentRequest").thenReturn(request);
6162
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
6263
when(request.getLocalPort()).thenReturn(99999);
6364

@@ -70,7 +71,8 @@ public void verifyOutputNoAppName() {
7071
}
7172

7273
@Test
73-
public void verifyOutputNullAppName() {
74+
public void verifyOutputNullAppName() throws Exception {
75+
when(ESAPI.class, "currentRequest").thenReturn(request);
7476
when(request.getLocalAddr()).thenReturn("LOCAL_ADDR");
7577
when(request.getLocalPort()).thenReturn(99999);
7678

0 commit comments

Comments
 (0)