Updated more tests
This commit is contained in:
@@ -10,6 +10,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,10 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/bifid")
|
||||
public class BifidCipherController{
|
||||
@GetMapping
|
||||
public ObjectNode getCipherInfo(){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
log.info("Getting info for {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
|
||||
|
||||
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.BIFID_CIPHER_NAME, CipherInfoUtil.BIFID_CIPHER_DESCRIPTION);
|
||||
}
|
||||
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeBifid(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Bifid");
|
||||
log.info("Encoding Bifid");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
log.info("Encoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
@@ -44,8 +54,8 @@ public class BifidCipherController{
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeBifid(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Bifid");
|
||||
log.info("Decoding Bifid");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
log.info("Decoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,10 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/columnar")
|
||||
public class ColumnarCipherController{
|
||||
@GetMapping
|
||||
public ObjectNode getCipherInfo(){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
log.info("Getting info for {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
|
||||
|
||||
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.COLUMNAR_CIPHER_NAME, CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION);
|
||||
}
|
||||
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeColumnar(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Columnar");
|
||||
log.info("Encoding Columnar");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
log.info("Encoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
@@ -44,8 +54,8 @@ public class ColumnarCipherController{
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeColumnar(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Columnar");
|
||||
log.info("Decoding Columnar");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
log.info("Decoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -21,10 +22,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/hill")
|
||||
public class HillCipherController{
|
||||
@GetMapping
|
||||
public ObjectNode getCipherInfo(){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
log.info("Getting info for {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
|
||||
|
||||
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.HILL_CIPHER_NAME, CipherInfoUtil.HILL_CIPHER_DESCRIPTION);
|
||||
}
|
||||
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Hill");
|
||||
log.info("Encoding Hill");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
log.info("Encoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyHillParams(cipherParams);
|
||||
@@ -46,8 +56,8 @@ public class HillCipherController{
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Hill");
|
||||
log.info("Decoding Hill");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
log.info("Decoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyHillParams(cipherParams);
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,10 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/morse")
|
||||
public class MorseCodeController{
|
||||
@GetMapping
|
||||
public ObjectNode getCipherInfo(){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
log.info("Getting info for {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
|
||||
|
||||
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.MORSE_CIPHER_NAME, CipherInfoUtil.MORSE_CIPHER_DESCRIPTION);
|
||||
}
|
||||
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeMorse(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Morse");
|
||||
log.info("Encoding Morse");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
log.info("Encoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyMorseParams(cipherParams);
|
||||
@@ -40,8 +50,8 @@ public class MorseCodeController{
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeMorse(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Morse");
|
||||
log.info("Decoding Morse");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
log.info("Decoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyMorseParams(cipherParams);
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,10 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/playfair")
|
||||
public class PlayfairCipherController{
|
||||
@GetMapping
|
||||
public ObjectNode getCipherInfo(){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
log.info("Getting info for {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
|
||||
|
||||
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.PLAYFAIR_CIPHER_NAME, CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION);
|
||||
}
|
||||
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodePlayfair(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Playfair");
|
||||
log.info("Encoding Playfair");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
log.info("Encoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
@@ -44,8 +54,8 @@ public class PlayfairCipherController{
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodePlayfair(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Playfair");
|
||||
log.info("Decoding Playfair");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
log.info("Decoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,10 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/polybius")
|
||||
public class PolybiusSquareController{
|
||||
@GetMapping
|
||||
public ObjectNode getCipherInfo(){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
log.info("Getting info for {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
|
||||
|
||||
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION);
|
||||
}
|
||||
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodePolybius(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Polybius Square");
|
||||
log.info("Encoding Polybius");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
log.info("Encoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyPolybiusParams(cipherParams);
|
||||
@@ -43,8 +53,8 @@ public class PolybiusSquareController{
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodePolybius(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Polybius Square");
|
||||
log.info("Decoding Polybius");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
log.info("Decoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyPolybiusParams(cipherParams);
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,10 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/railFence")
|
||||
public class RailFenceController{
|
||||
@GetMapping
|
||||
public ObjectNode getCipherInfo(){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
log.info("Getting info for {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
|
||||
|
||||
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION);
|
||||
}
|
||||
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeRailFence(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Rail Fence");
|
||||
log.info("Encoding Rail Fence");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
log.info("Encoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyRailFenceParams(cipherParams);
|
||||
@@ -44,8 +54,8 @@ public class RailFenceController{
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeRailFence(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Rail Fence");
|
||||
log.info("Decoding Rail Fence");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
log.info("Decoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyRailFenceParams(cipherParams);
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -19,10 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RestController
|
||||
@RequestMapping("/cipherStream/trifid")
|
||||
public class TrifidCipherController{
|
||||
@GetMapping
|
||||
public ObjectNode getCipherInfo(){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
log.info("Getting info for {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
|
||||
|
||||
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.TRIFID_CIPHER_NAME, CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION);
|
||||
}
|
||||
|
||||
@GetMapping("/encode")
|
||||
public ObjectNode encodeTrifid(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Trifid");
|
||||
log.info("Encoding Trifid");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
log.info("Encoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyTrifidParams(cipherParams);
|
||||
@@ -46,8 +56,8 @@ public class TrifidCipherController{
|
||||
|
||||
@GetMapping("/decode")
|
||||
public ObjectNode decodeTrifid(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Trifid");
|
||||
log.info("Decoding Trifid");
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
log.info("Decoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
|
||||
|
||||
CipherParameterUtil.verifyTrifidParams(cipherParams);
|
||||
|
||||
@@ -16,9 +16,12 @@ public class CipherInfoUtil{
|
||||
public static final String CIPHER_NAME = "name";
|
||||
public static final String CIPHER_DESCRIPTION = "description";
|
||||
|
||||
|
||||
//Cipher Names
|
||||
//Combination
|
||||
public static final String ADFGVX_CIPHER_NAME = "ADFGVX";
|
||||
public static final String ADFGX_CIPHER_NAME = "ADFGX";
|
||||
//Mono-Substitution
|
||||
public static final String AFFINE_CIPHER_NAME = "Affine";
|
||||
public static final String ATBASH_CIPHER_NAME = "Atbash";
|
||||
public static final String AUTOKEY_CIPHER_NAME = "Autokey";
|
||||
@@ -30,10 +33,22 @@ public class CipherInfoUtil{
|
||||
public static final String PORTA_CIPHER_NAME = "Porta";
|
||||
public static final String SUBSTITUTION_CIPHER_NAME = "Substitution";
|
||||
public static final String VIGENERE_CIPHER_NAME = "Vigenere";
|
||||
//Poly-Substitution
|
||||
public static final String BIFID_CIPHER_NAME = "Bifid";
|
||||
public static final String COLUMNAR_CIPHER_NAME = "Columnar";
|
||||
public static final String HILL_CIPHER_NAME = "Hill";
|
||||
public static final String MORSE_CIPHER_NAME = "Morse";
|
||||
public static final String PLAYFAIR_CIPHER_NAME = "Playfair";
|
||||
public static final String POLYBIUS_SQUARE_CIPHER_NAME = "Polybius Square";
|
||||
public static final String RAIL_FENCE_CIPHER_NAME = "Rail Fence";
|
||||
public static final String TRIFID_CIPHER_NAME = "Trifid Cipher";
|
||||
|
||||
|
||||
//TODO: Cipher descriptions
|
||||
//Combintation
|
||||
public static final String ADFGVX_CIPHER_DESCRIPTION = "ADFGVX Cipher";
|
||||
public static final String ADFGX_CIPHER_DESCRIPTION = "ADFGX Cipher";
|
||||
//Mono-Substitution
|
||||
public static final String AFFINE_CIPHER_DESCRIPTION = "Affine Cipher";
|
||||
public static final String ATBASH_CIPHER_DESCRIPTION = "Atbash Cipher";
|
||||
public static final String AUTOKEY_CIPHER_DESCRIPTION = "Autokey Cipher";
|
||||
@@ -45,6 +60,15 @@ public class CipherInfoUtil{
|
||||
public static final String PORTA_CIPHER_DESCRIPTION = "Porta Cipher";
|
||||
public static final String SUBSTITUTION_CIPHER_DESCRIPTION = "Substitution Cipher";
|
||||
public static final String VIGENERE_CIPHER_DESCRIPTION = "Vigenere Cipher";
|
||||
//Poly-Substitution
|
||||
public static final String BIFID_CIPHER_DESCRIPTION = "Bifid Cipher";
|
||||
public static final String COLUMNAR_CIPHER_DESCRIPTION = "Columnar Cipher";
|
||||
public static final String HILL_CIPHER_DESCRIPTION = "Hill Cipher";
|
||||
public static final String MORSE_CIPHER_DESCRIPTION = "Morse Code";
|
||||
public static final String PLAYFAIR_CIPHER_DESCRIPTION = "Playfair Cipher";
|
||||
public static final String POLYBIUS_SQUARE_CIPHER_DESCRIPTION = "Polybius Square Cipher";
|
||||
public static final String RAIL_FENCE_CIPHER_DESCRIPTION = "Rail Fence Cipher";
|
||||
public static final String TRIFID_CIPHER_DESCRIPTION = "Trifid Cipher";
|
||||
|
||||
|
||||
public static ObjectNode buildInfoNode(String name, String description){
|
||||
|
||||
@@ -38,53 +38,6 @@ public class CipherStreamControllerIntegrationTestBase{
|
||||
@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")
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,12 +26,16 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController")
|
||||
private Logger adfgvxLogger;
|
||||
//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";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -60,7 +66,7 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ADFGVX_CIPHER_NAME))
|
||||
@@ -78,7 +84,7 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
public void testEncodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -93,11 +99,30 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Encoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -111,4 +136,23 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Decoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,13 +21,26 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AdfgvxCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AdfgvxCipherController adfgvxCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGVX_CIPHER_NAME, CipherInfoUtil.ADFGVX_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgvxCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx(){
|
||||
ObjectNode cipherParams = generateParams(KEYWORD, SQUARE_KEYWORD, INPUT_STRING);
|
||||
@@ -37,9 +51,10 @@ public class AdfgvxCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeAdfgvx_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgvxCipherController.encodeAdfgvx(blankNode);
|
||||
});
|
||||
@@ -55,22 +70,26 @@ public class AdfgvxCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_invalidParameters(){
|
||||
//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();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,12 +26,16 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AdfgxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController")
|
||||
private Logger adfgxLogger;
|
||||
//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";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -60,7 +66,7 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ADFGX_CIPHER_NAME))
|
||||
@@ -78,7 +84,7 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
public void testEncodeAdfgx() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -93,11 +99,30 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Encoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgx() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -111,4 +136,23 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Decoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,11 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AdfgxCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AdfgxCipherController adfgxCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGX_CIPHER_NAME, CipherInfoUtil.ADFGX_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgxCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx(){
|
||||
@@ -36,9 +51,10 @@ public class AdfgxCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeAdfgx_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgxCipherController.encodeAdfgx(blankNode);
|
||||
});
|
||||
@@ -54,22 +70,25 @@ public class AdfgxCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeAdfgx_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgxCipherController.decodeAdfgx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String squareKeyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,12 +26,16 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AffineCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController")
|
||||
private Logger affineLogger;
|
||||
//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;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -60,7 +66,7 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION))
|
||||
@@ -78,7 +84,7 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
public void testEncodeAffine() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -93,11 +99,30 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAffine_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Encoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAffine() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -111,4 +136,23 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAffine_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Decoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,13 +21,26 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AffineCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AffineCipherController affineCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AFFINE_CIPHER_NAME, CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = affineCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAffine(){
|
||||
ObjectNode cipherParams = generateParams(AFFINE_KEY_1, AFFINE_KEY_2, AFFINE_INPUT_STRING);
|
||||
@@ -37,9 +51,9 @@ public class AffineCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AFFINE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
}
|
||||
@Test
|
||||
public void testEncodeAffine_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
affineCipherController.encodeAffine(blankNode);
|
||||
});
|
||||
@@ -55,22 +69,24 @@ public class AffineCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AFFINE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
}
|
||||
@Test
|
||||
public void testDecodeAffine_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
affineCipherController.decodeAffine(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int key1, int key2, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,10 +26,14 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AtbashCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController")
|
||||
protected Logger atbashLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/atbash";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Nvhhztv gl^vmxlwv";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,7 +60,7 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.ATBASH_CIPHER_DESCRIPTION))
|
||||
@@ -72,7 +78,7 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
public void testEncodeAtbash() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -87,11 +93,30 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAtbash_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Encoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAtbash() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -105,4 +130,23 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAtbash_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Decoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AtbashCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AtbashCipherController atbashCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
@@ -33,9 +35,9 @@ public class AtbashCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ATBASH_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
}
|
||||
@Test
|
||||
public void testEncodeAtbash_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
atbashCipherController.encodeAtbash(blankNode);
|
||||
});
|
||||
@@ -49,20 +51,22 @@ public class AtbashCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ATBASH_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
}
|
||||
@Test
|
||||
public void testDecodeAtbash_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
atbashCipherController.decodeAtbash(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,16 +26,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AutokeyCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController")
|
||||
protected Logger autokeyLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/autokey";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh fs^wfcuhx";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
@@ -58,7 +63,7 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION))
|
||||
@@ -76,7 +81,7 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
public void testEncodeAutokey() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -91,11 +96,30 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAutokey_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Encoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -109,4 +133,23 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Decoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class AutokeyCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AutokeyCipherController autokeyCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AUTOKEY_CIPHER_NAME, CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = autokeyCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAutokey(){
|
||||
ObjectNode cipherParams = generateParams(AUTOKEY_KEYWORD, AUTOKEY_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class AutokeyCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AUTOKEY_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeAutokey_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
autokeyCipherController.encodeAutokey(blankNode);
|
||||
});
|
||||
@@ -54,21 +69,24 @@ public class AutokeyCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AUTOKEY_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeAutokey_invapidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
autokeyCipherController.decodeAutokey(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,10 +26,14 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BaconianCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController")
|
||||
protected Logger baconianLogger;
|
||||
//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";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,7 +60,7 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION))
|
||||
@@ -72,7 +78,7 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
public void testEncodeBaconian() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -87,11 +93,30 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaconian_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Encoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaconian() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -105,4 +130,23 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaconian_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Decoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BaconianCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BaconianCipherController baconianCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BACONIAN_CIPHER_NAME, CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baconianCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaconian(){
|
||||
ObjectNode cipherParams = generateParams(BACONIAN_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class BaconianCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BACONIAN_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeBaconian_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baconianCipherController.encodeBaconian(blankNode);
|
||||
});
|
||||
@@ -54,18 +69,21 @@ public class BaconianCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BACONIAN_DECODED_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeBaconian_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baconianCipherController.decodeBaconian(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BaseXCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController")
|
||||
protected Logger baseXLogger;
|
||||
//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;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -57,7 +63,7 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION))
|
||||
@@ -75,7 +81,7 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
public void testEncodeBaseXEncode() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -90,11 +96,30 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaseX_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Encoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaseXDecode() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -108,4 +133,23 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaseX_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Decoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BaseXCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BaseXCipherController baseXCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BASE_X_CIPHER_NAME, CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baseXCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaseX(){
|
||||
ObjectNode cipherParams = generateParams(BASE_X_BASE, BASE_X_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class BaseXCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BASE_X_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeBaseX_invalidParameter(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baseXCipherController.encodeBaseX(blankNode);
|
||||
});
|
||||
@@ -54,18 +69,21 @@ public class BaseXCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BASE_X_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeBaseX_invalidParameter(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baseXCipherController.decodeBaseX(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int base, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
cipherParams.put(CipherParameterUtil.BASE_X_BASE, base);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BeaufortCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController")
|
||||
protected Logger beaufortLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/beaufort";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Yageolz rq^ujmdag";
|
||||
private String keyword = "Ke*y word";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -57,7 +63,7 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION))
|
||||
@@ -75,7 +81,7 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
public void testEncodeBeaufort() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -90,11 +96,30 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Encoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBeaufort() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -108,4 +133,23 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Decoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,14 +21,27 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BeaufortCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BeaufortCipherController beaufortCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void encodeBeaufort(){
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BEAUFORT_CIPHER_NAME, CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = beaufortCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBeaufort(){
|
||||
ObjectNode cipherParams = generateParams(BEAUFORT_KEYWORD, BEAUFORT_INPUT_STRING);
|
||||
|
||||
|
||||
@@ -36,16 +50,17 @@ public class BeaufortCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BEAUFORT_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeBeaufort_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
beaufortCipherController.encodeBeaufort(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeBeaufort(){
|
||||
public void testDecodeBeaufort(){
|
||||
ObjectNode cipherParams = generateParams(BEAUFORT_KEYWORD, BEAUFORT_OUTPUT_STRING);
|
||||
|
||||
|
||||
@@ -54,21 +69,24 @@ public class BeaufortCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BEAUFORT_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeBeaufort_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
beaufortCipherController.decodeBeaufort(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class CaesarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController")
|
||||
protected Logger caesarLogger;
|
||||
//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;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -57,7 +63,7 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION))
|
||||
@@ -75,7 +81,7 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
public void testEncodeCaesar() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -90,11 +96,30 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Encoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeCaesar() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -108,4 +133,23 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Decoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class CaesarCipherControllerTest{
|
||||
@InjectMocks
|
||||
private CaesarCipherController caesarCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.CAESAR_CIPHER_NAME, CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = caesarCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeCaesar(){
|
||||
ObjectNode cipherParams = generateParams(CAESAR_SHIFT_AMOUNT, CAESAR_INPUT_STRING);
|
||||
@@ -36,11 +50,12 @@ public class CaesarCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(CAESAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeCaesar_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
caesarCipherController.encodeCaesar(blankParams);
|
||||
caesarCipherController.encodeCaesar(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,21 +69,24 @@ public class CaesarCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(CAESAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeCaesar_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
caesarCipherController.decodeCaesar(blankParams);
|
||||
caesarCipherController.decodeCaesar(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int shiftAmount, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class OneTimePadCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController")
|
||||
protected Logger oneTimePadLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/oneTimePad";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh mv^egkgws";
|
||||
private String keyword = "keywordThatIsTotallyRandom";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -57,7 +63,7 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION))
|
||||
@@ -75,7 +81,7 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
public void testEncodeOneTimePad() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -90,11 +96,30 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Encoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeOneTimePad() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -108,4 +133,23 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Decoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,10 +21,24 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class OneTimePadCipherControllerTest{
|
||||
@InjectMocks
|
||||
private OneTimePadCipherController oneTimePadCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME, CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = oneTimePadCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeOneTimePad(){
|
||||
@@ -35,9 +50,10 @@ public class OneTimePadCipherControllerTest{
|
||||
|
||||
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();
|
||||
@Test
|
||||
public void testEncodeOneTimePad_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
oneTimePadCipherController.encodeOneTimePad(blankNode);
|
||||
});
|
||||
@@ -53,21 +69,24 @@ public class OneTimePadCipherControllerTest{
|
||||
|
||||
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();
|
||||
@Test
|
||||
public void testDecodeOneTimePad_invalidParameter(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
oneTimePadCipherController.decodeOneTimePad(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -25,11 +27,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PortaCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController")
|
||||
protected Logger portaLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/porta";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Rtghuos bm^qcwgrw";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -58,7 +64,7 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.PORTA_CIPHER_DESCRIPTION))
|
||||
@@ -76,7 +82,7 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
public void testEncodePorta() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -86,7 +92,7 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
//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("ip", ipAddress);
|
||||
verify(mdc, times(1)).put("url", url + "/encode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
@@ -95,11 +101,30 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Encoding {}", CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePorta() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -109,7 +134,7 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
//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("ip", ipAddress);
|
||||
verify(mdc, times(1)).put("url", url + "/decode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
@@ -117,4 +142,23 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Decoding {}", CipherInfoUtil.PORTA_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PortaCipherControllerTest{
|
||||
@InjectMocks
|
||||
private PortaCipherController portaCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PORTA_CIPHER_NAME, CipherInfoUtil.PORTA_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = portaCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePorta(){
|
||||
ObjectNode cipherParams = generateParams(PORTA_KEYWORD, PORTA_INPUT_STRING);
|
||||
@@ -36,11 +50,12 @@ public class PortaCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PORTA_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodePorta_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
portaCipherController.encodePorta(blankParams);
|
||||
portaCipherController.encodePorta(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,21 +69,24 @@ public class PortaCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PORTA_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodePorta_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
portaCipherController.decodePorta(blankParams);
|
||||
portaCipherController.decodePorta(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class SubstitutionCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController")
|
||||
protected Logger substitutionLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/substitution";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Oguucig vq^gpeqfg";
|
||||
private String keyword = "cdefghijklmnopqrstuvwxyzab";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -57,7 +63,7 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION))
|
||||
@@ -75,7 +81,7 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
public void testEncodeSubstitution() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -90,11 +96,30 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Encoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeSubstitution() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -108,4 +133,23 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Decoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class SubstitutionCipherControllerTest{
|
||||
@InjectMocks
|
||||
private SubstitutionCipherController substitutionCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.SUBSTITUTION_CIPHER_NAME, CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = substitutionCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeSubstitution(){
|
||||
ObjectNode cipherParams = generateParams(SUBSTITUTION_KEYWORD, SUBSTITUTION_INPUT_STRING);
|
||||
@@ -36,11 +50,12 @@ public class SubstitutionCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(SUBSTITUTION_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeSubstitution_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
substitutionCipherController.encodeSubstitution(blankParams);
|
||||
substitutionCipherController.encodeSubstitution(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,21 +69,24 @@ public class SubstitutionCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(SUBSTITUTION_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeSubstitution_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
substitutionCipherController.decodeSubstitution(blankParams);
|
||||
substitutionCipherController.decodeSubstitution(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -24,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class VigenereCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController")
|
||||
protected Logger vigenereLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/vigenere";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh ds^cjqfgo";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -57,7 +63,7 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1"))
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION))
|
||||
@@ -75,7 +81,7 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
public void testEncodeVigenere() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -90,11 +96,30 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Encoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeVigenere() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -108,4 +133,23 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Decoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class VigenereCipherControllerTest{
|
||||
@InjectMocks
|
||||
private VigenereCipherController vigenereCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.VIGENERE_CIPHER_NAME, CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = vigenereCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeVigenere(){
|
||||
ObjectNode cipherParams = generateParams(VIGENERE_KEYWORD, VIGENERE_INPUT_STRING);
|
||||
@@ -36,11 +50,12 @@ public class VigenereCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(VIGENERE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeVigenere_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
vigenereCipherController.encodeVigenere(blankParams);
|
||||
vigenereCipherController.encodeVigenere(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,21 +69,24 @@ public class VigenereCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(VIGENERE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeVigenere_invalidparameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
vigenereCipherController.decodeVigenere(blankParams);
|
||||
vigenereCipherController.decodeVigenere(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
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.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController")
|
||||
protected Logger bifidLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/bifid";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Mqaokne kc^vdodzd";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BIFID_CIPHER_NAME, CipherInfoUtil.BIFID_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BIFID_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BIFID_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Encoding Bifid");
|
||||
verify(bifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Decoding Bifid");
|
||||
verify(bifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BifidCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BifidCipherController bifidCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BIFID_CIPHER_NAME, CipherInfoUtil.BIFID_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = bifidCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid(){
|
||||
ObjectNode cipherParams = generateParams(BIFID_KEYWORD, BIFID_INPUT_STRING);
|
||||
@@ -36,16 +50,17 @@ public class BifidCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeBifid_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
bifidCipherController.encodeBifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey(){
|
||||
public void testDecodeBifid(){
|
||||
ObjectNode cipherParams = generateParams(BIFID_KEYWORD, BIFID_OUTPUT_STRING);
|
||||
|
||||
|
||||
@@ -54,21 +69,24 @@ public class BifidCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeBifid_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
bifidCipherController.decodeBifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
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.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class ColumnarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController")
|
||||
protected Logger columnarLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/columnar";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Edeomte ac^gosnse";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.COLUMNAR_CIPHER_NAME, CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.COLUMNAR_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Getting info for {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Encoding Columnar");
|
||||
verify(columnarLogger, times(1)).info("Encoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Encoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeColumnar() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Decoding Columnar");
|
||||
verify(columnarLogger, times(1)).info("Decoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Decoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class ColumnarCipherControllerTest{
|
||||
@InjectMocks
|
||||
private ColumnarCipherController columnarCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.COLUMNAR_CIPHER_NAME, CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = columnarCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar(){
|
||||
ObjectNode cipherParams = generateParams(COLUMNAR_KEYWORD, COLUMNAR_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class ColumnarCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeColumnar_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
columnarCipherController.encodeColumnar(blankNode);
|
||||
});
|
||||
@@ -54,21 +69,24 @@ public class ColumnarCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeColumnar_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
columnarCipherController.decodeColumnar(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
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.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class HillCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController")
|
||||
protected Logger hillLogger;
|
||||
//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}};
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.HILL_CIPHER_NAME, CipherInfoUtil.HILL_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.HILL_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.HILL_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Getting info for {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Encoding Hill");
|
||||
verify(hillLogger, times(1)).info("Encoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Encoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeHill() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Decoding Hill");
|
||||
verify(hillLogger, times(1)).info("Decoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Decoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,12 +23,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class HillCipherControllerTest{
|
||||
@InjectMocks
|
||||
private HillCipherController hillCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.HILL_CIPHER_NAME, CipherInfoUtil.HILL_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = hillCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws JsonProcessingException{
|
||||
ObjectNode cipherParams = generateParams(HILL_INPUT_STRING);
|
||||
@@ -38,9 +52,10 @@ public class HillCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeHill_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
hillCipherController.encodeHill(blankNode);
|
||||
});
|
||||
@@ -56,22 +71,24 @@ public class HillCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeHill_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
hillCipherController.decodeHill(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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);
|
||||
JsonNode keyNode = mapper.valueToTree(KEY);
|
||||
cipherParams.set(CipherParameterUtil.HILL_KEY, keyNode);
|
||||
|
||||
return cipherParams;
|
||||
|
||||
@@ -8,12 +8,16 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
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.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,10 +26,14 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController")
|
||||
protected Logger morseLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/morse";
|
||||
private String decodedString = "Message to^encode123";
|
||||
private String encodedString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -39,12 +47,31 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.MORSE_CIPHER_NAME, CipherInfoUtil.MORSE_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.MORSE_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.MORSE_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Getting info for {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -54,16 +81,35 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Encoding Morse");
|
||||
verify(morseLogger, times(1)).info("Encoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Encoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeMorse() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -73,8 +119,27 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Decoding Morse");
|
||||
verify(morseLogger, times(1)).info("Decoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Decoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,11 +21,24 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class MorseCodeControllerTest{
|
||||
@InjectMocks
|
||||
private MorseCodeController morseCodeController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String MORSE_INPUT_STRING = "SOS";
|
||||
private static final String MORSE_OUTPUT_STRING = "... --- ...";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.MORSE_CIPHER_NAME, CipherInfoUtil.MORSE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = morseCodeController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse(){
|
||||
ObjectNode cipherParams = generateParams(MORSE_INPUT_STRING);
|
||||
@@ -35,9 +49,10 @@ public class MorseCodeControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncoderMorse_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
morseCodeController.encodeMorse(blankNode);
|
||||
});
|
||||
@@ -53,17 +68,20 @@ public class MorseCodeControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeMorse_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
morseCodeController.decodeMorse(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
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.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,12 +26,16 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PlayfairCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController")
|
||||
protected Logger playfairLogger;
|
||||
//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";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -50,11 +58,31 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PLAYFAIR_CIPHER_NAME, CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.PLAYFAIR_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(playfairLogger, times(1)).info("Getting info for {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -64,16 +92,35 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(playfiarLogger, times(1)).info("Encoding Playfair");
|
||||
verify(playfairLogger, times(1)).info("Encoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(playfairLogger, times(1)).info("Encoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePlayfair() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -83,8 +130,27 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(playfiarLogger, times(1)).info("Decoding Playfair");
|
||||
verify(playfairLogger, times(1)).info("Decoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(playfairLogger, times(1)).info("Decoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,13 +21,26 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PlayfairCipherControllerTest{
|
||||
@InjectMocks
|
||||
private PlayfairCipherController playfairCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PLAYFAIR_CIPHER_NAME, CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = playfairCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair(){
|
||||
ObjectNode cipherParams = generateParams(PLAYFAIR_KEYWORD, PLAYFAIR_INPUT_STRING);
|
||||
@@ -37,9 +51,10 @@ public class PlayfairCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PLAYFAIR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodePlayfair_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
playfairCipherController.encodePlayfair(blankNode);
|
||||
});
|
||||
@@ -55,21 +70,24 @@ public class PlayfairCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(DECODED_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodePlayfair_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
playfairCipherController.decodePlayfair(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
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.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PolybiusSquareControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController")
|
||||
protected Logger polybiusLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/polybius";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "41124545233212 5115^124225152212";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Getting info for {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Encoding Polybius");
|
||||
verify(polybiusLogger, times(1)).info("Encoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_WHITESPACE + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Encoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePolybius() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Decoding Polybius");
|
||||
verify(polybiusLogger, times(1)).info("Decoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_WHITESPACE + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Decoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PolybiusSquareControllerTest{
|
||||
@InjectMocks
|
||||
private PolybiusSquareController polybiusSquareController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = polybiusSquareController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius(){
|
||||
ObjectNode cipherParams = generateParams(POLYBIUS_KEYWORD, POLYBIUS_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class PolybiusSquareControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodePolybius_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
polybiusSquareController.encodePolybius(blankNode);
|
||||
});
|
||||
@@ -54,21 +69,24 @@ public class PolybiusSquareControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodePolybius_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
polybiusSquareController.decodePolybius(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
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.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class RailFenceControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController")
|
||||
protected Logger railFenceLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/railFence";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Maooesg te^cdsene";
|
||||
private int rails = 3;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Getting info for {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Encoding Rail Fence");
|
||||
verify(railFenceLogger, times(1)).info("Encoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Encoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRailFence() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Decoding Rail Fence");
|
||||
verify(railFenceLogger, times(1)).info("Decoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Decoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class RailFenceControllerTest{
|
||||
@InjectMocks
|
||||
private RailFenceController railFenceController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = railFenceController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence(){
|
||||
ObjectNode cipherParams = generateParams(RAIL_FENCE_RAILS, RAIL_FENCE_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class RailFenceControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeRailFence_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
@@ -54,21 +69,24 @@ public class RailFenceControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeRailFence_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int rails, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ 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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
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.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,6 +26,9 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class TrifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController")
|
||||
protected Logger trifidLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/trifid";
|
||||
private String decodedString = "Message to^encode+";
|
||||
@@ -29,6 +36,7 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
private String keyword = "keyword";
|
||||
private String trifidFill = "=";
|
||||
private int grouplength = Integer.MAX_VALUE;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,11 +63,31 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.TRIFID_CIPHER_NAME, CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.TRIFID_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Getting info for {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -69,16 +97,35 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Encoding Trifid");
|
||||
verify(trifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeTrifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -88,8 +135,27 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Decoding Trifid");
|
||||
verify(trifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,14 +21,27 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class TrifidCipherControllerTest{
|
||||
@InjectMocks
|
||||
private TrifidCipherController trifidCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
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();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.TRIFID_CIPHER_NAME, CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = trifidCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid(){
|
||||
ObjectNode cipherParams = generateParams(TRIFID_KEYWORD, TRIFID_FILL_ID, TRIFID_GROUP_LENGTH, TRIFID_INPUT_STRING);
|
||||
@@ -38,9 +52,10 @@ public class TrifidCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeTrifid_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
trifidCipherController.encodeTrifid(blankNode);
|
||||
});
|
||||
@@ -56,16 +71,18 @@ public class TrifidCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeTrifid_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
trifidCipherController.decodeTrifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, char fill, int groupLength, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
@@ -73,6 +90,7 @@ public class TrifidCipherControllerTest{
|
||||
cipherParams.put(CipherParameterUtil.TRIFID_FILL, String.valueOf(fill));
|
||||
cipherParams.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, groupLength);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user