-
Notifications
You must be signed in to change notification settings - Fork 72
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
Added a test case to verify password encryption in logs. #567
Closed
Closed
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8370410
Fixed the issue by encrypting the passwords when updation of the subs…
f78cec2
Added a new test case to validate password encryption.
c3b27c2
Merge branch 'eiffel-community:master' into EIFA-3663
nidhi-fr cf47078
Added a test case to check for password encryption in the logs.
478d6ec
Added testcases to check if the Subscription Password is visible in c…
0d0133d
Added testcases for verification of passwords in log files.
7128a6f
Removed empty lines at the end
ebf59a4
Added Test cases for verification of password in logs.
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 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,40 @@ | ||
package com.ericsson.ei.logFilter; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.filter.Filter; | ||
import ch.qos.logback.core.spi.FilterReply; | ||
import org.springframework.context.annotation.PropertySource; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
@PropertySource("classpath:logback.xml") | ||
public class LogFilter extends Filter<ILoggingEvent> { | ||
|
||
public boolean filter(LocalDateTime start, LocalDateTime end, String logLine) { | ||
DateTimeFormatter logFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss,SSS"); | ||
LocalDateTime current=start; | ||
while(current.isBefore(end)) | ||
{ | ||
String time=current.format(logFormatter); | ||
if(logLine.contains(time)) | ||
{ | ||
return (true); | ||
} | ||
else | ||
{ | ||
current=current.plus(1, ChronoUnit.MILLIS); | ||
} | ||
|
||
|
||
} | ||
return (false); | ||
} | ||
|
||
@Override | ||
public FilterReply decide(ILoggingEvent iLoggingEvent) { | ||
return null; | ||
} | ||
} | ||
|
This file contains 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 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 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 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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>eiffel-intelligence.log</file> | ||
<encoder> | ||
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> | ||
</encoder> | ||
<filter class="com.ericsson.ei.logFilter.LogFilter" /> | ||
</appender> | ||
|
||
<root level="DEBUG"> | ||
<appender-ref ref="FILE" /> | ||
</root> | ||
</configuration> |
This file contains 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 |
---|---|---|
|
@@ -16,17 +16,21 @@ | |
*/ | ||
package com.ericsson.ei.services; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
|
||
import com.ericsson.ei.logFilter.LogFilter; | ||
import org.apache.commons.io.FileUtils; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
|
@@ -62,6 +66,8 @@ | |
import com.mongodb.BasicDBObject; | ||
import com.mongodb.client.MongoClient; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
@TestPropertySource(properties = { | ||
"spring.data.mongodb.database: SubscriptionServiceTest", | ||
"failed.notifications.collection.name: SubscriptionServiceTest-failedNotifications", | ||
|
@@ -83,11 +89,17 @@ public class SubscriptionServiceTest { | |
@Value("${subscriptions.repeat.handler.collection.name}") | ||
private String repeatFlagHandlerCollection; | ||
|
||
@Value("${logging.file.name}") | ||
private File logFileName; | ||
|
||
private String subscriptionName; | ||
|
||
@Autowired | ||
private ISubscriptionService subscriptionService; | ||
|
||
@Autowired | ||
private SubscriptionService subService; | ||
|
||
@Autowired | ||
private MongoDBHandler mongoDBHandler; | ||
|
||
|
@@ -137,16 +149,16 @@ public void testUpdateSubscription() { | |
Subscription subscription2 = mapper.readValue(jsonArray.getJSONObject(0).toString(), Subscription.class); | ||
String expectedSubscriptionName = subscription2.getSubscriptionName(); | ||
String expectedUserName = subscription2.getUserName(); | ||
|
||
subscriptionService.modifySubscription(subscription2, expectedSubscriptionName); | ||
subscriptionService.addSubscription(subscription2); | ||
// Fetch the inserted subscription | ||
subscription2 = null; | ||
subscription2 = subscriptionService.getSubscription(expectedSubscriptionName); | ||
subscriptionName = subscription2.getSubscriptionName(); | ||
|
||
SecurityContextHolder.setContext(securityContext); | ||
Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); | ||
Mockito.when(authentication.getName()).thenReturn("ABC"); | ||
|
||
assertEquals(subscriptionName, expectedSubscriptionName); | ||
assertEquals(authentication.getName(), expectedUserName); | ||
|
||
|
@@ -163,7 +175,6 @@ public void testUpdateSubscription() { | |
subscription = subscriptionService.getSubscription(expectedModifiedSubscriptionName); | ||
subscriptionName = subscription.getSubscriptionName(); | ||
assertEquals(subscriptionName, expectedModifiedSubscriptionName); | ||
|
||
assertEquals(authentication.getName(), expectedModifiedSubscriptionName); | ||
|
||
// deleting the test data | ||
|
@@ -360,4 +371,66 @@ private void deleteSubscriptionsByName(String subscriptionName) throws AccessExc | |
Mockito.when(authentication.getName()).thenReturn("ABC"); | ||
subscriptionService.deleteSubscription(subscriptionName); | ||
} | ||
} | ||
@Test | ||
public void testLogForPasswordAdd() throws Exception { | ||
|
||
try { | ||
Path logFilePath=Paths.get(String.valueOf(logFileName)); | ||
Scanner scanner = new Scanner(logFilePath); | ||
LocalDateTime start = LocalDateTime.now(); | ||
Subscription subscription2 = mapper.readValue(jsonArray.getJSONObject(0).toString(), Subscription.class); | ||
String expectedSubscriptionName = subscription2.getSubscriptionName(); | ||
subscription2.setAuthenticationType("BASIC_AUTH"); | ||
String expectedSubscriptionPassword = subscription2.getPassword(); | ||
subService.addSubscription(subscription2); | ||
LocalDateTime end = LocalDateTime.now(); | ||
LogFilter log = new LogFilter(); | ||
while (scanner.hasNextLine()) { | ||
String line = scanner.nextLine(); | ||
if (log.filter(start, end, line)) { | ||
if ((line.contains(expectedSubscriptionName) && (line.contains("password")))) { | ||
assertFalse(line.contains(expectedSubscriptionPassword)); | ||
} | ||
} | ||
} | ||
// deleting the test data | ||
deleteSubscriptionsByName(expectedSubscriptionName); | ||
Files.delete(logFilePath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. close the scanner |
||
} | ||
catch(Exception e) { | ||
LOGGER.error(e.getMessage(),e); | ||
} | ||
} | ||
@Test | ||
public void testLogForPasswordUpdate() throws Exception { | ||
|
||
try { | ||
Path logFilePath=Paths.get(String.valueOf(logFileName)); | ||
Scanner scanner = new Scanner(logFilePath); | ||
LocalDateTime start = LocalDateTime.now(); | ||
Subscription subscription2 = mapper.readValue(jsonArray.getJSONObject(0).toString(), Subscription.class); | ||
String expectedSubscriptionName = subscription2.getSubscriptionName(); | ||
subscription2.setAuthenticationType("BASIC_AUTH"); | ||
subscription2.setPassword("token123"); | ||
String expectedSubscriptionPassword = subscription2.getPassword(); | ||
subscriptionService.modifySubscription(subscription2,expectedSubscriptionName); | ||
subService.addSubscription(subscription2); | ||
LocalDateTime end = LocalDateTime.now(); | ||
LogFilter log = new LogFilter(); | ||
while (scanner.hasNextLine()) { | ||
String line = scanner.nextLine(); | ||
if (log.filter(start, end, line)) { | ||
if ((line.contains(expectedSubscriptionName) && (line.contains("password")))) { | ||
assertFalse(line.contains(expectedSubscriptionPassword)); | ||
} | ||
} | ||
} | ||
// deleting the test data | ||
deleteSubscriptionsByName(expectedSubscriptionName); | ||
Files.delete(logFilePath); | ||
} | ||
catch(Exception e) { | ||
LOGGER.error(e.getMessage(),e); | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use /tmp as the root path might not be accesible in different hosts