Skip to content
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

Sensitive commands [WIP] #1705

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Sensitive commands [WIP] #1705

wants to merge 5 commits into from

Conversation

sgdc3
Copy link
Member

@sgdc3 sgdc3 commented Dec 7, 2018

Test doesn't compile, needs feedback.
#1703 related

Test doesn't compile, needs feedback.
#1703 related
@sgdc3 sgdc3 requested a review from ljacqu December 7, 2018 11:25
@sgdc3 sgdc3 changed the title Sensitive commands Sensitive commands [WIP] Dec 7, 2018
@sgdc3
Copy link
Member Author

sgdc3 commented Dec 7, 2018

@ljacqu what do you think about that? I think that using the ConsoleFilter(LogFilterService) constructor is a bit dirty, any suggestion?

* @param sensitive The sensitive data flag
* @return The builder
*/
public CommandBuilder sensitive(boolean sensitive) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I would suggest making sensitive to a small boolean on the builder and to change this method to just be isSensitive(), setting the sensitive flag to true.

String rawCommand = message.substring(message.indexOf("/"));
List<String> components = Arrays.asList(rawCommand.split(" "));
FoundCommandResult command = commandMapper.mapPartsToCommand(null, components);
switch (command.getResultStatus()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really cool! Do you think we should somehow cache invocations of the commands? I'm a little worried about performance since this will be performed every time someone issues a command, and I'm not quite sure how efficient the commandMapper is.
Failing that, I just saw that the LogFilterHelper has a test (LogFilterHelperTest) that ensures that all of those previously hard-coded labels are present. The alternative would be to keep the list and to update the test to use the sensitive flag.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yeah, performance can be a problem hmm... we should test it.
  2. I'm not sure about the test :/ What would you do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll drop the test class for the moment, as it needs to be redone.

Copy link
Member

@ljacqu ljacqu Dec 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you know what, it makes sense to drop the test and to move some of that logic into the filter service. If the filter service gets all commands it can filter out the sensitive ones and create the set of "forbidden messages" by itself. This skips the command mapper and makes sure it's always up-to-date, solving both problems :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, yeah, which portion of logic do you want to move?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously it knew all forbidden command labels instead of calling the command mapper, right? Well, the test had the logic (more or less) to construct them - if you inject the CommandInitializer into here you have access to all the sensitive commands and can do exactly that

default:
break;
}
return command.getCommandDescription().isSensitive();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: if we're playing code beauty contest I'd suggest putting the return statement in the default clause instead of breaking from it there; that way we oppose both cases directly to each other.

private LogFilterService filterService;

public Log4JFilter(LogFilterService filterService) {
this.filterService = filterService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that using the ConsoleFilter(LogFilterService) constructor is a bid dirty, any suggestion?

I don't really have a better suggestion. In theory we could put @Inject on the constructor and have a Log4JFilter instance injected into OnstartupTasks, but given the nature of how it is set up (in OnStartupTasks we have compatibility checks in case a certain log class doesn't exist) I wouldn't recommend doing that. I think your current solution works out nicely :)

@Xephi Xephi changed the title Sensitive commands [WIP] WIP - Sensitive commands Feb 27, 2019
@sgdc3 sgdc3 changed the title WIP - Sensitive commands Sensitive commands [WIP] Aug 8, 2019
@sgdc3 sgdc3 requested a review from ljacqu August 8, 2019 15:42
@sgdc3
Copy link
Member Author

sgdc3 commented Aug 8, 2019

@ljacqu Could you please have again a look at this? :)

@sgdc3 sgdc3 self-assigned this Aug 8, 2019
@sgdc3 sgdc3 added this to the 5.6.0 Release milestone Aug 8, 2019
@ljacqu
Copy link
Member

ljacqu commented Aug 8, 2019

Comment #1705 (comment) still stands, ideally we can construct all combinations of sensitive commands and keep them in a Set, rather than calling the slow command mapper on every command.

I'm also missing tests for the new LogFilterService ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants