|
16 | 16 | package org.owasp.esapi.reference;
|
17 | 17 |
|
18 | 18 | import java.io.IOException;
|
| 19 | +import java.io.StringWriter; |
19 | 20 | import java.util.Arrays;
|
20 | 21 |
|
21 | 22 | import junit.framework.Test;
|
22 | 23 | import junit.framework.TestCase;
|
23 | 24 | import junit.framework.TestSuite;
|
24 | 25 |
|
| 26 | +import org.apache.log4j.*; |
| 27 | +import org.apache.log4j.xml.XMLLayout; |
25 | 28 | import org.owasp.esapi.ESAPI;
|
26 | 29 | import org.owasp.esapi.Logger;
|
27 | 30 | import org.owasp.esapi.errors.AuthenticationException;
|
@@ -460,4 +463,24 @@ public void testAlways() {
|
460 | 463 | }
|
461 | 464 | }
|
462 | 465 |
|
| 466 | + /** |
| 467 | + * Validation for issue: https://code.google.com/p/owasp-esapi-java/issues/detail?id=268 |
| 468 | + * Line number must be the line of the caller and not of the wrapper. |
| 469 | + */ |
| 470 | + public void testLine() { |
| 471 | + StringWriter sw = new StringWriter(); |
| 472 | + Layout layout = new PatternLayout("%d{ISO8601}%5p [%t] %C:%L - %m%n"); |
| 473 | + Appender appender = new WriterAppender(layout, sw); |
| 474 | + log4JLogger.addAppender(appender); |
| 475 | + try { |
| 476 | + log4JLogger.fatal("testLine"); |
| 477 | + String generatedLine = sw.toString(); |
| 478 | + System.out.println("-> " + generatedLine + " <-"); |
| 479 | + assertTrue("generated line should not have the name of the wrapper class", |
| 480 | + // need to add the ":" sufix otherwise the test would also fail with this test class name |
| 481 | + !generatedLine.contains(Log4JLogger.class.getName()+":")); |
| 482 | + } finally { |
| 483 | + log4JLogger.removeAppender(appender); |
| 484 | + } |
| 485 | + } |
463 | 486 | }
|
0 commit comments