Initial commit
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.mattrixwv.cipherstream;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
public class CipherStreamAPI{
|
||||
public static void main(String[] args){
|
||||
SpringApplication.run(CipherStreamAPI.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mattrixwv.cipherstream.aspect;
|
||||
|
||||
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Configuration
|
||||
public class CipherStreamLoggingAspect{
|
||||
public static final String CIPHER_NAME_LOGGING = "cipher";
|
||||
|
||||
|
||||
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping) || @annotation(org.springframework.web.bind.annotation.GetMapping) || @annotation(org.springframework.web.bind.annotation.PutMapping) || @annotation(org.springframework.web.bind.annotation.PostMapping) || @annotation(org.springframework.web.bind.annotation.DeleteMapping)")
|
||||
public void mappedFunction(){
|
||||
//Intentionally blank
|
||||
}
|
||||
|
||||
@Pointcut("execution(* com.mattrixwv.cipherstream.controller..*(..))")
|
||||
public void cipherMethod(){
|
||||
//Intentionally blank
|
||||
}
|
||||
|
||||
@AfterReturning(pointcut = "cipherMethod() && mappedFunction()", returning = "returnedJson")
|
||||
public void getCipherInfo(ObjectNode returnedJson){
|
||||
//Print a log
|
||||
log.info("CipherStream log {}", returnedJson);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mattrixwv.cipherstream.config;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class FullFilter extends OncePerRequestFilter{
|
||||
@Override
|
||||
protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) throws ServletException, IOException{
|
||||
//Get the requestId
|
||||
if(request.getHeader("X-Request-Id") != null){
|
||||
MDC.put("requestId", request.getHeader("X-Request-Id"));
|
||||
}
|
||||
|
||||
//Get IP address
|
||||
if(request.getHeader("X-Forwarded-For") != null){
|
||||
MDC.put("ip", request.getHeader("X-Forwarded-For").split(",")[0]);
|
||||
}
|
||||
|
||||
//Get all of the parameters in the request and print them in the log
|
||||
StringJoiner parameters = new StringJoiner(", ");
|
||||
request.getParameterMap().entrySet().forEach(entry -> {
|
||||
if(!entry.getKey().equals("_")){
|
||||
String key = entry.getKey();
|
||||
String value = "";
|
||||
if(entry.getValue().length > 1){
|
||||
StringJoiner joiner = new StringJoiner(", ", "[", "]");
|
||||
for(String str : entry.getValue()){
|
||||
joiner.add(str);
|
||||
}
|
||||
value = joiner.toString();
|
||||
}
|
||||
else{
|
||||
value = entry.getValue()[0];
|
||||
}
|
||||
parameters.add(key + "->" + value);
|
||||
}
|
||||
});
|
||||
if(parameters.length() > 0){
|
||||
log.info("Request parameters: {}", parameters);
|
||||
}
|
||||
|
||||
//Get the path
|
||||
MDC.put("url", request.getRequestURI());
|
||||
|
||||
//Continue to the controller
|
||||
filterChain.doFilter(request, response);
|
||||
|
||||
//Clear the MDC for the next request
|
||||
MDC.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.mattrixwv.cipherstream.controller;
|
||||
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestControllerAdvice(annotations = RestController.class)
|
||||
public class ExceptionRestController extends ResponseEntityExceptionHandler{
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
|
||||
@ExceptionHandler(InvalidCipherParameterException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ResponseBody
|
||||
public ObjectNode invalidCipherParameterHandler(InvalidCipherParameterException error){
|
||||
log.warn("Invalid user input was supplied: {}", error.getMessage());
|
||||
|
||||
|
||||
ObjectNode returnJson = mapper.createObjectNode();
|
||||
returnJson.put("message", error.getMessage());
|
||||
|
||||
|
||||
return returnJson;
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ResponseBody
|
||||
public ObjectNode genericExceptionHandler(Exception error){
|
||||
log.error(error.getMessage(), error);
|
||||
|
||||
|
||||
ObjectNode returnJson = mapper.createObjectNode();
|
||||
returnJson.put("message", error.getMessage());
|
||||
|
||||
|
||||
return returnJson;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.combination.ADFGVX;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("adfgvx")
|
||||
public class AdfgvxCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeAdfgvx(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "ADFGVX");
|
||||
log.info("Encoding ADFGVX");
|
||||
|
||||
|
||||
CipherParameterUtil.verifySquareKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
ADFGVX adfgvx = new ADFGVX(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = adfgvx.encode(squareKeyword, keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeAdfgvx(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "ADFGVX");
|
||||
log.info("Decoding ADFGVX");
|
||||
|
||||
|
||||
CipherParameterUtil.verifySquareKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
ADFGVX adfgvx = new ADFGVX(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = adfgvx.decode(squareKeyword, keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.combination.ADFGX;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("adfgx")
|
||||
public class AdfgxCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeAdfgx(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "ADFGX");
|
||||
log.info("Encoding ADFGX");
|
||||
|
||||
|
||||
CipherParameterUtil.verifySquareKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
ADFGX adfgx = new ADFGX(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = adfgx.encode(squareKeyword, keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeAdfgx(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "ADFGX");
|
||||
log.info("Decoding ADFGX");
|
||||
|
||||
|
||||
CipherParameterUtil.verifySquareKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
ADFGX adfgx = new ADFGX(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = adfgx.decode(squareKeyword, keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Affine;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/affine")
|
||||
public class AffineCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeAffine(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Affine");
|
||||
log.info("Encoding Affine");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyAffineParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int key1 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_1).asInt();
|
||||
int key2 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_2).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Affine affine = new Affine(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = affine.encode(key1, key2, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeAffine(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Affine");
|
||||
log.info("Decoding Affine");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyAffineParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int key1 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_1).asInt();
|
||||
int key2 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_2).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Affine affine = new Affine(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = affine.decode(key1, key2, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Atbash;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/atbash")
|
||||
public class AtbashCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeAtbash(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Atbash");
|
||||
log.info("Encoding Atbash");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyAtbashParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Atbash atbash = new Atbash(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = atbash.encode(inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeAtbash(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Atbash");
|
||||
log.info("Decoding Atbash");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyAtbashParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Atbash atbash = new Atbash(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = atbash.decode(inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Autokey;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/autokey")
|
||||
public class AutokeyCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeAutokey(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Autokey");
|
||||
log.info("Encoding Autokey");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Autokey autokey = new Autokey(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = autokey.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeAutokey(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Autokey");
|
||||
log.info("Decoding Autokey");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Autokey autokey = new Autokey(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = autokey.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Baconian;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/baconian")
|
||||
public class BaconianCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeBaconian(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Baconian");
|
||||
log.info("Encoding Baconian");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyBaconianParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Baconian baconian = new Baconian(preserveCapitals);
|
||||
String outputString = baconian.encode(inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeBaconian(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Baconian");
|
||||
log.info("Decoding Baconian");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyBaconianParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Baconian baconian = new Baconian(preserveCapitals);
|
||||
String outputString = baconian.decode(inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.BaseX;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/basex")
|
||||
public class BaseXCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeBaseX(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "BaseX");
|
||||
log.info("Encoding BaseX");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyBaseXParams(cipherParams);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
int base = cipherParams.get(CipherParameterUtil.BASE_X_BASE).asInt();
|
||||
|
||||
|
||||
BaseX baseX = new BaseX(base);
|
||||
String outputString = baseX.encode(inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeBaseX(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "BaseX");
|
||||
log.info("Decoding BaseX");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyBaseXParams(cipherParams);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
int base = cipherParams.get(CipherParameterUtil.BASE_X_BASE).asInt();
|
||||
|
||||
|
||||
BaseX baseX = new BaseX(base);
|
||||
String outputString = baseX.decode(inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Beaufort;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/beaufort")
|
||||
public class BeaufortCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeBeaufort(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Beaufort");
|
||||
log.info("Encoding Beaufort");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Beaufort beaufort = new Beaufort(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = beaufort.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeBeaufort(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Beaufort");
|
||||
log.info("Decoding Beaufort");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Beaufort beaufort = new Beaufort(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = beaufort.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Caesar;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/caesar")
|
||||
public class CaesarCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeCaesar(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Caesar");
|
||||
log.info("Encoding Caesar");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyCaesarParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int shiftAmount = cipherParams.get(CipherParameterUtil.CAESAR_SHIFT_AMOUNT).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Caesar caesar = new Caesar(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = caesar.encode(shiftAmount, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeCaesar(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Caesar");
|
||||
log.info("Decoding Caesar");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyCaesarParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int shiftAmount = cipherParams.get(CipherParameterUtil.CAESAR_SHIFT_AMOUNT).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
Caesar caesar = new Caesar(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = caesar.decode(shiftAmount, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.OneTimePad;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/oneTimePad")
|
||||
public class OneTimePadCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeOneTimePad(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "One-Time Pad");
|
||||
log.info("Encoding One Time Pad");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
OneTimePad oneTimePad = new OneTimePad(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = oneTimePad.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeOneTimePad(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "One-Time Pad");
|
||||
log.info("Decoding One Time Pad");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
OneTimePad oneTimePad = new OneTimePad(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = oneTimePad.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Porta;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/porta")
|
||||
public class PortaCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodePorta(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Porta");
|
||||
log.info("Encoding Porta");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Porta porta = new Porta(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = porta.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodePorta(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Porta");
|
||||
log.info("Decoding Porta");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Porta porta = new Porta(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = porta.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Substitution;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/substitution")
|
||||
public class SubstitutionCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeSubstitution(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Substitution");
|
||||
log.info("Encoding Substitution");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Substitution substitution = new Substitution(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = substitution.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeSubstitution(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Substitution");
|
||||
log.info("Decoding Substitution");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Substitution substitution = new Substitution(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = substitution.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Vigenere;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/vigenere")
|
||||
public class VigenereCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeVigenere(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Vigenere");
|
||||
log.info("Encoding Vigenere");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Vigenere vigenere = new Vigenere(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = vigenere.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeVigenere(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Vigenere");
|
||||
log.info("Decoding Vigenere");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Vigenere vigenere = new Vigenere(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = vigenere.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Bifid;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/bifid")
|
||||
public class BifidCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeBifid(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Bifid");
|
||||
log.info("Encoding Bifid");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Bifid bifid = new Bifid(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = bifid.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeBifid(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Bifid");
|
||||
log.info("Decoding Bifid");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Bifid bifid = new Bifid(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = bifid.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Columnar;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/columnar")
|
||||
public class ColumnarCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeColumnar(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Columnar");
|
||||
log.info("Encoding Columnar");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Columnar columnar = new Columnar(preserveCapitals, preserveWhitespace, preserveSymbols, true);
|
||||
String outputString = columnar.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeColumnar(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Columnar");
|
||||
log.info("Decoding Columnar");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Columnar columnar = new Columnar(preserveCapitals, preserveWhitespace, preserveSymbols, true);
|
||||
String outputString = columnar.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Hill;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/hill")
|
||||
public class HillCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Hill");
|
||||
log.info("Encoding Hill");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyHillParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int[][] key = new ObjectMapper().treeToValue(cipherParams.get(CipherParameterUtil.HILL_KEY), int[][].class);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Hill hill = new Hill(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = hill.encode(key, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Hill");
|
||||
log.info("Decoding Hill");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyHillParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int[][] key = new ObjectMapper().treeToValue(cipherParams.get(CipherParameterUtil.HILL_KEY), int[][].class);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Hill hill = new Hill(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = hill.decode(key, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Morse;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/morse")
|
||||
public class MorseCodeController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeMorse(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Morse");
|
||||
log.info("Encoding Morse");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyMorseParams(cipherParams);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Morse morse = new Morse();
|
||||
String outputString = morse.encode(inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeMorse(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Morse");
|
||||
log.info("Decoding Morse");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyMorseParams(cipherParams);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Morse morse = new Morse();
|
||||
String outputString = morse.decode(inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Playfair;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/playfair")
|
||||
public class PlayfairCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodePlayfair(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Playfair");
|
||||
log.info("Encoding Playfair");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Playfair playfair = new Playfair(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = playfair.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodePlayfair(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Playfair");
|
||||
log.info("Decoding Playfair");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Playfair playfair = new Playfair(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = playfair.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/polybius")
|
||||
public class PolybiusSquareController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodePolybius(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Polybius Square");
|
||||
log.info("Encoding Polybius");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyPolybiusParams(cipherParams);
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
PolybiusSquare polybiusSquare = new PolybiusSquare(preserveWhitespace, preserveSymbols);
|
||||
String outputString = polybiusSquare.encode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodePolybius(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Polybius Square");
|
||||
log.info("Decoding Polybius");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyPolybiusParams(cipherParams);
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
PolybiusSquare polybiusSquare = new PolybiusSquare(preserveWhitespace, preserveSymbols);
|
||||
String outputString = polybiusSquare.decode(keyword, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.RailFence;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/railFence")
|
||||
public class RailFenceController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeRailFence(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Rail Fence");
|
||||
log.info("Encoding Rail Fence");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyRailFenceParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int rails = cipherParams.get(CipherParameterUtil.RAIL_FENCE_RAILS).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
RailFence railFence = new RailFence(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = railFence.encode(rails, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeRailFence(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Rail Fence");
|
||||
log.info("Decoding Rail Fence");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyRailFenceParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int rails = cipherParams.get(CipherParameterUtil.RAIL_FENCE_RAILS).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
RailFence railFence = new RailFence(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = railFence.decode(rails, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Trifid;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/trifid")
|
||||
public class TrifidCipherController{
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeTrifid(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Trifid");
|
||||
log.info("Encoding Trifid");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyTrifidParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
char fill = cipherParams.get(CipherParameterUtil.TRIFID_FILL).asText().charAt(0);
|
||||
int groupLength = cipherParams.get(CipherParameterUtil.TRIFID_GROUP_LENGTH).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Trifid trifid = new Trifid(preserveCapitals, preserveWhitespace, preserveSymbols, fill);
|
||||
String outputString = trifid.encode(keyword, groupLength, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeTrifid(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Trifid");
|
||||
log.info("Decoding Trifid");
|
||||
|
||||
|
||||
CipherParameterUtil.verifyTrifidParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
char fill = cipherParams.get(CipherParameterUtil.TRIFID_FILL).asText().charAt(0);
|
||||
int groupLength = cipherParams.get(CipherParameterUtil.TRIFID_GROUP_LENGTH).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
|
||||
|
||||
Trifid trifid = new Trifid(preserveCapitals, preserveWhitespace, preserveSymbols, fill);
|
||||
String outputString = trifid.decode(keyword, groupLength, inputString);
|
||||
|
||||
cipherParams.put(CipherParameterUtil.OUTPUT_STRING, outputString);
|
||||
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mattrixwv.cipherstream.exception;
|
||||
|
||||
|
||||
public class InvalidCipherParameterException extends RuntimeException{
|
||||
public InvalidCipherParameterException(){
|
||||
super();
|
||||
}
|
||||
public InvalidCipherParameterException(String message){
|
||||
super(message);
|
||||
}
|
||||
public InvalidCipherParameterException(Throwable throwable){
|
||||
super(throwable);
|
||||
}
|
||||
public InvalidCipherParameterException(String message, Throwable throwable){
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package com.mattrixwv.cipherstream.utils;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public class CipherParameterUtil{
|
||||
//Error messages
|
||||
public static final String PRESENT_MESSAGE = " must be present";
|
||||
public static final String INTEGER_MESSAGE = " must be an integer";
|
||||
public static final String TEXT_MESSAGE = " must be text";
|
||||
public static final String BOOLEAN_MESSAGE = " must be a boolean";
|
||||
public static final String INTEGER_ARRAY_MESSAGE = " must be an integer array";
|
||||
public static final String CHARACTER_MESSAGE = " must be a single character";
|
||||
//General
|
||||
public static final String PRESERVE_CAPITALS = "preserveCapitals";
|
||||
public static final String PRESERVE_WHITESPACE = "preserveWhitespace";
|
||||
public static final String PRESERVE_SYMBOLS = "preserveSymbols";
|
||||
public static final String INPUT_STRING = "inputString";
|
||||
public static final String OUTPUT_STRING = "outputString";
|
||||
public static final String KEYWORD = "keyword";
|
||||
|
||||
|
||||
//Caesar
|
||||
public static final String CAESAR_SHIFT_AMOUNT = "shiftAmount";
|
||||
|
||||
//Affine
|
||||
public static final String AFFINE_KEY_1 = "key1";
|
||||
public static final String AFFINE_KEY_2 = "key2";
|
||||
|
||||
//BaseX
|
||||
public static final String BASE_X_BASE = "base";
|
||||
|
||||
//ADFGX
|
||||
public static final String SQUARE_KEYWORD = "squareKeyword";
|
||||
|
||||
//Hill
|
||||
public static final String HILL_KEY = "key";
|
||||
|
||||
//Rail Fence
|
||||
public static final String RAIL_FENCE_RAILS = "rails";
|
||||
|
||||
//Trifid
|
||||
public static final String TRIFID_FILL = "fill";
|
||||
public static final String TRIFID_GROUP_LENGTH = "groupLength";
|
||||
|
||||
|
||||
public static void verifyUniversalParams(ObjectNode params){
|
||||
if(!params.has(PRESERVE_CAPITALS)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_CAPITALS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_CAPITALS).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_CAPITALS + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(PRESERVE_WHITESPACE)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_WHITESPACE + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_WHITESPACE).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_WHITESPACE + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(PRESERVE_SYMBOLS)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_SYMBOLS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_SYMBOLS).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_SYMBOLS + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyParamsWithKeyword(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(KEYWORD)){
|
||||
throw new InvalidCipherParameterException(KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(KEYWORD).isTextual()){
|
||||
throw new InvalidCipherParameterException(KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyCaesarParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(CAESAR_SHIFT_AMOUNT)){
|
||||
throw new InvalidCipherParameterException(CAESAR_SHIFT_AMOUNT + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(CAESAR_SHIFT_AMOUNT).isInt()){
|
||||
throw new InvalidCipherParameterException(CAESAR_SHIFT_AMOUNT + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyAffineParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(AFFINE_KEY_1)){
|
||||
throw new InvalidCipherParameterException(AFFINE_KEY_1 + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(AFFINE_KEY_1).isInt()){
|
||||
throw new InvalidCipherParameterException(AFFINE_KEY_1 + INTEGER_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(AFFINE_KEY_2)){
|
||||
throw new InvalidCipherParameterException(AFFINE_KEY_2 + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(AFFINE_KEY_2).isInt()){
|
||||
throw new InvalidCipherParameterException(AFFINE_KEY_2 + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyAtbashParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
}
|
||||
|
||||
public static void verifyBaconianParams(ObjectNode params){
|
||||
if(!params.has(PRESERVE_CAPITALS)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_CAPITALS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_CAPITALS).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_CAPITALS + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyBaseXParams(ObjectNode params){
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(BASE_X_BASE)){
|
||||
throw new InvalidCipherParameterException(BASE_X_BASE + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(BASE_X_BASE).isInt()){
|
||||
throw new InvalidCipherParameterException(BASE_X_BASE + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifySquareKeyword(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(SQUARE_KEYWORD)){
|
||||
throw new InvalidCipherParameterException(SQUARE_KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(SQUARE_KEYWORD).isTextual()){
|
||||
throw new InvalidCipherParameterException(SQUARE_KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyHillParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(HILL_KEY)){
|
||||
throw new InvalidCipherParameterException(HILL_KEY + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(HILL_KEY).isArray()){
|
||||
throw new InvalidCipherParameterException(HILL_KEY + INTEGER_ARRAY_MESSAGE);
|
||||
}
|
||||
if(!params.get(HILL_KEY).get(0).isArray()){
|
||||
throw new InvalidCipherParameterException(HILL_KEY + INTEGER_ARRAY_MESSAGE);
|
||||
}
|
||||
if(!params.get(HILL_KEY).get(0).get(0).isInt()){
|
||||
throw new InvalidCipherParameterException(HILL_KEY + INTEGER_ARRAY_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyMorseParams(ObjectNode params){
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyPolybiusParams(ObjectNode params){
|
||||
if(!params.has(PRESERVE_WHITESPACE)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_WHITESPACE + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_WHITESPACE).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_WHITESPACE + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(PRESERVE_SYMBOLS)){
|
||||
throw new InvalidCipherParameterException(PRESERVE_SYMBOLS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(PRESERVE_SYMBOLS).isBoolean()){
|
||||
throw new InvalidCipherParameterException(PRESERVE_SYMBOLS + BOOLEAN_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(KEYWORD)){
|
||||
throw new InvalidCipherParameterException(KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(KEYWORD).isTextual()){
|
||||
throw new InvalidCipherParameterException(KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyRailFenceParams(ObjectNode params){
|
||||
verifyUniversalParams(params);
|
||||
|
||||
if(!params.has(RAIL_FENCE_RAILS)){
|
||||
throw new InvalidCipherParameterException(RAIL_FENCE_RAILS + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(RAIL_FENCE_RAILS).isInt()){
|
||||
throw new InvalidCipherParameterException(RAIL_FENCE_RAILS + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyTrifidParams(ObjectNode params){
|
||||
verifyParamsWithKeyword(params);
|
||||
|
||||
if(!params.has(TRIFID_FILL)){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(TRIFID_FILL).isTextual()){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + TEXT_MESSAGE);
|
||||
}
|
||||
if(params.get(TRIFID_FILL).asText().length() > 1){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + CHARACTER_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(TRIFID_GROUP_LENGTH)){
|
||||
throw new InvalidCipherParameterException(TRIFID_GROUP_LENGTH);
|
||||
}
|
||||
if(!params.get(TRIFID_GROUP_LENGTH).isInt()){
|
||||
throw new InvalidCipherParameterException(TRIFID_GROUP_LENGTH + INTEGER_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
0
src/main/resources/application.properties
Normal file
0
src/main/resources/application.properties
Normal file
27
src/main/resources/log4j2-spring.xml
Normal file
27
src/main/resources/log4j2-spring.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--<Configuration strict="true" xmlns="http://logging.apache.org/log4j/2.0/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config https://raw.githubusercontent.com/apache/logging-log4j2/master/log4j-core/src/main/resources/Log4j-config.xsd">-->
|
||||
<Configuration>
|
||||
<Appenders>
|
||||
<Console name="console" target="SYSTEM_OUT">
|
||||
<PatternLayout disableAnsi="false">
|
||||
<Pattern>
|
||||
%style{%d{MM-dd-yyyy HH:mm:ss.SSSZ}}{bright, black} %highlight{%5p} %style{function=}{bright, black}%style{%50.50replace{%c{0}.%M}{}{}}{blue, bright} %style{requestId=%36.36X{requestId}}{bright, black} %style{username=%X{username}}{bright, black} %highlight{---} %message%n
|
||||
</Pattern>
|
||||
</PatternLayout>
|
||||
</Console>
|
||||
<RollingRandomAccessFile name="file" fileName="cipherStreamWeb.log" immediateFlush="true">
|
||||
<JsonTemplateLayout eventTemplateUri="classpath:template.json"></JsonTemplateLayout>
|
||||
<Policies>
|
||||
<SizeBasedTriggeringPolicy size="10MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="20"/>
|
||||
</RollingRandomAccessFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="info" includeLocation="true">
|
||||
<AppenderRef ref="console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
37
src/main/resources/template.json
Normal file
37
src/main/resources/template.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"timestamp": {
|
||||
"$resolver": "timestamp",
|
||||
"pattern": {
|
||||
"format": "yyy-MM-dd HH:mm:ss.SSSZ"
|
||||
}
|
||||
},
|
||||
"level": {
|
||||
"$resolver": "level",
|
||||
"field": "name"
|
||||
},
|
||||
"requestId": {
|
||||
"$resolver": "mdc",
|
||||
"key": "requestId"
|
||||
},
|
||||
"message": {
|
||||
"$resolver": "message",
|
||||
"stringified": true
|
||||
},
|
||||
"exception": {
|
||||
"exception_class": {
|
||||
"$resolver": "exception",
|
||||
"field": "className"
|
||||
},
|
||||
"exception_message": {
|
||||
"$resolver": "exception",
|
||||
"field": "message"
|
||||
},
|
||||
"stacktrace": {
|
||||
"$resolver": "exception",
|
||||
"field": "stackTrace",
|
||||
"stackTrace": {
|
||||
"stringified": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.mattrixwv.cipherstream.aspect;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class CipherStreamLoggingAspectTest{
|
||||
@InjectMocks
|
||||
private CipherStreamLoggingAspect aspect;
|
||||
|
||||
|
||||
@Test
|
||||
public void testMappedFunction(){
|
||||
aspect.mappedFunction();
|
||||
|
||||
|
||||
assertNotNull(aspect);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCipherMethod(){
|
||||
aspect.cipherMethod();
|
||||
|
||||
|
||||
assertNotNull(aspect);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode jsonNode = new ObjectMapper().createObjectNode();
|
||||
jsonNode.put("something", "Something Important");
|
||||
|
||||
|
||||
aspect.getCipherInfo(null);
|
||||
|
||||
|
||||
assertNotNull(aspect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mattrixwv.cipherstream.config;
|
||||
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = CaesarCipherController.class)
|
||||
public class FullFilterIntegrationTest{
|
||||
//HTTP
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Mock
|
||||
private HttpServletRequest request;
|
||||
@Mock
|
||||
private HttpServletResponse response;
|
||||
//Logging
|
||||
@Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
|
||||
private Logger logger;
|
||||
@Mock
|
||||
private MDCAdapter mdc;
|
||||
//Fields
|
||||
private UUID requestId = UUID.randomUUID();
|
||||
private String ipAddresses = "192.168.1.1,192.168.1.2,192.168.1.3";
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal() throws Exception{
|
||||
mockMvc.perform(get("/cipherStream")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddresses)
|
||||
.param("param1", "value1")
|
||||
.param("param2", "value2.1")
|
||||
.param("param2", "value2.2")
|
||||
.param("_", "value3"))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verify(logger, times(1)).info(eq("Request parameters: {}"), any(StringJoiner.class));
|
||||
verify(mdc, times(1)).put("requestId", requestId.toString());
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_NoParameters() throws Exception{
|
||||
mockMvc.perform(get("/cipherStream")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddresses))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verify(logger, never()).info(anyString(), any(Object.class));
|
||||
verify(mdc, times(1)).put("requestId", requestId.toString());
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.mattrixwv.cipherstream.config;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class FullFilterTest{
|
||||
@InjectMocks
|
||||
private FullFilter fullFilter;
|
||||
@Mock
|
||||
private HttpServletRequest request;
|
||||
@Mock
|
||||
private HttpServletResponse response;
|
||||
@Mock
|
||||
private FilterChain filterChain;
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal() throws Exception{
|
||||
HashMap<String, String[]> parameterMap = new HashMap<>();
|
||||
parameterMap.put("key1", new String[]{"value1"});
|
||||
parameterMap.put("key2", new String[]{"value2.1", "value2.2"});
|
||||
parameterMap.put("_", new String[]{"value3"});
|
||||
|
||||
|
||||
doReturn("X-Request-Id").when(request).getHeader("X-Request-Id");
|
||||
doReturn("192.168.1.1,192.168.1.2,192.168.1.3").when(request).getHeader("X-Forwarded-For");
|
||||
doReturn(parameterMap).when(request).getParameterMap();
|
||||
doReturn("/testURL").when(request).getRequestURI();
|
||||
|
||||
|
||||
fullFilter.doFilterInternal(request, response, filterChain);
|
||||
|
||||
|
||||
verify(request, times(2)).getHeader("X-Request-Id");
|
||||
verify(request, times(2)).getHeader("X-Forwarded-For");
|
||||
verify(filterChain, times(1)).doFilter(request, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_NoParameters() throws Exception{
|
||||
doReturn("X-Request-Id").when(request).getHeader("X-Request-Id");
|
||||
doReturn("192.168.1.1,192.168.1.2,192.168.1.3").when(request).getHeader("X-Forwarded-For");
|
||||
doReturn(new HashMap<>()).when(request).getParameterMap();
|
||||
doReturn("/testURL").when(request).getRequestURI();
|
||||
|
||||
|
||||
fullFilter.doFilterInternal(request, response, filterChain);
|
||||
|
||||
|
||||
verify(request, times(2)).getHeader("X-Request-Id");
|
||||
verify(request, times(2)).getHeader("X-Forwarded-For");
|
||||
verify(filterChain, times(1)).doFilter(request, response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.mattrixwv.cipherstream.controller;
|
||||
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.config.FullFilter;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@Import({AopAutoConfiguration.class, FullFilter.class, CipherStreamLoggingAspect.class})
|
||||
public class CipherStreamControllerIntegrationTestBase{
|
||||
protected static final ObjectMapper mapper = new ObjectMapper();
|
||||
//Objects
|
||||
protected ObjectNode decodedNode;
|
||||
protected ObjectNode encodedNode;
|
||||
//Fields
|
||||
protected static final String requestId = UUID.randomUUID().toString();
|
||||
protected static final String ipAddress = "192.168.1.1";
|
||||
|
||||
//MDC
|
||||
@Mock
|
||||
protected MDCAdapter mdc;
|
||||
|
||||
//Base
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.CipherStreamController")
|
||||
protected Logger baseLogger;
|
||||
|
||||
//Combination
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController")
|
||||
protected Logger adfgvxLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController")
|
||||
protected Logger adfgxLogger;
|
||||
|
||||
//Monosubstitution
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController")
|
||||
protected Logger affineLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController")
|
||||
protected Logger atbashLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController")
|
||||
protected Logger autokeyLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController")
|
||||
protected Logger baconianLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController")
|
||||
protected Logger baseXLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController")
|
||||
protected Logger beaufortLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController")
|
||||
protected Logger caesarLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController")
|
||||
protected Logger oneTimePadLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController")
|
||||
protected Logger portaLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController")
|
||||
protected Logger substitutionLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController")
|
||||
protected Logger vigenereLogger;
|
||||
|
||||
//Polysubstitution
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController")
|
||||
protected Logger bifidLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController")
|
||||
protected Logger columnarLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController")
|
||||
protected Logger hillLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController")
|
||||
protected Logger morseLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController")
|
||||
protected Logger playfiarLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController")
|
||||
protected Logger polybiusLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController")
|
||||
protected Logger railFenceLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController")
|
||||
protected Logger trifidLogger;
|
||||
|
||||
//Misc
|
||||
@Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
|
||||
protected Logger filterLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect")
|
||||
protected Logger aspectLogger;
|
||||
|
||||
|
||||
protected void verifyFilter(String url){
|
||||
verify(filterLogger, never()).info(eq("Request parameters: {}"), any(StringBuilder.class));
|
||||
verify(mdc, times(1)).put(eq("requestId"), any());
|
||||
verify(mdc, times(1)).put("ip", ipAddress);
|
||||
verify(mdc, times(1)).put("url", url);
|
||||
verify(mdc, times(1)).clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.mattrixwv.cipherstream.controller;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ExceptionRestControllerTest{
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
@InjectMocks
|
||||
private ExceptionRestController controller;
|
||||
//Fields
|
||||
private static final String errorMessage = "Error message";
|
||||
|
||||
|
||||
@Test
|
||||
public void testInvalidCipherParameterHandler(){
|
||||
//Setup variables
|
||||
InvalidCipherParameterException error = new InvalidCipherParameterException(errorMessage);
|
||||
ObjectNode expectedJson = mapper.createObjectNode();
|
||||
expectedJson.put("message", errorMessage);
|
||||
|
||||
|
||||
//Run the function
|
||||
ObjectNode returnJson = controller.invalidCipherParameterHandler(error);
|
||||
|
||||
|
||||
//Verify the data
|
||||
assertEquals(expectedJson, returnJson);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenericExceptionHandler(){
|
||||
//Setup variables
|
||||
Exception error = new Exception(errorMessage);
|
||||
ObjectNode expectedJson = mapper.createObjectNode();
|
||||
expectedJson.put("message", errorMessage);
|
||||
|
||||
|
||||
//Run the function
|
||||
JsonNode returnJson = controller.genericExceptionHandler(error);
|
||||
|
||||
|
||||
//Verify the data
|
||||
assertEquals(expectedJson, returnJson);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AdfgvxCipherController.class)
|
||||
public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/adfgvx";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
private String keyword = "keyword";
|
||||
private String squareKeyword = "SquareKeyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Encoding ADFGVX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Decoding ADFGVX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AdfgvxCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AdfgvxCipherController adfgvxCipherController;
|
||||
private static final String KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
|
||||
private static final String INPUT_STRING = "Message to-encode";
|
||||
private static final String OUTPUT_STRING = "AXgvdavfxgagfa afag-aaxdxfgdagda";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx(){
|
||||
ObjectNode cipherParams = generateParams(KEYWORD, SQUARE_KEYWORD, INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgvxCipherController.encodeAdfgvx(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgvxCipherController.encodeAdfgvx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx(){
|
||||
ObjectNode cipherParams = generateParams(KEYWORD, SQUARE_KEYWORD, OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgvxCipherController.decodeAdfgvx(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgvxCipherController.decodeAdfgvx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String squareKeyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AdfgxCipherController.class)
|
||||
public class AdfgxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/adfgx";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private String keyword = "keyword";
|
||||
private String squareKeyword = "SquareKeyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Encoding ADFGX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgx() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Decoding ADFGX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AdfgxCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AdfgxCipherController adfgxCipherController;
|
||||
private static final String ADFGX_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String ADFGX_SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
|
||||
private static final String ADFGX_INPUT_STRING = "Message to^encode";
|
||||
private static final String ADFGX_OUTPUT_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx(){
|
||||
ObjectNode cipherParams = generateParams(ADFGX_KEYWORD, ADFGX_SQUARE_KEYWORD, ADFGX_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgxCipherController.encodeAdfgx(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgxCipherController.encodeAdfgx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgx(){
|
||||
ObjectNode cipherParams = generateParams(ADFGX_KEYWORD, ADFGX_SQUARE_KEYWORD, ADFGX_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgxCipherController.decodeAdfgx(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgxCipherController.decodeAdfgx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String squareKeyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AffineCipherController.class)
|
||||
public class AffineCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/affine";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Pbtthlb yz^burzwb";
|
||||
private int key1 = 5;
|
||||
private int key2 = 7;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.AFFINE_KEY_1, key1);
|
||||
decodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.AFFINE_KEY_1, key1);
|
||||
encodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAffine() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Encoding Affine");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAffine() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Decoding Affine");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AffineCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AffineCipherController affineCipherController;
|
||||
private static final String AFFINE_INPUT_STRING = "Message to^encode";
|
||||
private static final String AFFINE_OUTPUT_STRING = "Pbtthlb yz^burzwb";
|
||||
private static final int AFFINE_KEY_1 = 5;
|
||||
private static final int AFFINE_KEY_2 = 7;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAffine(){
|
||||
ObjectNode cipherParams = generateParams(AFFINE_KEY_1, AFFINE_KEY_2, AFFINE_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = affineCipherController.encodeAffine(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AFFINE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
affineCipherController.encodeAffine(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAffine(){
|
||||
ObjectNode cipherParams = generateParams(AFFINE_KEY_1, AFFINE_KEY_2, AFFINE_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = affineCipherController.decodeAffine(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AFFINE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
affineCipherController.decodeAffine(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int key1, int key2, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.AFFINE_KEY_1, key1);
|
||||
cipherParams.put(CipherParameterUtil.AFFINE_KEY_2, key2);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AtbashCipherController.class)
|
||||
public class AtbashCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/atbash";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Nvhhztv gl^vmxlwv";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAtbash() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Encoding Atbash");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAtbash() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Decoding Atbash");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AtbashCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AtbashCipherController atbashCipherController;
|
||||
private static final String ATBASH_INPUT_STRING = "Message to^encode";
|
||||
private static final String ATBASH_OUTPUT_STRING = "Nvhhztv gl^vmxlwv";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAtbash(){
|
||||
ObjectNode cipherParams = generateParams(ATBASH_INPUT_STRING);
|
||||
|
||||
ObjectNode returnedJson = atbashCipherController.encodeAtbash(cipherParams);
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ATBASH_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
atbashCipherController.encodeAtbash(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAtbash(){
|
||||
ObjectNode cipherParams = generateParams(ATBASH_OUTPUT_STRING);
|
||||
|
||||
ObjectNode returnedJson = atbashCipherController.decodeAtbash(cipherParams);
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ATBASH_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
atbashCipherController.decodeAtbash(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AutokeyCipherController.class)
|
||||
public class AutokeyCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/autokey";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh fs^wfcuhx";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAutokey() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Encoding Autokey");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Decoding Autokey");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AutokeyCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AutokeyCipherController autokeyCipherController;
|
||||
private static final String AUTOKEY_INPUT_STRING = "Message to^encode";
|
||||
private static final String AUTOKEY_OUTPUT_STRING = "Wiqooxh fs^wfcuhx";
|
||||
private static final String AUTOKEY_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAutokey(){
|
||||
ObjectNode cipherParams = generateParams(AUTOKEY_KEYWORD, AUTOKEY_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = autokeyCipherController.encodeAutokey(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AUTOKEY_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
autokeyCipherController.encodeAutokey(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey(){
|
||||
ObjectNode cipherParams = generateParams(AUTOKEY_KEYWORD, AUTOKEY_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = autokeyCipherController.decodeAutokey(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AUTOKEY_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
autokeyCipherController.decodeAutokey(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = BaconianCipherController.class)
|
||||
public class BaconianCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/baconian";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.replaceAll("[^a-zA-Z]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaconian() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Encoding Baconian");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaconian() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.replaceAll("[^a-zA-Z]", "")));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Decoding Baconian");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BaconianCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BaconianCipherController baconianCipherController;
|
||||
private static final String BACONIAN_INPUT_STRING = "Message to-encode";
|
||||
private static final String BACONIAN_OUTPUT_STRING = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
private static final String BACONIAN_DECODED_STRING = "Messagetoencode";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBaconian(){
|
||||
ObjectNode cipherParams = generateParams(BACONIAN_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baconianCipherController.encodeBaconian(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BACONIAN_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baconianCipherController.encodeBaconian(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaconian(){
|
||||
ObjectNode cipherParams = generateParams(BACONIAN_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baconianCipherController.decodeBaconian(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BACONIAN_DECODED_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baconianCipherController.decodeBaconian(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = BaseXCipherController.class)
|
||||
public class BaseXCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/basex";
|
||||
private String decodedString = "A+B@C d\te\nf";
|
||||
private String encodedString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private int base = 2;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.BASE_X_BASE, base);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.BASE_X_BASE, base);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBaseXEncode() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Encoding BaseX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaseXDecode() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Decoding BaseX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BaseXCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BaseXCipherController baseXCipherController;
|
||||
private static final int BASE_X_BASE = 2;
|
||||
private static final String BASE_X_INPUT_STRING = "A+B@C d\te\nf";
|
||||
private static final String BASE_X_OUTPUT_STRING = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBaseX(){
|
||||
ObjectNode cipherParams = generateParams(BASE_X_BASE, BASE_X_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baseXCipherController.encodeBaseX(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BASE_X_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baseXCipherController.encodeBaseX(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaseX(){
|
||||
ObjectNode cipherParams = generateParams(BASE_X_BASE, BASE_X_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baseXCipherController.decodeBaseX(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BASE_X_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baseXCipherController.decodeBaseX(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int base, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
cipherParams.put(CipherParameterUtil.BASE_X_BASE, base);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = BeaufortCipherController.class)
|
||||
public class BeaufortCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/beaufort";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Yageolz rq^ujmdag";
|
||||
private String keyword = "Ke*y word";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBeaufort() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Encoding Beaufort");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBeaufort() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Decoding Beaufort");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BeaufortCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BeaufortCipherController beaufortCipherController;
|
||||
private static final String BEAUFORT_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String BEAUFORT_INPUT_STRING = "Message to^encode";
|
||||
private static final String BEAUFORT_OUTPUT_STRING = "Yageolz rq^ujmdag";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void encodeBeaufort(){
|
||||
ObjectNode cipherParams = generateParams(BEAUFORT_KEYWORD, BEAUFORT_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = beaufortCipherController.encodeBeaufort(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BEAUFORT_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
beaufortCipherController.encodeBeaufort(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeBeaufort(){
|
||||
ObjectNode cipherParams = generateParams(BEAUFORT_KEYWORD, BEAUFORT_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = beaufortCipherController.decodeBeaufort(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BEAUFORT_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
beaufortCipherController.decodeBeaufort(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = CaesarCipherController.class)
|
||||
public class CaesarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/caesar";
|
||||
private String decodedString = "The quick brown fox jumps over - the lazy dog";
|
||||
private String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private int shiftAmount = 23;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeCaesar() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Encoding Caesar");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeCaesar() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Decoding Caesar");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class CaesarCipherControllerTest{
|
||||
@InjectMocks
|
||||
private CaesarCipherController caesarCipherController;
|
||||
private static final String CAESAR_INPUT_STRING = "The quick brown fox jumps over - the lazy dog";
|
||||
private static final String CAESAR_OUTPUT_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private static final int CAESAR_SHIFT_AMOUNT = 23;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeCaesar(){
|
||||
ObjectNode cipherParams = generateParams(CAESAR_SHIFT_AMOUNT, CAESAR_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = caesarCipherController.encodeCaesar(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(CAESAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
caesarCipherController.encodeCaesar(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeCaesar(){
|
||||
ObjectNode cipherParams = generateParams(CAESAR_SHIFT_AMOUNT, CAESAR_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = caesarCipherController.decodeCaesar(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(CAESAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
caesarCipherController.decodeCaesar(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int shiftAmount, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = OneTimePadCipherController.class)
|
||||
public class OneTimePadCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/oneTimePad";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh mv^egkgws";
|
||||
private String keyword = "keywordThatIsTotallyRandom";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeOneTimePad() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Encoding One Time Pad");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeOneTimePad() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Decoding One Time Pad");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class OneTimePadCipherControllerTest{
|
||||
@InjectMocks
|
||||
private OneTimePadCipherController oneTimePadCipherController;
|
||||
private static final String ONE_TIME_PAD_KEYWORD = "keywordThatIsTotallyRandom";
|
||||
private static final String ONE_TIME_PAD_INPUT_STRING = "Message to^encode";
|
||||
private static final String ONE_TIME_PAD_OUTPUT_STRING = "Wiqooxh mv^egkgws";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
public void testEncodeOneTimePad(){
|
||||
ObjectNode cipherParams = generateParams(ONE_TIME_PAD_KEYWORD, ONE_TIME_PAD_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = oneTimePadCipherController.encodeOneTimePad(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ONE_TIME_PAD_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
oneTimePadCipherController.encodeOneTimePad(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeOneTimePad(){
|
||||
ObjectNode cipherParams = generateParams(ONE_TIME_PAD_KEYWORD, ONE_TIME_PAD_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = oneTimePadCipherController.decodeOneTimePad(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ONE_TIME_PAD_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
oneTimePadCipherController.decodeOneTimePad(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = PortaCipherController.class)
|
||||
public class PortaCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/porta";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Rtghuos bm^qcwgrw";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePorta() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
verify(filterLogger, never()).info(eq("Request parameters: {}"), anyString());
|
||||
verify(mdc, times(1)).put("requestId", requestId);
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).put("url", url + "/encode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Encoding Porta");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePorta() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
verify(filterLogger, never()).info(eq("Request parameters: {}"), anyString());
|
||||
verify(mdc, times(1)).put("requestId", requestId);
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).put("url", url + "/decode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Decoding Porta");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PortaCipherControllerTest{
|
||||
@InjectMocks
|
||||
private PortaCipherController portaCipherController;
|
||||
private static final String PORTA_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String PORTA_INPUT_STRING = "Message to^encode";
|
||||
private static final String PORTA_OUTPUT_STRING = "Rtghuos bm^qcwgrw";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePorta(){
|
||||
ObjectNode cipherParams = generateParams(PORTA_KEYWORD, PORTA_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = portaCipherController.encodePorta(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PORTA_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
portaCipherController.encodePorta(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePorta(){
|
||||
ObjectNode cipherParams = generateParams(PORTA_KEYWORD, PORTA_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = portaCipherController.decodePorta(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PORTA_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
portaCipherController.decodePorta(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = SubstitutionCipherController.class)
|
||||
public class SubstitutionCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/substitution";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Oguucig vq^gpeqfg";
|
||||
private String keyword = "cdefghijklmnopqrstuvwxyzab";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeSubstitution() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Encoding Substitution");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeSubstitution() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Decoding Substitution");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class SubstitutionCipherControllerTest{
|
||||
@InjectMocks
|
||||
private SubstitutionCipherController substitutionCipherController;
|
||||
private static final String SUBSTITUTION_KEYWORD = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
private static final String SUBSTITUTION_INPUT_STRING = "Message to&encode 123";
|
||||
private static final String SUBSTITUTION_OUTPUT_STRING = "Oguucig vq&gpeqfg 876";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeSubstitution(){
|
||||
ObjectNode cipherParams = generateParams(SUBSTITUTION_KEYWORD, SUBSTITUTION_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = substitutionCipherController.encodeSubstitution(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(SUBSTITUTION_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
substitutionCipherController.encodeSubstitution(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeSubstitution(){
|
||||
ObjectNode cipherParams = generateParams(SUBSTITUTION_KEYWORD, SUBSTITUTION_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = substitutionCipherController.decodeSubstitution(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(SUBSTITUTION_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
substitutionCipherController.decodeSubstitution(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = VigenereCipherController.class)
|
||||
public class VigenereCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/vigenere";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh ds^cjqfgo";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeVigenere() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Encoding Vigenere");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeVigenere() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Decoding Vigenere");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class VigenereCipherControllerTest{
|
||||
@InjectMocks
|
||||
private VigenereCipherController vigenereCipherController;
|
||||
private static final String VIGENERE_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String VIGENERE_INPUT_STRING = "Message to^encode";
|
||||
private static final String VIGENERE_OUTPUT_STRING = "Wiqooxh ds^cjqfgo";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeVigenere(){
|
||||
ObjectNode cipherParams = generateParams(VIGENERE_KEYWORD, VIGENERE_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = vigenereCipherController.encodeVigenere(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(VIGENERE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
vigenereCipherController.encodeVigenere(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeVigenere(){
|
||||
ObjectNode cipherParams = generateParams(VIGENERE_KEYWORD, VIGENERE_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = vigenereCipherController.decodeVigenere(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(VIGENERE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
vigenereCipherController.decodeVigenere(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = BifidCipherController.class)
|
||||
public class BifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/bifid";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Mqaokne kc^vdodzd";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Encoding Bifid");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Decoding Bifid");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BifidCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BifidCipherController bifidCipherController;
|
||||
private static final String BIFID_INPUT_STRING = "Message to^encode";
|
||||
private static final String BIFID_OUTPUT_STRING = "Mqaokne kc^vdodzd";
|
||||
private static final String BIFID_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid(){
|
||||
ObjectNode cipherParams = generateParams(BIFID_KEYWORD, BIFID_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = bifidCipherController.encodeBifid(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
bifidCipherController.encodeBifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey(){
|
||||
ObjectNode cipherParams = generateParams(BIFID_KEYWORD, BIFID_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = bifidCipherController.decodeBifid(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
bifidCipherController.decodeBifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = ColumnarCipherController.class)
|
||||
public class ColumnarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/columnar";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Edeomte ac^gosnse";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Encoding Columnar");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeColumnar() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Decoding Columnar");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ColumnarCipherControllerTest{
|
||||
@InjectMocks
|
||||
private ColumnarCipherController columnarCipherController;
|
||||
private static final String COLUMNAR_INPUT_STRING = "Message to*encode";
|
||||
private static final String COLUMNAR_OUTPUT_STRING = "Edeomte ac*gosnse";
|
||||
private static final String COLUMNAR_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar(){
|
||||
ObjectNode cipherParams = generateParams(COLUMNAR_KEYWORD, COLUMNAR_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = columnarCipherController.encodeColumnar(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
columnarCipherController.encodeColumnar(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeColumnar(){
|
||||
ObjectNode cipherParams = generateParams(COLUMNAR_KEYWORD, COLUMNAR_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = columnarCipherController.decodeColumnar(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
columnarCipherController.decodeColumnar(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = HillCipherController.class)
|
||||
public class HillCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/hill";
|
||||
private String decodedString = "Message to^encoded";
|
||||
private String encodedString = "Mgkeqge ul^ikhisplrd";
|
||||
private int[][] keyArray = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(keyArray));
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(keyArray));
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString + "xx");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Encoding Hill");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeHill() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString + "xx"));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Decoding Hill");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class HillCipherControllerTest{
|
||||
@InjectMocks
|
||||
private HillCipherController hillCipherController;
|
||||
private static final String HILL_INPUT_STRING = "Message to^encode";
|
||||
private static final String HILL_OUTPUT_STRING = "Mgkeqge ul^ikhisp";
|
||||
private static final int[][] KEY = {{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws JsonProcessingException{
|
||||
ObjectNode cipherParams = generateParams(HILL_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = hillCipherController.encodeHill(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
hillCipherController.encodeHill(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeHill() throws JsonProcessingException{
|
||||
ObjectNode cipherParams = generateParams(HILL_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = hillCipherController.decodeHill(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
hillCipherController.decodeHill(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
JsonNode keyNode = objectMapper.valueToTree(KEY);
|
||||
cipherParams.set(CipherParameterUtil.HILL_KEY, keyNode);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = MorseCodeController.class)
|
||||
public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/morse";
|
||||
private String decodedString = "Message to^encode123";
|
||||
private String encodedString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Encoding Morse");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeMorse() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.toUpperCase().replaceAll("[^A-Z0-9]", "")));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Decoding Morse");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MorseCodeControllerTest{
|
||||
@InjectMocks
|
||||
private MorseCodeController morseCodeController;
|
||||
private static final String MORSE_INPUT_STRING = "SOS";
|
||||
private static final String MORSE_OUTPUT_STRING = "... --- ...";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse(){
|
||||
ObjectNode cipherParams = generateParams(MORSE_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = morseCodeController.encodeMorse(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
morseCodeController.encodeMorse(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeMorse(){
|
||||
ObjectNode cipherParams = generateParams(MORSE_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = morseCodeController.decodeMorse(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
morseCodeController.decodeMorse(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = PlayfairCipherController.class)
|
||||
public class PlayfairCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/playfair";
|
||||
private String decodedString = "Hide the gold in - the@tree+stump";
|
||||
private String decodedStringPadded = "Hide the gold in - the@trexe+stump";
|
||||
private String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private String keyword = "Play-fair@Exam ple";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedStringPadded);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(playfiarLogger, times(1)).info("Encoding Playfair");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePlayfair() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedStringPadded));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(playfiarLogger, times(1)).info("Decoding Playfair");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PlayfairCipherControllerTest{
|
||||
@InjectMocks
|
||||
private PlayfairCipherController playfairCipherController;
|
||||
private static final String PLAYFAIR_INPUT_STRING = "Hide the gold in - the@tree+stump";
|
||||
private static final String DECODED_INPUT_STRING = "Hide the gold in - the@trexe+stump";
|
||||
private static final String PLAYFAIR_OUTPUT_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private static final String PLAYFAIR_KEYWORD = "Play-fair@Exam ple";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair(){
|
||||
ObjectNode cipherParams = generateParams(PLAYFAIR_KEYWORD, PLAYFAIR_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = playfairCipherController.encodePlayfair(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PLAYFAIR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
playfairCipherController.encodePlayfair(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePlayfair(){
|
||||
ObjectNode cipherParams = generateParams(PLAYFAIR_KEYWORD, PLAYFAIR_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = playfairCipherController.decodePlayfair(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(DECODED_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
playfairCipherController.decodePlayfair(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = PolybiusSquareController.class)
|
||||
public class PolybiusSquareControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/polybius";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "41124545233212 5115^124225152212";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Encoding Polybius");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePolybius() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.toUpperCase()));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Decoding Polybius");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PolybiusSquareControllerTest{
|
||||
@InjectMocks
|
||||
private PolybiusSquareController polybiusSquareController;
|
||||
private static final String POLYBIUS_INPUT_STRING = "B A-T";
|
||||
private static final String POLYBIUS_OUTPUT_STRING = "15 14-52";
|
||||
private static final String POLYBIUS_KEYWORD = "Z Y+ X-";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius(){
|
||||
ObjectNode cipherParams = generateParams(POLYBIUS_KEYWORD, POLYBIUS_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = polybiusSquareController.encodePolybius(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
polybiusSquareController.encodePolybius(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePolybius(){
|
||||
ObjectNode cipherParams = generateParams(POLYBIUS_KEYWORD, POLYBIUS_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = polybiusSquareController.decodePolybius(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
polybiusSquareController.decodePolybius(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = RailFenceController.class)
|
||||
public class RailFenceControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/railFence";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Maooesg te^cdsene";
|
||||
private int rails = 3;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Encoding Rail Fence");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRailFence() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Decoding Rail Fence");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class RailFenceControllerTest{
|
||||
@InjectMocks
|
||||
private RailFenceController railFenceController;
|
||||
private static final String RAIL_FENCE_INPUT_STRING = "Message to^encode";
|
||||
private static final String RAIL_FENCE_OUTPUT_STRING = "Moetese ne^sgcdao";
|
||||
private static final int RAIL_FENCE_RAILS = 5;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence(){
|
||||
ObjectNode cipherParams = generateParams(RAIL_FENCE_RAILS, RAIL_FENCE_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = railFenceController.encodeRailFence(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRailFence(){
|
||||
ObjectNode cipherParams = generateParams(RAIL_FENCE_RAILS, RAIL_FENCE_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = railFenceController.decodeRailFence(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int rails, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = TrifidCipherController.class)
|
||||
public class TrifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/trifid";
|
||||
private String decodedString = "Message to^encode+";
|
||||
private String encodedString = "Gqdokpd od^ljvflf+";
|
||||
private String keyword = "keyword";
|
||||
private String trifidFill = "=";
|
||||
private int grouplength = Integer.MAX_VALUE;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.TRIFID_FILL, trifidFill);
|
||||
decodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, grouplength);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.TRIFID_FILL, trifidFill);
|
||||
encodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, grouplength);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Encoding Trifid");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeTrifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Decoding Trifid");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TrifidCipherControllerTest{
|
||||
@InjectMocks
|
||||
private TrifidCipherController trifidCipherController;
|
||||
private static final String TRIFID_INPUT_STRING = "Message to^encode";
|
||||
private static final String TRIFID_OUTPUT_STRING = "Gpjqdvd of^odlklf";
|
||||
private static final String TRIFID_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final char TRIFID_FILL_ID = '+';
|
||||
private static final int TRIFID_GROUP_LENGTH = 3;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid(){
|
||||
ObjectNode cipherParams = generateParams(TRIFID_KEYWORD, TRIFID_FILL_ID, TRIFID_GROUP_LENGTH, TRIFID_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = trifidCipherController.encodeTrifid(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
trifidCipherController.encodeTrifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeTrifid(){
|
||||
ObjectNode cipherParams = generateParams(TRIFID_KEYWORD, TRIFID_FILL_ID, TRIFID_GROUP_LENGTH, TRIFID_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = trifidCipherController.decodeTrifid(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
trifidCipherController.decodeTrifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, char fill, int groupLength, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.TRIFID_FILL, String.valueOf(fill));
|
||||
cipherParams.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, groupLength);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.mattrixwv.cipherstream.exception;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class InvalidCipherParameterExceptionTest{
|
||||
//Fields
|
||||
private String message = "Error Message";
|
||||
private Throwable cause = new Throwable();
|
||||
|
||||
|
||||
@Test
|
||||
public void testConstructor_default(){
|
||||
InvalidCipherParameterException exception = new InvalidCipherParameterException();
|
||||
|
||||
assertNull(exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_message(){
|
||||
InvalidCipherParameterException exception = new InvalidCipherParameterException(message);
|
||||
|
||||
assertEquals(message, exception.getMessage());
|
||||
assertNull(exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_cause(){
|
||||
InvalidCipherParameterException exception = new InvalidCipherParameterException(cause);
|
||||
|
||||
assertEquals(cause.toString(), exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructor_messageCause(){
|
||||
InvalidCipherParameterException exception = new InvalidCipherParameterException(message, cause);
|
||||
|
||||
assertEquals(message, exception.getMessage());
|
||||
assertEquals(cause, exception.getCause());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
package com.mattrixwv.cipherstream.utils;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class CipherParameterUtilTest{
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testVerifyUniversalParams(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
//Missing Capitals
|
||||
params.remove(CipherParameterUtil.PRESERVE_CAPITALS);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
//Integer Capitals
|
||||
params.put(CipherParameterUtil.PRESERVE_CAPITALS, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
|
||||
//Missing Whitespace
|
||||
params.remove(CipherParameterUtil.PRESERVE_WHITESPACE);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
//Integer Whitespace
|
||||
params.put(CipherParameterUtil.PRESERVE_WHITESPACE, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
|
||||
//Missing Symbols
|
||||
params.remove(CipherParameterUtil.PRESERVE_SYMBOLS);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
//Integer Symbols
|
||||
params.put(CipherParameterUtil.PRESERVE_SYMBOLS, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
|
||||
//Missing Input
|
||||
params.remove(CipherParameterUtil.INPUT_STRING);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
//Integer Input
|
||||
params.put(CipherParameterUtil.INPUT_STRING, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.INPUT_STRING, "Input String");
|
||||
|
||||
//Full
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyUniversalParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyParamsWithKeyword(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
//Missing Keyword
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyParamsWithKeyword(params);
|
||||
});
|
||||
//Integer Keyword
|
||||
params.put(CipherParameterUtil.KEYWORD, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyParamsWithKeyword(params);
|
||||
});
|
||||
|
||||
//Full
|
||||
params.put(CipherParameterUtil.KEYWORD, CipherParameterUtil.KEYWORD);
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyParamsWithKeyword(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyCaesarParams(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
//Missing shift
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyCaesarParams(params);
|
||||
});
|
||||
//String shift
|
||||
params.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, "1");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyCaesarParams(params);
|
||||
});
|
||||
|
||||
//Full
|
||||
params.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, 1);
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyCaesarParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyAffineParams(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
//Missing Key1
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyAffineParams(params);
|
||||
});
|
||||
//String Key1
|
||||
params.put(CipherParameterUtil.AFFINE_KEY_1, "1");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyAffineParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.AFFINE_KEY_1, 1);
|
||||
|
||||
//Missing Key2
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyAffineParams(params);
|
||||
});
|
||||
//String Key2
|
||||
params.put(CipherParameterUtil.AFFINE_KEY_2, "1");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyAffineParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.AFFINE_KEY_2, 1);
|
||||
|
||||
//Full
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyAffineParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyAtbashParams(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyAtbashParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyBaconianParams(){
|
||||
ObjectNode params = objectMapper.createObjectNode();
|
||||
|
||||
//Missing Capitals
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyBaconianParams(params);
|
||||
});
|
||||
//Integer Capitals
|
||||
params.put(CipherParameterUtil.PRESERVE_CAPITALS, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyBaconianParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
|
||||
//Missing Input
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyBaconianParams(params);
|
||||
});
|
||||
//Integer Input
|
||||
params.put(CipherParameterUtil.INPUT_STRING, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyBaconianParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.INPUT_STRING, "Input String");
|
||||
|
||||
//Full
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyBaconianParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyBaseXParams(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
//Missing Input
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyBaseXParams(params);
|
||||
});
|
||||
//Integer Input
|
||||
params.put(CipherParameterUtil.INPUT_STRING, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyBaseXParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.INPUT_STRING, CipherParameterUtil.INPUT_STRING);
|
||||
|
||||
//Missing BaseX
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyBaseXParams(params);
|
||||
});
|
||||
//String BaseX
|
||||
params.put(CipherParameterUtil.BASE_X_BASE, "2");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyBaseXParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.BASE_X_BASE, 2);
|
||||
|
||||
//Full
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyBaseXParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifySquareKeyword(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
//Missing Keyword
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifySquareKeyword(params);
|
||||
});
|
||||
|
||||
//Integer Keyword
|
||||
params.put(CipherParameterUtil.SQUARE_KEYWORD, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifySquareKeyword(params);
|
||||
});
|
||||
|
||||
//Full
|
||||
params.put(CipherParameterUtil.SQUARE_KEYWORD, "squareKeyword");
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifySquareKeyword(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyHillParams(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
//Missing Key
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyHillParams(params);
|
||||
});
|
||||
|
||||
//Integer Key
|
||||
params.put(CipherParameterUtil.HILL_KEY, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyHillParams(params);
|
||||
});
|
||||
|
||||
//1D Array Key
|
||||
params.set(CipherParameterUtil.HILL_KEY, objectMapper.valueToTree(new int[]{1}));
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyHillParams(params);
|
||||
});
|
||||
|
||||
//String Array Key
|
||||
params.set(CipherParameterUtil.HILL_KEY, objectMapper.valueToTree(new String[][]{{"test"}}));
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyHillParams(params);
|
||||
});
|
||||
|
||||
//Full
|
||||
params.set(CipherParameterUtil.HILL_KEY, objectMapper.valueToTree(new int[][]{{1}}));
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyHillParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyMorseParams(){
|
||||
ObjectNode params = objectMapper.createObjectNode();
|
||||
|
||||
//Missing Input
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyMorseParams(params);
|
||||
});
|
||||
//Integer Input
|
||||
params.put(CipherParameterUtil.INPUT_STRING, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyMorseParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.INPUT_STRING, "Input String");
|
||||
|
||||
//Full
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyMorseParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyPolybiusParams(){
|
||||
ObjectNode params = objectMapper.createObjectNode();
|
||||
|
||||
//Missing Whitespace
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
//String Whitespace
|
||||
params.put(CipherParameterUtil.PRESERVE_WHITESPACE, "true");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
|
||||
//Missing Symbols
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
//String Symbols
|
||||
params.put(CipherParameterUtil.PRESERVE_SYMBOLS, "true");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
|
||||
//Missing Input
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
//Integer Input
|
||||
params.put(CipherParameterUtil.INPUT_STRING, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.INPUT_STRING, "");
|
||||
|
||||
//Missing Keyword
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
//Integer Keyword
|
||||
params.put(CipherParameterUtil.KEYWORD, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.KEYWORD, CipherParameterUtil.KEYWORD);
|
||||
|
||||
//Full
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyPolybiusParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyRailFenceParams(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
|
||||
//Missing Rails
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyRailFenceParams(params);
|
||||
});
|
||||
//String rails
|
||||
params.put(CipherParameterUtil.RAIL_FENCE_RAILS, "1");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyRailFenceParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.RAIL_FENCE_RAILS, 1);
|
||||
|
||||
//Full
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyRailFenceParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyTrifidParams(){
|
||||
ObjectNode params = setUniversalParams();
|
||||
params.put(CipherParameterUtil.KEYWORD, CipherParameterUtil.KEYWORD);
|
||||
|
||||
//Missing fill
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyTrifidParams(params);
|
||||
});
|
||||
//Integer fill
|
||||
params.put(CipherParameterUtil.TRIFID_FILL, 1);
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyTrifidParams(params);
|
||||
});
|
||||
//String fill
|
||||
params.put(CipherParameterUtil.TRIFID_FILL, "Input");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyTrifidParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.TRIFID_FILL, "+");
|
||||
|
||||
//Missing length
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyTrifidParams(params);
|
||||
});
|
||||
//String length
|
||||
params.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, "2");
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
CipherParameterUtil.verifyTrifidParams(params);
|
||||
});
|
||||
params.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, 2);
|
||||
|
||||
//Full
|
||||
assertDoesNotThrow(() -> {
|
||||
CipherParameterUtil.verifyTrifidParams(params);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private ObjectNode setUniversalParams(){
|
||||
ObjectNode universalParams = objectMapper.createObjectNode();
|
||||
universalParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
universalParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
universalParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
universalParams.put(CipherParameterUtil.INPUT_STRING, "Input String");
|
||||
return universalParams;
|
||||
}
|
||||
}
|
||||
1
src/test/resources/application.properties
Normal file
1
src/test/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
spring.main.banner-mode=off
|
||||
19
src/test/resources/log4j2-test.xml
Normal file
19
src/test/resources/log4j2-test.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<Configuration strict="true" xmlns="http://logging.apache.org/log4j/2.0/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config https://raw.githubusercontent.com/apache/logging-log4j2/master/log4j-core/src/main/resources/Log4j-config.xsd">
|
||||
<Appenders>
|
||||
<Console name="console" target="SYSTEM_OUT">
|
||||
<PatternLayout disableAnsi="false">
|
||||
<Pattern>
|
||||
%style{%d{MM-dd-yyyy HH:mm:ss.SSS}}{bright, black} %highlight{%5p} %style{%50.50replace{%c{0}.%M}{}{}}{blue, bright} %highlight{---} %message%n
|
||||
</Pattern>
|
||||
</PatternLayout>
|
||||
</Console>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="off" includeLocation="true">
|
||||
<AppenderRef ref="console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user