Commit 7254798d authored by amir.yosef's avatar amir.yosef

Adding validation to INFO command

parent f74874d4
...@@ -10,7 +10,6 @@ import java.util.stream.IntStream; ...@@ -10,7 +10,6 @@ import java.util.stream.IntStream;
public class CommandValidator { public class CommandValidator {
private CommandValidator() { private CommandValidator() {
} }
private static final class InstanceHolder { private static final class InstanceHolder {
...@@ -49,8 +48,11 @@ public class CommandValidator { ...@@ -49,8 +48,11 @@ public class CommandValidator {
} }
public boolean validateGetCommand(List<String> args) { public boolean validateGetCommand(List<String> args) {
return args != null && args.size() == 1; return args != null && args.size() == 1;
} }
public boolean validateInfoCommand(List<String> args) {
return args != null && args.size() == 1 && "replication".equalsIgnoreCase(args.getFirst());
}
} }
package command; package command;
import model.Command; import model.Command;
import util.Response;
import server.ServerInfo; import server.ServerInfo;
import util.Response;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -10,6 +10,7 @@ import java.util.stream.Collectors; ...@@ -10,6 +10,7 @@ import java.util.stream.Collectors;
public class InfoCommand implements CommandExecutable<byte[]> { public class InfoCommand implements CommandExecutable<byte[]> {
private final ServerInfo configuration = ServerInfo.getInstance(); private final ServerInfo configuration = ServerInfo.getInstance();
private final CommandValidator validator = CommandValidator.getInstance();
List<String> args; List<String> args;
public InfoCommand(List<String> args) { public InfoCommand(List<String> args) {
...@@ -18,6 +19,9 @@ public class InfoCommand implements CommandExecutable<byte[]> { ...@@ -18,6 +19,9 @@ public class InfoCommand implements CommandExecutable<byte[]> {
@Override @Override
public byte[] execute() { public byte[] execute() {
if (!validator.validateInfoCommand(args)) {
return "unsupported args".getBytes();
}
String command = args.getFirst(); String command = args.getFirst();
if (command.equalsIgnoreCase(Command.REPLICATION.getValue())) { if (command.equalsIgnoreCase(Command.REPLICATION.getValue())) {
Map<String, String> info = configuration.getInfo(); Map<String, String> info = configuration.getInfo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment