Initial commit
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
package com.mattrixwv.cipherstream.controller;
|
||||
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.config.FullFilter;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@Import({AopAutoConfiguration.class, FullFilter.class, CipherStreamLoggingAspect.class})
|
||||
public class CipherStreamControllerIntegrationTestBase{
|
||||
protected static final ObjectMapper mapper = new ObjectMapper();
|
||||
//Objects
|
||||
protected ObjectNode decodedNode;
|
||||
protected ObjectNode encodedNode;
|
||||
//Fields
|
||||
protected static final String requestId = UUID.randomUUID().toString();
|
||||
protected static final String ipAddress = "192.168.1.1";
|
||||
|
||||
//MDC
|
||||
@Mock
|
||||
protected MDCAdapter mdc;
|
||||
|
||||
//Base
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.CipherStreamController")
|
||||
protected Logger baseLogger;
|
||||
|
||||
//Combination
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController")
|
||||
protected Logger adfgvxLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController")
|
||||
protected Logger adfgxLogger;
|
||||
|
||||
//Monosubstitution
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController")
|
||||
protected Logger affineLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController")
|
||||
protected Logger atbashLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController")
|
||||
protected Logger autokeyLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController")
|
||||
protected Logger baconianLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController")
|
||||
protected Logger baseXLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController")
|
||||
protected Logger beaufortLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController")
|
||||
protected Logger caesarLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController")
|
||||
protected Logger oneTimePadLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController")
|
||||
protected Logger portaLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController")
|
||||
protected Logger substitutionLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController")
|
||||
protected Logger vigenereLogger;
|
||||
|
||||
//Polysubstitution
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController")
|
||||
protected Logger bifidLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController")
|
||||
protected Logger columnarLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController")
|
||||
protected Logger hillLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController")
|
||||
protected Logger morseLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController")
|
||||
protected Logger playfiarLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController")
|
||||
protected Logger polybiusLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController")
|
||||
protected Logger railFenceLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController")
|
||||
protected Logger trifidLogger;
|
||||
|
||||
//Misc
|
||||
@Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
|
||||
protected Logger filterLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect")
|
||||
protected Logger aspectLogger;
|
||||
|
||||
|
||||
protected void verifyFilter(String url){
|
||||
verify(filterLogger, never()).info(eq("Request parameters: {}"), any(StringBuilder.class));
|
||||
verify(mdc, times(1)).put(eq("requestId"), any());
|
||||
verify(mdc, times(1)).put("ip", ipAddress);
|
||||
verify(mdc, times(1)).put("url", url);
|
||||
verify(mdc, times(1)).clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.mattrixwv.cipherstream.controller;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ExceptionRestControllerTest{
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
@InjectMocks
|
||||
private ExceptionRestController controller;
|
||||
//Fields
|
||||
private static final String errorMessage = "Error message";
|
||||
|
||||
|
||||
@Test
|
||||
public void testInvalidCipherParameterHandler(){
|
||||
//Setup variables
|
||||
InvalidCipherParameterException error = new InvalidCipherParameterException(errorMessage);
|
||||
ObjectNode expectedJson = mapper.createObjectNode();
|
||||
expectedJson.put("message", errorMessage);
|
||||
|
||||
|
||||
//Run the function
|
||||
ObjectNode returnJson = controller.invalidCipherParameterHandler(error);
|
||||
|
||||
|
||||
//Verify the data
|
||||
assertEquals(expectedJson, returnJson);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenericExceptionHandler(){
|
||||
//Setup variables
|
||||
Exception error = new Exception(errorMessage);
|
||||
ObjectNode expectedJson = mapper.createObjectNode();
|
||||
expectedJson.put("message", errorMessage);
|
||||
|
||||
|
||||
//Run the function
|
||||
JsonNode returnJson = controller.genericExceptionHandler(error);
|
||||
|
||||
|
||||
//Verify the data
|
||||
assertEquals(expectedJson, returnJson);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AdfgvxCipherController.class)
|
||||
public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/adfgvx";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
private String keyword = "keyword";
|
||||
private String squareKeyword = "SquareKeyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Encoding ADFGVX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Decoding ADFGVX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AdfgvxCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AdfgvxCipherController adfgvxCipherController;
|
||||
private static final String KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
|
||||
private static final String INPUT_STRING = "Message to-encode";
|
||||
private static final String OUTPUT_STRING = "AXgvdavfxgagfa afag-aaxdxfgdagda";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx(){
|
||||
ObjectNode cipherParams = generateParams(KEYWORD, SQUARE_KEYWORD, INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgvxCipherController.encodeAdfgvx(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgvxCipherController.encodeAdfgvx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx(){
|
||||
ObjectNode cipherParams = generateParams(KEYWORD, SQUARE_KEYWORD, OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgvxCipherController.decodeAdfgvx(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgvxCipherController.decodeAdfgvx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String squareKeyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AdfgxCipherController.class)
|
||||
public class AdfgxCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/adfgx";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private String keyword = "keyword";
|
||||
private String squareKeyword = "SquareKeyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Encoding ADFGX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgx() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Decoding ADFGX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AdfgxCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AdfgxCipherController adfgxCipherController;
|
||||
private static final String ADFGX_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String ADFGX_SQUARE_KEYWORD = CipherParameterUtil.SQUARE_KEYWORD;
|
||||
private static final String ADFGX_INPUT_STRING = "Message to^encode";
|
||||
private static final String ADFGX_OUTPUT_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx(){
|
||||
ObjectNode cipherParams = generateParams(ADFGX_KEYWORD, ADFGX_SQUARE_KEYWORD, ADFGX_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgxCipherController.encodeAdfgx(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgxCipherController.encodeAdfgx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgx(){
|
||||
ObjectNode cipherParams = generateParams(ADFGX_KEYWORD, ADFGX_SQUARE_KEYWORD, ADFGX_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgxCipherController.decodeAdfgx(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
adfgxCipherController.decodeAdfgx(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String squareKeyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.SQUARE_KEYWORD, squareKeyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AffineCipherController.class)
|
||||
public class AffineCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/affine";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Pbtthlb yz^burzwb";
|
||||
private int key1 = 5;
|
||||
private int key2 = 7;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.AFFINE_KEY_1, key1);
|
||||
decodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.AFFINE_KEY_1, key1);
|
||||
encodedNode.put(CipherParameterUtil.AFFINE_KEY_2, key2);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAffine() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Encoding Affine");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAffine() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Decoding Affine");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AffineCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AffineCipherController affineCipherController;
|
||||
private static final String AFFINE_INPUT_STRING = "Message to^encode";
|
||||
private static final String AFFINE_OUTPUT_STRING = "Pbtthlb yz^burzwb";
|
||||
private static final int AFFINE_KEY_1 = 5;
|
||||
private static final int AFFINE_KEY_2 = 7;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAffine(){
|
||||
ObjectNode cipherParams = generateParams(AFFINE_KEY_1, AFFINE_KEY_2, AFFINE_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = affineCipherController.encodeAffine(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AFFINE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
affineCipherController.encodeAffine(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAffine(){
|
||||
ObjectNode cipherParams = generateParams(AFFINE_KEY_1, AFFINE_KEY_2, AFFINE_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = affineCipherController.decodeAffine(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AFFINE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
affineCipherController.decodeAffine(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int key1, int key2, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.AFFINE_KEY_1, key1);
|
||||
cipherParams.put(CipherParameterUtil.AFFINE_KEY_2, key2);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AtbashCipherController.class)
|
||||
public class AtbashCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/atbash";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Nvhhztv gl^vmxlwv";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAtbash() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Encoding Atbash");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAtbash() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Decoding Atbash");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AtbashCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AtbashCipherController atbashCipherController;
|
||||
private static final String ATBASH_INPUT_STRING = "Message to^encode";
|
||||
private static final String ATBASH_OUTPUT_STRING = "Nvhhztv gl^vmxlwv";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAtbash(){
|
||||
ObjectNode cipherParams = generateParams(ATBASH_INPUT_STRING);
|
||||
|
||||
ObjectNode returnedJson = atbashCipherController.encodeAtbash(cipherParams);
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ATBASH_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
atbashCipherController.encodeAtbash(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAtbash(){
|
||||
ObjectNode cipherParams = generateParams(ATBASH_OUTPUT_STRING);
|
||||
|
||||
ObjectNode returnedJson = atbashCipherController.decodeAtbash(cipherParams);
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ATBASH_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
atbashCipherController.decodeAtbash(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = AutokeyCipherController.class)
|
||||
public class AutokeyCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/autokey";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh fs^wfcuhx";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAutokey() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Encoding Autokey");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Decoding Autokey");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AutokeyCipherControllerTest{
|
||||
@InjectMocks
|
||||
private AutokeyCipherController autokeyCipherController;
|
||||
private static final String AUTOKEY_INPUT_STRING = "Message to^encode";
|
||||
private static final String AUTOKEY_OUTPUT_STRING = "Wiqooxh fs^wfcuhx";
|
||||
private static final String AUTOKEY_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeAutokey(){
|
||||
ObjectNode cipherParams = generateParams(AUTOKEY_KEYWORD, AUTOKEY_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = autokeyCipherController.encodeAutokey(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AUTOKEY_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
autokeyCipherController.encodeAutokey(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey(){
|
||||
ObjectNode cipherParams = generateParams(AUTOKEY_KEYWORD, AUTOKEY_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = autokeyCipherController.decodeAutokey(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AUTOKEY_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
autokeyCipherController.decodeAutokey(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = BaconianCipherController.class)
|
||||
public class BaconianCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/baconian";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.replaceAll("[^a-zA-Z]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaconian() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Encoding Baconian");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaconian() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.replaceAll("[^a-zA-Z]", "")));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Decoding Baconian");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BaconianCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BaconianCipherController baconianCipherController;
|
||||
private static final String BACONIAN_INPUT_STRING = "Message to-encode";
|
||||
private static final String BACONIAN_OUTPUT_STRING = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
private static final String BACONIAN_DECODED_STRING = "Messagetoencode";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBaconian(){
|
||||
ObjectNode cipherParams = generateParams(BACONIAN_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baconianCipherController.encodeBaconian(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BACONIAN_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baconianCipherController.encodeBaconian(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaconian(){
|
||||
ObjectNode cipherParams = generateParams(BACONIAN_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baconianCipherController.decodeBaconian(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BACONIAN_DECODED_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baconianCipherController.decodeBaconian(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = BaseXCipherController.class)
|
||||
public class BaseXCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/basex";
|
||||
private String decodedString = "A+B@C d\te\nf";
|
||||
private String encodedString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private int base = 2;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.BASE_X_BASE, base);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.BASE_X_BASE, base);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBaseXEncode() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Encoding BaseX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaseXDecode() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Decoding BaseX");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BaseXCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BaseXCipherController baseXCipherController;
|
||||
private static final int BASE_X_BASE = 2;
|
||||
private static final String BASE_X_INPUT_STRING = "A+B@C d\te\nf";
|
||||
private static final String BASE_X_OUTPUT_STRING = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBaseX(){
|
||||
ObjectNode cipherParams = generateParams(BASE_X_BASE, BASE_X_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baseXCipherController.encodeBaseX(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BASE_X_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baseXCipherController.encodeBaseX(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaseX(){
|
||||
ObjectNode cipherParams = generateParams(BASE_X_BASE, BASE_X_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baseXCipherController.decodeBaseX(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BASE_X_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
baseXCipherController.decodeBaseX(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int base, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
cipherParams.put(CipherParameterUtil.BASE_X_BASE, base);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = BeaufortCipherController.class)
|
||||
public class BeaufortCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/beaufort";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Yageolz rq^ujmdag";
|
||||
private String keyword = "Ke*y word";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBeaufort() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Encoding Beaufort");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBeaufort() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Decoding Beaufort");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BeaufortCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BeaufortCipherController beaufortCipherController;
|
||||
private static final String BEAUFORT_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String BEAUFORT_INPUT_STRING = "Message to^encode";
|
||||
private static final String BEAUFORT_OUTPUT_STRING = "Yageolz rq^ujmdag";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void encodeBeaufort(){
|
||||
ObjectNode cipherParams = generateParams(BEAUFORT_KEYWORD, BEAUFORT_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = beaufortCipherController.encodeBeaufort(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BEAUFORT_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
beaufortCipherController.encodeBeaufort(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeBeaufort(){
|
||||
ObjectNode cipherParams = generateParams(BEAUFORT_KEYWORD, BEAUFORT_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = beaufortCipherController.decodeBeaufort(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BEAUFORT_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
beaufortCipherController.decodeBeaufort(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = CaesarCipherController.class)
|
||||
public class CaesarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/caesar";
|
||||
private String decodedString = "The quick brown fox jumps over - the lazy dog";
|
||||
private String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private int shiftAmount = 23;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeCaesar() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Encoding Caesar");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeCaesar() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Decoding Caesar");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class CaesarCipherControllerTest{
|
||||
@InjectMocks
|
||||
private CaesarCipherController caesarCipherController;
|
||||
private static final String CAESAR_INPUT_STRING = "The quick brown fox jumps over - the lazy dog";
|
||||
private static final String CAESAR_OUTPUT_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private static final int CAESAR_SHIFT_AMOUNT = 23;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeCaesar(){
|
||||
ObjectNode cipherParams = generateParams(CAESAR_SHIFT_AMOUNT, CAESAR_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = caesarCipherController.encodeCaesar(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(CAESAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
caesarCipherController.encodeCaesar(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeCaesar(){
|
||||
ObjectNode cipherParams = generateParams(CAESAR_SHIFT_AMOUNT, CAESAR_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = caesarCipherController.decodeCaesar(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(CAESAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
caesarCipherController.decodeCaesar(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int shiftAmount, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, shiftAmount);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = OneTimePadCipherController.class)
|
||||
public class OneTimePadCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/oneTimePad";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh mv^egkgws";
|
||||
private String keyword = "keywordThatIsTotallyRandom";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeOneTimePad() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Encoding One Time Pad");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeOneTimePad() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Decoding One Time Pad");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class OneTimePadCipherControllerTest{
|
||||
@InjectMocks
|
||||
private OneTimePadCipherController oneTimePadCipherController;
|
||||
private static final String ONE_TIME_PAD_KEYWORD = "keywordThatIsTotallyRandom";
|
||||
private static final String ONE_TIME_PAD_INPUT_STRING = "Message to^encode";
|
||||
private static final String ONE_TIME_PAD_OUTPUT_STRING = "Wiqooxh mv^egkgws";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
public void testEncodeOneTimePad(){
|
||||
ObjectNode cipherParams = generateParams(ONE_TIME_PAD_KEYWORD, ONE_TIME_PAD_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = oneTimePadCipherController.encodeOneTimePad(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ONE_TIME_PAD_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
oneTimePadCipherController.encodeOneTimePad(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeOneTimePad(){
|
||||
ObjectNode cipherParams = generateParams(ONE_TIME_PAD_KEYWORD, ONE_TIME_PAD_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = oneTimePadCipherController.decodeOneTimePad(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ONE_TIME_PAD_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
oneTimePadCipherController.decodeOneTimePad(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = PortaCipherController.class)
|
||||
public class PortaCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/porta";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Rtghuos bm^qcwgrw";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePorta() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
verify(filterLogger, never()).info(eq("Request parameters: {}"), anyString());
|
||||
verify(mdc, times(1)).put("requestId", requestId);
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).put("url", url + "/encode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Encoding Porta");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePorta() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
verify(filterLogger, never()).info(eq("Request parameters: {}"), anyString());
|
||||
verify(mdc, times(1)).put("requestId", requestId);
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).put("url", url + "/decode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Decoding Porta");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PortaCipherControllerTest{
|
||||
@InjectMocks
|
||||
private PortaCipherController portaCipherController;
|
||||
private static final String PORTA_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String PORTA_INPUT_STRING = "Message to^encode";
|
||||
private static final String PORTA_OUTPUT_STRING = "Rtghuos bm^qcwgrw";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePorta(){
|
||||
ObjectNode cipherParams = generateParams(PORTA_KEYWORD, PORTA_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = portaCipherController.encodePorta(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PORTA_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
portaCipherController.encodePorta(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePorta(){
|
||||
ObjectNode cipherParams = generateParams(PORTA_KEYWORD, PORTA_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = portaCipherController.decodePorta(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PORTA_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
portaCipherController.decodePorta(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = SubstitutionCipherController.class)
|
||||
public class SubstitutionCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/substitution";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Oguucig vq^gpeqfg";
|
||||
private String keyword = "cdefghijklmnopqrstuvwxyzab";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeSubstitution() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Encoding Substitution");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeSubstitution() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Decoding Substitution");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class SubstitutionCipherControllerTest{
|
||||
@InjectMocks
|
||||
private SubstitutionCipherController substitutionCipherController;
|
||||
private static final String SUBSTITUTION_KEYWORD = "cdefghijklmnopqrstuvwxyzab9876543210";
|
||||
private static final String SUBSTITUTION_INPUT_STRING = "Message to&encode 123";
|
||||
private static final String SUBSTITUTION_OUTPUT_STRING = "Oguucig vq&gpeqfg 876";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeSubstitution(){
|
||||
ObjectNode cipherParams = generateParams(SUBSTITUTION_KEYWORD, SUBSTITUTION_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = substitutionCipherController.encodeSubstitution(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(SUBSTITUTION_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
substitutionCipherController.encodeSubstitution(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeSubstitution(){
|
||||
ObjectNode cipherParams = generateParams(SUBSTITUTION_KEYWORD, SUBSTITUTION_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = substitutionCipherController.decodeSubstitution(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(SUBSTITUTION_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
substitutionCipherController.decodeSubstitution(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = VigenereCipherController.class)
|
||||
public class VigenereCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/vigenere";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Wiqooxh ds^cjqfgo";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeVigenere() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Encoding Vigenere");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeVigenere() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Decoding Vigenere");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class VigenereCipherControllerTest{
|
||||
@InjectMocks
|
||||
private VigenereCipherController vigenereCipherController;
|
||||
private static final String VIGENERE_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final String VIGENERE_INPUT_STRING = "Message to^encode";
|
||||
private static final String VIGENERE_OUTPUT_STRING = "Wiqooxh ds^cjqfgo";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeVigenere(){
|
||||
ObjectNode cipherParams = generateParams(VIGENERE_KEYWORD, VIGENERE_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = vigenereCipherController.encodeVigenere(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(VIGENERE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
vigenereCipherController.encodeVigenere(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeVigenere(){
|
||||
ObjectNode cipherParams = generateParams(VIGENERE_KEYWORD, VIGENERE_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = vigenereCipherController.decodeVigenere(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(VIGENERE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankParams = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
vigenereCipherController.decodeVigenere(blankParams);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = BifidCipherController.class)
|
||||
public class BifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/bifid";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Mqaokne kc^vdodzd";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Encoding Bifid");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Decoding Bifid");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BifidCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BifidCipherController bifidCipherController;
|
||||
private static final String BIFID_INPUT_STRING = "Message to^encode";
|
||||
private static final String BIFID_OUTPUT_STRING = "Mqaokne kc^vdodzd";
|
||||
private static final String BIFID_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid(){
|
||||
ObjectNode cipherParams = generateParams(BIFID_KEYWORD, BIFID_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = bifidCipherController.encodeBifid(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
bifidCipherController.encodeBifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey(){
|
||||
ObjectNode cipherParams = generateParams(BIFID_KEYWORD, BIFID_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = bifidCipherController.decodeBifid(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
bifidCipherController.decodeBifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = ColumnarCipherController.class)
|
||||
public class ColumnarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/columnar";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Edeomte ac^gosnse";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Encoding Columnar");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeColumnar() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Decoding Columnar");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class ColumnarCipherControllerTest{
|
||||
@InjectMocks
|
||||
private ColumnarCipherController columnarCipherController;
|
||||
private static final String COLUMNAR_INPUT_STRING = "Message to*encode";
|
||||
private static final String COLUMNAR_OUTPUT_STRING = "Edeomte ac*gosnse";
|
||||
private static final String COLUMNAR_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar(){
|
||||
ObjectNode cipherParams = generateParams(COLUMNAR_KEYWORD, COLUMNAR_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = columnarCipherController.encodeColumnar(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
columnarCipherController.encodeColumnar(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeColumnar(){
|
||||
ObjectNode cipherParams = generateParams(COLUMNAR_KEYWORD, COLUMNAR_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = columnarCipherController.decodeColumnar(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
columnarCipherController.decodeColumnar(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = HillCipherController.class)
|
||||
public class HillCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/hill";
|
||||
private String decodedString = "Message to^encoded";
|
||||
private String encodedString = "Mgkeqge ul^ikhisplrd";
|
||||
private int[][] keyArray = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(keyArray));
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(keyArray));
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString + "xx");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Encoding Hill");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeHill() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString + "xx"));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Decoding Hill");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class HillCipherControllerTest{
|
||||
@InjectMocks
|
||||
private HillCipherController hillCipherController;
|
||||
private static final String HILL_INPUT_STRING = "Message to^encode";
|
||||
private static final String HILL_OUTPUT_STRING = "Mgkeqge ul^ikhisp";
|
||||
private static final int[][] KEY = {{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws JsonProcessingException{
|
||||
ObjectNode cipherParams = generateParams(HILL_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = hillCipherController.encodeHill(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
hillCipherController.encodeHill(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeHill() throws JsonProcessingException{
|
||||
ObjectNode cipherParams = generateParams(HILL_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = hillCipherController.decodeHill(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
hillCipherController.decodeHill(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
JsonNode keyNode = objectMapper.valueToTree(KEY);
|
||||
cipherParams.set(CipherParameterUtil.HILL_KEY, keyNode);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = MorseCodeController.class)
|
||||
public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/morse";
|
||||
private String decodedString = "Message to^encode123";
|
||||
private String encodedString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Encoding Morse");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeMorse() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.toUpperCase().replaceAll("[^A-Z0-9]", "")));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Decoding Morse");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MorseCodeControllerTest{
|
||||
@InjectMocks
|
||||
private MorseCodeController morseCodeController;
|
||||
private static final String MORSE_INPUT_STRING = "SOS";
|
||||
private static final String MORSE_OUTPUT_STRING = "... --- ...";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse(){
|
||||
ObjectNode cipherParams = generateParams(MORSE_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = morseCodeController.encodeMorse(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
morseCodeController.encodeMorse(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeMorse(){
|
||||
ObjectNode cipherParams = generateParams(MORSE_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = morseCodeController.decodeMorse(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
morseCodeController.decodeMorse(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = PlayfairCipherController.class)
|
||||
public class PlayfairCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/playfair";
|
||||
private String decodedString = "Hide the gold in - the@tree+stump";
|
||||
private String decodedStringPadded = "Hide the gold in - the@trexe+stump";
|
||||
private String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private String keyword = "Play-fair@Exam ple";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedStringPadded);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(playfiarLogger, times(1)).info("Encoding Playfair");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePlayfair() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedStringPadded));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(playfiarLogger, times(1)).info("Decoding Playfair");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PlayfairCipherControllerTest{
|
||||
@InjectMocks
|
||||
private PlayfairCipherController playfairCipherController;
|
||||
private static final String PLAYFAIR_INPUT_STRING = "Hide the gold in - the@tree+stump";
|
||||
private static final String DECODED_INPUT_STRING = "Hide the gold in - the@trexe+stump";
|
||||
private static final String PLAYFAIR_OUTPUT_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private static final String PLAYFAIR_KEYWORD = "Play-fair@Exam ple";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair(){
|
||||
ObjectNode cipherParams = generateParams(PLAYFAIR_KEYWORD, PLAYFAIR_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = playfairCipherController.encodePlayfair(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PLAYFAIR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
playfairCipherController.encodePlayfair(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePlayfair(){
|
||||
ObjectNode cipherParams = generateParams(PLAYFAIR_KEYWORD, PLAYFAIR_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = playfairCipherController.decodePlayfair(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(DECODED_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
playfairCipherController.decodePlayfair(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = PolybiusSquareController.class)
|
||||
public class PolybiusSquareControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/polybius";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "41124545233212 5115^124225152212";
|
||||
private String keyword = "keyword";
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Encoding Polybius");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePolybius() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString.toUpperCase()));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Decoding Polybius");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PolybiusSquareControllerTest{
|
||||
@InjectMocks
|
||||
private PolybiusSquareController polybiusSquareController;
|
||||
private static final String POLYBIUS_INPUT_STRING = "B A-T";
|
||||
private static final String POLYBIUS_OUTPUT_STRING = "15 14-52";
|
||||
private static final String POLYBIUS_KEYWORD = "Z Y+ X-";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius(){
|
||||
ObjectNode cipherParams = generateParams(POLYBIUS_KEYWORD, POLYBIUS_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = polybiusSquareController.encodePolybius(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
polybiusSquareController.encodePolybius(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePolybius(){
|
||||
ObjectNode cipherParams = generateParams(POLYBIUS_KEYWORD, POLYBIUS_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = polybiusSquareController.decodePolybius(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
polybiusSquareController.decodePolybius(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = RailFenceController.class)
|
||||
public class RailFenceControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/railFence";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Maooesg te^cdsene";
|
||||
private int rails = 3;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Encoding Rail Fence");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRailFence() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Decoding Rail Fence");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class RailFenceControllerTest{
|
||||
@InjectMocks
|
||||
private RailFenceController railFenceController;
|
||||
private static final String RAIL_FENCE_INPUT_STRING = "Message to^encode";
|
||||
private static final String RAIL_FENCE_OUTPUT_STRING = "Moetese ne^sgcdao";
|
||||
private static final int RAIL_FENCE_RAILS = 5;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence(){
|
||||
ObjectNode cipherParams = generateParams(RAIL_FENCE_RAILS, RAIL_FENCE_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = railFenceController.encodeRailFence(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRailFence(){
|
||||
ObjectNode cipherParams = generateParams(RAIL_FENCE_RAILS, RAIL_FENCE_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = railFenceController.decodeRailFence(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int rails, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = TrifidCipherController.class)
|
||||
public class TrifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Fields
|
||||
private String url = "/cipherStream/trifid";
|
||||
private String decodedString = "Message to^encode+";
|
||||
private String encodedString = "Gqdokpd od^ljvflf+";
|
||||
private String keyword = "keyword";
|
||||
private String trifidFill = "=";
|
||||
private int grouplength = Integer.MAX_VALUE;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
decodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
decodedNode.put(CipherParameterUtil.TRIFID_FILL, trifidFill);
|
||||
decodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, grouplength);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
encodedNode.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
encodedNode.put(CipherParameterUtil.TRIFID_FILL, trifidFill);
|
||||
encodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, grouplength);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(encodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Encoding Trifid");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeTrifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(decodedString));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Decoding Trifid");
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class TrifidCipherControllerTest{
|
||||
@InjectMocks
|
||||
private TrifidCipherController trifidCipherController;
|
||||
private static final String TRIFID_INPUT_STRING = "Message to^encode";
|
||||
private static final String TRIFID_OUTPUT_STRING = "Gpjqdvd of^odlklf";
|
||||
private static final String TRIFID_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final char TRIFID_FILL_ID = '+';
|
||||
private static final int TRIFID_GROUP_LENGTH = 3;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid(){
|
||||
ObjectNode cipherParams = generateParams(TRIFID_KEYWORD, TRIFID_FILL_ID, TRIFID_GROUP_LENGTH, TRIFID_INPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = trifidCipherController.encodeTrifid(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
trifidCipherController.encodeTrifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeTrifid(){
|
||||
ObjectNode cipherParams = generateParams(TRIFID_KEYWORD, TRIFID_FILL_ID, TRIFID_GROUP_LENGTH, TRIFID_OUTPUT_STRING);
|
||||
|
||||
|
||||
ObjectNode returnedJson = trifidCipherController.decodeTrifid(cipherParams);
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
trifidCipherController.decodeTrifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, char fill, int groupLength, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.TRIFID_FILL, String.valueOf(fill));
|
||||
cipherParams.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, groupLength);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user