-
Notifications
You must be signed in to change notification settings - Fork 369
Added property to omit event type information in logs #813
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eeda7ff
Added property to omit event type information in logs
RodolfoAndre fe4841c
Applied some review changes, moved the property reading to LogPrefixA…
RodolfoAndre 49e2e8e
Update LogPrefixAppender, added the omitEventTypeInLogs property to p…
RodolfoAndre 29db8c7
Remove of unused imports
RodolfoAndre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/test/java/org/owasp/esapi/logging/appender/LogPrefixAppenderOmitEventTypeInLogsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package org.owasp.esapi.logging.appender; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TestName; | ||
| import org.junit.runner.RunWith; | ||
| import org.owasp.esapi.ESAPI; | ||
| import org.owasp.esapi.Logger; | ||
| import org.owasp.esapi.Logger.EventType; | ||
| import org.owasp.esapi.SecurityConfiguration; | ||
| import org.owasp.esapi.SecurityConfigurationWrapper; | ||
| import org.powermock.core.classloader.annotations.PrepareForTest; | ||
| import org.powermock.modules.junit4.PowerMockRunner; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.spy; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.owasp.esapi.PropNames.OMIT_EVENT_TYPE_IN_LOGS; | ||
| import static org.powermock.api.mockito.PowerMockito.whenNew; | ||
|
|
||
| @RunWith(PowerMockRunner.class) | ||
| @PrepareForTest(LogPrefixAppender.class) | ||
| public class LogPrefixAppenderOmitEventTypeInLogsTest { | ||
| private static final String EMPTY_RESULT = " "; | ||
| private static final String ETL_RESULT = "EVENT_TYPE"; | ||
| private static final String CIS_RESULT = "CLIENT_INFO"; | ||
| private static final String UIS_RESULT = "USER_INFO"; | ||
| private static final String SIS_RESULT = "SERVER_INFO"; | ||
|
|
||
| @Rule | ||
| public TestName testName = new TestName(); | ||
|
|
||
| private String testLoggerName = testName.getMethodName() + "-LOGGER"; | ||
| private String testLogMessage = testName.getMethodName() + "-MESSAGE"; | ||
| private String testApplicationName = testName.getMethodName() + "-APPLICATION_NAME"; | ||
| private EventType testEventType = Logger.EVENT_UNSPECIFIED; | ||
|
|
||
| private EventTypeLogSupplier etlsSpy; | ||
| private ClientInfoSupplier cisSpy; | ||
| private UserInfoSupplier uisSpy; | ||
| private ServerInfoSupplier sisSpy; | ||
|
|
||
| private static class ConfOverride extends SecurityConfigurationWrapper { | ||
| private final boolean desiredReturn; | ||
|
|
||
| ConfOverride(SecurityConfiguration orig, boolean desiredReturn) { | ||
| super(orig); | ||
| this.desiredReturn = desiredReturn; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean getBooleanProp(String propName) { | ||
| // Would it be better making this file a static import? | ||
| if (propName.equals(OMIT_EVENT_TYPE_IN_LOGS)) { | ||
| return desiredReturn; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Before | ||
| public void buildSupplierSpies() { | ||
| etlsSpy = spy(new EventTypeLogSupplier(Logger.EVENT_UNSPECIFIED)); | ||
| uisSpy = spy(new UserInfoSupplier()); | ||
| cisSpy = spy(new ClientInfoSupplier()); | ||
| sisSpy = spy(new ServerInfoSupplier(testName.getMethodName())); | ||
|
|
||
| testLoggerName = testName.getMethodName() + "-LOGGER"; | ||
| testLogMessage = testName.getMethodName() + "-MESSAGE"; | ||
| testApplicationName = testName.getMethodName() + "-APPLICATION_NAME"; | ||
|
|
||
| ESAPI.override( | ||
| new LogPrefixAppenderOmitEventTypeInLogsTest.ConfOverride(ESAPI.securityConfiguration(), true) | ||
| ); | ||
| } | ||
| @Test | ||
| public void testLongContentWithOmitEventTypeInLogs() throws Exception { | ||
| runTest(ETL_RESULT, EMPTY_RESULT, EMPTY_RESULT, EMPTY_RESULT, ""); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLongContentWithOmitEventTypeInLogsAndUserInfo() throws Exception { | ||
| runTest(ETL_RESULT, UIS_RESULT, EMPTY_RESULT, EMPTY_RESULT, "[USER_INFO]"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLongContentWithOmitEventTypeInLogsAndClientInfo() throws Exception { | ||
| runTest(ETL_RESULT, EMPTY_RESULT, CIS_RESULT, EMPTY_RESULT, "[CLIENT_INFO]"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLongContentWithOmitEventTypeInLogsAndServerInfo() throws Exception { | ||
| runTest(ETL_RESULT, EMPTY_RESULT, EMPTY_RESULT, SIS_RESULT, "[-> SERVER_INFO]"); | ||
| } | ||
|
|
||
| private void runTest(String typeResult, String userResult, String clientResult, String serverResult, String exResult) throws Exception{ | ||
| when(etlsSpy.get()).thenReturn(typeResult); | ||
| when(uisSpy.get()).thenReturn(userResult); | ||
| when(cisSpy.get()).thenReturn(clientResult); | ||
| when(sisSpy.get()).thenReturn(serverResult); | ||
|
|
||
| whenNew(EventTypeLogSupplier.class).withArguments(testEventType).thenReturn(etlsSpy); | ||
| whenNew(UserInfoSupplier.class).withNoArguments().thenReturn(uisSpy); | ||
| whenNew(ClientInfoSupplier.class).withNoArguments().thenReturn(cisSpy); | ||
| whenNew(ServerInfoSupplier.class).withArguments(testLoggerName).thenReturn(sisSpy); | ||
|
|
||
| //Since everything is mocked these booleans don't much matter aside from the later verifies | ||
| LogPrefixAppender lpa = new LogPrefixAppender(false, false, false, false, null); | ||
|
|
||
| String actualResult = lpa.appendTo(testLoggerName, testEventType, testLogMessage); | ||
|
|
||
| StringBuilder expectedResult = new StringBuilder(); | ||
| if (!exResult.isEmpty()) { | ||
| expectedResult.append(exResult); | ||
| expectedResult.append(" "); | ||
| } | ||
| expectedResult.append(testName.getMethodName()); | ||
| expectedResult.append("-MESSAGE"); | ||
|
|
||
| assertEquals(expectedResult.toString() , actualResult); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.