Update cipher descriptions

This commit is contained in:
2024-04-22 00:03:36 -04:00
parent f40d18e54c
commit 71c50f0608
66 changed files with 1317 additions and 599 deletions

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.combination;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/adfgvx") @RequestMapping("/adfgvx")
@PropertySource("classpath:ciphers.properties")
public class AdfgvxCipherController{ public class AdfgvxCipherController{
@Value("${cipher.combination.adfgvx.name}")
private String adfgvxName;
@Value("${cipher.combination.adfgvx.description}")
private String adfgvxDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGVX_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
log.info("Getting info for {}", CipherInfoUtil.ADFGVX_CIPHER_NAME); log.info("Getting info for {}", adfgvxName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGVX_CIPHER_NAME, CipherInfoUtil.ADFGVX_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(adfgvxName, adfgvxDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeAdfgvx(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeAdfgvx(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGVX_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
log.info("Encoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME); log.info("Encoding {}", adfgvxName);
CipherParameterUtil.verifySquareKeyword(cipherParams); CipherParameterUtil.verifySquareKeyword(cipherParams);
@@ -56,8 +65,8 @@ public class AdfgvxCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeAdfgvx(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeAdfgvx(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGVX_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
log.info("Decoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME); log.info("Decoding {}", adfgvxName);
CipherParameterUtil.verifySquareKeyword(cipherParams); CipherParameterUtil.verifySquareKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.combination;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/adfgx") @RequestMapping("/adfgx")
@PropertySource("classpath:ciphers.properties")
public class AdfgxCipherController{ public class AdfgxCipherController{
@Value("${cipher.combination.adfgvx.name}")
private String adfgxName;
@Value("${cipher.combination.adfgvx.description}")
private String adfgxDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGX_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
log.info("Getting info for {}", CipherInfoUtil.ADFGX_CIPHER_NAME); log.info("Getting info for {}", adfgxName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGX_CIPHER_NAME, CipherInfoUtil.ADFGX_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(adfgxName, adfgxDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeAdfgx(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeAdfgx(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGX_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
log.info("Encoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME); log.info("Encoding {}", adfgxName);
CipherParameterUtil.verifySquareKeyword(cipherParams); CipherParameterUtil.verifySquareKeyword(cipherParams);
@@ -56,8 +65,8 @@ public class AdfgxCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeAdfgx(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeAdfgx(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGX_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
log.info("Decoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME); log.info("Decoding {}", adfgxName);
CipherParameterUtil.verifySquareKeyword(cipherParams); CipherParameterUtil.verifySquareKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/affine") @RequestMapping("/affine")
@PropertySource("classpath:ciphers.properties")
public class AffineCipherController{ public class AffineCipherController{
@Value("${cipher.mono.affine.name}")
private String affineName;
@Value("${cipher.mono.affine.description}")
private String affineDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
log.info("Getting info for {}", CipherInfoUtil.AFFINE_CIPHER_NAME); log.info("Getting info for {}", affineName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.AFFINE_CIPHER_NAME, CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(affineName, affineDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeAffine(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeAffine(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
log.info("Encoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME); log.info("Encoding {}", affineName);
CipherParameterUtil.verifyAffineParams(cipherParams); CipherParameterUtil.verifyAffineParams(cipherParams);
@@ -56,8 +65,8 @@ public class AffineCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeAffine(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeAffine(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
log.info("Decoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME); log.info("Decoding {}", affineName);
CipherParameterUtil.verifyAffineParams(cipherParams); CipherParameterUtil.verifyAffineParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/atbash") @RequestMapping("/atbash")
@PropertySource("classpath:ciphers.properties")
public class AtbashCipherController{ public class AtbashCipherController{
@Value("${cipher.mono.atbash.name}")
private String atbashName;
@Value("${cipher.mono.atbash.description}")
private String atbashDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
log.info("Getting info for {}", CipherInfoUtil.ATBASH_CIPHER_NAME); log.info("Getting info for {}", atbashName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.ATBASH_CIPHER_NAME, CipherInfoUtil.ATBASH_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(atbashName, atbashDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeAtbash(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeAtbash(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
log.info("Encoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME); log.info("Encoding {}", atbashName);
CipherParameterUtil.verifyAtbashParams(cipherParams); CipherParameterUtil.verifyAtbashParams(cipherParams);
@@ -54,8 +63,8 @@ public class AtbashCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeAtbash(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeAtbash(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
log.info("Decoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME); log.info("Decoding {}", atbashName);
CipherParameterUtil.verifyAtbashParams(cipherParams); CipherParameterUtil.verifyAtbashParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/autokey") @RequestMapping("/autokey")
@PropertySource("classpath:ciphers.properties")
public class AutokeyCipherController{ public class AutokeyCipherController{
@Value("${cipher.mono.autokey.name}")
private String autokeyName;
@Value("${cipher.mono.autokey.description}")
private String autokeyDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
log.info("Getting info for {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME); log.info("Getting info for {}", autokeyName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.AUTOKEY_CIPHER_NAME, CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(autokeyName, autokeyDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeAutokey(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeAutokey(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
log.info("Encoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME); log.info("Encoding {}", autokeyName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class AutokeyCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeAutokey(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeAutokey(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
log.info("Decoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME); log.info("Decoding {}", autokeyName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/baconian") @RequestMapping("/baconian")
@PropertySource("classpath:ciphers.properties")
public class BaconianCipherController{ public class BaconianCipherController{
@Value("${cipher.mono.baconian.name}")
private String baconianName;
@Value("${cipher.mono.baconian.description}")
private String baconianDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
log.info("Getting info for {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); log.info("Getting info for {}", baconianName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.BACONIAN_CIPHER_NAME, CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(baconianName, baconianDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeBaconian(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeBaconian(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Baconian"); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
log.info("Encoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); log.info("Encoding {}", baconianName);
CipherParameterUtil.verifyBaconianParams(cipherParams); CipherParameterUtil.verifyBaconianParams(cipherParams);
@@ -52,8 +61,8 @@ public class BaconianCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeBaconian(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeBaconian(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, "Baconian"); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
log.info("Decoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); log.info("Decoding {}", baconianName);
CipherParameterUtil.verifyBaconianParams(cipherParams); CipherParameterUtil.verifyBaconianParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/basex") @RequestMapping("/basex")
@PropertySource("classpath:ciphers.properties")
public class BaseXCipherController{ public class BaseXCipherController{
@Value("${cipher.mono.basex.name}")
private String baseXName;
@Value("${cipher.mono.basex.description}")
private String baseXDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
log.info("Getting info for {}", CipherInfoUtil.BASE_X_CIPHER_NAME); log.info("Getting info for {}", baseXName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.BASE_X_CIPHER_NAME, CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(baseXName, baseXDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeBaseX(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeBaseX(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
log.info("Encoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME); log.info("Encoding {}", baseXName);
CipherParameterUtil.verifyBaseXParams(cipherParams); CipherParameterUtil.verifyBaseXParams(cipherParams);
@@ -52,8 +61,8 @@ public class BaseXCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeBaseX(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeBaseX(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
log.info("Decoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME); log.info("Decoding {}", baseXName);
CipherParameterUtil.verifyBaseXParams(cipherParams); CipherParameterUtil.verifyBaseXParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/beaufort") @RequestMapping("/beaufort")
@PropertySource("classpath:ciphers.properties")
public class BeaufortCipherController{ public class BeaufortCipherController{
@Value("${cipher.mono.beaufort.name}")
private String beaufortName;
@Value("${cipher.mono.beaufort.description}")
private String beaufortDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
log.info("Getting info for {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME); log.info("Getting info for {}", beaufortName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.BEAUFORT_CIPHER_NAME, CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(beaufortName, beaufortDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeBeaufort(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeBeaufort(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
log.info("Encoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME); log.info("Encoding {}", beaufortName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class BeaufortCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeBeaufort(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeBeaufort(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
log.info("Decoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME); log.info("Decoding {}", beaufortName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/caesar") @RequestMapping("/caesar")
@PropertySource("classpath:ciphers.properties")
public class CaesarCipherController{ public class CaesarCipherController{
@Value("${cipher.mono.caesar.name}")
private String caesarName;
@Value("${cipher.mono.caesar.description}")
private String caesarDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
log.info("Getting info for {}", CipherInfoUtil.CAESAR_CIPHER_NAME); log.info("Getting info for {}", caesarName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.CAESAR_CIPHER_NAME, CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(caesarName, caesarDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeCaesar(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeCaesar(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
log.info("Encoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME); log.info("Encoding {}", caesarName);
CipherParameterUtil.verifyCaesarParams(cipherParams); CipherParameterUtil.verifyCaesarParams(cipherParams);
@@ -55,8 +64,8 @@ public class CaesarCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeCaesar(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeCaesar(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
log.info("Decoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME); log.info("Decoding {}", caesarName);
CipherParameterUtil.verifyCaesarParams(cipherParams); CipherParameterUtil.verifyCaesarParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/oneTimePad") @RequestMapping("/oneTimePad")
@PropertySource("classpath:ciphers.properties")
public class OneTimePadCipherController{ public class OneTimePadCipherController{
@Value("${cipher.mono.onetimepad.name}")
private String oneTimePadName;
@Value("${cipher.mono.onetimepad.description}")
private String oneTimePadDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
log.info("Getting info for {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); log.info("Getting info for {}", oneTimePadName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME, CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(oneTimePadName, oneTimePadDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeOneTimePad(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeOneTimePad(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
log.info("Encoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); log.info("Encoding {}", oneTimePadName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class OneTimePadCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeOneTimePad(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeOneTimePad(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
log.info("Decoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); log.info("Decoding {}", oneTimePadName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/porta") @RequestMapping("/porta")
@PropertySource("classpath:ciphers.properties")
public class PortaCipherController{ public class PortaCipherController{
@Value("${cipher.mono.porta.name}")
private String portaName;
@Value("${cipher.mono.porta.description}")
private String portaDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
log.info("Getting info for {}", CipherInfoUtil.PORTA_CIPHER_NAME); log.info("Getting info for {}", portaName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.PORTA_CIPHER_NAME, CipherInfoUtil.PORTA_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(portaName, portaDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodePorta(@RequestBody ObjectNode cipherParams){ public ObjectNode encodePorta(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
log.info("Encoding {}", CipherInfoUtil.PORTA_CIPHER_NAME); log.info("Encoding {}", portaName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class PortaCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodePorta(@RequestBody ObjectNode cipherParams){ public ObjectNode decodePorta(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
log.info("Decoding {}", CipherInfoUtil.PORTA_CIPHER_NAME); log.info("Decoding {}", portaName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/substitution") @RequestMapping("/substitution")
@PropertySource("classpath:ciphers.properties")
public class SubstitutionCipherController{ public class SubstitutionCipherController{
@Value("${cipher.mono.substitution.name}")
private String substitutionName;
@Value("${cipher.mono.substitution.description}")
private String substitutionDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
log.info("Getting info for {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); log.info("Getting info for {}", substitutionName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.SUBSTITUTION_CIPHER_NAME, CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(substitutionName, substitutionDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeSubstitution(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeSubstitution(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
log.info("Encoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); log.info("Encoding {}", substitutionName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class SubstitutionCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeSubstitution(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeSubstitution(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
log.info("Decoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); log.info("Decoding {}", substitutionName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/vigenere") @RequestMapping("/vigenere")
@PropertySource("classpath:ciphers.properties")
public class VigenereCipherController{ public class VigenereCipherController{
@Value("${cipher.mono.vigenere.name}")
private String vigenereName;
@Value("${cipher.mono.vigenere.description}")
private String vigenereDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
log.info("Getting info for {}", CipherInfoUtil.VIGENERE_CIPHER_NAME); log.info("Getting info for {}", vigenereName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.VIGENERE_CIPHER_NAME, CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(vigenereName, vigenereDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeVigenere(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeVigenere(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
log.info("Encoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME); log.info("Encoding {}", vigenereName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class VigenereCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeVigenere(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeVigenere(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
log.info("Decoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME); log.info("Decoding {}", vigenereName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/bifid") @RequestMapping("/bifid")
@PropertySource("classpath:ciphers.properties")
public class BifidCipherController{ public class BifidCipherController{
@Value("${cipher.poly.bifid.name}")
private String bifidName;
@Value("${cipher.poly.bifid.description}")
private String bifidDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
log.info("Getting info for {}", CipherInfoUtil.BIFID_CIPHER_NAME); log.info("Getting info for {}", bifidName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.BIFID_CIPHER_NAME, CipherInfoUtil.BIFID_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(bifidName, bifidDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeBifid(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeBifid(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
log.info("Encoding {}", CipherInfoUtil.BIFID_CIPHER_NAME); log.info("Encoding {}", bifidName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class BifidCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeBifid(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeBifid(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
log.info("Decoding {}", CipherInfoUtil.BIFID_CIPHER_NAME); log.info("Decoding {}", bifidName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/columnar") @RequestMapping("/columnar")
@PropertySource("classpath:ciphers.properties")
public class ColumnarCipherController{ public class ColumnarCipherController{
@Value("${cipher.poly.columnar.name}")
private String columnarName;
@Value("${cipher.poly.columnar.description}")
private String columnarDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
log.info("Getting info for {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME); log.info("Getting info for {}", columnarName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.COLUMNAR_CIPHER_NAME, CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(columnarName, columnarDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeColumnar(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeColumnar(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
log.info("Encoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME); log.info("Encoding {}", columnarName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class ColumnarCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeColumnar(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeColumnar(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
log.info("Decoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME); log.info("Decoding {}", columnarName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -22,20 +24,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/hill") @RequestMapping("/hill")
@PropertySource("classpath:ciphers.properties")
public class HillCipherController{ public class HillCipherController{
@Value("${cipher.poly.hill.name}")
private String hillName;
@Value("${cipher.poly.hill.description}")
private String hillDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
log.info("Getting info for {}", CipherInfoUtil.HILL_CIPHER_NAME); log.info("Getting info for {}", hillName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.HILL_CIPHER_NAME, CipherInfoUtil.HILL_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(hillName, hillDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{ public ObjectNode encodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
log.info("Encoding {}", CipherInfoUtil.HILL_CIPHER_NAME); log.info("Encoding {}", hillName);
CipherParameterUtil.verifyHillParams(cipherParams); CipherParameterUtil.verifyHillParams(cipherParams);
@@ -57,8 +66,8 @@ public class HillCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{ public ObjectNode decodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
log.info("Decoding {}", CipherInfoUtil.HILL_CIPHER_NAME); log.info("Decoding {}", hillName);
CipherParameterUtil.verifyHillParams(cipherParams); CipherParameterUtil.verifyHillParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/morse") @RequestMapping("/morse")
@PropertySource("classpath:ciphers.properties")
public class MorseCodeController{ public class MorseCodeController{
@Value("${cipher.poly.morse.name}")
private String morseName;
@Value("${cipher.poly.morse.description}")
private String morseDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
log.info("Getting info for {}", CipherInfoUtil.MORSE_CIPHER_NAME); log.info("Getting info for {}", morseName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.MORSE_CIPHER_NAME, CipherInfoUtil.MORSE_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(morseName, morseDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeMorse(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeMorse(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
log.info("Encoding {}", CipherInfoUtil.MORSE_CIPHER_NAME); log.info("Encoding {}", morseName);
CipherParameterUtil.verifyMorseParams(cipherParams); CipherParameterUtil.verifyMorseParams(cipherParams);
@@ -51,8 +60,8 @@ public class MorseCodeController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeMorse(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeMorse(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
log.info("Decoding {}", CipherInfoUtil.MORSE_CIPHER_NAME); log.info("Decoding {}", morseName);
CipherParameterUtil.verifyMorseParams(cipherParams); CipherParameterUtil.verifyMorseParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/playfair") @RequestMapping("/playfair")
@PropertySource("classpath:ciphers.properties")
public class PlayfairCipherController{ public class PlayfairCipherController{
@Value("${cipher.poly.playfair.name}")
private String playfairName;
@Value("${cipher.poly.playfair.description}")
private String playfairDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
log.info("Getting info for {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME); log.info("Getting info for {}", playfairName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.PLAYFAIR_CIPHER_NAME, CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(playfairName, playfairDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodePlayfair(@RequestBody ObjectNode cipherParams){ public ObjectNode encodePlayfair(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
log.info("Encoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME); log.info("Encoding {}", playfairName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);
@@ -55,8 +64,8 @@ public class PlayfairCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodePlayfair(@RequestBody ObjectNode cipherParams){ public ObjectNode decodePlayfair(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
log.info("Decoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME); log.info("Decoding {}", playfairName);
CipherParameterUtil.verifyParamsWithKeyword(cipherParams); CipherParameterUtil.verifyParamsWithKeyword(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/polybius") @RequestMapping("/polybius")
@PropertySource("classpath:ciphers.properties")
public class PolybiusSquareController{ public class PolybiusSquareController{
@Value("${cipher.poly.polybius.name}")
private String polybiusName;
@Value("${cipher.poly.polybius.description}")
private String polybiusDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
log.info("Getting info for {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); log.info("Getting info for {}", polybiusName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(polybiusName, polybiusDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodePolybius(@RequestBody ObjectNode cipherParams){ public ObjectNode encodePolybius(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
log.info("Encoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); log.info("Encoding {}", polybiusName);
CipherParameterUtil.verifyPolybiusParams(cipherParams); CipherParameterUtil.verifyPolybiusParams(cipherParams);
@@ -54,8 +63,8 @@ public class PolybiusSquareController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodePolybius(@RequestBody ObjectNode cipherParams){ public ObjectNode decodePolybius(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
log.info("Decoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); log.info("Decoding {}", polybiusName);
CipherParameterUtil.verifyPolybiusParams(cipherParams); CipherParameterUtil.verifyPolybiusParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/railFence") @RequestMapping("/railFence")
@PropertySource("classpath:ciphers.properties")
public class RailFenceController{ public class RailFenceController{
@Value("${cipher.poly.railfence.name}")
private String railFenceName;
@Value("${cipher.poly.railfence.description}")
private String railFenceDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
log.info("Getting info for {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); log.info("Getting info for {}", railFenceName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(railFenceName, railFenceDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeRailFence(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeRailFence(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
log.info("Encoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); log.info("Encoding {}", railFenceName);
CipherParameterUtil.verifyRailFenceParams(cipherParams); CipherParameterUtil.verifyRailFenceParams(cipherParams);
@@ -55,8 +64,8 @@ public class RailFenceController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeRailFence(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeRailFence(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
log.info("Decoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); log.info("Decoding {}", railFenceName);
CipherParameterUtil.verifyRailFenceParams(cipherParams); CipherParameterUtil.verifyRailFenceParams(cipherParams);

View File

@@ -2,6 +2,8 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@@ -20,20 +22,27 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/trifid") @RequestMapping("/trifid")
@PropertySource("classpath:ciphers.properties")
public class TrifidCipherController{ public class TrifidCipherController{
@Value("${cipher.poly.trifid.name}")
private String trifidName;
@Value("${cipher.poly.trifid.description}")
private String trifidDescription;
@GetMapping @GetMapping
public ObjectNode getCipherInfo(){ public ObjectNode getCipherInfo(){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
log.info("Getting info for {}", CipherInfoUtil.TRIFID_CIPHER_NAME); log.info("Getting info for {}", trifidName);
return CipherInfoUtil.buildInfoNode(CipherInfoUtil.TRIFID_CIPHER_NAME, CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION); return CipherInfoUtil.buildInfoNode(trifidName, trifidDescription);
} }
@PostMapping("/encode") @PostMapping("/encode")
public ObjectNode encodeTrifid(@RequestBody ObjectNode cipherParams){ public ObjectNode encodeTrifid(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
log.info("Encoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME); log.info("Encoding {}", trifidName);
CipherParameterUtil.verifyTrifidParams(cipherParams); CipherParameterUtil.verifyTrifidParams(cipherParams);
@@ -57,8 +66,8 @@ public class TrifidCipherController{
@PostMapping("/decode") @PostMapping("/decode")
public ObjectNode decodeTrifid(@RequestBody ObjectNode cipherParams){ public ObjectNode decodeTrifid(@RequestBody ObjectNode cipherParams){
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME); MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
log.info("Decoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME); log.info("Decoding {}", trifidName);
CipherParameterUtil.verifyTrifidParams(cipherParams); CipherParameterUtil.verifyTrifidParams(cipherParams);

View File

@@ -17,60 +17,6 @@ public class CipherInfoUtil{
public static final String CIPHER_DESCRIPTION = "description"; 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";
public static final String BACONIAN_CIPHER_NAME = "Baconian";
public static final String BASE_X_CIPHER_NAME = "Base X";
public static final String BEAUFORT_CIPHER_NAME = "Beaufort";
public static final String CAESAR_CIPHER_NAME = "Caesar";
public static final String ONE_TIME_PAD_CIPHER_NAME = "One-Time Pad";
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";
public static final String BACONIAN_CIPHER_DESCRIPTION = "Baconian Cipher";
public static final String BASE_X_CIPHER_DESCRIPTION = "Base X Cipher";
public static final String BEAUFORT_CIPHER_DESCRIPTION = "Beaufort Cipher";
public static final String CAESAR_CIPHER_DESCRIPTION = "Caesar Cipher";
public static final String ONE_TIME_PAD_CIPHER_DESCRIPTION = "One-Time Pad Cipher";
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){ public static ObjectNode buildInfoNode(String name, String description){
ObjectNode infoNode = mapper.createObjectNode(); ObjectNode infoNode = mapper.createObjectNode();

View File

@@ -1 +1 @@
server.port=8001 server.port=8001

View File

@@ -0,0 +1,198 @@
#Mono-Substitution
#Affine
cipher.mono.affine.name=Affine
cipher.mono.affine.description=The Affine cipher is a monoalphabetic substitution cipher, where each letter in an alphabet is mapped to a numeric equivalent, encrypted, and then converted back to a letter. \
The formula used in this encryption is F(x) = (ax + b) % m, where x is the original letter, a and b are the keys of the cipher, and m is the length of the alphabet, with a and m being coprime.\
Decryption is performed using the formula F(x) = a^-1(x - b) % m.\
The Affine cipher is a relatively weak cipher compared to modern encryption methods because it's vulnerable to frequency analysis and other cryptanalysis techniques. However, it's simple to implement and understand, making it a good introduction to encryption concepts.
cipher.mono.affine.facts=
#Atbash
cipher.mono.atbash.name=Atbash
cipher.mono.atbash.description=The Atbash cipher is a monoalphabetic substitution cipher and is one of the simplest and oldest forms of encryption. \
Encryption involves replacing each letter with its reverse counterpart. i.e. A becomes Z, B becomes Y, etc. \
Decryption is performed using the same formula as encryption. \
Atbash cipher can effectively obscure the meaning of a message to those unfamiliar with the technique. However, it's very vulnerable to cryptanalysis, especially frequency analysis, and it provides very little security against modern decryption techniques.
cipher.mono.atbash.facts=Atbash gets its name from a technique using the Hebrew alphabet, where the first letter "Aleph" is replaced with the last latter "Tav", "Bet" is replaced with "shin", etc. \
The Atbash cipher is a special case of the Affine cipher with a = 25 and b = 25.
#Autokey
cipher.mono.autokey.name=Autokey
cipher.mono.autokey.description=The autokey cipher extends the Vigenere cipher. Like the Vigenere cipher it uses a keyword to encrypt plaintext, but it also incorporates the plaintext itself into the keystream. \
Encryption works by concatenating the message to the keyword. Then you convert the resulting key into a series of numeric values mod 26. Then you advance each letter the indicated number of letters similar to the Caesar cipher. \
Decryption works by converting the key the same as encryption, but instead of advancing each letter the given amount the values retreat. As each letter is decrypted the letter needs added to the key as well as the output so that decryption can continue. \
The Autokey cipher is more secure than the Vigenere cipher due to the keyword including part of the text to be encoded. However, like the Vigenere cipher, the Autokey cipher is vulnerable to frequency analysis and other cryptanalysis techniques, especially if the keyword is short or if there are patterns in the plaintext.
cipher.mono.autokey.facts=
#Baconian
cipher.mono.baconian.name=Baconian
cipher.mono.baconian.description=The Baconian cipher, also known as the Baconian alphabet or Bacon's cipher, is a type of substitution cipher used for encoding and decoding messages. \
In the Baconian cipher, each letter of the alphabet is replaced by a sequence of five characters, consisting of 'A' and 'B'. \
These characters represent the binary encoding of the letter, where 'A' stands for one binary digit (usually 0) and 'B' stands for the other binary digit (usually 1). \
During encoding I and J are generally encoded as the same letter. \
To encode a message using the Baconian cipher, each letter of the plaintext is replaced by its corresponding binary sequence according to the table above. Spaces and punctuation are typically ignored. \
The Baconian cipher is relatively easy to encode and decode, especially with the aid of a table or key. However, it provides only limited security against modern cryptanalysis techniques and is mainly of historical interest.
cipher.mono.baconian.facts=It was developed by Sir Francis Bacon in the late 16th century.
#TODO
#Base X
cipher.mono.basex.name=Base X
cipher.mono.basex.description=Base X is an abstraction for Base 2, Base 16, etc. Base X uses the integer values for each character and displays them in the desired base.
cipher.mono.basex.facts=
#Beaufort
cipher.mono.beaufort.name=Beaufort
cipher.mono.beaufort.description=The Beaufort cipher is a type of substitution cipher similar to the Vigenere cipher but with a different method of encryption. \
In the Beaufort cipher, encryption and decryption are performed by using a keyword to determine the amount of backward displacement within the alphabet for each letter of the text, unlike the Vigenere cipher, where the key is added. \
The Beaufort cipher, like the Vigenere cipher, is vulnerable to frequency analysis and other cryptanalysis techniques, especially if the keyword is short or if there are patterns in the plaintext. \
However, it provides some variation in encryption compared to the Vigenere cipher, which may offer slightly different cryptographic properties.
cipher.mono.beaufort.facts=It was named after Sir Francis Beaufort, an Irish hydrographer, and admiral.
#Caesar
cipher.mono.caesar.name=Caesar
cipher.mono.caesar.description=The Caesar cipher is one of the simplest and most widely known encryption techniques. It's a type of substitution cipher where each letter in the plaintext is shifted a certain number of places down or up the alphabet. \
For encryption a shift value is used which determines how many letters forward each letter in the text should be shifted. \
Decryption uses the same shift, but shifts each letter down rather than up. \
The Caesar cipher is a special case of the substitution cipher with a fixed shift. While it's straightforward to implement and understand, it's also highly vulnerable to cryptanalysis, especially through frequency analysis. \
With only 25 possible keys, it's easily broken by trying all possible shifts. Despite its simplicity, it's still sometimes used as a part of more complex encryption algorithms or for educational purposes.
cipher.mono.caesar.facts=The Caesar cipher, named after Julius Caesar who is said to have used it for communication.
#One-Time Pad
cipher.mono.onetimepad.name=One-Time Pad
cipher.mono.onetimepad.description=A One-Time Pad cipher is a type of encryption technique that provides perfect secrecy when used correctly. The essence of a One-Time Pad cipher lies in the use of a randomly generated key that is at least as long as the message being encrypted. \
The key is never reused and is kept completely secret between the sender and the recipient. Each character of the plaintext message is combined with the corresponding bit or character of the key using a the same shift as the Caesar cipher. \
In a slightly less secure, but more practical key selection, the passage of a book can also be used. Preferably one with a good mix of many characters that would make frequency analysis more difficult. \
When these principles are followed, the One-Time Pad provides perfect secrecy, meaning that the ciphertext reveals no information about the plaintext, even when the attacker has unlimited computational power. However, achieving and maintaining these conditions in practice can be extremely challenging, which limits the practical use of the One-Time Pad cipher.
cipher.mono.onetimepad.facts=It was invented independently by Gilbert Vernam in 1917 and later rediscovered by Joseph Mauborgne and patented by both in 1919.
#Porta
cipher.mono.porta.name=Porta
cipher.mono.porta.description=The Porta cipher, also known as the Porta square or Portax cipher, is a variant of the Vigenere cipher and shares some similarities with it. \
In the Porta cipher, encryption and decryption are performed using a keyword and a tabula recta or Porta square. The Porta square is a table that consists of 26 rows and 26 columns, where each row represents the alphabet shifted by a certain number of positions. \
The Porta square is constructed by shifting the letters of the alphabet by an amount determined by the keyword. \
Each row of the square represents a different shift of the alphabet, with the first row being shifted by 0 positions, the second row by 1 position, the third row by 2 positions, and so on until the last row, which is shifted by 25 positions. \
The Porta cipher provides stronger encryption than simple substitution ciphers. However, it is still susceptible to frequency analysis and other cryptanalysis techniques.
cipher.mono.porta.facts=It was invented by Giovanni Battista della Porta in the 16th century.
#Substitution
cipher.mono.substitution.name=Substitution
cipher.mono.substitution.description=A substitution cipher is a method of encryption where each letter in the plaintext is replaced by another letter or symbol according to a predetermined set of rules. In other words, it substitutes each plaintext character with another character. \
Substitution ciphers are among the simplest forms of encryption and have been used throughout history for secret communication. \
However, they are generally less secure compared to modern encryption techniques and are vulnerable to various cryptanalysis methods, such as frequency analysis, which exploits patterns in the ciphertext to reveal information about the plaintext. \
Despite their vulnerabilities, substitution ciphers are often used in educational settings to introduce basic concepts of cryptography.
cipher.mono.substitution.facts=
#Vigenere
cipher.mono.vigenere.name=Vigenere
cipher.mono.vigenere.description=The Vigenere cipher adds more security compared to simple monoalphabetic substitution ciphers like the Caesar cipher. \
In the Vigenere cipher, encryption and decryption are performed using a keyword or keyphrase. The key is used to determine the shift applied to each letter in the plaintext, with different parts of the key determining different shifts. \
Decryption is performed by applying the reverse process. Given the ciphertext and the keyword, the original plaintext can be recovered. \ The Vigenere cipher provides stronger encryption compared to simple substitution ciphers because it uses multiple Caesar ciphers in a repeating pattern determined by the keyword. \
However, it is still vulnerable to frequency analysis and other cryptanalysis techniques, especially if the keyword is short or if there are patterns in the plaintext. \Despite its vulnerabilities, the Vigenere cipher was considered unbreakable for centuries and was widely used for secure communication.
cipher.mono.vigenere.facts=It was invented by Giovan Battista Bellaso in the 16th century and later misattributed to Blaise de Vigenere, hence the name.
#Poly-Substitution
#Bifid
cipher.poly.bifid.name=Bifid
cipher.poly.bifid.description=The Bifid cipher is a type of polyalphabetic substitution cipher that combines elements of both transposition and substitution. \
It was invented by Felix Delastelle in 1901 and was considered one of the strongest ciphers at the time due to its complexity. \
Encryption is done by creating a 5x5 grid, known as the Polybius square, is created. The letters of the alphabet (excluding 'J' in most cases) are arranged in the grid, typically starting with 'A' and ending with 'Z', omitting 'J'. \
Each letter of the plaintext is first converted into its corresponding row and column numbers in the grid. For example, the letter 'C' may correspond to the row 1, column 3. These numerical representations are then combined into pairs of numbers. \
The pairs of numbers are then arranged into a single line of digits. For example, if the plaintext is "HELLO", and the corresponding pairs of numbers are (1,3), (4,1), (2,4), (2,4), and (4,2), then the resulting line of digits would be "134142442". \
The resulting line of digits is then transposed using a keyword or keyphrase. This typically involves writing the digits into a grid of a certain width determined by the length of the keyword, and then reading the columns of the grid in the order specified by the keyword. \
The transposed digits are then converted back into pairs of row and column numbers, which correspond to the letters in the Polybius square. The resulting pairs of numbers are then used to retrieve the ciphertext letters from the grid. \
The Bifid cipher provides a higher level of security compared to simple substitution ciphers due to its combination of fractionation and transposition. However, it can still be susceptible to cryptanalysis, especially if the keyword is short or if there are patterns in the plaintext. \
Overall, the Bifid cipher is a historically significant encryption technique that demonstrates the use of both fractionation and transposition in cryptography.
cipher.poly.bifid.facts=
#Columnar
cipher.poly.columnar.name=Columnar
cipher.poly.columnar.description=The Columnar cipher, also known as the Columnar Transposition cipher, is a type of transposition cipher where the characters of the plaintext are rearranged according to a specific method based on the columns of a grid. \
Start by writing the plaintext message into a grid, row by row, with a fixed number of columns. The number of columns is determined by the key, which is a word or a sequence of letters chosen by the sender. \
Arrange the columns of the grid in alphabetical order based on the letters of the key. For example, if the key is "KEYWORD", arrange the columns of the grid in the order of the letters in "KEYWORD". \
Read the ciphertext from the grid by going column by column, starting with the column that corresponds to the first letter of the key, then the second letter of the key, and so on, until all columns have been read. \
The Columnar cipher is relatively simple to implement and understand, and it provides a moderate level of security against casual attempts to decrypt it. However, it is vulnerable to more sophisticated cryptanalysis methods, especially if the key is short or if there are patterns in the plaintext.
cipher.poly.columnar.facts=
#Hill
cipher.poly.hill.name=Hill
cipher.poly.hill.description=The Hill cipher is a type of polygraphic substitution cipher based on linear algebra and is one of the earliest known examples of a block cipher. The Hill cipher operates on blocks of plaintext letters and uses matrix multiplication to encrypt and decrypt messages. \
The encryption key in the Hill cipher is a square matrix called the encryption matrix. The size of the matrix (i.e., the number of rows and columns) depends on the key length and the block size of the plaintext. The determinant of the encryption matrix must be relatively prime to the size of the alphabet used (typically 26 for English text) to ensure that the encryption matrix is invertible. \
To encrypt a message, the plaintext is divided into blocks of letters, each block matching the size of the encryption matrix. Each block is then represented as a column vector, with each element of the vector representing the numerical value of a letter in the plaintext. The encryption matrix is multiplied by each column vector of plaintext letters modulo the size of the alphabet. The resulting matrix of encrypted numerical values is then converted back into ciphertext letters. \
Decryption is performed by multiplying the ciphertext column vectors by the inverse of the encryption matrix modulo the size of the alphabet. The resulting numerical values are converted back into plaintext letters. \
The Hill cipher offers a higher level of security compared to simple substitution ciphers because it operates on blocks of letters rather than individual letters, making it resistant to frequency analysis. However, it is vulnerable to known plaintext attacks if the attacker can obtain enough ciphertext and corresponding plaintext pairs to deduce the encryption matrix. \
One limitation of the Hill cipher is that it requires the plaintext to be divided into blocks of fixed length, which can result in padding if the plaintext length is not a multiple of the block size. Additionally, the size of the encryption matrix and the choice of plaintext block size can impact the complexity and security of the cipher.
cipher.poly.hill.facts=It was invented by Lester S. Hill in 1929.
#Morse
cipher.poly.morse.name=Morse Code
cipher.poly.morse.description=Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks. Morse code encodes characters (letters, numbers, and punctuation) as sequences of dots (short signals) and dashes (long signals) arranged in specific patterns. \
The basic elemens of Morse Code are dots and dashes. Each letter, number, or punctuation mark is represented by a unique combination of dots and dashes. Numbers and punctuation marks also have their own Morse code representations. \
Morse code has been widely used in various forms of communication, including telegraphy, radio communication, aviation, and navigation. Despite advances in technology, Morse code remains relevant today, particularly in emergency communication, amateur radio, and certain military applications. It is also used by some individuals for its simplicity and effectiveness in situations where other forms of communication may be unreliable or unavailable.
cipher.poly.morse.facts=It was developed in the early 19th century by Samuel Morse and Alfred Vail as a means of long-distance communication using telegraphy.
#Playfair
cipher.poly.playfair.name=Playfair
cipher.poly.playfair.description=The Playfair cipher is a type of digraph substitution cipher. It was used for secure communication in the early days of telegraphy. \
To encode start with a 5x5 grid, known as the Playfair square. The letters of the alphabet (usually excluding 'J', which is combined with 'I') are written into the grid in order, omitting any duplicates. Choose a keyword or keyphrase and use it to fill in the rest of the grid, omitting any duplicate letters. \
To encrypt a message, split the plaintext into pairs of letters (digraphs). If the pair consists of two identical letters, insert a filler letter (often 'X') between them. For each digraph, apply the following rules:\n\
If both letters are in the same row of the grid, replace each letter with the letter to its right (wrapping around to the beginning of the row if necessary).\n\
If both letters are in the same column, replace each letter with the letter below it (wrapping around to the top of the column if necessary).\n\
If the letters form a rectangle, replace them with the letters on the same row, but in the column of the other letter.\n\
To decrypt a message, the reverse of the encryption process is performed. Each digraph is replaced by the letters that are in the same row, column, or rectangle in the Playfair square. \
The Playfair cipher provides a higher level of security compared to simple substitution ciphers because it operates on pairs of letters rather than individual letters. However, it is still vulnerable to cryptanalysis, especially if the key is short or if there are patterns in the plaintext. \
Overall, the Playfair cipher is a historically significant encryption technique that demonstrates the use of digraph substitution in cryptography.
cipher.poly.playfair.facts=It was invented by Charles Wheatstone and popularized by Lyon Playfair in the 19th century.
#Polybius
cipher.poly.polybius.name=Polybius
cipher.poly.polybius.description=The Polybius Square cipher, also known as the Polybius checkerboard, is a method of encryption that replaces pairs of letters with coordinates from a grid. \
The cipher typically uses a 5x5 grid, with the letters of the alphabet (usually excluding 'J') arranged within it. Each letter is represented by its row and column coordinates in the grid. For example, if 'A' is in the first row and first column, it could be represented as "11", and if 'B' is in the first row and second column, it could be represented as "12". \
In this grid, each letter is represented by its row and column coordinates. For instance, 'A' is at coordinates (1,1), so it's encoded as "11", 'B' is at (1,2), so it's encoded as "12", and so on. \
To encrypt a message using the Polybius Square cipher, each letter is first located in the grid, and then its coordinates are noted down. These coordinates form the encrypted message. To decrypt the message, the process is reversed: each pair of coordinates is converted back into the corresponding letter from the grid. \
It's a relatively simple cipher, but it provides a method of encryption that can be implemented by hand without requiring complex mathematical operations. However, it's also relatively easy to break using frequency analysis or other cryptographic techniques.
cipher.poly.polybius.facts= It was named after the ancient Greek historian Polybius who first described it.
#Rail Fence
cipher.poly.railfence.name=Rail Fence
cipher.poly.railfence.description=The Rail Fence cipher is a transposition cipher that works by writing the plaintext in a zigzag pattern across a number of "rails" or "fences," and then reading off the ciphertext from the pattern formed by the rails. \
We first write the message in a zigzag pattern across 3 "rails." Then we read off the ciphertext by concatenating the characters from each rail. So, "HELLO WORLD" is encrypted to "HOLL ELWRLOL" using the Rail Fence cipher with 3 rails. \
To decrypt a Rail Fence ciphertext, the process is reversed. Write the ciphertext in a zigzag pattern across the rails. Read off the plaintext from the pattern formed by the rails. \
The Rail Fence cipher is relatively easy to implement and understand, but it's not very secure against modern cryptanalysis techniques. It's often used as a teaching tool rather than for serious encryption.
cipher.poly.railfence.facts=
#Trifid
cipher.poly.trifid.name=Trifid
cipher.poly.trifid.description=The trifid cipher is a polygraphic substitution cipher and is an extention of the Bifid cipher. \
To encode, a key matrix is generated, typically a permutation of the alphabet plus some additional symbols. Each letter of the plaintext is converted into its corresponding coordinates in the 3x3x3 grid. For example, if the letter is 'A', it could be represented as (1,1,1). \
The coordinates are then rearranged according to the key matrix and teh plaintext coordinate is (1,1,1), in might be rearranged to 2,3,1 based on the position of 'A' in the key matrix. The rearranged coordinates are converted back into letters. \
The process is reversed. The ciphertext is first converted into coordinates, rearranged back using the key matrix, and then converted back into plaintext. \
The Trifid cipher provides a higher degree of security compared to simpler ciphers like Caesar or Atbash, but it's still vulnerable to cryptanalysis, especially with modern computational methods. Despite its age, it remains an interesting historical cipher and is occasionally used in puzzles and cryptography challenges.
cipher.poly.trifid.facts=It was invented by Felix Delastelle in 1901.
#Combination
#ADFGVX
cipher.combination.adfgvx.name=ADFGVX
cipher.combination.adfgvx.description=The ADFGVX cipher is a fractionating transposition cipher and was named after the six letters used in the cipher. \
This cipher was notable for its use of a 6x6 grid to encode letters, making it more complex than many other ciphers of its time. \
To encode a 6x6 grid, usually called the Polybius square, is created. The rows and columns are labeled with the letters A, D, F, G, V, and X. \
Each letter of the plaintext is replaced with its corresponding pair of letters from the grid. For example, if the letter 'C' corresponds to 'FD', then 'C' is replaced with 'FD' in the ciphertext. \
The resulting fractionated ciphertext is then transposed using a keyword or keyphrase. The transposition can be done in various ways, such as columnar transposition. \
The final step is to arrange the transposed ciphertext into a single line to produce the encrypted message. \
The use of both fractionation and transposition makes the ADFGVX cipher more secure than simple substitution ciphers. The fractionation step increases the complexity of the cipher, making it resistant to frequency analysis, while the transposition step further scrambles the ciphertext. \
Overall, the ADFGVX cipher is a historically significant encryption technique that demonstrates the use of both fractionation and transposition in cryptography.
cipher.combination.adfgvx.facts=It was used by the German Army during World War 1. \
It was used extensively by the German Army during World War I for secure communication. However, it was eventually broken by French cryptanalysts, contributing to the Allies' efforts in the war.
#ADFGX
cipher.combination.adfgx.name=ADFGX
cipher.combination.adfgx.description=The ADFGX cipher is a variant of the ADFGVX cipher. Both the ADFGX and ADFGVX ciphers are similar in structure and operation, but the ADFGX cipher uses a 5x5 grid instead of a 6x6 grid. \
A 5x5 grid, usually called the Polybius square, is created. The rows and columns are labeled with the letters A, D, F, G, and X. \
Each letter of the plaintext is replaced with its corresponding pair of letters from the grid. For example, if the letter 'C' corresponds to 'DG', then 'C' is replaced with 'DG' in the ciphertext. \
The resulting fractionated ciphertext is then encrypted using a keyword or keyphrase, similar to the ADFGVX cipher. This typically involves a transposition step, such as columnar transposition, to rearrange the letters of the fractionated ciphertext. \
The transposed ciphertext is then arranged into a single line to produce the final encrypted message. \
Like the ADFGVX cipher, the ADFGX cipher combines both fractionation and transposition to enhance security. The fractionation step increases the complexity of the cipher, making it resistant to frequency analysis, while the transposition step further scrambles the ciphertext. \
Overall, the ADFGX cipher is a historically significant encryption technique that demonstrates the use of both fractionation and transposition in cryptography.
cipher.combination.adfgx.facts=It was used by the German Army during World War 1. \
It was used extensively by the German Army during World War I for secure communication. However, it was eventually broken by French cryptanalysts, contributing to the Allies' efforts in the war.

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,16 +28,20 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private AdfgvxCipherController adfgvxCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController")
private Logger adfgvxLogger; private Logger adfgvxLogger;
//Fields //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(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/adfgvx";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
private static final String keyword = "keyword";
private static final String squareKeyword = "SquareKeyword";
private static final String adfgvxName = "adfgvxName";
private static final String adfgvxDescription = "adfgvxDescription";
@BeforeEach @BeforeEach
@@ -58,26 +63,29 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword); encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", adfgvxName);
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", adfgvxDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGVX_CIPHER_NAME, CipherInfoUtil.ADFGVX_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(adfgvxName, adfgvxDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ADFGVX_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(adfgvxName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.ADFGVX_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(adfgvxDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(adfgvxLogger, times(1)).info("Getting info for {}", CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(adfgvxLogger, times(1)).info("Getting info for {}", adfgvxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -96,8 +104,8 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(adfgvxLogger, times(1)).info("Encoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(adfgvxLogger, times(1)).info("Encoding {}", adfgvxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -116,8 +124,8 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(adfgvxLogger, times(1)).info("Encoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(adfgvxLogger, times(1)).info("Encoding {}", adfgvxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -136,8 +144,8 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(adfgvxLogger, times(1)).info("Decoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(adfgvxLogger, times(1)).info("Decoding {}", adfgvxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -156,8 +164,8 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(adfgvxLogger, times(1)).info("Decoding {}", CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(adfgvxLogger, times(1)).info("Decoding {}", adfgvxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGVX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.combination;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,16 +25,24 @@ public class AdfgvxCipherControllerTest{
private AdfgvxCipherController adfgvxCipherController; private AdfgvxCipherController adfgvxCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String KEYWORD = CipherParameterUtil.KEYWORD; private static final String KEYWORD = CipherParameterUtil.KEYWORD;
private static final String SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD; private static final String SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
private static final String INPUT_STRING = "Message to-encode"; private static final String INPUT_STRING = "Message to-encode";
private static final String OUTPUT_STRING = "AXgvdavfxgagfa afag-aaxdxfgdagda"; private static final String OUTPUT_STRING = "AXgvdavfxgagfa afag-aaxdxfgdagda";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String adfgvxName = "adfgvxName";
private static final String adfgvxDescription = "adfgvxDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", adfgvxName);
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", adfgvxDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGVX_CIPHER_NAME, CipherInfoUtil.ADFGVX_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(adfgvxName, adfgvxDescription);
ObjectNode returnedJson = adfgvxCipherController.getCipherInfo(); ObjectNode returnedJson = adfgvxCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,16 +28,20 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class AdfgxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class AdfgxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private AdfgxCipherController adfgxCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController")
private Logger adfgxLogger; private Logger adfgxLogger;
//Fields //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(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/adfgx";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "AAgagadfagaxxd axdx^adafafxddgdf";
private static final String keyword = "keyword";
private static final String squareKeyword = "SquareKeyword";
private static final String adfgxName = "adfgxName";
private static final String adfgxDescription = "adfgxDescription";
@BeforeEach @BeforeEach
@@ -58,26 +63,29 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword); encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", adfgxName);
ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", adfgxDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGX_CIPHER_NAME, CipherInfoUtil.ADFGX_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(adfgxName, adfgxDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ADFGX_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(adfgxName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.ADFGX_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(adfgxDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(adfgxLogger, times(1)).info("Getting info for {}", CipherInfoUtil.ADFGX_CIPHER_NAME); verify(adfgxLogger, times(1)).info("Getting info for {}", adfgxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -96,8 +104,8 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(adfgxLogger, times(1)).info("Encoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME); verify(adfgxLogger, times(1)).info("Encoding {}", adfgxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -116,8 +124,8 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(adfgxLogger, times(1)).info("Encoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME); verify(adfgxLogger, times(1)).info("Encoding {}", adfgxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -136,8 +144,8 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(adfgxLogger, times(1)).info("Decoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME); verify(adfgxLogger, times(1)).info("Decoding {}", adfgxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -156,8 +164,8 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(adfgxLogger, times(1)).info("Decoding {}", CipherInfoUtil.ADFGX_CIPHER_NAME); verify(adfgxLogger, times(1)).info("Decoding {}", adfgxName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ADFGX_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.combination;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,16 +25,24 @@ public class AdfgxCipherControllerTest{
private AdfgxCipherController adfgxCipherController; private AdfgxCipherController adfgxCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String ADFGX_KEYWORD = CipherParameterUtil.KEYWORD; private static final String ADFGX_KEYWORD = CipherParameterUtil.KEYWORD;
private static final String ADFGX_SQUARE_KEYWORD = CipherParameterUtil.SQUARE_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_INPUT_STRING = "Message to^encode";
private static final String ADFGX_OUTPUT_STRING = "AAgagadfagaxxd axdx^adafafxddgdf"; private static final String ADFGX_OUTPUT_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String adfgxName = "adfgxName";
private static final String adfgxDescription = "adfgxDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", adfgxName);
ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", adfgxDescription);
}
@Test @Test
public void testGetCipherInfo(){ public void testGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ADFGX_CIPHER_NAME, CipherInfoUtil.ADFGX_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(adfgxName, adfgxDescription);
ObjectNode returnedJson = adfgxCipherController.getCipherInfo(); ObjectNode returnedJson = adfgxCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class AffineCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class AffineCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private AffineCipherController affineCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController")
private Logger affineLogger; private Logger affineLogger;
//Fields //Fields
private String url = "/affine"; private static final String url = "/affine";
private String decodedString = "Message to^encode"; private static final String decodedString = "Message to^encode";
private String encodedString = "Pbtthlb yz^burzwb"; private static final String encodedString = "Pbtthlb yz^burzwb";
private int key1 = 5; private static final int key1 = 5;
private int key2 = 7; private static final int key2 = 7;
private static final String affineName = "affineCipherName";
private static final String affineDescription = "affineCipherDescription";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
@@ -58,26 +63,29 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
encodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2); encodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(affineCipherController, "affineName", affineName);
ReflectionTestUtils.setField(affineCipherController, "affineDescription", affineDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AFFINE_CIPHER_NAME, CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(affineName, affineDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(affineDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.AFFINE_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(affineName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(affineLogger, times(1)).info("Getting info for {}", CipherInfoUtil.AFFINE_CIPHER_NAME); verify(affineLogger, times(1)).info("Getting info for {}", affineName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -96,8 +104,8 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(affineLogger, times(1)).info("Encoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME); verify(affineLogger, times(1)).info("Encoding {}", affineName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -116,8 +124,8 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(affineLogger, times(1)).info("Encoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME); verify(affineLogger, times(1)).info("Encoding {}", affineName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -136,8 +144,8 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(affineLogger, times(1)).info("Decoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME); verify(affineLogger, times(1)).info("Decoding {}", affineName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -156,8 +164,8 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(affineLogger, times(1)).info("Decoding {}", CipherInfoUtil.AFFINE_CIPHER_NAME); verify(affineLogger, times(1)).info("Decoding {}", affineName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AFFINE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -28,11 +30,19 @@ public class AffineCipherControllerTest{
private static final int AFFINE_KEY_1 = 5; private static final int AFFINE_KEY_1 = 5;
private static final int AFFINE_KEY_2 = 7; private static final int AFFINE_KEY_2 = 7;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String affineName = "affineCipherName";
private static final String affineDescription = "affineCipherDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(affineCipherController, "affineName", affineName);
ReflectionTestUtils.setField(affineCipherController, "affineDescription", affineDescription);
}
@Test @Test
public void testGetCipherInfo(){ public void testGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AFFINE_CIPHER_NAME, CipherInfoUtil.AFFINE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(affineName, affineDescription);
ObjectNode returnedJson = affineCipherController.getCipherInfo(); ObjectNode returnedJson = affineCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,14 +28,18 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class AtbashCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class AtbashCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private AtbashCipherController atbashController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController")
protected Logger atbashLogger; protected Logger atbashLogger;
//Fields //Fields
private String url = "/atbash";
private String decodedString = "Message to^encode";
private String encodedString = "Nvhhztv gl^vmxlwv";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/atbash";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Nvhhztv gl^vmxlwv";
private static final String atbashName = "atbashName";
private static final String atbashDescription = "atbashDescription";
@BeforeEach @BeforeEach
@@ -52,26 +57,29 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true); encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(atbashController, "atbashName", atbashName);
ReflectionTestUtils.setField(atbashController, "atbashDescription", atbashDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ATBASH_CIPHER_NAME, CipherInfoUtil.ATBASH_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(atbashName, atbashDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.ATBASH_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(atbashDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ATBASH_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(atbashName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(atbashLogger, times(1)).info("Getting info for {}", CipherInfoUtil.ATBASH_CIPHER_NAME); verify(atbashLogger, times(1)).info("Getting info for {}", atbashName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -90,8 +98,8 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(atbashLogger, times(1)).info("Encoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME); verify(atbashLogger, times(1)).info("Encoding {}", atbashName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -110,8 +118,8 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(atbashLogger, times(1)).info("Encoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME); verify(atbashLogger, times(1)).info("Encoding {}", atbashName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -130,8 +138,8 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(atbashLogger, times(1)).info("Decoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME); verify(atbashLogger, times(1)).info("Decoding {}", atbashName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -150,8 +158,8 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(atbashLogger, times(1)).info("Decoding {}", CipherInfoUtil.ATBASH_CIPHER_NAME); verify(atbashLogger, times(1)).info("Decoding {}", atbashName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ATBASH_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -22,11 +24,19 @@ public class AtbashCipherControllerTest{
private AtbashCipherController atbashCipherController; private AtbashCipherController atbashCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String ATBASH_INPUT_STRING = "Message to^encode"; private static final String ATBASH_INPUT_STRING = "Message to^encode";
private static final String ATBASH_OUTPUT_STRING = "Nvhhztv gl^vmxlwv"; private static final String ATBASH_OUTPUT_STRING = "Nvhhztv gl^vmxlwv";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String atbashName = "atbashName";
private static final String atbashDescription = "atbashDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(atbashCipherController, "atbashName", atbashName);
ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", atbashDescription);
}
@Test @Test
public void testEncodeAtbash(){ public void testEncodeAtbash(){
ObjectNode cipherParams = generateParams(ATBASH_INPUT_STRING); ObjectNode cipherParams = generateParams(ATBASH_INPUT_STRING);

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class AutokeyCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private AutokeyCipherController autokeyCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController")
protected Logger autokeyLogger; protected Logger autokeyLogger;
//Fields //Fields
private String url = "/autokey";
private String decodedString = "Message to^encode";
private String encodedString = "Wiqooxh fs^wfcuhx";
private String keyword = "keyword";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/autokey";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Wiqooxh fs^wfcuhx";
private static final String keyword = "keyword";
private static final String autokeyName = "autokeyName";
private static final String autokeyDescription = "autokeyDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", autokeyName);
ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", autokeyDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AUTOKEY_CIPHER_NAME, CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(autokeyName, autokeyDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(autokeyDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.AUTOKEY_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(autokeyName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(autokeyLogger, times(1)).info("Getting info for {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(autokeyLogger, times(1)).info("Getting info for {}", autokeyName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(autokeyLogger, times(1)).info("Encoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(autokeyLogger, times(1)).info("Encoding {}", autokeyName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(autokeyLogger, times(1)).info("Encoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(autokeyLogger, times(1)).info("Encoding {}", autokeyName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(autokeyLogger, times(1)).info("Decoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(autokeyLogger, times(1)).info("Decoding {}", autokeyName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(autokeyLogger, times(1)).info("Decoding {}", CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(autokeyLogger, times(1)).info("Decoding {}", autokeyName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.AUTOKEY_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,23 @@ public class AutokeyCipherControllerTest{
private AutokeyCipherController autokeyCipherController; private AutokeyCipherController autokeyCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String AUTOKEY_INPUT_STRING = "Message to^encode"; 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_OUTPUT_STRING = "Wiqooxh fs^wfcuhx";
private static final String AUTOKEY_KEYWORD = CipherParameterUtil.KEYWORD; private static final String AUTOKEY_KEYWORD = CipherParameterUtil.KEYWORD;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String autokeyName = "autokeyName";
private static final String autokeyDescription = "autokeyDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", autokeyName);
ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", autokeyDescription);
}
@Test @Test
public void testGetCipherInfo(){ public void testGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.AUTOKEY_CIPHER_NAME, CipherInfoUtil.AUTOKEY_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(autokeyName, autokeyDescription);
ObjectNode returnedJson = autokeyCipherController.getCipherInfo(); ObjectNode returnedJson = autokeyCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,14 +28,18 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class BaconianCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class BaconianCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private BaconianCipherController baconianCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController")
protected Logger baconianLogger; protected Logger baconianLogger;
//Fields //Fields
private String url = "/baconian"; private static final String url = "/baconian";
private String decodedString = "Message to^encode"; private static final 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 String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String baconianName = "baconianName";
private static final String baconianDescription = "baconianDescription";
@BeforeEach @BeforeEach
@@ -52,26 +57,29 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true); encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.replaceAll("[^a-zA-Z]", "")); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.replaceAll("[^a-zA-Z]", ""));
ReflectionTestUtils.setField(baconianCipherController, "baconianName", baconianName);
ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", baconianDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BACONIAN_CIPHER_NAME, CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baconianName, baconianDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(baconianDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BACONIAN_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(baconianName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(baconianLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(baconianLogger, times(1)).info("Getting info for {}", baconianName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -90,8 +98,8 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(baconianLogger, times(1)).info("Encoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(baconianLogger, times(1)).info("Encoding {}", baconianName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -110,8 +118,8 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(baconianLogger, times(1)).info("Encoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(baconianLogger, times(1)).info("Encoding {}", baconianName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -130,8 +138,8 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(baconianLogger, times(1)).info("Decoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(baconianLogger, times(1)).info("Decoding {}", baconianName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -150,8 +158,8 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(baconianLogger, times(1)).info("Decoding {}", CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(baconianLogger, times(1)).info("Decoding {}", baconianName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BACONIAN_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,11 +29,20 @@ public class BaconianCipherControllerTest{
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_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 static final String BACONIAN_DECODED_STRING = "Messagetoencode";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String baconianName = "baconianName";
private static final String baconianDescription = "baconianDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(baconianCipherController, "baconianName", baconianName);
ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", baconianDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BACONIAN_CIPHER_NAME, CipherInfoUtil.BACONIAN_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baconianName, baconianDescription);
ObjectNode returnedJson = baconianCipherController.getCipherInfo(); ObjectNode returnedJson = baconianCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class BaseXCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class BaseXCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private BaseXCipherController baseXCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController")
protected Logger baseXLogger; protected Logger baseXLogger;
//Fields //Fields
private String url = "/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(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/basex";
private static final String decodedString = "A+B@C d\te\nf";
private static final String encodedString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
private static final int base = 2;
private static final String baseXName = "baseXName";
private static final String baseXDescription = "baseXDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
encodedNode.put(CipherParameterUtil.BASE_X_BASE, base); encodedNode.put(CipherParameterUtil.BASE_X_BASE, base);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(baseXCipherController, "baseXName", baseXName);
ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", baseXDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BASE_X_CIPHER_NAME, CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baseXName, baseXDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(baseXDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BASE_X_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(baseXName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(baseXLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BASE_X_CIPHER_NAME); verify(baseXLogger, times(1)).info("Getting info for {}", baseXName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(baseXLogger, times(1)).info("Encoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME); verify(baseXLogger, times(1)).info("Encoding {}", baseXName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(baseXLogger, times(1)).info("Encoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME); verify(baseXLogger, times(1)).info("Encoding {}", baseXName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(baseXLogger, times(1)).info("Decoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME); verify(baseXLogger, times(1)).info("Decoding {}", baseXName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(baseXLogger, times(1)).info("Decoding {}", CipherInfoUtil.BASE_X_CIPHER_NAME); verify(baseXLogger, times(1)).info("Decoding {}", baseXName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BASE_X_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,23 @@ public class BaseXCipherControllerTest{
private BaseXCipherController baseXCipherController; private BaseXCipherController baseXCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final int BASE_X_BASE = 2; 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_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 static final String BASE_X_OUTPUT_STRING = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String baseXName = "baseXName";
private static final String baseXDescription = "baseXDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(baseXCipherController, "baseXName", baseXName);
ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", baseXDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BASE_X_CIPHER_NAME, CipherInfoUtil.BASE_X_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baseXName, baseXDescription);
ObjectNode returnedJson = baseXCipherController.getCipherInfo(); ObjectNode returnedJson = baseXCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class BeaufortCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private BeaufortCipherController beaufortCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController")
protected Logger beaufortLogger; protected Logger beaufortLogger;
//Fields //Fields
private String url = "/beaufort"; private static final String url = "/beaufort";
private String decodedString = "Message to^encode"; private static final String decodedString = "Message to^encode";
private String encodedString = "Yageolz rq^ujmdag"; private static final String encodedString = "Yageolz rq^ujmdag";
private String keyword = "Ke*y word"; private static final String keyword = "Ke*y word";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String beaufortName = "beaufortName";
private static final String beaufortDescription = "beaufortDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", beaufortName);
ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", beaufortDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BEAUFORT_CIPHER_NAME, CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(beaufortName, beaufortDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(beaufortDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BEAUFORT_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(beaufortName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(beaufortLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(beaufortLogger, times(1)).info("Getting info for {}", beaufortName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(beaufortLogger, times(1)).info("Encoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(beaufortLogger, times(1)).info("Encoding {}", beaufortName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(beaufortLogger, times(1)).info("Encoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(beaufortLogger, times(1)).info("Encoding {}", beaufortName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(beaufortLogger, times(1)).info("Decoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(beaufortLogger, times(1)).info("Decoding {}", beaufortName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(beaufortLogger, times(1)).info("Decoding {}", CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(beaufortLogger, times(1)).info("Decoding {}", beaufortName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BEAUFORT_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,11 +29,19 @@ public class BeaufortCipherControllerTest{
private static final String BEAUFORT_INPUT_STRING = "Message to^encode"; private static final String BEAUFORT_INPUT_STRING = "Message to^encode";
private static final String BEAUFORT_OUTPUT_STRING = "Yageolz rq^ujmdag"; private static final String BEAUFORT_OUTPUT_STRING = "Yageolz rq^ujmdag";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String beaufortName = "beaufortName";
private static final String beaufortDescription = "beaufortDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", beaufortName);
ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", beaufortDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BEAUFORT_CIPHER_NAME, CipherInfoUtil.BEAUFORT_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(beaufortName, beaufortDescription);
ObjectNode returnedJson = beaufortCipherController.getCipherInfo(); ObjectNode returnedJson = beaufortCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class CaesarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class CaesarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private CaesarCipherController caesarCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController")
protected Logger caesarLogger; protected Logger caesarLogger;
//Fields //Fields
private String url = "/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(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/caesar";
private static final String decodedString = "The quick brown fox jumps over - the lazy dog";
private static final String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
private static final int shiftAmount = 23;
private static final String caesarName = "caesarName";
private static final String caesarDescription = "caesarDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
encodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount); encodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(caesarCipherController, "caesarName", caesarName);
ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", caesarDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.CAESAR_CIPHER_NAME, CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(caesarName, caesarDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(caesarDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.CAESAR_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(caesarName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(caesarLogger, times(1)).info("Getting info for {}", CipherInfoUtil.CAESAR_CIPHER_NAME); verify(caesarLogger, times(1)).info("Getting info for {}", caesarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(caesarLogger, times(1)).info("Encoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME); verify(caesarLogger, times(1)).info("Encoding {}", caesarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(caesarLogger, times(1)).info("Encoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME); verify(caesarLogger, times(1)).info("Encoding {}", caesarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(caesarLogger, times(1)).info("Decoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME); verify(caesarLogger, times(1)).info("Decoding {}", caesarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(caesarLogger, times(1)).info("Decoding {}", CipherInfoUtil.CAESAR_CIPHER_NAME); verify(caesarLogger, times(1)).info("Decoding {}", caesarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.CAESAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,11 +29,19 @@ public class CaesarCipherControllerTest{
private static final String CAESAR_OUTPUT_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald"; 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 static final int CAESAR_SHIFT_AMOUNT = 23;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String caesarName = "caesarName";
private static final String caesarDescription = "caesarDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(caesarCipherController, "caesarName", caesarName);
ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", caesarDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.CAESAR_CIPHER_NAME, CipherInfoUtil.CAESAR_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(caesarName, caesarDescription);
ObjectNode returnedJson = caesarCipherController.getCipherInfo(); ObjectNode returnedJson = caesarCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class OneTimePadCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private OneTimePadCipherController oneTimePadCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController")
protected Logger oneTimePadLogger; protected Logger oneTimePadLogger;
//Fields //Fields
private String url = "/oneTimePad";
private String decodedString = "Message to^encode";
private String encodedString = "Wiqooxh mv^egkgws";
private String keyword = "keywordThatIsTotallyRandom";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/oneTimePad";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Wiqooxh mv^egkgws";
private static final String keyword = "keywordThatIsTotallyRandom";
private static final String oneTimePadName = "oneTimePadName";
private static final String oneTimePadDescription = "oneTimePadDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", oneTimePadName);
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", oneTimePadDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME, CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(oneTimePadName, oneTimePadDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(oneTimePadDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(oneTimePadName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(oneTimePadLogger, times(1)).info("Getting info for {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(oneTimePadLogger, times(1)).info("Getting info for {}", oneTimePadName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(oneTimePadLogger, times(1)).info("Encoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(oneTimePadLogger, times(1)).info("Encoding {}", oneTimePadName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(oneTimePadLogger, times(1)).info("Encoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(oneTimePadLogger, times(1)).info("Encoding {}", oneTimePadName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(oneTimePadLogger, times(1)).info("Decoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(oneTimePadLogger, times(1)).info("Decoding {}", oneTimePadName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(oneTimePadLogger, times(1)).info("Decoding {}", CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(oneTimePadLogger, times(1)).info("Decoding {}", oneTimePadName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,23 @@ public class OneTimePadCipherControllerTest{
private OneTimePadCipherController oneTimePadCipherController; private OneTimePadCipherController oneTimePadCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String ONE_TIME_PAD_KEYWORD = "keywordThatIsTotallyRandom"; 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_INPUT_STRING = "Message to^encode";
private static final String ONE_TIME_PAD_OUTPUT_STRING = "Wiqooxh mv^egkgws"; private static final String ONE_TIME_PAD_OUTPUT_STRING = "Wiqooxh mv^egkgws";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String oneTimePadName = "oneTimePadName";
private static final String oneTimePadDescription = "oneTimePadDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", oneTimePadName);
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", oneTimePadDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.ONE_TIME_PAD_CIPHER_NAME, CipherInfoUtil.ONE_TIME_PAD_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(oneTimePadName, oneTimePadDescription);
ObjectNode returnedJson = oneTimePadCipherController.getCipherInfo(); ObjectNode returnedJson = oneTimePadCipherController.getCipherInfo();

View File

@@ -14,6 +14,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -28,15 +29,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class PortaCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class PortaCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private PortaCipherController portaCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController")
protected Logger portaLogger; protected Logger portaLogger;
//Fields //Fields
private String url = "/porta";
private String decodedString = "Message to^encode";
private String encodedString = "Rtghuos bm^qcwgrw";
private String keyword = "keyword";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/porta";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Rtghuos bm^qcwgrw";
private static final String keyword = "keyword";
private static final String portaName = "portaName";
private static final String portaDescription = "portaDescription";
@BeforeEach @BeforeEach
@@ -56,26 +61,29 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(portaCipherController, "portaName", portaName);
ReflectionTestUtils.setField(portaCipherController, "portaDescription", portaDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PORTA_CIPHER_NAME, CipherInfoUtil.PORTA_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(portaName, portaDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.PORTA_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(portaDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.PORTA_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(portaName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(portaLogger, times(1)).info("Getting info for {}", CipherInfoUtil.PORTA_CIPHER_NAME); verify(portaLogger, times(1)).info("Getting info for {}", portaName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -98,8 +106,8 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
verify(mdc, times(1)).put("url", url + "/encode"); verify(mdc, times(1)).put("url", url + "/encode");
verify(mdc, times(1)).clear(); verify(mdc, times(1)).clear();
//Controller //Controller
verify(portaLogger, times(1)).info("Encoding {}", CipherInfoUtil.PORTA_CIPHER_NAME); verify(portaLogger, times(1)).info("Encoding {}", portaName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -118,8 +126,8 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(portaLogger, times(1)).info("Encoding {}", CipherInfoUtil.PORTA_CIPHER_NAME); verify(portaLogger, times(1)).info("Encoding {}", portaName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -142,8 +150,8 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
verify(mdc, times(1)).put("url", url + "/decode"); verify(mdc, times(1)).put("url", url + "/decode");
verify(mdc, times(1)).clear(); verify(mdc, times(1)).clear();
//Controller //Controller
verify(portaLogger, times(1)).info("Decoding {}", CipherInfoUtil.PORTA_CIPHER_NAME); verify(portaLogger, times(1)).info("Decoding {}", portaName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -162,8 +170,8 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(portaLogger, times(1)).info("Decoding {}", CipherInfoUtil.PORTA_CIPHER_NAME); verify(portaLogger, times(1)).info("Decoding {}", portaName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PORTA_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,23 @@ public class PortaCipherControllerTest{
private PortaCipherController portaCipherController; private PortaCipherController portaCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String PORTA_KEYWORD = CipherParameterUtil.KEYWORD; private static final String PORTA_KEYWORD = CipherParameterUtil.KEYWORD;
private static final String PORTA_INPUT_STRING = "Message to^encode"; private static final String PORTA_INPUT_STRING = "Message to^encode";
private static final String PORTA_OUTPUT_STRING = "Rtghuos bm^qcwgrw"; private static final String PORTA_OUTPUT_STRING = "Rtghuos bm^qcwgrw";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String portaName = "portaName";
private static final String portaDescription = "portaDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(portaCipherController, "portaName", portaName);
ReflectionTestUtils.setField(portaCipherController, "portaDescription", portaDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PORTA_CIPHER_NAME, CipherInfoUtil.PORTA_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(portaName, portaDescription);
ObjectNode returnedJson = portaCipherController.getCipherInfo(); ObjectNode returnedJson = portaCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class SubstitutionCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private SubstitutionCipherController substitutionCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController")
protected Logger substitutionLogger; protected Logger substitutionLogger;
//Fields //Fields
private String url = "/substitution";
private String decodedString = "Message to^encode";
private String encodedString = "Oguucig vq^gpeqfg";
private String keyword = "cdefghijklmnopqrstuvwxyzab";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/substitution";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Oguucig vq^gpeqfg";
private static final String keyword = "cdefghijklmnopqrstuvwxyzab";
private static final String substitutionName = "substitutionName";
private static final String substitutionDescription = "substitutionDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", substitutionName);
ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", substitutionDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.SUBSTITUTION_CIPHER_NAME, CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(substitutionName, substitutionDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(substitutionDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.SUBSTITUTION_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(substitutionName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(substitutionLogger, times(1)).info("Getting info for {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(substitutionLogger, times(1)).info("Getting info for {}", substitutionName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(substitutionLogger, times(1)).info("Encoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(substitutionLogger, times(1)).info("Encoding {}", substitutionName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(substitutionLogger, times(1)).info("Encoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(substitutionLogger, times(1)).info("Encoding {}", substitutionName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(substitutionLogger, times(1)).info("Decoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(substitutionLogger, times(1)).info("Decoding {}", substitutionName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(substitutionLogger, times(1)).info("Decoding {}", CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(substitutionLogger, times(1)).info("Decoding {}", substitutionName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.SUBSTITUTION_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,23 @@ public class SubstitutionCipherControllerTest{
private SubstitutionCipherController substitutionCipherController; private SubstitutionCipherController substitutionCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String SUBSTITUTION_KEYWORD = "cdefghijklmnopqrstuvwxyzab9876543210"; private static final String SUBSTITUTION_KEYWORD = "cdefghijklmnopqrstuvwxyzab9876543210";
private static final String SUBSTITUTION_INPUT_STRING = "Message to&encode 123"; private static final String SUBSTITUTION_INPUT_STRING = "Message to&encode 123";
private static final String SUBSTITUTION_OUTPUT_STRING = "Oguucig vq&gpeqfg 876"; private static final String SUBSTITUTION_OUTPUT_STRING = "Oguucig vq&gpeqfg 876";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String substitutionName = "substitutionName";
private static final String substitutionDescription = "substitutionDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", substitutionName);
ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", substitutionDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.SUBSTITUTION_CIPHER_NAME, CipherInfoUtil.SUBSTITUTION_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(substitutionName, substitutionDescription);
ObjectNode returnedJson = substitutionCipherController.getCipherInfo(); ObjectNode returnedJson = substitutionCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class VigenereCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class VigenereCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private VigenereCipherController vigenereCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController")
protected Logger vigenereLogger; protected Logger vigenereLogger;
//Fields //Fields
private String url = "/vigenere";
private String decodedString = "Message to^encode";
private String encodedString = "Wiqooxh ds^cjqfgo";
private String keyword = "keyword";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/vigenere";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Wiqooxh ds^cjqfgo";
private static final String keyword = "keyword";
private static final String vigenereName = "vigenereName";
private static final String vigenereDescription = "vigenereDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", vigenereName);
ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", vigenereDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.VIGENERE_CIPHER_NAME, CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(vigenereName, vigenereDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(vigenereDescription))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.VIGENERE_CIPHER_NAME)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(vigenereName));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(vigenereLogger, times(1)).info("Getting info for {}", CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(vigenereLogger, times(1)).info("Getting info for {}", vigenereName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(vigenereLogger, times(1)).info("Encoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(vigenereLogger, times(1)).info("Encoding {}", vigenereName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(vigenereLogger, times(1)).info("Encoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(vigenereLogger, times(1)).info("Encoding {}", vigenereName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(vigenereLogger, times(1)).info("Decoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(vigenereLogger, times(1)).info("Decoding {}", vigenereName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(vigenereLogger, times(1)).info("Decoding {}", CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(vigenereLogger, times(1)).info("Decoding {}", vigenereName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.VIGENERE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,23 @@ public class VigenereCipherControllerTest{
private VigenereCipherController vigenereCipherController; private VigenereCipherController vigenereCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String VIGENERE_KEYWORD = CipherParameterUtil.KEYWORD; private static final String VIGENERE_KEYWORD = CipherParameterUtil.KEYWORD;
private static final String VIGENERE_INPUT_STRING = "Message to^encode"; private static final String VIGENERE_INPUT_STRING = "Message to^encode";
private static final String VIGENERE_OUTPUT_STRING = "Wiqooxh ds^cjqfgo"; private static final String VIGENERE_OUTPUT_STRING = "Wiqooxh ds^cjqfgo";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String vigenereName = "vigenereName";
private static final String vigenereDescription = "vigenereDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", vigenereName);
ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", vigenereDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.VIGENERE_CIPHER_NAME, CipherInfoUtil.VIGENERE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(vigenereName, vigenereDescription);
ObjectNode returnedJson = vigenereCipherController.getCipherInfo(); ObjectNode returnedJson = vigenereCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class BifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class BifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private BifidCipherController bifidCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController")
protected Logger bifidLogger; protected Logger bifidLogger;
//Fields //Fields
private String url = "/bifid";
private String decodedString = "Message to^encode";
private String encodedString = "Mqaokne kc^vdodzd";
private String keyword = "keyword";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/bifid";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Mqaokne kc^vdodzd";
private static final String keyword = "keyword";
private static final String bifidName = "bifidName";
private static final String bifidDescription = "bifidDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(bifidCipherController, "bifidName", bifidName);
ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", bifidDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BIFID_CIPHER_NAME, CipherInfoUtil.BIFID_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(bifidName, bifidDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BIFID_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(bifidName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BIFID_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(bifidDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(bifidLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BIFID_CIPHER_NAME); verify(bifidLogger, times(1)).info("Getting info for {}", bifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(bifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.BIFID_CIPHER_NAME); verify(bifidLogger, times(1)).info("Encoding {}", bifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(bifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.BIFID_CIPHER_NAME); verify(bifidLogger, times(1)).info("Encoding {}", bifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(bifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.BIFID_CIPHER_NAME); verify(bifidLogger, times(1)).info("Decoding {}", bifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(bifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.BIFID_CIPHER_NAME); verify(bifidLogger, times(1)).info("Decoding {}", bifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.BIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,23 @@ public class BifidCipherControllerTest{
private BifidCipherController bifidCipherController; private BifidCipherController bifidCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String BIFID_INPUT_STRING = "Message to^encode"; 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_OUTPUT_STRING = "Mqaokne kc^vdodzd";
private static final String BIFID_KEYWORD = CipherParameterUtil.KEYWORD; private static final String BIFID_KEYWORD = CipherParameterUtil.KEYWORD;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String bifidName = "bifidName";
private static final String bifidDescription = "bifidDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(bifidCipherController, "bifidName", bifidName);
ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", bifidDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BIFID_CIPHER_NAME, CipherInfoUtil.BIFID_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(bifidName, bifidDescription);
ObjectNode returnedJson = bifidCipherController.getCipherInfo(); ObjectNode returnedJson = bifidCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class ColumnarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private ColumnarCipherController columnarCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController")
protected Logger columnarLogger; protected Logger columnarLogger;
//Fields //Fields
private String url = "/columnar";
private String decodedString = "Message to^encode";
private String encodedString = "Edeomte ac^gosnse";
private String keyword = "keyword";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/columnar";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Edeomte ac^gosnse";
private static final String keyword = "keyword";
private static final String columnarName = "columnarName";
private static final String columnarDescription = "columnarDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(columnarCipherController, "columnarName", columnarName);
ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", columnarDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.COLUMNAR_CIPHER_NAME, CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(columnarName, columnarDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.COLUMNAR_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(columnarName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(columnarDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(columnarLogger, times(1)).info("Getting info for {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(columnarLogger, times(1)).info("Getting info for {}", columnarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(columnarLogger, times(1)).info("Encoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(columnarLogger, times(1)).info("Encoding {}", columnarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(columnarLogger, times(1)).info("Encoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(columnarLogger, times(1)).info("Encoding {}", columnarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(columnarLogger, times(1)).info("Decoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(columnarLogger, times(1)).info("Decoding {}", columnarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(columnarLogger, times(1)).info("Decoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(columnarLogger, times(1)).info("Decoding {}", columnarName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.COLUMNAR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,24 @@ public class ColumnarCipherControllerTest{
private ColumnarCipherController columnarCipherController; private ColumnarCipherController columnarCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String COLUMNAR_INPUT_STRING = "Message to*encode"; 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_OUTPUT_STRING = "Edeomte ac*gosnse";
private static final String COLUMNAR_KEYWORD = CipherParameterUtil.KEYWORD; private static final String COLUMNAR_KEYWORD = CipherParameterUtil.KEYWORD;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String columnarName = "columnarName";
private static final String columnarDescription = "columnarDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(columnarCipherController, "columnarName", columnarName);
ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", columnarDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.COLUMNAR_CIPHER_NAME, CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(columnarName, columnarDescription);
ObjectNode returnedJson = columnarCipherController.getCipherInfo(); ObjectNode returnedJson = columnarCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class HillCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class HillCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private HillCipherController hillCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController")
protected Logger hillLogger; protected Logger hillLogger;
//Fields //Fields
private String url = "/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(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/hill";
private static final String decodedString = "Message to^encoded";
private static final String encodedString = "Mgkeqge ul^ikhisplrd";
private static final int[][] keyArray = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
private static final String hillName = "hillName";
private static final String hillDescription = "hillDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
encodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(keyArray)); encodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(keyArray));
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString + "xx"); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString + "xx");
ReflectionTestUtils.setField(hillCipherController, "hillName", hillName);
ReflectionTestUtils.setField(hillCipherController, "hillDescription", hillDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.HILL_CIPHER_NAME, CipherInfoUtil.HILL_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(hillName, hillDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.HILL_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(hillName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.HILL_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(hillDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(hillLogger, times(1)).info("Getting info for {}", CipherInfoUtil.HILL_CIPHER_NAME); verify(hillLogger, times(1)).info("Getting info for {}", hillName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(hillLogger, times(1)).info("Encoding {}", CipherInfoUtil.HILL_CIPHER_NAME); verify(hillLogger, times(1)).info("Encoding {}", hillName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(hillLogger, times(1)).info("Encoding {}", CipherInfoUtil.HILL_CIPHER_NAME); verify(hillLogger, times(1)).info("Encoding {}", hillName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(hillLogger, times(1)).info("Decoding {}", CipherInfoUtil.HILL_CIPHER_NAME); verify(hillLogger, times(1)).info("Decoding {}", hillName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(hillLogger, times(1)).info("Decoding {}", CipherInfoUtil.HILL_CIPHER_NAME); verify(hillLogger, times(1)).info("Decoding {}", hillName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.HILL_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@@ -25,15 +27,24 @@ public class HillCipherControllerTest{
private HillCipherController hillCipherController; private HillCipherController hillCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String HILL_INPUT_STRING = "Message to^encode"; private static final String HILL_INPUT_STRING = "Message to^encode";
private static final String HILL_OUTPUT_STRING = "Mgkeqge ul^ikhisp"; 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 static final int[][] KEY = {{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String hillName = "hillName";
private static final String hillDescription = "hillDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(hillCipherController, "hillName", hillName);
ReflectionTestUtils.setField(hillCipherController, "hillDescription", hillDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.HILL_CIPHER_NAME, CipherInfoUtil.HILL_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(hillName, hillDescription);
ObjectNode returnedJson = hillCipherController.getCipherInfo(); ObjectNode returnedJson = hillCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,14 +28,18 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private MorseCodeController morseCodeController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController") @Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController")
protected Logger morseLogger; protected Logger morseLogger;
//Fields //Fields
private String url = "/morse";
private String decodedString = "Message to^encode123";
private String encodedString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/morse";
private static final String decodedString = "Message to^encode123";
private static final String encodedString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
private static final String morseName = "morseName";
private static final String morseDescription = "morseDescription";
@BeforeEach @BeforeEach
@@ -46,25 +51,28 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
encodedNode = mapper.createObjectNode(); encodedNode = mapper.createObjectNode();
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase().replaceAll("[^A-Z0-9]", "")); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""));
ReflectionTestUtils.setField(morseCodeController, "morseName", morseName);
ReflectionTestUtils.setField(morseCodeController, "morseDescription", morseDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.MORSE_CIPHER_NAME, CipherInfoUtil.MORSE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(morseName, morseDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.MORSE_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(morseName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.MORSE_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(morseDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(morseLogger, times(1)).info("Getting info for {}", CipherInfoUtil.MORSE_CIPHER_NAME); verify(morseLogger, times(1)).info("Getting info for {}", morseName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -83,8 +91,8 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(morseLogger, times(1)).info("Encoding {}", CipherInfoUtil.MORSE_CIPHER_NAME); verify(morseLogger, times(1)).info("Encoding {}", morseName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -103,8 +111,8 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(morseLogger, times(1)).info("Encoding {}", CipherInfoUtil.MORSE_CIPHER_NAME); verify(morseLogger, times(1)).info("Encoding {}", morseName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -123,8 +131,8 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(morseLogger, times(1)).info("Decoding {}", CipherInfoUtil.MORSE_CIPHER_NAME); verify(morseLogger, times(1)).info("Decoding {}", morseName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -143,8 +151,8 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(morseLogger, times(1)).info("Decoding {}", CipherInfoUtil.MORSE_CIPHER_NAME); verify(morseLogger, times(1)).info("Decoding {}", morseName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.MORSE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,14 +25,23 @@ public class MorseCodeControllerTest{
private MorseCodeController morseCodeController; private MorseCodeController morseCodeController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String MORSE_INPUT_STRING = "SOS"; private static final String MORSE_INPUT_STRING = "SOS";
private static final String MORSE_OUTPUT_STRING = "... --- ..."; private static final String MORSE_OUTPUT_STRING = "... --- ...";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String morseName = "morseName";
private static final String morseDescription = "morseDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(morseCodeController, "morseName", morseName);
ReflectionTestUtils.setField(morseCodeController, "morseDescription", morseDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.MORSE_CIPHER_NAME, CipherInfoUtil.MORSE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(morseName, morseDescription);
ObjectNode returnedJson = morseCodeController.getCipherInfo(); ObjectNode returnedJson = morseCodeController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,16 +28,20 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class PlayfairCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private PlayfairCipherController playfairCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController")
protected Logger playfairLogger; protected Logger playfairLogger;
//Fields //Fields
private String url = "/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(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/playfair";
private static final String decodedString = "Hide the gold in - the@tree+stump";
private static final String decodedStringPadded = "Hide the gold in - the@trexe+stump";
private static final String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
private static final String keyword = "Play-fair@Exam ple";
private static final String playfairName = "playfairName";
private static final String playfairDescription = "playfairDescription";
@BeforeEach @BeforeEach
@@ -56,26 +61,29 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedStringPadded); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedStringPadded);
ReflectionTestUtils.setField(playfairCipherController, "playfairName", playfairName);
ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", playfairDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PLAYFAIR_CIPHER_NAME, CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(playfairName, playfairDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.PLAYFAIR_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(playfairName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(playfairDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(playfairLogger, times(1)).info("Getting info for {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(playfairLogger, times(1)).info("Getting info for {}", playfairName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -94,8 +102,8 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(playfairLogger, times(1)).info("Encoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(playfairLogger, times(1)).info("Encoding {}", playfairName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -114,8 +122,8 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(playfairLogger, times(1)).info("Encoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(playfairLogger, times(1)).info("Encoding {}", playfairName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -134,8 +142,8 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(playfairLogger, times(1)).info("Decoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(playfairLogger, times(1)).info("Decoding {}", playfairName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -154,8 +162,8 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(playfairLogger, times(1)).info("Decoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(playfairLogger, times(1)).info("Decoding {}", playfairName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.PLAYFAIR_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,16 +25,25 @@ public class PlayfairCipherControllerTest{
private PlayfairCipherController playfairCipherController; private PlayfairCipherController playfairCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String PLAYFAIR_INPUT_STRING = "Hide the gold in - the@tree+stump"; 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 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_OUTPUT_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
private static final String PLAYFAIR_KEYWORD = "Play-fair@Exam ple"; private static final String PLAYFAIR_KEYWORD = "Play-fair@Exam ple";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String playfairName = "playfairName";
private static final String playfairDescription = "playfairDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(playfairCipherController, "playfairName", playfairName);
ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", playfairDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PLAYFAIR_CIPHER_NAME, CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(playfairName, playfairDescription);
ObjectNode returnedJson = playfairCipherController.getCipherInfo(); ObjectNode returnedJson = playfairCipherController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class PolybiusSquareControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private PolybiusSquareController polybiusSquareController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController") @Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController")
protected Logger polybiusLogger; protected Logger polybiusLogger;
//Fields //Fields
private String url = "/polybius";
private String decodedString = "Message to^encode";
private String encodedString = "41124545233212 5115^124225152212";
private String keyword = "keyword";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/polybius";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "41124545233212 5115^124225152212";
private static final String keyword = "keyword";
private static final String polybiusName = "polybiusName";
private static final String polybiusDescription = "polybiusDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
encodedNode.put(CipherParameterUtil.KEYWORD, keyword); encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase()); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase());
ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", polybiusName);
ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", polybiusDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(polybiusName, polybiusDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(polybiusName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(polybiusDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(polybiusLogger, times(1)).info("Getting info for {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(polybiusLogger, times(1)).info("Getting info for {}", polybiusName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(polybiusLogger, times(1)).info("Encoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(polybiusLogger, times(1)).info("Encoding {}", polybiusName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(polybiusLogger, times(1)).info("Encoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(polybiusLogger, times(1)).info("Encoding {}", polybiusName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(polybiusLogger, times(1)).info("Decoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(polybiusLogger, times(1)).info("Decoding {}", polybiusName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(polybiusLogger, times(1)).info("Decoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(polybiusLogger, times(1)).info("Decoding {}", polybiusName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,23 @@ public class PolybiusSquareControllerTest{
private PolybiusSquareController polybiusSquareController; private PolybiusSquareController polybiusSquareController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String POLYBIUS_INPUT_STRING = "B A-T"; 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_OUTPUT_STRING = "15 14-52";
private static final String POLYBIUS_KEYWORD = "Z Y+ X-"; private static final String POLYBIUS_KEYWORD = "Z Y+ X-";
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String polybiusName = "polybiusName";
private static final String polybiusDescription = "polybiusDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", polybiusName);
ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", polybiusDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(polybiusName, polybiusDescription);
ObjectNode returnedJson = polybiusSquareController.getCipherInfo(); ObjectNode returnedJson = polybiusSquareController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,15 +28,19 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class RailFenceControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private RailFenceController railFenceController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController") @Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController")
protected Logger railFenceLogger; protected Logger railFenceLogger;
//Fields //Fields
private String url = "/railFence";
private String decodedString = "Message to^encode";
private String encodedString = "Maooesg te^cdsene";
private int rails = 3;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/railFence";
private static final String decodedString = "Message to^encode";
private static final String encodedString = "Maooesg te^cdsene";
private static final int rails = 3;
private static final String railFenceName = "railFenceName";
private static final String railFenceDescription = "railFenceDescription";
@BeforeEach @BeforeEach
@@ -55,26 +60,29 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
encodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails); encodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(railFenceController, "railFenceName", railFenceName);
ReflectionTestUtils.setField(railFenceController, "railFenceDescription", railFenceDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(railFenceName, railFenceDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(railFenceName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(railFenceDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(railFenceLogger, times(1)).info("Getting info for {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(railFenceLogger, times(1)).info("Getting info for {}", railFenceName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -93,8 +101,8 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(railFenceLogger, times(1)).info("Encoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(railFenceLogger, times(1)).info("Encoding {}", railFenceName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -113,8 +121,8 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(railFenceLogger, times(1)).info("Encoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(railFenceLogger, times(1)).info("Encoding {}", railFenceName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -133,8 +141,8 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(railFenceLogger, times(1)).info("Decoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(railFenceLogger, times(1)).info("Decoding {}", railFenceName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -153,8 +161,8 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(railFenceLogger, times(1)).info("Decoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(railFenceLogger, times(1)).info("Decoding {}", railFenceName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.RAIL_FENCE_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,15 +25,24 @@ public class RailFenceControllerTest{
private RailFenceController railFenceController; private RailFenceController railFenceController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String RAIL_FENCE_INPUT_STRING = "Message to^encode"; 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 String RAIL_FENCE_OUTPUT_STRING = "Moetese ne^sgcdao";
private static final int RAIL_FENCE_RAILS = 5; private static final int RAIL_FENCE_RAILS = 5;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String railFenceName = "railFenceName";
private static final String railFenceDescription = "railFenceDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(railFenceController, "railFenceName", railFenceName);
ReflectionTestUtils.setField(railFenceController, "railFenceDescription", railFenceDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(railFenceName, railFenceDescription);
ObjectNode returnedJson = railFenceController.getCipherInfo(); ObjectNode returnedJson = railFenceController.getCipherInfo();

View File

@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -27,17 +28,21 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
public class TrifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{ public class TrifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired
private TrifidCipherController trifidCipherController;
//Loggers //Loggers
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController") @Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController")
protected Logger trifidLogger; protected Logger trifidLogger;
//Fields //Fields
private String url = "/trifid";
private String decodedString = "Message to^encode+";
private String encodedString = "Gqdokpd od^ljvflf+";
private String keyword = "keyword";
private String trifidFill = "=";
private int grouplength = Integer.MAX_VALUE;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String url = "/trifid";
private static final String decodedString = "Message to^encode+";
private static final String encodedString = "Gqdokpd od^ljvflf+";
private static final String keyword = "keyword";
private static final String trifidFill = "=";
private static final int grouplength = Integer.MAX_VALUE;
private static final String trifidName = "trifidName";
private static final String trifidDescription = "trifidDescription";
@BeforeEach @BeforeEach
@@ -61,26 +66,29 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
encodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, grouplength); encodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, grouplength);
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString); encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString); encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
ReflectionTestUtils.setField(trifidCipherController, "trifidName", trifidName);
ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", trifidDescription);
} }
@Test @Test
public void testGetCipherInfo() throws Exception{ public void testGetCipherInfo() throws Exception{
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.TRIFID_CIPHER_NAME, CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(trifidName, trifidDescription);
mockMvc.perform(get(url) mockMvc.perform(get(url)
.header("X-Request-Id", requestId) .header("X-Request-Id", requestId)
.header("X-Forwarded-For", ipAddress)) .header("X-Forwarded-For", ipAddress))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.TRIFID_CIPHER_NAME)) .andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(trifidName))
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION)); .andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(trifidDescription));
//Filter //Filter
super.verifyFilter(url); super.verifyFilter(url);
//Controller //Controller
verify(trifidLogger, times(1)).info("Getting info for {}", CipherInfoUtil.TRIFID_CIPHER_NAME); verify(trifidLogger, times(1)).info("Getting info for {}", trifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode); verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
} }
@@ -99,8 +107,8 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(trifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME); verify(trifidLogger, times(1)).info("Encoding {}", trifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
} }
@@ -119,8 +127,8 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/encode"); super.verifyFilter(url + "/encode");
//Controller //Controller
verify(trifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME); verify(trifidLogger, times(1)).info("Encoding {}", trifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }
@@ -139,8 +147,8 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(trifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME); verify(trifidLogger, times(1)).info("Decoding {}", trifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
//Cipher Aspect //Cipher Aspect
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode); verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
} }
@@ -159,8 +167,8 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
//Filter //Filter
super.verifyFilter(url + "/decode"); super.verifyFilter(url + "/decode");
//Controller //Controller
verify(trifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME); verify(trifidLogger, times(1)).info("Decoding {}", trifidName);
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, CipherInfoUtil.TRIFID_CIPHER_NAME); verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
//Cipher Aspect //Cipher Aspect
verifyNoInteractions(aspectLogger); verifyNoInteractions(aspectLogger);
} }

View File

@@ -3,11 +3,13 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -23,17 +25,26 @@ public class TrifidCipherControllerTest{
private TrifidCipherController trifidCipherController; private TrifidCipherController trifidCipherController;
//Fields //Fields
private static final ObjectMapper mapper = new ObjectMapper(); private static final ObjectMapper mapper = new ObjectMapper();
private static final ObjectNode blankNode = mapper.createObjectNode();
private static final String TRIFID_INPUT_STRING = "Message to^encode"; 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_OUTPUT_STRING = "Gpjqdvd of^odlklf";
private static final String TRIFID_KEYWORD = CipherParameterUtil.KEYWORD; private static final String TRIFID_KEYWORD = CipherParameterUtil.KEYWORD;
private static final char TRIFID_FILL_ID = '+'; private static final char TRIFID_FILL_ID = '+';
private static final int TRIFID_GROUP_LENGTH = 3; private static final int TRIFID_GROUP_LENGTH = 3;
private static final ObjectNode blankNode = mapper.createObjectNode(); private static final String trifidName = "trifidName";
private static final String trifidDescription = "trifidDescription";
@BeforeEach
public void setup(){
ReflectionTestUtils.setField(trifidCipherController, "trifidName", trifidName);
ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", trifidDescription);
}
@Test @Test
public void tetGetCipherInfo(){ public void tetGetCipherInfo(){
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.TRIFID_CIPHER_NAME, CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION); ObjectNode infoNode = CipherInfoUtil.buildInfoNode(trifidName, trifidDescription);
ObjectNode returnedJson = trifidCipherController.getCipherInfo(); ObjectNode returnedJson = trifidCipherController.getCipherInfo();