Initial commit

This commit is contained in:
2024-04-07 19:41:57 -04:00
parent 2b3212cb44
commit 8f0d1c64bd
95 changed files with 6787 additions and 45 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}