Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 374
Issue #839 JavaLogFactory ConcMod#840
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -14,12 +14,8 @@ | ||
| */ | ||
| package org.owasp.esapi.logging.java; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.List; | ||
| import java.util.logging.LogManager; | ||
| import org.hamcrest.CustomMatcher; | ||
| import org.junit.Assert; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| @@ -28,7 +24,6 @@ | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.owasp.esapi.Logger; | ||
| import org.owasp.esapi.errors.ConfigurationException; | ||
| import org.owasp.esapi.logging.appender.LogAppender; | ||
| import org.owasp.esapi.logging.appender.LogPrefixAppender; | ||
| import org.owasp.esapi.logging.cleaning.CodecLogScrubber; | ||
| @@ -48,83 +43,6 @@ public class JavaLogFactoryTest { | ||
| @Rule | ||
| public ExpectedException exEx = ExpectedException.none(); | ||
| @Test | ||
xeno6696 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| public void testLogManagerConfigurationAsClass() throws Exception { | ||
| String propKey = "java.util.logging.config.class"; | ||
| //If defined, grab the value; otherwise, set to a known value to allow for prop to be cleared. | ||
| String sysDefault = System.getProperties().stringPropertyNames().contains(propKey) ? System.getProperty(propKey) : testName.getMethodName(); | ||
| System.setProperty(propKey, "some.defined.value"); | ||
| LogManager testLogManager = new LogManager() { | ||
| @Override | ||
| public void readConfiguration(InputStream ins) throws IOException, SecurityException { | ||
| throw new IOException(testName.getMethodName()); | ||
| } | ||
| }; | ||
| try { | ||
| // This would throw an IOException if the LogManager was not being respected since no esapi-java-logging file is specified | ||
| JavaLogFactory.readLoggerConfiguration(testLogManager); | ||
| } finally { | ||
| //Restore original prop values | ||
| if (testName.getMethodName().equals(sysDefault)) | ||
| System.clearProperty(propKey); | ||
| else { | ||
| System.setProperty(propKey, sysDefault); | ||
| } | ||
| } | ||
| } | ||
| @Test | ||
| public void testLogManagerConfigurationAsFile() throws Exception { | ||
| String propKey = "java.util.logging.config.file"; | ||
| //If defined, grab the value; otherwise, set to a known value to allow for prop to be cleared. | ||
| String sysDefault = System.getProperties().stringPropertyNames().contains(propKey) ? System.getProperty(propKey) : testName.getMethodName(); | ||
| System.setProperty(propKey, "some.defined.value"); | ||
| LogManager testLogManager = new LogManager() { | ||
| @Override | ||
| public void readConfiguration(InputStream ins) throws IOException, SecurityException { | ||
| throw new IOException(testName.getMethodName()); | ||
| } | ||
| }; | ||
| try { | ||
| // This would throw an IOException if the LogManager was not being respected since no esapi-java-logging file is specified | ||
| JavaLogFactory.readLoggerConfiguration(testLogManager); | ||
| } finally { | ||
| //Restore original prop values | ||
| if (testName.getMethodName().equals(sysDefault)) { | ||
| System.clearProperty(propKey); | ||
| } else { | ||
| System.setProperty(propKey, sysDefault); | ||
| } | ||
| } | ||
| } | ||
| @Test | ||
| public void testConfigurationExceptionOnMissingConfiguration() throws Exception { | ||
| final IOException originException = new IOException(testName.getMethodName()); | ||
| LogManager testLogManager = new LogManager() { | ||
| @Override | ||
| public void readConfiguration(InputStream ins) throws IOException, SecurityException { | ||
| throw originException; | ||
| } | ||
| }; | ||
| exEx.expectMessage("Failed to load esapi-java-logging.properties"); | ||
| exEx.expect(ConfigurationException.class); | ||
| exEx.expectCause(new CustomMatcher<Throwable>("Check for IOException") { | ||
| @Override | ||
| public boolean matches(Object item) { | ||
| return item instanceof IOException; | ||
| } | ||
| }); | ||
| JavaLogFactory.readLoggerConfiguration(testLogManager); | ||
| } | ||
| @Test | ||
| public void testCreateLoggerByString() { | ||
| Logger logger = new JavaLogFactory().getLogger("test"); | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.