Updated more tests
This commit is contained in:
@@ -8,12 +8,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController")
|
||||
protected Logger bifidLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/bifid";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Mqaokne kc^vdodzd";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BIFID_CIPHER_NAME, CipherInfoUtil.BIFID_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.BIFID_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.BIFID_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Getting info for {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Encoding Bifid");
|
||||
verify(bifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Decoding Bifid");
|
||||
verify(bifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.BIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class BifidCipherControllerTest{
|
||||
@InjectMocks
|
||||
private BifidCipherController bifidCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String BIFID_INPUT_STRING = "Message to^encode";
|
||||
private static final String BIFID_OUTPUT_STRING = "Mqaokne kc^vdodzd";
|
||||
private static final String BIFID_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.BIFID_CIPHER_NAME, CipherInfoUtil.BIFID_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = bifidCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid(){
|
||||
ObjectNode cipherParams = generateParams(BIFID_KEYWORD, BIFID_INPUT_STRING);
|
||||
@@ -36,16 +50,17 @@ public class BifidCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeBifid_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
bifidCipherController.encodeBifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey(){
|
||||
public void testDecodeBifid(){
|
||||
ObjectNode cipherParams = generateParams(BIFID_KEYWORD, BIFID_OUTPUT_STRING);
|
||||
|
||||
|
||||
@@ -54,21 +69,24 @@ public class BifidCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeBifid_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
bifidCipherController.decodeBifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class ColumnarCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController")
|
||||
protected Logger columnarLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/columnar";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Edeomte ac^gosnse";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.COLUMNAR_CIPHER_NAME, CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.COLUMNAR_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Getting info for {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Encoding Columnar");
|
||||
verify(columnarLogger, times(1)).info("Encoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Encoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeColumnar() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Decoding Columnar");
|
||||
verify(columnarLogger, times(1)).info("Decoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Decoding {}", CipherInfoUtil.COLUMNAR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class ColumnarCipherControllerTest{
|
||||
@InjectMocks
|
||||
private ColumnarCipherController columnarCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String COLUMNAR_INPUT_STRING = "Message to*encode";
|
||||
private static final String COLUMNAR_OUTPUT_STRING = "Edeomte ac*gosnse";
|
||||
private static final String COLUMNAR_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.COLUMNAR_CIPHER_NAME, CipherInfoUtil.COLUMNAR_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = columnarCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar(){
|
||||
ObjectNode cipherParams = generateParams(COLUMNAR_KEYWORD, COLUMNAR_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class ColumnarCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeColumnar_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
columnarCipherController.encodeColumnar(blankNode);
|
||||
});
|
||||
@@ -54,21 +69,24 @@ public class ColumnarCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeColumnar_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
columnarCipherController.decodeColumnar(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class HillCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController")
|
||||
protected Logger hillLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/hill";
|
||||
private String decodedString = "Message to^encoded";
|
||||
private String encodedString = "Mgkeqge ul^ikhisplrd";
|
||||
private int[][] keyArray = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.HILL_CIPHER_NAME, CipherInfoUtil.HILL_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.HILL_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.HILL_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Getting info for {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Encoding Hill");
|
||||
verify(hillLogger, times(1)).info("Encoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Encoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeHill() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Decoding Hill");
|
||||
verify(hillLogger, times(1)).info("Decoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Decoding {}", CipherInfoUtil.HILL_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,12 +23,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class HillCipherControllerTest{
|
||||
@InjectMocks
|
||||
private HillCipherController hillCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String HILL_INPUT_STRING = "Message to^encode";
|
||||
private static final String HILL_OUTPUT_STRING = "Mgkeqge ul^ikhisp";
|
||||
private static final int[][] KEY = {{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.HILL_CIPHER_NAME, CipherInfoUtil.HILL_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = hillCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws JsonProcessingException{
|
||||
ObjectNode cipherParams = generateParams(HILL_INPUT_STRING);
|
||||
@@ -38,9 +52,10 @@ public class HillCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeHill_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
hillCipherController.encodeHill(blankNode);
|
||||
});
|
||||
@@ -56,22 +71,24 @@ public class HillCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeHill_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
hillCipherController.decodeHill(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
JsonNode keyNode = objectMapper.valueToTree(KEY);
|
||||
JsonNode keyNode = mapper.valueToTree(KEY);
|
||||
cipherParams.set(CipherParameterUtil.HILL_KEY, keyNode);
|
||||
|
||||
return cipherParams;
|
||||
|
||||
@@ -8,12 +8,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,10 +26,14 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController")
|
||||
protected Logger morseLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/morse";
|
||||
private String decodedString = "Message to^encode123";
|
||||
private String encodedString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -39,12 +47,31 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.MORSE_CIPHER_NAME, CipherInfoUtil.MORSE_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.MORSE_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.MORSE_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Getting info for {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -54,16 +81,35 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Encoding Morse");
|
||||
verify(morseLogger, times(1)).info("Encoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Encoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeMorse() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -73,8 +119,27 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Decoding Morse");
|
||||
verify(morseLogger, times(1)).info("Decoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Decoding {}", CipherInfoUtil.MORSE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,11 +21,24 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class MorseCodeControllerTest{
|
||||
@InjectMocks
|
||||
private MorseCodeController morseCodeController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String MORSE_INPUT_STRING = "SOS";
|
||||
private static final String MORSE_OUTPUT_STRING = "... --- ...";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.MORSE_CIPHER_NAME, CipherInfoUtil.MORSE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = morseCodeController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse(){
|
||||
ObjectNode cipherParams = generateParams(MORSE_INPUT_STRING);
|
||||
@@ -35,9 +49,10 @@ public class MorseCodeControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncoderMorse_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
morseCodeController.encodeMorse(blankNode);
|
||||
});
|
||||
@@ -53,17 +68,20 @@ public class MorseCodeControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeMorse_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
morseCodeController.decodeMorse(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,12 +26,16 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PlayfairCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController")
|
||||
protected Logger playfairLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/playfair";
|
||||
private String decodedString = "Hide the gold in - the@tree+stump";
|
||||
private String decodedStringPadded = "Hide the gold in - the@trexe+stump";
|
||||
private String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private String keyword = "Play-fair@Exam ple";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -50,11 +58,31 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PLAYFAIR_CIPHER_NAME, CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.PLAYFAIR_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(playfairLogger, times(1)).info("Getting info for {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -64,16 +92,35 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(playfiarLogger, times(1)).info("Encoding Playfair");
|
||||
verify(playfairLogger, times(1)).info("Encoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(playfairLogger, times(1)).info("Encoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePlayfair() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -83,8 +130,27 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(playfiarLogger, times(1)).info("Decoding Playfair");
|
||||
verify(playfairLogger, times(1)).info("Decoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(playfairLogger, times(1)).info("Decoding {}", CipherInfoUtil.PLAYFAIR_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,13 +21,26 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PlayfairCipherControllerTest{
|
||||
@InjectMocks
|
||||
private PlayfairCipherController playfairCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String PLAYFAIR_INPUT_STRING = "Hide the gold in - the@tree+stump";
|
||||
private static final String DECODED_INPUT_STRING = "Hide the gold in - the@trexe+stump";
|
||||
private static final String PLAYFAIR_OUTPUT_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private static final String PLAYFAIR_KEYWORD = "Play-fair@Exam ple";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.PLAYFAIR_CIPHER_NAME, CipherInfoUtil.PLAYFAIR_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = playfairCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair(){
|
||||
ObjectNode cipherParams = generateParams(PLAYFAIR_KEYWORD, PLAYFAIR_INPUT_STRING);
|
||||
@@ -37,9 +51,10 @@ public class PlayfairCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PLAYFAIR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodePlayfair_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
playfairCipherController.encodePlayfair(blankNode);
|
||||
});
|
||||
@@ -55,21 +70,24 @@ public class PlayfairCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(DECODED_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodePlayfair_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
playfairCipherController.decodePlayfair(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PolybiusSquareControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController")
|
||||
protected Logger polybiusLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/polybius";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "41124545233212 5115^124225152212";
|
||||
private String keyword = "keyword";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Getting info for {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Encoding Polybius");
|
||||
verify(polybiusLogger, times(1)).info("Encoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_WHITESPACE + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Encoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePolybius() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Decoding Polybius");
|
||||
verify(polybiusLogger, times(1)).info("Decoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_WHITESPACE + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Decoding {}", CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class PolybiusSquareControllerTest{
|
||||
@InjectMocks
|
||||
private PolybiusSquareController polybiusSquareController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String POLYBIUS_INPUT_STRING = "B A-T";
|
||||
private static final String POLYBIUS_OUTPUT_STRING = "15 14-52";
|
||||
private static final String POLYBIUS_KEYWORD = "Z Y+ X-";
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_NAME, CipherInfoUtil.POLYBIUS_SQUARE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = polybiusSquareController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius(){
|
||||
ObjectNode cipherParams = generateParams(POLYBIUS_KEYWORD, POLYBIUS_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class PolybiusSquareControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodePolybius_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
polybiusSquareController.encodePolybius(blankNode);
|
||||
});
|
||||
@@ -54,21 +69,24 @@ public class PolybiusSquareControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodePolybius_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
polybiusSquareController.decodePolybius(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.KEYWORD, keyword);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,11 +26,15 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class RailFenceControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController")
|
||||
protected Logger railFenceLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/railFence";
|
||||
private String decodedString = "Message to^encode";
|
||||
private String encodedString = "Maooesg te^cdsene";
|
||||
private int rails = 3;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -49,11 +57,31 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Getting info for {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -63,16 +91,35 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Encoding Rail Fence");
|
||||
verify(railFenceLogger, times(1)).info("Encoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Encoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRailFence() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -82,8 +129,27 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Decoding Rail Fence");
|
||||
verify(railFenceLogger, times(1)).info("Decoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Decoding {}", CipherInfoUtil.RAIL_FENCE_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,12 +21,25 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class RailFenceControllerTest{
|
||||
@InjectMocks
|
||||
private RailFenceController railFenceController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String RAIL_FENCE_INPUT_STRING = "Message to^encode";
|
||||
private static final String RAIL_FENCE_OUTPUT_STRING = "Moetese ne^sgcdao";
|
||||
private static final int RAIL_FENCE_RAILS = 5;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.RAIL_FENCE_CIPHER_NAME, CipherInfoUtil.RAIL_FENCE_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = railFenceController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence(){
|
||||
ObjectNode cipherParams = generateParams(RAIL_FENCE_RAILS, RAIL_FENCE_INPUT_STRING);
|
||||
@@ -36,9 +50,10 @@ public class RailFenceControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeRailFence_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
@@ -54,21 +69,24 @@ public class RailFenceControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify inavlid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeRailFence_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
railFenceController.encodeRailFence(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(int rails, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
cipherParams.put(CipherParameterUtil.RAIL_FENCE_RAILS, rails);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -22,6 +26,9 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class TrifidCipherControllerIntegrationTest extends CipherStreamControllerIntegrationTestBase{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController")
|
||||
protected Logger trifidLogger;
|
||||
//Fields
|
||||
private String url = "/cipherStream/trifid";
|
||||
private String decodedString = "Message to^encode+";
|
||||
@@ -29,6 +36,7 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
private String keyword = "keyword";
|
||||
private String trifidFill = "=";
|
||||
private int grouplength = Integer.MAX_VALUE;
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,11 +63,31 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.TRIFID_CIPHER_NAME, CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION);
|
||||
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CipherInfoUtil.TRIFID_CIPHER_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Getting info for {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", infoNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(decodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -69,16 +97,35 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Encoding Trifid");
|
||||
verify(trifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Encoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeTrifid() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", "192.168.1.1")
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(encodedNode.toString()))
|
||||
.andExpect(status().isOk())
|
||||
@@ -88,8 +135,27 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Decoding Trifid");
|
||||
verify(trifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(get(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Decoding {}", CipherInfoUtil.TRIFID_CIPHER_NAME);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
|
||||
@@ -20,14 +21,27 @@ import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
public class TrifidCipherControllerTest{
|
||||
@InjectMocks
|
||||
private TrifidCipherController trifidCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final String TRIFID_INPUT_STRING = "Message to^encode";
|
||||
private static final String TRIFID_OUTPUT_STRING = "Gpjqdvd of^odlklf";
|
||||
private static final String TRIFID_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final char TRIFID_FILL_ID = '+';
|
||||
private static final int TRIFID_GROUP_LENGTH = 3;
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CipherInfoUtil.TRIFID_CIPHER_NAME, CipherInfoUtil.TRIFID_CIPHER_DESCRIPTION);
|
||||
|
||||
|
||||
ObjectNode returnedJson = trifidCipherController.getCipherInfo();
|
||||
|
||||
|
||||
assertEquals(infoNode, returnedJson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid(){
|
||||
ObjectNode cipherParams = generateParams(TRIFID_KEYWORD, TRIFID_FILL_ID, TRIFID_GROUP_LENGTH, TRIFID_INPUT_STRING);
|
||||
@@ -38,9 +52,10 @@ public class TrifidCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testEncodeTrifid_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
trifidCipherController.encodeTrifid(blankNode);
|
||||
});
|
||||
@@ -56,16 +71,18 @@ public class TrifidCipherControllerTest{
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
}
|
||||
|
||||
//Verify invalid params are caught
|
||||
final ObjectNode blankNode = objectMapper.createObjectNode();
|
||||
@Test
|
||||
public void testDecodeTrifid_invalidParameters(){
|
||||
assertThrows(InvalidCipherParameterException.class, () -> {
|
||||
trifidCipherController.decodeTrifid(blankNode);
|
||||
});
|
||||
}
|
||||
|
||||
private ObjectNode generateParams(String keyword, char fill, int groupLength, String inputString){
|
||||
ObjectNode cipherParams = objectMapper.createObjectNode();
|
||||
ObjectNode cipherParams = mapper.createObjectNode();
|
||||
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_CAPITALS, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_WHITESPACE, true);
|
||||
cipherParams.put(CipherParameterUtil.PRESERVE_SYMBOLS, true);
|
||||
@@ -73,6 +90,7 @@ public class TrifidCipherControllerTest{
|
||||
cipherParams.put(CipherParameterUtil.TRIFID_FILL, String.valueOf(fill));
|
||||
cipherParams.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, groupLength);
|
||||
cipherParams.put(CipherParameterUtil.INPUT_STRING, inputString);
|
||||
|
||||
return cipherParams;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user