|
15 | 15 | */
|
16 | 16 | package org.owasp.esapi.reference;
|
17 | 17 |
|
18 |
| -import java.io.IOException; |
19 |
| -import java.util.Arrays; |
20 |
| - |
21 | 18 | import junit.framework.Test;
|
22 | 19 | import junit.framework.TestCase;
|
23 | 20 | import junit.framework.TestSuite;
|
24 |
| - |
| 21 | +import org.apache.log4j.Appender; |
| 22 | +import org.apache.log4j.Layout; |
| 23 | +import org.apache.log4j.WriterAppender; |
| 24 | +import org.apache.log4j.spi.LoggingEvent; |
25 | 25 | import org.owasp.esapi.ESAPI;
|
26 | 26 | import org.owasp.esapi.Logger;
|
27 | 27 | import org.owasp.esapi.errors.AuthenticationException;
|
28 | 28 | import org.owasp.esapi.errors.ValidationException;
|
29 | 29 | import org.owasp.esapi.http.MockHttpServletRequest;
|
30 | 30 | import org.owasp.esapi.http.MockHttpServletResponse;
|
31 | 31 |
|
| 32 | +import java.io.IOException; |
| 33 | +import java.io.StringWriter; |
| 34 | +import java.util.Arrays; |
| 35 | + |
32 | 36 | /**
|
33 | 37 | * The Class LoggerTest.
|
34 | 38 | *
|
@@ -460,4 +464,37 @@ public void testAlways() {
|
460 | 464 | }
|
461 | 465 | }
|
462 | 466 |
|
| 467 | + /** |
| 468 | + * Validation for issue: https://code.google.com/p/owasp-esapi-java/issues/detail?id=268 |
| 469 | + * Line number must be the line of the caller and not of the wrapper. |
| 470 | + */ |
| 471 | + public void testLine() { |
| 472 | + final String message = "testing only"; |
| 473 | + StringWriter sw = new StringWriter(); |
| 474 | + Layout layout = new Layout() { |
| 475 | + @Override |
| 476 | + public String format(LoggingEvent event) { |
| 477 | + assertEquals("the calling class is this test class", Log4JLoggerTest.class.getName(),event.getLocationInformation().getClassName()); |
| 478 | + return message; |
| 479 | + } |
| 480 | + |
| 481 | + @Override |
| 482 | + public boolean ignoresThrowable() { |
| 483 | + return false; |
| 484 | + } |
| 485 | + |
| 486 | + @Override |
| 487 | + public void activateOptions() { |
| 488 | + |
| 489 | + } |
| 490 | + }; |
| 491 | + Appender appender = new WriterAppender(layout, sw); |
| 492 | + log4JLogger.addAppender(appender); |
| 493 | + try { |
| 494 | + log4JLogger.fatal("testLine"); |
| 495 | + assertEquals("message not generated as expected", message, sw.toString()); |
| 496 | + } finally { |
| 497 | + log4JLogger.removeAppender(appender); |
| 498 | + } |
| 499 | + } |
463 | 500 | }
|
0 commit comments