Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
1d2ed0153a
|
|||
|
3fec7b2755
|
|||
|
0d49fbe0da
|
|||
|
00e4882c2a
|
|||
|
e184b00ef5
|
|||
|
1fe4fc2d82
|
|||
|
e646d6c888
|
|||
| 18593fcfc5 | |||
| b869f6bc28 | |||
| d7c2591dab | |||
| b6bfcc0290 | |||
| 4e34267856 | |||
| 5f246d79a6 | |||
| caea64a9bf | |||
| 90369a4cd1 | |||
| e29228a84b | |||
| cd13fb8e15 | |||
| 915034315c | |||
| fb094d2e8d | |||
| e61d4a15a6 | |||
| 917246f877 | |||
| a53c765c9c | |||
| 0be6b6bcc1 | |||
| 9a4b3a19f8 | |||
| ac492307ab | |||
| b1ffde262a | |||
| af302d49db | |||
| b0efac01e0 | |||
| 2879310392 | |||
| 3eb3161eb0 | |||
| 8e5846647b | |||
|
|
9b5965e4b5 | ||
| 9d00124062 | |||
| eda3e70e73 | |||
| 5fb237cb5c | |||
| 00eb61a1ea | |||
| 10c7532878 | |||
| 6a8b69371f | |||
| c6d98c72ef | |||
| cc0aa2986d | |||
| 1183cab5f1 | |||
| 28a7a60de3 | |||
| 4a5a221605 | |||
| 3b9a984659 |
2
.mvn/maven.config
Normal file
2
.mvn/maven.config
Normal file
@@ -0,0 +1,2 @@
|
||||
-Dstyle.color=always
|
||||
-T1C
|
||||
@@ -7,9 +7,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.springframework.lang.Nulla
|
||||
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=25
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=21
|
||||
org.eclipse.jdt.core.compiler.compliance=25
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
@@ -102,4 +102,4 @@ org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.processAnnotations=enabled
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=21
|
||||
org.eclipse.jdt.core.compiler.source=25
|
||||
|
||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"sonarlint.connectedMode.project": {
|
||||
"connectionId": "mattrixwvSonarqube",
|
||||
"projectKey": "CipherStreamWeb"
|
||||
"projectKey": "CipherStreamAPI"
|
||||
},
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"java.compile.nullAnalysis.mode": "automatic",
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Cipher Stream API
|
||||
|
||||
[](https://sonarqube.mattrixwv.com/dashboard?id=CipherStreamAPI)
|
||||
|
||||
16
dependencySuppression.xml
Normal file
16
dependencySuppression.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
|
||||
<suppress>
|
||||
<notes><![CDATA[
|
||||
Spring Boot devs say this is not a problem
|
||||
]]></notes>
|
||||
<packageUrl regex="true">^pkg:maven/org\.springframework/spring\-web@.*$</packageUrl>
|
||||
<cve>CVE-2016-1000027</cve>
|
||||
</suppress>
|
||||
<suppress>
|
||||
<notes><![CDATA[
|
||||
False positive, CVE only affects plugins and devtools are not included in production builds
|
||||
]]></notes>
|
||||
<packageUrl regex="true">^pkg:maven/org\.springframework\.boot/spring-boot-devtools@.*$</packageUrl>
|
||||
<cve>CVE-2022-31691</cve>
|
||||
</suppress>
|
||||
</suppressions>
|
||||
181
pom.xml
181
pom.xml
@@ -1,32 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.mattrixwv.cipherstream</groupId>
|
||||
<artifactId>cipherstream-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0.0</version>
|
||||
<version>1.2.0</version>
|
||||
<name>CipherStream API</name>
|
||||
<url>https://api.cipherstream.mattrixwv.com</url>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Matthew Ellison</name>
|
||||
<email>m_ellison@ymail.com</email>
|
||||
<url>https://git.mattrixwv.com/matthew</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git://git.mattrixwv.com/HomeLab/CipherStreamAPI.git</connection>
|
||||
<developerConnection>scm:git:ssh://git.mattrixwv.com/HomeLab/CipherStreamAPI.git</developerConnection>
|
||||
<url>https://git.mattrixwv.com/HomeLab/CipherStreamAPI</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<!--Compile-->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<java.version>21</java.version>
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
<java.version>25</java.version>
|
||||
|
||||
<!--Sonarqube-->
|
||||
<sonar.java.source>21</sonar.java.source>
|
||||
<sonar.java.source>25</sonar.java.source>
|
||||
<sonar.dependencyCheck.jsonReportPath>target/dependency-check-report.json</sonar.dependencyCheck.jsonReportPath>
|
||||
<sonar.dependencyCheck.htmlReportPath>target/dependency-check-report.html</sonar.dependencyCheck.htmlReportPath>
|
||||
|
||||
<argLine></argLine>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.5</version>
|
||||
<version>4.0.2</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -44,19 +60,29 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!--Boilerplate Generator-->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.32</version>
|
||||
<version>1.18.42</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -64,7 +90,7 @@
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.13</version>
|
||||
<version>2.0.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -73,7 +99,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-layout-template-json</artifactId>
|
||||
<version>2.23.1</version>
|
||||
<version>2.25.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
@@ -85,14 +111,14 @@
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.22</version>
|
||||
<version>1.9.25.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--My libraries-->
|
||||
<dependency>
|
||||
<groupId>com.mattrixwv</groupId>
|
||||
<artifactId>cipher-stream-java</artifactId>
|
||||
<version>1.3.4</version>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--Tests-->
|
||||
@@ -105,17 +131,63 @@
|
||||
<groupId>com.vaadin.external.google</groupId>
|
||||
<artifactId>android-json</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.simplify4u</groupId>
|
||||
<artifactId>slf4j2-mock</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!--Ensure maven is the correct version-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-maven</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>properties</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
<!--Sonarqube-->
|
||||
<plugin>
|
||||
<groupId>org.owasp</groupId>
|
||||
<artifactId>dependency-check-maven</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -125,13 +197,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-maven</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<version>3.6.2</version>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
@@ -139,26 +205,32 @@
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.9.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<version>3.4.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<version>3.14.1</version>
|
||||
<configuration>
|
||||
<compilerArgs>
|
||||
<arg>-Xlint:all</arg>
|
||||
<arg>-proc:full</arg>
|
||||
<arg>-Xlint:-serial</arg>
|
||||
<arg>-Xlint:-processing</arg>
|
||||
</compilerArgs>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
@@ -167,36 +239,34 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.2.5</version>
|
||||
<version>3.5.4</version>
|
||||
<configuration>
|
||||
<skipTests>${skip.unit.tests}</skipTests>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
</excludes>
|
||||
<classpathDependencyExcludes>
|
||||
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j2-impl</classpathDependencyExclude>
|
||||
</classpathDependencyExcludes>
|
||||
<argLine>@{argLine} -Xshare:off -javaagent:${org.mockito:mockito-core:jar}</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.1.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<version>3.1.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>3.2.5</version>
|
||||
<version>3.5.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
@@ -204,9 +274,7 @@
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
</includes>
|
||||
<classpathDependencyExcludes>
|
||||
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j2-impl</classpathDependencyExclude>
|
||||
</classpathDependencyExcludes>
|
||||
<argLine>@{argLine} -Xshare:off -javaagent:${org.mockito:mockito-core:jar}</argLine>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -214,17 +282,17 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.12.1</version>
|
||||
<version>3.21.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<version>3.9.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>versions-maven-plugin</artifactId>
|
||||
<version>2.16.2</version>
|
||||
<version>2.21.0</version>
|
||||
<configuration>
|
||||
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
||||
</configuration>
|
||||
@@ -233,12 +301,12 @@
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>3.11.0.3922</version>
|
||||
<version>5.5.0.6356</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.12</version>
|
||||
<version>0.8.14</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/CipherStreamAPI*</exclude>
|
||||
@@ -264,23 +332,22 @@
|
||||
<plugin>
|
||||
<groupId>org.owasp</groupId>
|
||||
<artifactId>dependency-check-maven</artifactId>
|
||||
<version>9.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<version>12.2.0</version>
|
||||
<configuration>
|
||||
<formats>
|
||||
<format>json</format>
|
||||
<format>html</format>
|
||||
</formats>
|
||||
<nvdApiServerId>nvd</nvdApiServerId>
|
||||
<failBuildOnCVSS>7</failBuildOnCVSS>
|
||||
<ossIndexServerId>ossindex</ossIndexServerId>
|
||||
<suppressionFiles>
|
||||
<suppressionFile>${project.basedir}/dependencySuppression.xml</suppressionFile>
|
||||
</suppressionFiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
|
||||
@@ -4,11 +4,11 @@ package com.mattrixwv.cipherstream.aspect;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -35,7 +35,17 @@ public class CipherStreamLoggingAspect{
|
||||
|
||||
@AfterReturning(pointcut = "cipherMethod() && postFunction()", returning = "returnedJson")
|
||||
public void getCipherInfo(ObjectNode returnedJson){
|
||||
//Extract JSON to MDC
|
||||
returnedJson.properties().forEach(entry -> {
|
||||
if(entry.getValue().isString()){
|
||||
MDC.put(entry.getKey(), entry.getValue().asString());
|
||||
}
|
||||
else{
|
||||
MDC.put(entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
});
|
||||
|
||||
//Print a log
|
||||
log.info("CipherStream log {}", returnedJson);
|
||||
log.info("CipherStream log");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.mattrixwv.cipherstream.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
@@ -20,11 +20,26 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Component
|
||||
public class FullFilter extends OncePerRequestFilter{
|
||||
@Override
|
||||
protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain filterChain) throws ServletException, IOException{
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException{
|
||||
if(!request.getMethod().equalsIgnoreCase("OPTIONS")){
|
||||
setupMDC(request);
|
||||
}
|
||||
|
||||
//Continue to the controller
|
||||
filterChain.doFilter(request, response);
|
||||
|
||||
//Clear the MDC for the next request
|
||||
MDC.clear();
|
||||
}
|
||||
|
||||
private void setupMDC(HttpServletRequest request){
|
||||
//Get the requestId
|
||||
if(request.getHeader("X-Request-Id") != null){
|
||||
MDC.put("requestId", request.getHeader("X-Request-Id"));
|
||||
}
|
||||
else{
|
||||
MDC.put("requestId", UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
//Get IP address
|
||||
if(request.getHeader("X-Forwarded-For") != null){
|
||||
@@ -56,11 +71,5 @@ public class FullFilter extends OncePerRequestFilter{
|
||||
|
||||
//Get the path
|
||||
MDC.put("url", request.getRequestURI());
|
||||
|
||||
//Continue to the controller
|
||||
filterChain.doFilter(request, response);
|
||||
|
||||
//Clear the MDC for the next request
|
||||
MDC.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.mattrixwv.cipherstream.config;
|
||||
|
||||
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
@@ -11,9 +11,13 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@Component
|
||||
@EnableWebMvc
|
||||
public class WebConfig implements WebMvcConfigurer{
|
||||
@Value("${allowedOrigins}")
|
||||
private String allowedOrigins;
|
||||
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(@NonNull CorsRegistry registry){
|
||||
public void addCorsMappings(CorsRegistry registry){
|
||||
registry.addMapping("/**")
|
||||
.allowedOriginPatterns("http://localhost:3000");
|
||||
.allowedOriginPatterns(allowedOrigins);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mattrixwv.cipherstream.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class HealthCheckController{
|
||||
@RequestMapping(value = "/health", method = RequestMethod.OPTIONS)
|
||||
public void healthCheck(){
|
||||
log.debug("Health check");
|
||||
}
|
||||
}
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.combination.ADFGVX;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,9 +55,9 @@ public class AdfgvxCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
ADFGVX adfgvx = new ADFGVX(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -79,9 +79,9 @@ public class AdfgvxCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
ADFGVX adfgvx = new ADFGVX(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.combination.ADFGX;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,9 +55,9 @@ public class AdfgxCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
ADFGX adfgx = new ADFGX(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -79,9 +79,9 @@ public class AdfgxCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String squareKeyword = cipherParams.get(CipherParameterUtil.SQUARE_KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
ADFGX adfgx = new ADFGX(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Affine;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -57,7 +57,7 @@ public class AffineCipherController{
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int key1 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_1).asInt();
|
||||
int key2 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_2).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Affine affine = new Affine(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -81,7 +81,7 @@ public class AffineCipherController{
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int key1 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_1).asInt();
|
||||
int key2 = cipherParams.get(CipherParameterUtil.AFFINE_KEY_2).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Affine affine = new Affine(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Atbash;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,7 +55,7 @@ public class AtbashCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Atbash atbash = new Atbash(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -77,7 +77,7 @@ public class AtbashCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Atbash atbash = new Atbash(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Autokey;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class AutokeyCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Autokey autokey = new Autokey(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -78,8 +78,8 @@ public class AutokeyCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Autokey autokey = new Autokey(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Baconian;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -53,7 +53,7 @@ public class BaconianCipherController{
|
||||
|
||||
CipherParameterUtil.verifyBaconianParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Baconian baconian = new Baconian(preserveCapitals);
|
||||
@@ -73,7 +73,7 @@ public class BaconianCipherController{
|
||||
|
||||
CipherParameterUtil.verifyBaconianParams(cipherParams);
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Baconian baconian = new Baconian(preserveCapitals);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.BaseX;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -52,7 +52,7 @@ public class BaseXCipherController{
|
||||
|
||||
|
||||
CipherParameterUtil.verifyBaseXParams(cipherParams);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
int base = cipherParams.get(CipherParameterUtil.BASE_X_BASE).asInt();
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class BaseXCipherController{
|
||||
|
||||
|
||||
CipherParameterUtil.verifyBaseXParams(cipherParams);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
int base = cipherParams.get(CipherParameterUtil.BASE_X_BASE).asInt();
|
||||
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Beaufort;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class BeaufortCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Beaufort beaufort = new Beaufort(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -78,8 +78,8 @@ public class BeaufortCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Beaufort beaufort = new Beaufort(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Caesar;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -56,7 +56,7 @@ public class CaesarCipherController{
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int shiftAmount = cipherParams.get(CipherParameterUtil.CAESAR_SHIFT_AMOUNT).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Caesar caesar = new Caesar(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -79,7 +79,7 @@ public class CaesarCipherController{
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int shiftAmount = cipherParams.get(CipherParameterUtil.CAESAR_SHIFT_AMOUNT).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
Caesar caesar = new Caesar(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
String outputString = caesar.decode(shiftAmount, inputString);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.OneTimePad;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class OneTimePadCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
OneTimePad oneTimePad = new OneTimePad(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -78,8 +78,8 @@ public class OneTimePadCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
OneTimePad oneTimePad = new OneTimePad(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Porta;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class PortaCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Porta porta = new Porta(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -78,8 +78,8 @@ public class PortaCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Porta porta = new Porta(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Substitution;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class SubstitutionCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Substitution substitution = new Substitution(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -78,8 +78,8 @@ public class SubstitutionCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Substitution substitution = new Substitution(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.monosubstitution.Vigenere;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class VigenereCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Vigenere vigenere = new Vigenere(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -78,8 +78,8 @@ public class VigenereCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Vigenere vigenere = new Vigenere(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Bifid;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class BifidCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Bifid bifid = new Bifid(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -78,8 +78,8 @@ public class BifidCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Bifid bifid = new Bifid(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Columnar;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class ColumnarCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Columnar columnar = new Columnar(preserveCapitals, preserveWhitespace, preserveSymbols, true);
|
||||
@@ -78,8 +78,8 @@ public class ColumnarCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Columnar columnar = new Columnar(preserveCapitals, preserveWhitespace, preserveSymbols, true);
|
||||
|
||||
@@ -12,15 +12,14 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Hill;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -48,7 +47,7 @@ public class HillCipherController{
|
||||
}
|
||||
|
||||
@PostMapping("/encode")
|
||||
public ObjectNode encodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
|
||||
public ObjectNode encodeHill(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
log.info("Encoding {}", hillName);
|
||||
|
||||
@@ -58,7 +57,7 @@ public class HillCipherController{
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int[][] key = new ObjectMapper().treeToValue(cipherParams.get(CipherParameterUtil.HILL_KEY), int[][].class);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Hill hill = new Hill(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -71,7 +70,7 @@ public class HillCipherController{
|
||||
}
|
||||
|
||||
@PostMapping("/decode")
|
||||
public ObjectNode decodeHill(@RequestBody ObjectNode cipherParams) throws JsonProcessingException{
|
||||
public ObjectNode decodeHill(@RequestBody ObjectNode cipherParams){
|
||||
MDC.put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
log.info("Decoding {}", hillName);
|
||||
|
||||
@@ -81,7 +80,7 @@ public class HillCipherController{
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int[][] key = new ObjectMapper().treeToValue(cipherParams.get(CipherParameterUtil.HILL_KEY), int[][].class);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Hill hill = new Hill(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Morse;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -52,7 +52,7 @@ public class MorseCodeController{
|
||||
|
||||
|
||||
CipherParameterUtil.verifyMorseParams(cipherParams);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Morse morse = new Morse();
|
||||
@@ -71,7 +71,7 @@ public class MorseCodeController{
|
||||
|
||||
|
||||
CipherParameterUtil.verifyMorseParams(cipherParams);
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Morse morse = new Morse();
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Playfair;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,8 +55,8 @@ public class PlayfairCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Playfair playfair = new Playfair(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -78,8 +78,8 @@ public class PlayfairCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Playfair playfair = new Playfair(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.PolybiusSquare;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -54,8 +54,8 @@ public class PolybiusSquareController{
|
||||
CipherParameterUtil.verifyPolybiusParams(cipherParams);
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
PolybiusSquare polybiusSquare = new PolybiusSquare(preserveWhitespace, preserveSymbols);
|
||||
@@ -76,8 +76,8 @@ public class PolybiusSquareController{
|
||||
CipherParameterUtil.verifyPolybiusParams(cipherParams);
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
PolybiusSquare polybiusSquare = new PolybiusSquare(preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.RailFence;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -56,7 +56,7 @@ public class RailFenceController{
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int rails = cipherParams.get(CipherParameterUtil.RAIL_FENCE_RAILS).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
RailFence railFence = new RailFence(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
@@ -79,7 +79,7 @@ public class RailFenceController{
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
int rails = cipherParams.get(CipherParameterUtil.RAIL_FENCE_RAILS).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
RailFence railFence = new RailFence(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.polysubstitution.Trifid;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -55,10 +55,10 @@ public class TrifidCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
char fill = cipherParams.get(CipherParameterUtil.TRIFID_FILL).asText().charAt(0);
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
char fill = cipherParams.get(CipherParameterUtil.TRIFID_FILL).asString().charAt(0);
|
||||
int groupLength = cipherParams.get(CipherParameterUtil.TRIFID_GROUP_LENGTH).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Trifid trifid = new Trifid(preserveCapitals, preserveWhitespace, preserveSymbols, fill);
|
||||
@@ -80,10 +80,10 @@ public class TrifidCipherController{
|
||||
boolean preserveCapitals = cipherParams.get(CipherParameterUtil.PRESERVE_CAPITALS).asBoolean();
|
||||
boolean preserveWhitespace = cipherParams.get(CipherParameterUtil.PRESERVE_WHITESPACE).asBoolean();
|
||||
boolean preserveSymbols = cipherParams.get(CipherParameterUtil.PRESERVE_SYMBOLS).asBoolean();
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asText();
|
||||
char fill = cipherParams.get(CipherParameterUtil.TRIFID_FILL).asText().charAt(0);
|
||||
String keyword = cipherParams.get(CipherParameterUtil.KEYWORD).asString();
|
||||
char fill = cipherParams.get(CipherParameterUtil.TRIFID_FILL).asString().charAt(0);
|
||||
int groupLength = cipherParams.get(CipherParameterUtil.TRIFID_GROUP_LENGTH).asInt();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asText();
|
||||
String inputString = cipherParams.get(CipherParameterUtil.INPUT_STRING).asString();
|
||||
|
||||
|
||||
Trifid trifid = new Trifid(preserveCapitals, preserveWhitespace, preserveSymbols, fill);
|
||||
|
||||
@@ -3,10 +3,9 @@ package com.mattrixwv.cipherstream.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.mattrixwv.cipherstream.utils;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
@@ -74,7 +74,7 @@ public class CipherParameterUtil{
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
if(!params.get(INPUT_STRING).isString()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class CipherParameterUtil{
|
||||
if(!params.has(KEYWORD)){
|
||||
throw new InvalidCipherParameterException(KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(KEYWORD).isTextual()){
|
||||
if(!params.get(KEYWORD).isString()){
|
||||
throw new InvalidCipherParameterException(KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class CipherParameterUtil{
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
if(!params.get(INPUT_STRING).isString()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class CipherParameterUtil{
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
if(!params.get(INPUT_STRING).isString()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class CipherParameterUtil{
|
||||
if(!params.has(SQUARE_KEYWORD)){
|
||||
throw new InvalidCipherParameterException(SQUARE_KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(SQUARE_KEYWORD).isTextual()){
|
||||
if(!params.get(SQUARE_KEYWORD).isString()){
|
||||
throw new InvalidCipherParameterException(SQUARE_KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public class CipherParameterUtil{
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
if(!params.get(INPUT_STRING).isString()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
@@ -210,14 +210,14 @@ public class CipherParameterUtil{
|
||||
if(!params.has(INPUT_STRING)){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(INPUT_STRING).isTextual()){
|
||||
if(!params.get(INPUT_STRING).isString()){
|
||||
throw new InvalidCipherParameterException(INPUT_STRING + TEXT_MESSAGE);
|
||||
}
|
||||
|
||||
if(!params.has(KEYWORD)){
|
||||
throw new InvalidCipherParameterException(KEYWORD + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(KEYWORD).isTextual()){
|
||||
if(!params.get(KEYWORD).isString()){
|
||||
throw new InvalidCipherParameterException(KEYWORD + TEXT_MESSAGE);
|
||||
}
|
||||
}
|
||||
@@ -239,10 +239,10 @@ public class CipherParameterUtil{
|
||||
if(!params.has(TRIFID_FILL)){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + PRESENT_MESSAGE);
|
||||
}
|
||||
if(!params.get(TRIFID_FILL).isTextual()){
|
||||
if(!params.get(TRIFID_FILL).isString()){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + TEXT_MESSAGE);
|
||||
}
|
||||
if(params.get(TRIFID_FILL).asText().length() > 1){
|
||||
if(params.get(TRIFID_FILL).asString().length() > 1){
|
||||
throw new InvalidCipherParameterException(TRIFID_FILL + CHARACTER_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"groups":[
|
||||
],
|
||||
"properties":[
|
||||
{
|
||||
"name": "allowed-origins",
|
||||
"type": "java.lang.String",
|
||||
"description": "Allowed CORS origins",
|
||||
"defaultValue": "http://localhost:3000"
|
||||
}
|
||||
],
|
||||
"hints":[
|
||||
{
|
||||
"name": "allowed-origins",
|
||||
"values": [
|
||||
{
|
||||
"value": "http://localhost:3000",
|
||||
"description": "Local development"
|
||||
},
|
||||
{
|
||||
"value": "https://api.cipherstream.mattrixwv.com",
|
||||
"description": "Production"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1 +1,8 @@
|
||||
#Server options
|
||||
spring.web.error.include-stacktrace=always
|
||||
server.port=8001
|
||||
server.shutdown=graceful
|
||||
spring.lifecycle.timeoutPerShutdownPhase=10s
|
||||
|
||||
#CORS
|
||||
allowedOrigins=http://localhost:3000
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#Mono-Substitution
|
||||
#Affine
|
||||
cipher.mono.affine.name=Affine
|
||||
cipher.mono.affine.description=The Affine cipher is a monoalphabetic substitution cipher where each letter in the alphabet is mapped to a numeric equivalent and encrypted using a mathematical function.
|
||||
cipher.mono.affine.description=The Affine cipher is a mono-alphabetic substitution cipher where each letter in the alphabet is mapped to a numeric equivalent and encrypted using a mathematical function.
|
||||
cipher.mono.affine.explanation={\
|
||||
"Encryption is performed by converting every letter to a number with a = 0, b = 1, c = 2, etc., then applying a function to each number, then converting each number back to a letter.",\
|
||||
"The formula used in this encryption is F(x) = (ax + b) % m, where x is the original letter, a and b are the keys of the cipher, and m is the length of the alphabet, with a and m being coprime.",\
|
||||
"The formula used in this encryption is F(x) = (ax + b) % m, where x is the original letter, a and b are the keys of the cipher, and m is the length of the alphabet, with a and m being co-prime.",\
|
||||
"Decryption is performed using the formula F(x) = a^-1(x - b) % m.",\
|
||||
"The Affine cipher is a relatively weak cipher compared to modern encryption methods because it's vulnerable to frequency analysis and other cryptanalysis techniques. However, it's simple to implement and understand, making it a good introduction to encryption concepts."\
|
||||
}
|
||||
@@ -15,7 +15,7 @@ cipher.mono.affine.facts={\
|
||||
cipher.mono.atbash.name=Atbash
|
||||
cipher.mono.atbash.description=The Atbash cipher is a substitution cipher where each letter of the plaintext is replaced by its counterpart in the reverse alphabet.
|
||||
cipher.mono.atbash.explanation={\
|
||||
"The Atbash cipher is a monoalphabetic substitution cipher and is one of the simplest and oldest forms of encryption.",\
|
||||
"The Atbash cipher is a mono-alphabetic substitution cipher and is one of the simplest and oldest forms of encryption.",\
|
||||
"Encryption involves replacing each letter with its reverse counterpart. i.e. A becomes Z, B becomes Y, etc.",\
|
||||
"Decryption is performed using the same formula as encryption.",\
|
||||
"Atbash cipher can effectively obscure the meaning of a message to those unfamiliar with the technique. However, it's very vulnerable to cryptanalysis, especially frequency analysis, and it provides very little security against modern decryption techniques."\
|
||||
@@ -28,7 +28,7 @@ cipher.mono.atbash.facts={\
|
||||
|
||||
#Autokey
|
||||
cipher.mono.autokey.name=Autokey
|
||||
cipher.mono.autokey.description=The Autokey cipher is a polyalphabetic substitution cipher where each letter of the plaintext is combined with a letter from a predetermined key sequence to generate the ciphertext.
|
||||
cipher.mono.autokey.description=The Autokey cipher is a poly-alphabetic substitution cipher where each letter of the plaintext is combined with a letter from a predetermined key sequence to generate the ciphertext.
|
||||
cipher.mono.autokey.explanation={\
|
||||
"The autokey cipher extends the Vigenere cipher. Like the Vigenere cipher it uses a keyword to encrypt plaintext, but it also incorporates the plaintext itself into the key stream.",\
|
||||
"Encryption works by concatenating the message to the keyword. Then you convert the resulting key into a series of numeric values mod 26. Then you advance each letter the indicated number of letters similar to the Caesar cipher.",\
|
||||
@@ -36,7 +36,7 @@ cipher.mono.autokey.explanation={\
|
||||
"The Autokey cipher is more secure than the Vigenere cipher due to the keyword including part of the text to be encoded. However, like the Vigenere cipher, the Autokey cipher is vulnerable to frequency analysis and other cryptanalysis techniques, especially if the keyword is short or if there are patterns in the plaintext."\
|
||||
}
|
||||
cipher.mono.autokey.facts={\
|
||||
"The Autokey cipher was the inspiriation for the ADFGVX cipher, which Germany used during World War I",\
|
||||
"The Autokey cipher was the inspiration for the ADFGVX cipher, which Germany used during World War I",\
|
||||
"It has also served as the precursor to more complex modern encryption methods"\
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ cipher.mono.onetimepad.facts={\
|
||||
|
||||
#Porta
|
||||
cipher.mono.porta.name=Porta
|
||||
cipher.mono.porta.description=The Porta cipher is a polyalphabetic substitution cipher where each letter in the plaintext is shifted based on a keyword, using a fixed tabula.
|
||||
cipher.mono.porta.description=The Porta cipher is a poly-alphabetic substitution cipher where each letter in the plaintext is shifted based on a keyword, using a fixed tabula.
|
||||
cipher.mono.porta.explanation={\
|
||||
"The Porta cipher, also known as the Porta square or Portax cipher, is a variant of the Vigenere cipher and shares some similarities with it.",\
|
||||
"In the Porta cipher, encryption and decryption are performed using a keyword and a tabula recta or Porta square. The Porta square is a table that consists of 26 rows and 26 columns, where each row represents the alphabet shifted by a certain number of positions.",\
|
||||
@@ -121,8 +121,8 @@ cipher.mono.porta.explanation={\
|
||||
}
|
||||
cipher.mono.porta.facts={\
|
||||
"It was invented by Giovanni Battista della Porta in the 16th century.",\
|
||||
"It is one of the earliest known polyalphabetic ciphers, preceding the Vigenere cipher by several centuries.",\
|
||||
"It was one of the first ciphers to use a keyword to deetermine the alphabetic shift."\
|
||||
"It is one of the earliest known poly-alphabetic ciphers, preceding the Vigenere cipher by several centuries.",\
|
||||
"It was one of the first ciphers to use a keyword to determine the alphabetic shift."\
|
||||
}
|
||||
|
||||
#Substitution
|
||||
@@ -142,9 +142,9 @@ cipher.mono.substitution.facts={\
|
||||
|
||||
#Vigenere
|
||||
cipher.mono.vigenere.name=Vigenere
|
||||
cipher.mono.vigenere.description=The Vigenere cipher is a polyalphabetic encryption method that uses a keyword and series of interwoven Caesar ciphers.
|
||||
cipher.mono.vigenere.description=The Vigenere cipher is a poly-alphabetic encryption method that uses a keyword and series of interwoven Caesar ciphers.
|
||||
cipher.mono.vigenere.explanation={\
|
||||
"The Vigenere cipher adds more security compared to simple monoalphabetic substitution ciphers like the Caesar cipher.",\
|
||||
"The Vigenere cipher adds more security compared to simple mono-alphabetic substitution ciphers like the Caesar cipher.",\
|
||||
"In the Vigenere cipher, encryption and decryption are performed using a keyword or keyphrase. The key is used to determine the shift applied to each letter in the plaintext, with different parts of the key determining different shifts.",\
|
||||
"Decryption is performed by applying the reverse process. Given the ciphertext and the keyword, the original plaintext can be recovered.",\
|
||||
"The Vigenere cipher provides stronger encryption compared to simple substitution ciphers because it uses multiple Caesar ciphers in a repeating pattern determined by the keyword.",\
|
||||
@@ -153,7 +153,7 @@ cipher.mono.vigenere.explanation={\
|
||||
}
|
||||
cipher.mono.vigenere.facts={\
|
||||
"It was invented by Giovan Battista Bellaso in the 16th century and later misattributed to Blaise de Vigenere, hence the name.",\
|
||||
"It is one of the earliest known examples of a polyalphabetic substitution cipher.",\
|
||||
"It is one of the earliest known examples of a poly-alphabetic substitution cipher.",\
|
||||
"It was cracked in the mid-19th century by Charles Babbage's assistant, Friedrich Kasiski. The method now known as the Kasiski examination exploits the repeated patters in the ciphertext to determine the length of the keyword."\
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ cipher.mono.vigenere.facts={\
|
||||
cipher.poly.bifid.name=Bifid
|
||||
cipher.poly.bifid.description=The Bifid cipher involves converting plaintext characters into coordinates in a 5x5 grid, then transposing them into a single string using a keyword.
|
||||
cipher.poly.bifid.explanation={\
|
||||
"The Bifid cipher is a type of polyalphabetic substitution cipher that combines elements of both transposition and substitution.",\
|
||||
"The Bifid cipher is a type of poly-alphabetic substitution cipher that combines elements of both transposition and substitution.",\
|
||||
"It was invented by Felix Delastelle in 1901 and was considered one of the strongest ciphers at the time due to its complexity.",\
|
||||
"Encryption is done by creating a 5x5 grid, known as the Polybius square, is created. The letters of the alphabet (excluding 'J' in most cases) are arranged in the grid, typically starting with 'A' and ending with 'Z', omitting 'J'.",\
|
||||
"Each letter of the plaintext is first converted into its corresponding row and column numbers in the grid. For example, the letter 'C' may correspond to the row 1, column 3. These numerical representations are then combined into pairs of numbers.",\
|
||||
@@ -212,7 +212,7 @@ cipher.poly.morse.name=Morse Code
|
||||
cipher.poly.morse.description=Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks, with each character represented by a unique sequence of dots and dashes.
|
||||
cipher.poly.morse.explanation={\
|
||||
"Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks. Morse code encodes characters (letters, numbers, and punctuation) as sequences of dots (short signals) and dashes (long signals) arranged in specific patterns.",\
|
||||
"The basic elemens of Morse Code are dots and dashes. Each letter, number, or punctuation mark is represented by a unique combination of dots and dashes. Numbers and punctuation marks also have their own Morse code representations.",\
|
||||
"The basic elements of Morse Code are dots and dashes. Each letter, number, or punctuation mark is represented by a unique combination of dots and dashes. Numbers and punctuation marks also have their own Morse code representations.",\
|
||||
"Morse code has been widely used in various forms of communication, including telegraphy, radio communication, aviation, and navigation. Despite advances in technology, Morse code remains relevant today, particularly in emergency communication, amateur radio, and certain military applications. It is also used by some individuals for its simplicity and effectiveness in situations where other forms of communication may be unreliable or unavailable."\
|
||||
}
|
||||
cipher.poly.morse.facts={\
|
||||
@@ -272,9 +272,9 @@ cipher.poly.railfence.facts={\
|
||||
cipher.poly.trifid.name=Trifid
|
||||
cipher.poly.trifid.description=The Trifid cipher is a polygraphic substitution cipher substituting each letter in the plaintext with coordinates in a 3x3x3 grid.
|
||||
cipher.poly.trifid.explanation={\
|
||||
"The trifid cipher is a polygraphic substitution cipher and is an extention of the Bifid cipher.",\
|
||||
"The trifid cipher is a polygraphic substitution cipher and is an extension of the Bifid cipher.",\
|
||||
"To encode, a key matrix is generated, typically a permutation of the alphabet plus some additional symbols. Each letter of the plaintext is converted into its corresponding coordinates in the 3x3x3 grid. For example, if the letter is 'A', it could be represented as (1,1,1).",\
|
||||
"The coordinates are then rearranged according to the key matrix and teh plaintext coordinate is (1,1,1), in might be rearranged to 2,3,1 based on the position of 'A' in the key matrix. The rearranged coordinates are converted back into letters.",\
|
||||
"The coordinates are then rearranged according to the key matrix and the plaintext coordinate is (1,1,1), it might be rearranged to 2,3,1 based on the position of 'A' in the key matrix. The rearranged coordinates are converted back into letters.",\
|
||||
"The process is reversed. The ciphertext is first converted into coordinates, rearranged back using the key matrix, and then converted back into plaintext.",\
|
||||
"The Trifid cipher provides a higher degree of security compared to simpler ciphers like Caesar or Atbash, but it's still vulnerable to cryptanalysis, especially with modern computational methods. Despite its age, it remains an interesting historical cipher and is occasionally used in puzzles and cryptography challenges."\
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
</Pattern>
|
||||
</PatternLayout>
|
||||
</Console>
|
||||
|
||||
|
||||
<RollingRandomAccessFile name="file" fileName="cipherStreamAPI.log" filePattern="%d{MM-dd-yyyy}-cipherStreamAPI.log.gz" immediateFlush="true">
|
||||
<JsonTemplateLayout eventTemplateUri="classpath:template.json"></JsonTemplateLayout>
|
||||
<Policies>
|
||||
@@ -17,6 +19,16 @@
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="20"/>
|
||||
</RollingRandomAccessFile>
|
||||
|
||||
|
||||
<Console name="consoleJSON" target="SYSTEM_OUT">
|
||||
<JsonTemplateLayout eventTemplateUri="classpath:template.json"/>
|
||||
</Console>
|
||||
|
||||
|
||||
<Socket name="graylog" host="loggingpi.mattrixwv.com" port="1502">
|
||||
<JsonTemplateLayout eventTemplateUri="classpath:template.json"/>
|
||||
</Socket>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
|
||||
@@ -2,16 +2,21 @@
|
||||
"timestamp": {
|
||||
"$resolver": "timestamp",
|
||||
"pattern": {
|
||||
"format": "yyy-MM-dd HH:mm:ss.SSSZ"
|
||||
"format": "yyyy-MM-dd HH:mm:ss.SSSZ"
|
||||
}
|
||||
},
|
||||
"level": {
|
||||
"$resolver": "level",
|
||||
"field": "name"
|
||||
},
|
||||
"requestId": {
|
||||
"logger": {
|
||||
"$resolver": "logger",
|
||||
"field": "name"
|
||||
},
|
||||
"mdc":{
|
||||
"$resolver": "mdc",
|
||||
"key": "requestId"
|
||||
"flatten": false,
|
||||
"stringified": false
|
||||
},
|
||||
"message": {
|
||||
"$resolver": "message",
|
||||
|
||||
@@ -9,8 +9,8 @@ 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 tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@@ -42,7 +42,7 @@ public class CipherStreamLoggingAspectTest{
|
||||
jsonNode.put("something", "Something Important");
|
||||
|
||||
|
||||
aspect.getCipherInfo(null);
|
||||
aspect.getCipherInfo(jsonNode);
|
||||
|
||||
|
||||
assertNotNull(aspect);
|
||||
|
||||
@@ -6,23 +6,18 @@ import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = CaesarCipherController.class)
|
||||
@@ -30,24 +25,19 @@ public class FullFilterIntegrationTest{
|
||||
//HTTP
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Mock
|
||||
private HttpServletRequest request;
|
||||
@Mock
|
||||
private HttpServletResponse response;
|
||||
//Logging
|
||||
@Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
|
||||
private Logger logger;
|
||||
@Mock
|
||||
private MDCAdapter mdc;
|
||||
@MockitoSpyBean
|
||||
private FullFilter fullFilter;
|
||||
//Fields
|
||||
private static final String url = "/caesar";
|
||||
private static final String URL = "/caesar";
|
||||
private UUID requestId = UUID.randomUUID();
|
||||
private String ipAddresses = "192.168.1.1,192.168.1.2,192.168.1.3";
|
||||
@Value("${cipher.mono.caesar.name}")
|
||||
private String caesarName;
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddresses)
|
||||
.param("param1", "value1")
|
||||
@@ -56,22 +46,30 @@ public class FullFilterIntegrationTest{
|
||||
.param("_", "value3"))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verify(logger, times(1)).info(eq("Request parameters: {}"), any(StringJoiner.class));
|
||||
verify(mdc, times(1)).put("requestId", requestId.toString());
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).clear();
|
||||
verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_NoParameters() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
public void testDoFilterInternal_noParameters() throws Exception{
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddresses))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verify(logger, never()).info(anyString(), any(Object.class));
|
||||
verify(mdc, times(1)).put("requestId", requestId.toString());
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).clear();
|
||||
verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_options() throws Exception{
|
||||
mockMvc.perform(options(URL)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddresses)
|
||||
.param("param1", "value1")
|
||||
.param("param2", "value2.1")
|
||||
.param("param2", "value2.2")
|
||||
.param("_", "value3"))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public class FullFilterTest{
|
||||
parameterMap.put("_", new String[]{"value3"});
|
||||
|
||||
|
||||
doReturn("GET").when(request).getMethod();
|
||||
doReturn("X-Request-Id").when(request).getHeader("X-Request-Id");
|
||||
doReturn("192.168.1.1,192.168.1.2,192.168.1.3").when(request).getHeader("X-Forwarded-For");
|
||||
doReturn(parameterMap).when(request).getParameterMap();
|
||||
@@ -47,14 +48,18 @@ public class FullFilterTest{
|
||||
fullFilter.doFilterInternal(request, response, filterChain);
|
||||
|
||||
|
||||
verify(request, times(1)).getMethod();
|
||||
verify(request, times(2)).getHeader("X-Request-Id");
|
||||
verify(request, times(2)).getHeader("X-Forwarded-For");
|
||||
verify(request, times(1)).getParameterMap();
|
||||
verifyNoMoreInteractions(request);
|
||||
verify(filterChain, times(1)).doFilter(request, response);
|
||||
verifyNoMoreInteractions(filterChain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_NoParameters() throws Exception{
|
||||
doReturn("GET").when(request).getMethod();
|
||||
doReturn("X-Request-Id").when(request).getHeader("X-Request-Id");
|
||||
doReturn("192.168.1.1,192.168.1.2,192.168.1.3").when(request).getHeader("X-Forwarded-For");
|
||||
doReturn(new HashMap<>()).when(request).getParameterMap();
|
||||
@@ -64,14 +69,18 @@ public class FullFilterTest{
|
||||
fullFilter.doFilterInternal(request, response, filterChain);
|
||||
|
||||
|
||||
verify(request, times(1)).getMethod();
|
||||
verify(request, times(2)).getHeader("X-Request-Id");
|
||||
verify(request, times(2)).getHeader("X-Forwarded-For");
|
||||
verify(request, times(1)).getParameterMap();
|
||||
verifyNoMoreInteractions(request);
|
||||
verify(filterChain, times(1)).doFilter(request, response);
|
||||
verifyNoMoreInteractions(filterChain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_noHeaders() throws Exception{
|
||||
doReturn("GET").when(request).getMethod();
|
||||
doReturn(new HashMap<>()).when(request).getParameterMap();
|
||||
doReturn("/testURL").when(request).getRequestURI();
|
||||
|
||||
@@ -79,9 +88,26 @@ public class FullFilterTest{
|
||||
fullFilter.doFilterInternal(request, response, filterChain);
|
||||
|
||||
|
||||
verify(request, times(1)).getMethod();
|
||||
verify(request, times(1)).getHeader("X-Request-Id");
|
||||
verify(request, times(1)).getHeader("X-Forwarded-For");
|
||||
verify(request, times(1)).getParameterMap();
|
||||
verifyNoMoreInteractions(request);
|
||||
verify(filterChain, times(1)).doFilter(request, response);
|
||||
verifyNoMoreInteractions(filterChain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_options() throws Exception{
|
||||
doReturn("OPTIONS").when(request).getMethod();
|
||||
|
||||
|
||||
fullFilter.doFilterInternal(request, response, filterChain);
|
||||
|
||||
|
||||
verify(request, times(1)).getMethod();
|
||||
verifyNoMoreInteractions(request);
|
||||
verify(filterChain, times(1)).doFilter(request, response);
|
||||
verifyNoMoreInteractions(filterChain);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,53 +4,49 @@ package com.mattrixwv.cipherstream.controller;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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 org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
|
||||
|
||||
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;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@Import({AopAutoConfiguration.class, FullFilter.class, CipherStreamLoggingAspect.class})
|
||||
public class CipherStreamControllerIntegrationTestBase{
|
||||
protected static final ObjectMapper mapper = new ObjectMapper();
|
||||
//Filter
|
||||
@MockitoSpyBean
|
||||
private FullFilter fullFilter;
|
||||
//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;
|
||||
protected ObjectMapper mapper;
|
||||
protected ObjectNode blankNode;
|
||||
protected static final String REQUEST_ID = UUID.randomUUID().toString();
|
||||
protected static final String IP_ADDRESS = "192.168.1.1";
|
||||
|
||||
|
||||
//Misc
|
||||
@Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
|
||||
protected Logger filterLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect")
|
||||
protected Logger aspectLogger;
|
||||
@BeforeEach
|
||||
public void setupJson(){
|
||||
mapper = new ObjectMapper();
|
||||
blankNode = mapper.createObjectNode();
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
@AfterEach
|
||||
public void checkFilter() throws ServletException, IOException{
|
||||
verify(fullFilter, times(1)).doFilter(any(), any(), any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ 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;
|
||||
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -22,15 +23,15 @@ public class ExceptionRestControllerTest{
|
||||
@InjectMocks
|
||||
private ExceptionRestController controller;
|
||||
//Fields
|
||||
private static final String errorMessage = "Error message";
|
||||
private static final String ERROR_MESSAGE = "Error message";
|
||||
|
||||
|
||||
@Test
|
||||
public void testInvalidCipherParameterHandler(){
|
||||
//Setup variables
|
||||
InvalidCipherParameterException error = new InvalidCipherParameterException(errorMessage);
|
||||
InvalidCipherParameterException error = new InvalidCipherParameterException(ERROR_MESSAGE);
|
||||
ObjectNode expectedJson = mapper.createObjectNode();
|
||||
expectedJson.put("message", errorMessage);
|
||||
expectedJson.put("message", ERROR_MESSAGE);
|
||||
|
||||
|
||||
//Run the function
|
||||
@@ -45,9 +46,9 @@ public class ExceptionRestControllerTest{
|
||||
@Test
|
||||
public void testGenericExceptionHandler(){
|
||||
//Setup variables
|
||||
Exception error = new Exception(errorMessage);
|
||||
Exception error = new Exception(ERROR_MESSAGE);
|
||||
ObjectNode expectedJson = mapper.createObjectNode();
|
||||
expectedJson.put("message", errorMessage);
|
||||
expectedJson.put("message", ERROR_MESSAGE);
|
||||
|
||||
|
||||
//Run the function
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.mattrixwv.cipherstream.controller;
|
||||
|
||||
|
||||
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 java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
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.autoconfigure.aop.AopAutoConfiguration;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.config.FullFilter;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("integration-test")
|
||||
@WebMvcTest(controllers = HealthCheckController.class)
|
||||
@Import({AopAutoConfiguration.class, FullFilter.class, CipherStreamLoggingAspect.class})
|
||||
public class HealthCheckControllerIntegrationTest{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@MockitoSpyBean
|
||||
private FullFilter fullFilter;
|
||||
//Fields
|
||||
protected ObjectMapper mapper;
|
||||
protected ObjectNode blankNode;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setupJson(){
|
||||
mapper = new ObjectMapper();
|
||||
blankNode = mapper.createObjectNode();
|
||||
}
|
||||
|
||||
|
||||
@AfterEach
|
||||
public void checkFilter() throws ServletException, IOException{
|
||||
verify(fullFilter, times(1)).doFilter(any(), any(), any());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHealthCheck() throws Exception{
|
||||
mockMvc.perform(options("/health"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,20 +28,16 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private AdfgvxCipherController adfgvxCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgvxCipherController")
|
||||
private Logger adfgvxLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/adfgvx";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String squareKeyword = "SquareKeyword";
|
||||
private static final String adfgvxName = "adfgvxName";
|
||||
private static final String adfgvxDescription = "adfgvxDescription";
|
||||
private static final List<String> adfgvxExplanation = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
|
||||
private static final List<String> adfgvxFacts = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
|
||||
private static final String URL = "/adfgvx";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "AXgvdavfxgagfa afag^aaxdxfgdagda";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String SQUARE_KEYWORD = "SquareKeyword";
|
||||
private static final String ADFGVX_NAME = "adfgvxName";
|
||||
private static final String ADFGVX_DESCRIPTION = "adfgvxDescription";
|
||||
private static final List<String> ADFGVX_EXPLANATION = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
|
||||
private static final List<String> ADFGVX_FACTS = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,127 +46,89 @@ public class AdfgvxCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, SQUARE_KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, SQUARE_KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", adfgvxName);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", adfgvxDescription);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxExplanation", adfgvxExplanation);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxFacts", adfgvxFacts);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", ADFGVX_NAME);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", ADFGVX_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxExplanation", ADFGVX_EXPLANATION);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxFacts", ADFGVX_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(adfgvxName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(adfgvxDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(ADFGVX_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(ADFGVX_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(adfgvxExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(adfgvxExplanation.get(0), adfgvxExplanation.get(1), adfgvxExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(ADFGVX_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(ADFGVX_EXPLANATION.get(0), ADFGVX_EXPLANATION.get(1), ADFGVX_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(adfgvxFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(adfgvxFacts.get(0), adfgvxFacts.get(1), adfgvxFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Getting info for {}", adfgvxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(ADFGVX_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(ADFGVX_FACTS.get(0), ADFGVX_FACTS.get(1), ADFGVX_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", adfgvxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Encoding {}", adfgvxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", adfgvxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgvxLogger, times(1)).info("Decoding {}", adfgvxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -32,23 +33,23 @@ public class AdfgvxCipherControllerTest{
|
||||
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 static final String adfgvxName = "adfgvxName";
|
||||
private static final String adfgvxDescription = "adfgvxDescription";
|
||||
private static final List<String> adfgvxExplanation = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
|
||||
private static final List<String> adfgvxFacts = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
|
||||
private static final String ADFGVX_NAME = "adfgvxName";
|
||||
private static final String ADFGVX_DESCRIPTION = "adfgvxDescription";
|
||||
private static final List<String> ADFGVX_EXPLANATION = List.of("adfgvxExplanation1", "adfgvxExplanation2", "adfgvxExplanation3");
|
||||
private static final List<String> ADFGVX_FACTS = List.of("adfgvxFact1", "adfgvxFact2", "adfgvxFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", adfgvxName);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", adfgvxDescription);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxExplanation", adfgvxExplanation);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxFacts", adfgvxFacts);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxName", ADFGVX_NAME);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxDescription", ADFGVX_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxExplanation", ADFGVX_EXPLANATION);
|
||||
ReflectionTestUtils.setField(adfgvxCipherController, "adfgvxFacts", ADFGVX_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(adfgvxName, adfgvxDescription, adfgvxExplanation, adfgvxFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(ADFGVX_NAME, ADFGVX_DESCRIPTION, ADFGVX_EXPLANATION, ADFGVX_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgvxCipherController.getCipherInfo();
|
||||
@@ -66,7 +67,7 @@ public class AdfgvxCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +86,7 @@ public class AdfgvxCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.combination;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,20 +28,16 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private AdfgxCipherController adfgxCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.combination.AdfgxCipherController")
|
||||
private Logger adfgxLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/adfgx";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String squareKeyword = "SquareKeyword";
|
||||
private static final String adfgxName = "adfgxName";
|
||||
private static final String adfgxDescription = "adfgxDescription";
|
||||
private static final List<String> adfgxExplanation = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
|
||||
private static final List<String> adfgxFacts = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
|
||||
private static final String URL = "/adfgx";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "AAgagadfagaxxd axdx^adafafxddgdf";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String SQUARE_KEYWORD = "SquareKeyword";
|
||||
private static final String ADFGX_NAME = "adfgxName";
|
||||
private static final String ADFGX_DESCRIPTION = "adfgxDescription";
|
||||
private static final List<String> ADFGX_EXPLANATION = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
|
||||
private static final List<String> ADFGX_FACTS = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,127 +46,89 @@ public class AdfgxCipherControllerIntegrationTest extends CipherStreamController
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, SQUARE_KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.SQUARE_KEYWORD, SQUARE_KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", adfgxName);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", adfgxDescription);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxExplanation", adfgxExplanation);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxFacts", adfgxFacts);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", ADFGX_NAME);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", ADFGX_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxExplanation", ADFGX_EXPLANATION);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxFacts", ADFGX_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(adfgxName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(adfgxDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(ADFGX_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(ADFGX_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(adfgxExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(adfgxExplanation.get(0), adfgxExplanation.get(1), adfgxExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(ADFGX_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(ADFGX_EXPLANATION.get(0), ADFGX_EXPLANATION.get(1), ADFGX_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(adfgxFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(adfgxFacts.get(0), adfgxFacts.get(1), adfgxFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Getting info for {}", adfgxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(ADFGX_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(ADFGX_FACTS.get(0), ADFGX_FACTS.get(1), ADFGX_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", adfgxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Encoding {}", adfgxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgx() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", adfgxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(adfgxLogger, times(1)).info("Decoding {}", adfgxName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -32,23 +33,23 @@ public class AdfgxCipherControllerTest{
|
||||
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 static final String adfgxName = "adfgxName";
|
||||
private static final String adfgxDescription = "adfgxDescription";
|
||||
private static final List<String> adfgxExplanation = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
|
||||
private static final List<String> adfgxFacts = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
|
||||
private static final String ADFGX_NAME = "adfgxName";
|
||||
private static final String ADFGX_DESCRIPTION = "adfgxDescription";
|
||||
private static final List<String> ADFGX_EXPLANATION = List.of("adfgxExplanation1", "adfgxExplanation2", "adfgxExplanation3");
|
||||
private static final List<String> ADFGX_FACTS = List.of("adfgxFact1", "adfgxFact2", "adfgxFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", adfgxName);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", adfgxDescription);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxExplanation", adfgxExplanation);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxFacts", adfgxFacts);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxName", ADFGX_NAME);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxDescription", ADFGX_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxExplanation", ADFGX_EXPLANATION);
|
||||
ReflectionTestUtils.setField(adfgxCipherController, "adfgxFacts", ADFGX_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(adfgxName, adfgxDescription, adfgxExplanation, adfgxFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(ADFGX_NAME, ADFGX_DESCRIPTION, ADFGX_EXPLANATION, ADFGX_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = adfgxCipherController.getCipherInfo();
|
||||
@@ -66,7 +67,7 @@ public class AdfgxCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(ADFGX_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +86,7 @@ public class AdfgxCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ADFGX_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(ADFGX_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,20 +28,16 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private AffineCipherController affineCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AffineCipherController")
|
||||
private Logger affineLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/affine";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Pbtthlb yz^burzwb";
|
||||
private static final int key1 = 5;
|
||||
private static final int key2 = 7;
|
||||
private static final String affineName = "affineCipherName";
|
||||
private static final String affineDescription = "affineCipherDescription";
|
||||
private static final List<String> affineExplanation = List.of("affineExplanation1", "affineExplanation2", "affineExplanation3");
|
||||
private static final List<String> affineFacts = List.of("affineFact1", "affineFact2", "affineFact3");
|
||||
private static final String URL = "/affine";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Pbtthlb yz^burzwb";
|
||||
private static final int KEY_1 = 5;
|
||||
private static final int KEY_2 = 7;
|
||||
private static final String AFFINE_NAME = "affineCipherName";
|
||||
private static final String AFFINE_DESCRIPTION = "affineCipherDescription";
|
||||
private static final List<String> AFFINE_EXPLANATION = List.of("affineExplanation1", "affineExplanation2", "affineExplanation3");
|
||||
private static final List<String> AFFINE_FACTS = List.of("affineFact1", "affineFact2", "affineFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,127 +46,89 @@ public class AffineCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.AFFINE_KEY_1, KEY_1);
|
||||
decodedNode.put(CipherParameterUtil.AFFINE_KEY_2, KEY_2);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.AFFINE_KEY_1, KEY_1);
|
||||
encodedNode.put(CipherParameterUtil.AFFINE_KEY_2, KEY_2);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineName", affineName);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineDescription", affineDescription);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineExplanation", affineExplanation);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineFacts", affineFacts);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineName", AFFINE_NAME);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineDescription", AFFINE_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineExplanation", AFFINE_EXPLANATION);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineFacts", AFFINE_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(affineDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(affineName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(AFFINE_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(AFFINE_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(affineExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(affineExplanation.get(0), affineExplanation.get(1), affineExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(AFFINE_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(AFFINE_EXPLANATION.get(0), AFFINE_EXPLANATION.get(1), AFFINE_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(affineFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(affineFacts.get(0), affineFacts.get(1), affineFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Getting info for {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(AFFINE_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(AFFINE_FACTS.get(0), AFFINE_FACTS.get(1), AFFINE_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAffine() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAffine_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Encoding {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAffine() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAffine_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(affineLogger, times(1)).info("Decoding {}", affineName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -27,28 +28,28 @@ public class AffineCipherControllerTest{
|
||||
private AffineCipherController affineCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
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 static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String affineName = "affineCipherName";
|
||||
private static final String affineDescription = "affineCipherDescription";
|
||||
private static final List<String> affineExplanation = List.of("affineExplanation1", "affineExplanation2", "affineExplanation3");
|
||||
private static final List<String> affineFacts = List.of("affineFact1", "affineFact2", "affineFact3");
|
||||
private static final String AFFINE_NAME = "affineCipherName";
|
||||
private static final String AFFINE_DESCRIPTION = "affineCipherDescription";
|
||||
private static final List<String> AFFINE_EXPLANATION = List.of("affineExplanation1", "affineExplanation2", "affineExplanation3");
|
||||
private static final List<String> AFFINE_FACTS = List.of("affineFact1", "affineFact2", "affineFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineName", affineName);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineDescription", affineDescription);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineExplanation", affineExplanation);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineFacts", affineFacts);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineName", AFFINE_NAME);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineDescription", AFFINE_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineExplanation", AFFINE_EXPLANATION);
|
||||
ReflectionTestUtils.setField(affineCipherController, "affineFacts", AFFINE_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(affineName, affineDescription, affineExplanation, affineFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(AFFINE_NAME, AFFINE_DESCRIPTION, AFFINE_EXPLANATION, AFFINE_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = affineCipherController.getCipherInfo();
|
||||
@@ -66,7 +67,7 @@ public class AffineCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AFFINE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(AFFINE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
@Test
|
||||
public void testEncodeAffine_invalidParameters(){
|
||||
@@ -84,7 +85,7 @@ public class AffineCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AFFINE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(AFFINE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
@Test
|
||||
public void testDecodeAffine_invalidParameters(){
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,18 +28,14 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private AtbashCipherController atbashCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AtbashCipherController")
|
||||
protected Logger atbashLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/atbash";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Nvhhztv gl^vmxlwv";
|
||||
private static final String atbashName = "atbashName";
|
||||
private static final String atbashDescription = "atbashDescription";
|
||||
private static final List<String> atbashExplanation = List.of("atbashExplanation1", "atbashExplanation2", "atbashExplanation3");
|
||||
private static final List<String> atbashFacts = List.of("atbashFact1", "atbashFact2", "atbashFact3");
|
||||
private static final String URL = "/atbash";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Nvhhztv gl^vmxlwv";
|
||||
private static final String ATBASH_NAME = "atbashName";
|
||||
private static final String ATBASH_DESCRIPTION = "atbashDescription";
|
||||
private static final List<String> ATBASH_EXPLANATION = List.of("atbashExplanation1", "atbashExplanation2", "atbashExplanation3");
|
||||
private static final List<String> ATBASH_FACTS = List.of("atbashFact1", "atbashFact2", "atbashFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -53,123 +44,85 @@ public class AtbashCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashName", atbashName);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", atbashDescription);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashExplanation", atbashExplanation);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashFacts", atbashFacts);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashName", ATBASH_NAME);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", ATBASH_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashExplanation", ATBASH_EXPLANATION);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashFacts", ATBASH_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(atbashDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(atbashName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(ATBASH_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(ATBASH_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(atbashExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(atbashExplanation.get(0), atbashExplanation.get(1), atbashExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(ATBASH_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(ATBASH_EXPLANATION.get(0), ATBASH_EXPLANATION.get(1), ATBASH_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(atbashFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(atbashFacts.get(0), atbashFacts.get(1), atbashFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Getting info for {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(ATBASH_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(ATBASH_FACTS.get(0), ATBASH_FACTS.get(1), ATBASH_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAtbash() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAtbash_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Encoding {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAtbash() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAtbash_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(atbashLogger, times(1)).info("Decoding {}", atbashName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -30,24 +31,24 @@ public class AtbashCipherControllerTest{
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String ATBASH_INPUT_STRING = "Message to^encode";
|
||||
private static final String ATBASH_OUTPUT_STRING = "Nvhhztv gl^vmxlwv";
|
||||
private static final String atbashName = "atbashName";
|
||||
private static final String atbashDescription = "atbashDescription";
|
||||
private static final List<String> atbashExplanation = List.of("atbashExplanation1", "atbashExplanation2", "atbashExplanation3");
|
||||
private static final List<String> atbashFacts = List.of("atbashFact1", "atbashFact2", "atbashFact3");
|
||||
private static final String ATBASH_NAME = "atbashName";
|
||||
private static final String ATBASH_DESCRIPTION = "atbashDescription";
|
||||
private static final List<String> ATBASH_EXPLANATION = List.of("atbashExplanation1", "atbashExplanation2", "atbashExplanation3");
|
||||
private static final List<String> ATBASH_FACTS = List.of("atbashFact1", "atbashFact2", "atbashFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashName", atbashName);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", atbashDescription);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashExplanation", atbashExplanation);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashFacts", atbashFacts);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashName", ATBASH_NAME);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashDescription", ATBASH_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashExplanation", ATBASH_EXPLANATION);
|
||||
ReflectionTestUtils.setField(atbashCipherController, "atbashFacts", ATBASH_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(atbashName, atbashDescription, atbashExplanation, atbashFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(ATBASH_NAME, ATBASH_DESCRIPTION, ATBASH_EXPLANATION, ATBASH_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = atbashCipherController.getCipherInfo();
|
||||
@@ -63,7 +64,7 @@ public class AtbashCipherControllerTest{
|
||||
ObjectNode returnedJson = atbashCipherController.encodeAtbash(cipherParams);
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ATBASH_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(ATBASH_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
@Test
|
||||
public void testEncodeAtbash_invalidParameters(){
|
||||
@@ -79,7 +80,7 @@ public class AtbashCipherControllerTest{
|
||||
ObjectNode returnedJson = atbashCipherController.decodeAtbash(cipherParams);
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ATBASH_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(ATBASH_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
@Test
|
||||
public void testDecodeAtbash_invalidParameters(){
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private AutokeyCipherController autokeyCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.AutokeyCipherController")
|
||||
protected Logger autokeyLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/autokey";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Wiqooxh fs^wfcuhx";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String autokeyName = "autokeyName";
|
||||
private static final String autokeyDescription = "autokeyDescription";
|
||||
private static final List<String> autokeyExplanation = List.of("autokeyExplanation1", "autokeyExplanation2", "autokeyExplanation3");
|
||||
private static final List<String> autokeyFacts = List.of("autokeyFact1", "autokeyFact2", "autokeyFact3");
|
||||
private static final String URL = "/autokey";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Wiqooxh fs^wfcuhx";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String AUTOKEY_NAME = "autokeyName";
|
||||
private static final String AUTOKEY_DESCRIPTION = "autokeyDescription";
|
||||
private static final List<String> AUTOKEY_EXPLANATION = List.of("autokeyExplanation1", "autokeyExplanation2", "autokeyExplanation3");
|
||||
private static final List<String> AUTOKEY_FACTS = List.of("autokeyFact1", "autokeyFact2", "autokeyFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class AutokeyCipherControllerIntegrationTest extends CipherStreamControll
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", autokeyName);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", autokeyDescription);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyExplanation", autokeyExplanation);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyFacts", autokeyFacts);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", AUTOKEY_NAME);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", AUTOKEY_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyExplanation", AUTOKEY_EXPLANATION);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyFacts", AUTOKEY_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(autokeyDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(autokeyName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(AUTOKEY_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(AUTOKEY_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(autokeyExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(autokeyExplanation.get(0), autokeyExplanation.get(1), autokeyExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(AUTOKEY_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(AUTOKEY_EXPLANATION.get(0), AUTOKEY_EXPLANATION.get(1), AUTOKEY_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(autokeyFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(autokeyFacts.get(0), autokeyFacts.get(1), autokeyFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Getting info for {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(AUTOKEY_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(AUTOKEY_FACTS.get(0), AUTOKEY_FACTS.get(1), AUTOKEY_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAutokey() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAutokey_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Encoding {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAutokey_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(autokeyLogger, times(1)).info("Decoding {}", autokeyName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,23 +32,23 @@ public class AutokeyCipherControllerTest{
|
||||
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 static final String autokeyName = "autokeyName";
|
||||
private static final String autokeyDescription = "autokeyDescription";
|
||||
private static final List<String> autokeyExplanation = List.of("autokeyExplanation1", "autokeyExplanation2", "autokeyExplanation3");
|
||||
private static final List<String> autokeyFacts = List.of("autokeyFact1", "autokeyFact2", "autokeyFact3");
|
||||
private static final String AUTOKEY_NAME = "autokeyName";
|
||||
private static final String AUTOKEY_DESCRIPTION = "autokeyDescription";
|
||||
private static final List<String> AUTOKEY_EXPLANATION = List.of("autokeyExplanation1", "autokeyExplanation2", "autokeyExplanation3");
|
||||
private static final List<String> AUTOKEY_FACTS = List.of("autokeyFact1", "autokeyFact2", "autokeyFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", autokeyName);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", autokeyDescription);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyExplanation", autokeyExplanation);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyFacts", autokeyFacts);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyName", AUTOKEY_NAME);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyDescription", AUTOKEY_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyExplanation", AUTOKEY_EXPLANATION);
|
||||
ReflectionTestUtils.setField(autokeyCipherController, "autokeyFacts", AUTOKEY_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(autokeyName, autokeyDescription, autokeyExplanation, autokeyFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(AUTOKEY_NAME, AUTOKEY_DESCRIPTION, AUTOKEY_EXPLANATION, AUTOKEY_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = autokeyCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class AutokeyCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AUTOKEY_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(AUTOKEY_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class AutokeyCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(AUTOKEY_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(AUTOKEY_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,18 +28,14 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private BaconianCipherController baconianCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaconianCipherController")
|
||||
protected Logger baconianLogger;
|
||||
//Fields
|
||||
private static final String url = "/baconian";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String baconianName = "baconianName";
|
||||
private static final String baconianDescription = "baconianDescription";
|
||||
private static final List<String> baconianExplanation = List.of("baconianExplanation1", "baconianExplanation2", "baconianExplanation3");
|
||||
private static final List<String> baconianFacts = List.of("baconianFact1", "baconianFact2", "baconianFact3");
|
||||
private static final String URL = "/baconian";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "ABABB aabaa baaab baaab aaaaa aabba aabaa baaba abbab aabaa abbaa aaaba abbab aaabb aabaa";
|
||||
private static final String BACONIAN_NAME = "baconianName";
|
||||
private static final String BACONIAN_DESCRIPTION = "baconianDescription";
|
||||
private static final List<String> BACONIAN_EXPLANATION = List.of("baconianExplanation1", "baconianExplanation2", "baconianExplanation3");
|
||||
private static final List<String> BACONIAN_FACTS = List.of("baconianFact1", "baconianFact2", "baconianFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -53,123 +44,85 @@ public class BaconianCipherControllerIntegrationTest extends CipherStreamControl
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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]", ""));
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING.replaceAll("[^a-zA-Z]", ""));
|
||||
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianName", baconianName);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", baconianDescription);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianExplanation", baconianExplanation);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianFacts", baconianFacts);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianName", BACONIAN_NAME);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", BACONIAN_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianExplanation", BACONIAN_EXPLANATION);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianFacts", BACONIAN_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(baconianDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(baconianName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(BACONIAN_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(BACONIAN_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(baconianExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(baconianExplanation.get(0), baconianExplanation.get(1), baconianExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(BACONIAN_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(BACONIAN_EXPLANATION.get(0), BACONIAN_EXPLANATION.get(1), BACONIAN_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(baconianFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(baconianFacts.get(0), baconianFacts.get(1), baconianFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Getting info for {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(BACONIAN_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(BACONIAN_FACTS.get(0), BACONIAN_FACTS.get(1), BACONIAN_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaconian() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaconian_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Encoding {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaconian() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING.replaceAll("[^a-zA-Z]", "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaconian_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baconianLogger, times(1)).info("Decoding {}", baconianName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -27,28 +28,28 @@ public class BaconianCipherControllerTest{
|
||||
private BaconianCipherController baconianCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
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 static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String baconianName = "baconianName";
|
||||
private static final String baconianDescription = "baconianDescription";
|
||||
private static final List<String> baconianExplanation = List.of("baconianExplanation1", "baconianExplanation2", "baconianExplanation3");
|
||||
private static final List<String> baconianFacts = List.of("baconianFact1", "baconianFact2", "baconianFact3");
|
||||
private static final String BACONIAN_NAME = "baconianName";
|
||||
private static final String BACONIAN_DESCRIPTION = "baconianDescription";
|
||||
private static final List<String> BACONIAN_EXPLANATION = List.of("baconianExplanation1", "baconianExplanation2", "baconianExplanation3");
|
||||
private static final List<String> BACONIAN_FACTS = List.of("baconianFact1", "baconianFact2", "baconianFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianName", baconianName);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", baconianDescription);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianExplanation", baconianExplanation);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianFacts", baconianFacts);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianName", BACONIAN_NAME);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianDescription", BACONIAN_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianExplanation", BACONIAN_EXPLANATION);
|
||||
ReflectionTestUtils.setField(baconianCipherController, "baconianFacts", BACONIAN_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baconianName, baconianDescription, baconianExplanation, baconianFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(BACONIAN_NAME, BACONIAN_DESCRIPTION, BACONIAN_EXPLANATION, BACONIAN_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baconianCipherController.getCipherInfo();
|
||||
@@ -66,7 +67,7 @@ public class BaconianCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BACONIAN_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(BACONIAN_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +86,7 @@ public class BaconianCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BACONIAN_DECODED_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(BACONIAN_DECODED_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private BaseXCipherController baseXCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BaseXCipherController")
|
||||
protected Logger baseXLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/basex";
|
||||
private static final String decodedString = "A+B@C d\te\nf";
|
||||
private static final String encodedString = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private static final int base = 2;
|
||||
private static final String baseXName = "baseXName";
|
||||
private static final String baseXDescription = "baseXDescription";
|
||||
private static final List<String> baseXExplanation = List.of("baseXExplanation1", "baseXExplanation2", "baseXExplanation3");
|
||||
private static final List<String> baseXFacts = List.of("baseXFact1", "baseXFact2", "baseXFact3");
|
||||
private static final String URL = "/basex";
|
||||
private static final String DECODED_STRING = "A+B@C d\te\nf";
|
||||
private static final String ENCODED_STRING = "1000001 101011 1000010 1000000 1000011 100000 1100100 1001 1100101 1010 1100110";
|
||||
private static final int BASE = 2;
|
||||
private static final String BASE_X_NAME = "baseXName";
|
||||
private static final String BASE_X_DESCRIPTION = "baseXDescription";
|
||||
private static final List<String> BASE_X_EXPLANATION = List.of("baseXExplanation1", "baseXExplanation2", "baseXExplanation3");
|
||||
private static final List<String> BASE_X_FACTS = List.of("baseXFact1", "baseXFact2", "baseXFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class BaseXCipherControllerIntegrationTest extends CipherStreamController
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.BASE_X_BASE, BASE);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.BASE_X_BASE, BASE);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXName", baseXName);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", baseXDescription);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXExplanation", baseXExplanation);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXFacts", baseXFacts);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXName", BASE_X_NAME);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", BASE_X_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXExplanation", BASE_X_EXPLANATION);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXFacts", BASE_X_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(baseXDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(baseXName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(BASE_X_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(BASE_X_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(baseXExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(baseXExplanation.get(0), baseXExplanation.get(1), baseXExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(BASE_X_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(BASE_X_EXPLANATION.get(0), BASE_X_EXPLANATION.get(1), BASE_X_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(baseXFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(baseXFacts.get(0), baseXFacts.get(1), baseXFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Getting info for {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(BASE_X_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(BASE_X_FACTS.get(0), BASE_X_FACTS.get(1), BASE_X_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaseXEncode() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBaseX_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Encoding {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaseXDecode() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBaseX_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.INPUT_STRING + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(baseXLogger, times(1)).info("Decoding {}", baseXName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,23 +32,23 @@ public class BaseXCipherControllerTest{
|
||||
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 static final String baseXName = "baseXName";
|
||||
private static final String baseXDescription = "baseXDescription";
|
||||
private static final List<String> baseXExplanation = List.of("baseXExplanation1", "baseXExplanation2", "baseXExplanation3");
|
||||
private static final List<String> baseXFacts = List.of("baseXFact1", "baseXFact2", "baseXFact3");
|
||||
private static final String BASE_X_NAME = "baseXName";
|
||||
private static final String BASE_X_DESCRIPTION = "baseXDescription";
|
||||
private static final List<String> BASE_X_EXPLANATION = List.of("baseXExplanation1", "baseXExplanation2", "baseXExplanation3");
|
||||
private static final List<String> BASE_X_FACTS = List.of("baseXFact1", "baseXFact2", "baseXFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXName", baseXName);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", baseXDescription);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXExplanation", baseXExplanation);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXFacts", baseXFacts);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXName", BASE_X_NAME);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXDescription", BASE_X_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXExplanation", BASE_X_EXPLANATION);
|
||||
ReflectionTestUtils.setField(baseXCipherController, "baseXFacts", BASE_X_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(baseXName, baseXDescription, baseXExplanation, baseXFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(BASE_X_NAME, BASE_X_DESCRIPTION, BASE_X_EXPLANATION, BASE_X_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = baseXCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class BaseXCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BASE_X_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(BASE_X_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class BaseXCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BASE_X_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(BASE_X_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private BeaufortCipherController beaufortCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.BeaufortCipherController")
|
||||
protected Logger beaufortLogger;
|
||||
//Fields
|
||||
private static final String url = "/beaufort";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Yageolz rq^ujmdag";
|
||||
private static final String keyword = "Ke*y word";
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String beaufortName = "beaufortName";
|
||||
private static final String beaufortDescription = "beaufortDescription";
|
||||
private static final List<String> beaufortExplanation = List.of("beaufortExplanation1", "beaufortExplanation2", "beaufortExplanation3");
|
||||
private static final List<String> beaufortFacts = List.of("beaufortFact1", "beaufortFact2", "beaufortFact3");
|
||||
private static final String URL = "/beaufort";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Yageolz rq^ujmdag";
|
||||
private static final String KEYWORD = "Ke*y word";
|
||||
private static final String BEAUFORT_NAME = "beaufortName";
|
||||
private static final String BEAUFORT_DESCRIPTION = "beaufortDescription";
|
||||
private static final List<String> BEAUFORT_EXPLANATION = List.of("beaufortExplanation1", "beaufortExplanation2", "beaufortExplanation3");
|
||||
private static final List<String> BEAUFORT_FACTS = List.of("beaufortFact1", "beaufortFact2", "beaufortFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class BeaufortCipherControllerIntegrationTest extends CipherStreamControl
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", beaufortName);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", beaufortDescription);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortExplanation", beaufortExplanation);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortFacts", beaufortFacts);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", BEAUFORT_NAME);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", BEAUFORT_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortExplanation", BEAUFORT_EXPLANATION);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortFacts", BEAUFORT_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(beaufortDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(beaufortName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(BEAUFORT_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(BEAUFORT_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(beaufortExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(beaufortExplanation.get(0), beaufortExplanation.get(1), beaufortExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(BEAUFORT_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(BEAUFORT_EXPLANATION.get(0), BEAUFORT_EXPLANATION.get(1), BEAUFORT_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(beaufortFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(beaufortFacts.get(0), beaufortFacts.get(1), beaufortFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Getting info for {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(BEAUFORT_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(BEAUFORT_FACTS.get(0), BEAUFORT_FACTS.get(1), BEAUFORT_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBeaufort() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Encoding {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBeaufort() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(beaufortLogger, times(1)).info("Decoding {}", beaufortName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -27,27 +28,27 @@ public class BeaufortCipherControllerTest{
|
||||
private BeaufortCipherController beaufortCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
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 static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String beaufortName = "beaufortName";
|
||||
private static final String beaufortDescription = "beaufortDescription";
|
||||
private static final List<String> beaufortExplanation = List.of("beaufortExplanation1", "beaufortExplanation2", "beaufortExplanation3");
|
||||
private static final List<String> beaufortFacts = List.of("beaufortFact1", "beaufortFact2", "beaufortFact3");
|
||||
private static final String BEAUFORT_NAME = "beaufortName";
|
||||
private static final String BEAUFORT_DESCRIPTION = "beaufortDescription";
|
||||
private static final List<String> BEAUFORT_EXPLANATION = List.of("beaufortExplanation1", "beaufortExplanation2", "beaufortExplanation3");
|
||||
private static final List<String> BEAUFORT_FACTS = List.of("beaufortFact1", "beaufortFact2", "beaufortFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", beaufortName);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", beaufortDescription);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortExplanation", beaufortExplanation);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortFacts", beaufortFacts);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortName", BEAUFORT_NAME);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortDescription", BEAUFORT_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortExplanation", BEAUFORT_EXPLANATION);
|
||||
ReflectionTestUtils.setField(beaufortCipherController, "beaufortFacts", BEAUFORT_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(beaufortName, beaufortDescription, beaufortExplanation, beaufortFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(BEAUFORT_NAME, BEAUFORT_DESCRIPTION, BEAUFORT_EXPLANATION, BEAUFORT_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = beaufortCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class BeaufortCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BEAUFORT_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(BEAUFORT_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class BeaufortCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BEAUFORT_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(BEAUFORT_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private CaesarCipherController caesarCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController")
|
||||
protected Logger caesarLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/caesar";
|
||||
private static final String decodedString = "The quick brown fox jumps over - the lazy dog";
|
||||
private static final String encodedString = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private static final int shiftAmount = 23;
|
||||
private static final String caesarName = "caesarName";
|
||||
private static final String caesarDescription = "caesarDescription";
|
||||
private static final List<String> caesarExplanation = List.of("caesarExplanation1", "caesarExplanation2", "caesarExplanation3");
|
||||
private static final List<String> caesarFacts = List.of("caesarFact1", "caesarFact2", "caesarFact3");
|
||||
private static final String URL = "/caesar";
|
||||
private static final String DECODED_STRING = "The quick brown fox jumps over - the lazy dog";
|
||||
private static final String ENCODED_STRING = "Qeb nrfzh yoltk clu grjmp lsbo - qeb ixwv ald";
|
||||
private static final int SHIFT_AMOUNT = 23;
|
||||
private static final String CAESAR_NAME = "caesarName";
|
||||
private static final String CAESAR_DESCRIPTION = "caesarDescription";
|
||||
private static final List<String> CAESAR_EXPLANATION = List.of("caesarExplanation1", "caesarExplanation2", "caesarExplanation3");
|
||||
private static final List<String> CAESAR_FACTS = List.of("caesarFact1", "caesarFact2", "caesarFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class CaesarCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, SHIFT_AMOUNT);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.CAESAR_SHIFT_AMOUNT, SHIFT_AMOUNT);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarName", caesarName);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", caesarDescription);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarExplanation", caesarExplanation);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarFacts", caesarFacts);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarName", CAESAR_NAME);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", CAESAR_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarExplanation", CAESAR_EXPLANATION);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarFacts", CAESAR_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(caesarDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(caesarName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(CAESAR_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(CAESAR_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(caesarExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(caesarExplanation.get(0), caesarExplanation.get(1), caesarExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(CAESAR_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(CAESAR_EXPLANATION.get(0), CAESAR_EXPLANATION.get(1), CAESAR_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(caesarFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(caesarFacts.get(0), caesarFacts.get(1), caesarFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Getting info for {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(CAESAR_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(CAESAR_FACTS.get(0), CAESAR_FACTS.get(1), CAESAR_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeCaesar() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Encoding {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeCaesar() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(caesarLogger, times(1)).info("Decoding {}", caesarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -27,27 +28,27 @@ public class CaesarCipherControllerTest{
|
||||
private CaesarCipherController caesarCipherController;
|
||||
//Fields
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
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 static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String caesarName = "caesarName";
|
||||
private static final String caesarDescription = "caesarDescription";
|
||||
private static final List<String> caesarExplanation = List.of("caesarExplanation1", "caesarExplanation2", "caesarExplanation3");
|
||||
private static final List<String> caesarFacts = List.of("caesarFact1", "caesarFact2", "caesarFact3");
|
||||
private static final String CAESAR_NAME = "caesarName";
|
||||
private static final String CAESAR_DESCRIPTION = "caesarDescription";
|
||||
private static final List<String> CAESAR_EXPLANATION = List.of("caesarExplanation1", "caesarExplanation2", "caesarExplanation3");
|
||||
private static final List<String> CAESAR_FACTS = List.of("caesarFact1", "caesarFact2", "caesarFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarName", caesarName);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", caesarDescription);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarExplanation", caesarExplanation);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarFacts", caesarFacts);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarName", CAESAR_NAME);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarDescription", CAESAR_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarExplanation", CAESAR_EXPLANATION);
|
||||
ReflectionTestUtils.setField(caesarCipherController, "caesarFacts", CAESAR_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(caesarName, caesarDescription, caesarExplanation, caesarFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(CAESAR_NAME, CAESAR_DESCRIPTION, CAESAR_EXPLANATION, CAESAR_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = caesarCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class CaesarCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(CAESAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(CAESAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class CaesarCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(CAESAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(CAESAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private OneTimePadCipherController oneTimePadCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.OneTimePadCipherController")
|
||||
protected Logger oneTimePadLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/oneTimePad";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Wiqooxh mv^egkgws";
|
||||
private static final String keyword = "keywordThatIsTotallyRandom";
|
||||
private static final String oneTimePadName = "oneTimePadName";
|
||||
private static final String oneTimePadDescription = "oneTimePadDescription";
|
||||
private static final List<String> oneTimePadExplanation = List.of("oneTimePadExplanation1", "oneTimePadExplanation2", "oneTimePadExplanation3");
|
||||
private static final List<String> oneTimePadFacts = List.of("oneTimePadFact1", "oneTimePadFact2", "oneTimePadFact3");
|
||||
private static final String URL = "/oneTimePad";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Wiqooxh mv^egkgws";
|
||||
private static final String KEYWORD = "keywordThatIsTotallyRandom";
|
||||
private static final String ONE_TIME_PAD_NAME = "oneTimePadName";
|
||||
private static final String ONE_TIME_PAD_DESCRIPTION = "oneTimePadDescription";
|
||||
private static final List<String> ONE_TIME_PAD_EXPLANATION = List.of("oneTimePadExplanation1", "oneTimePadExplanation2", "oneTimePadExplanation3");
|
||||
private static final List<String> ONE_TIME_PAD_FACTS = List.of("oneTimePadFact1", "oneTimePadFact2", "oneTimePadFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class OneTimePadCipherControllerIntegrationTest extends CipherStreamContr
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", oneTimePadName);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", oneTimePadDescription);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadExplanation", oneTimePadExplanation);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadFacts", oneTimePadFacts);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", ONE_TIME_PAD_NAME);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", ONE_TIME_PAD_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadExplanation", ONE_TIME_PAD_EXPLANATION);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadFacts", ONE_TIME_PAD_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(oneTimePadDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(oneTimePadName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(ONE_TIME_PAD_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(ONE_TIME_PAD_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(oneTimePadExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(oneTimePadExplanation.get(0), oneTimePadExplanation.get(1), oneTimePadExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(ONE_TIME_PAD_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(ONE_TIME_PAD_EXPLANATION.get(0), ONE_TIME_PAD_EXPLANATION.get(1), ONE_TIME_PAD_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(oneTimePadFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(oneTimePadFacts.get(0), oneTimePadFacts.get(1), oneTimePadFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Getting info for {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(ONE_TIME_PAD_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(ONE_TIME_PAD_FACTS.get(0), ONE_TIME_PAD_FACTS.get(1), ONE_TIME_PAD_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeOneTimePad() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Encoding {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeOneTimePad() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(oneTimePadLogger, times(1)).info("Decoding {}", oneTimePadName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,23 +32,23 @@ public class OneTimePadCipherControllerTest{
|
||||
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 static final String oneTimePadName = "oneTimePadName";
|
||||
private static final String oneTimePadDescription = "oneTimePadDescription";
|
||||
private static final List<String> oneTimePadExplanation = List.of("oneTimePadExplanation1", "oneTimePadExplanation2", "oneTimePadExplanation3");
|
||||
private static final List<String> oneTimePadFacts = List.of("oneTimePadFact1", "oneTimePadFact2", "oneTimePadFact3");
|
||||
private static final String ONE_TIME_PAD_NAME = "oneTimePadName";
|
||||
private static final String ONE_TIME_PAD_DESCRIPTION = "oneTimePadDescription";
|
||||
private static final List<String> ONE_TIME_PAD_EXPLANATION = List.of("oneTimePadExplanation1", "oneTimePadExplanation2", "oneTimePadExplanation3");
|
||||
private static final List<String> ONE_TIME_PAD_FACTS = List.of("oneTimePadFact1", "oneTimePadFact2", "oneTimePadFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", oneTimePadName);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", oneTimePadDescription);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadExplanation", oneTimePadExplanation);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadFacts", oneTimePadFacts);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadName", ONE_TIME_PAD_NAME);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadDescription", ONE_TIME_PAD_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadExplanation", ONE_TIME_PAD_EXPLANATION);
|
||||
ReflectionTestUtils.setField(oneTimePadCipherController, "oneTimePadFacts", ONE_TIME_PAD_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(oneTimePadName, oneTimePadDescription, oneTimePadExplanation, oneTimePadFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(ONE_TIME_PAD_NAME, ONE_TIME_PAD_DESCRIPTION, ONE_TIME_PAD_EXPLANATION, ONE_TIME_PAD_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = oneTimePadCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class OneTimePadCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ONE_TIME_PAD_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(ONE_TIME_PAD_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class OneTimePadCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(ONE_TIME_PAD_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(ONE_TIME_PAD_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
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.*;
|
||||
|
||||
@@ -12,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -34,19 +28,15 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private PortaCipherController portaCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.PortaCipherController")
|
||||
protected Logger portaLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/porta";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Rtghuos bm^qcwgrw";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String portaName = "portaName";
|
||||
private static final String portaDescription = "portaDescription";
|
||||
private static final List<String> portaExplanation = List.of("portaExplanation1", "portaExplanation2", "portaExplanation3");
|
||||
private static final List<String> portaFacts = List.of("portaFact1", "portaFact2", "portaFact3");
|
||||
private static final String URL = "/porta";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Rtghuos bm^qcwgrw";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String PORTA_NAME = "portaName";
|
||||
private static final String PORTA_DESCRIPTION = "portaDescription";
|
||||
private static final List<String> PORTA_EXPLANATION = List.of("portaExplanation1", "portaExplanation2", "portaExplanation3");
|
||||
private static final List<String> PORTA_FACTS = List.of("portaFact1", "portaFact2", "portaFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,133 +45,87 @@ public class PortaCipherControllerIntegrationTest extends CipherStreamController
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaName", portaName);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaDescription", portaDescription);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaExplanation", portaExplanation);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaFacts", portaFacts);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaName", PORTA_NAME);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaDescription", PORTA_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaExplanation", PORTA_EXPLANATION);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaFacts", PORTA_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(portaDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(portaName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(PORTA_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(PORTA_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(portaExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(portaExplanation.get(0), portaExplanation.get(1), portaExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(PORTA_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(PORTA_EXPLANATION.get(0), PORTA_EXPLANATION.get(1), PORTA_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(portaFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(portaFacts.get(0), portaFacts.get(1), portaFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Getting info for {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(PORTA_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(PORTA_FACTS.get(0), PORTA_FACTS.get(1), PORTA_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePorta() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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", ipAddress);
|
||||
verify(mdc, times(1)).put("url", url + "/encode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Encoding {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Encoding {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePorta() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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", ipAddress);
|
||||
verify(mdc, times(1)).put("url", url + "/decode");
|
||||
verify(mdc, times(1)).clear();
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Decoding {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(portaLogger, times(1)).info("Decoding {}", portaName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,23 +32,23 @@ public class PortaCipherControllerTest{
|
||||
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 static final String portaName = "portaName";
|
||||
private static final String portaDescription = "portaDescription";
|
||||
private static final List<String> portaExplanation = List.of("portaExplanation1", "portaExplanation2", "portaExplanation3");
|
||||
private static final List<String> portaFacts = List.of("portaFact1", "portaFact2", "portaFact3");
|
||||
private static final String PORTA_NAME = "portaName";
|
||||
private static final String PORTA_DESCRIPTION = "portaDescription";
|
||||
private static final List<String> PORTA_EXPLANATION = List.of("portaExplanation1", "portaExplanation2", "portaExplanation3");
|
||||
private static final List<String> PORTA_FACTS = List.of("portaFact1", "portaFact2", "portaFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaName", portaName);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaDescription", portaDescription);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaExplanation", portaExplanation);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaFacts", portaFacts);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaName", PORTA_NAME);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaDescription", PORTA_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaExplanation", PORTA_EXPLANATION);
|
||||
ReflectionTestUtils.setField(portaCipherController, "portaFacts", PORTA_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(portaName, portaDescription, portaExplanation, portaFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(PORTA_NAME, PORTA_DESCRIPTION, PORTA_EXPLANATION, PORTA_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = portaCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class PortaCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PORTA_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(PORTA_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class PortaCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PORTA_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(PORTA_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private SubstitutionCipherController substitutionCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.SubstitutionCipherController")
|
||||
protected Logger substitutionLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/substitution";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Oguucig vq^gpeqfg";
|
||||
private static final String keyword = "cdefghijklmnopqrstuvwxyzab";
|
||||
private static final String substitutionName = "substitutionName";
|
||||
private static final String substitutionDescription = "substitutionDescription";
|
||||
private static final List<String> substitutionExplanation = List.of("substitutionExplanation1", "substitutionExplanation2", "substitutionExplanation3");
|
||||
private static final List<String> substitutionFacts = List.of("substitutionFact1", "substitutionFact2", "substitutionFact3");
|
||||
private static final String URL = "/substitution";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Oguucig vq^gpeqfg";
|
||||
private static final String KEYWORD = "cdefghijklmnopqrstuvwxyzab";
|
||||
private static final String SUBSTITUTION_NAME = "substitutionName";
|
||||
private static final String SUBSTITUTION_DESCRIPTION = "substitutionDescription";
|
||||
private static final List<String> SUBSTITUTION_EXPLANATION = List.of("substitutionExplanation1", "substitutionExplanation2", "substitutionExplanation3");
|
||||
private static final List<String> SUBSTITUTION_FACTS = List.of("substitutionFact1", "substitutionFact2", "substitutionFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class SubstitutionCipherControllerIntegrationTest extends CipherStreamCon
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", substitutionName);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", substitutionDescription);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionExplanation", substitutionExplanation);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionFacts", substitutionFacts);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", SUBSTITUTION_NAME);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", SUBSTITUTION_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionExplanation", SUBSTITUTION_EXPLANATION);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionFacts", SUBSTITUTION_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(substitutionDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(substitutionName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(SUBSTITUTION_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(SUBSTITUTION_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(substitutionExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(substitutionExplanation.get(0), substitutionExplanation.get(1), substitutionExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(SUBSTITUTION_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(SUBSTITUTION_EXPLANATION.get(0), SUBSTITUTION_EXPLANATION.get(1), SUBSTITUTION_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(substitutionFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(substitutionFacts.get(0), substitutionFacts.get(1), substitutionFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Getting info for {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(SUBSTITUTION_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(SUBSTITUTION_FACTS.get(0), SUBSTITUTION_FACTS.get(1), SUBSTITUTION_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeSubstitution() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Encoding {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeSubstitution() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(substitutionLogger, times(1)).info("Decoding {}", substitutionName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,23 +32,23 @@ public class SubstitutionCipherControllerTest{
|
||||
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 static final String substitutionName = "substitutionName";
|
||||
private static final String substitutionDescription = "substitutionDescription";
|
||||
private static final List<String> substitutionExplanation = List.of("substitutionExplanation1", "substitutionExplanation2", "substitutionExplanation3");
|
||||
private static final List<String> substitutionFacts = List.of("substitutionFact1", "substitutionFact2", "substitutionFact3");
|
||||
private static final String SUBSTITUTION_NAME = "substitutionName";
|
||||
private static final String SUBSTITUTION_DESCRIPTION = "substitutionDescription";
|
||||
private static final List<String> SUBSTITUTION_EXPLANATION = List.of("substitutionExplanation1", "substitutionExplanation2", "substitutionExplanation3");
|
||||
private static final List<String> SUBSTITUTION_FACTS = List.of("substitutionFact1", "substitutionFact2", "substitutionFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", substitutionName);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", substitutionDescription);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionExplanation", substitutionExplanation);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionFacts", substitutionFacts);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionName", SUBSTITUTION_NAME);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionDescription", SUBSTITUTION_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionExplanation", SUBSTITUTION_EXPLANATION);
|
||||
ReflectionTestUtils.setField(substitutionCipherController, "substitutionFacts", SUBSTITUTION_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(substitutionName, substitutionDescription, substitutionExplanation, substitutionFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(SUBSTITUTION_NAME, SUBSTITUTION_DESCRIPTION, SUBSTITUTION_EXPLANATION, SUBSTITUTION_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = substitutionCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class SubstitutionCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(SUBSTITUTION_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(SUBSTITUTION_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class SubstitutionCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(SUBSTITUTION_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(SUBSTITUTION_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.monosubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private VigenereCipherController vigenereCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.monosubstitution.VigenereCipherController")
|
||||
protected Logger vigenereLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/vigenere";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Wiqooxh ds^cjqfgo";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String vigenereName = "vigenereName";
|
||||
private static final String vigenereDescription = "vigenereDescription";
|
||||
private static final List<String> vigenereExplanation = List.of("vigenereExplanation1", "vigenereExplanation2", "vigenereExplanation3");
|
||||
private static final List<String> vigenereFacts = List.of("vigenereFact1", "vigenereFact2", "vigenereFact3");
|
||||
private static final String URL = "/vigenere";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Wiqooxh ds^cjqfgo";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String VIGENERE_NAME = "vigenereName";
|
||||
private static final String VIGENERE_DESCRIPTION = "vigenereDescription";
|
||||
private static final List<String> VIGENERE_EXPLANATION = List.of("vigenereExplanation1", "vigenereExplanation2", "vigenereExplanation3");
|
||||
private static final List<String> VIGENERE_FACTS = List.of("vigenereFact1", "vigenereFact2", "vigenereFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class VigenereCipherControllerIntegrationTest extends CipherStreamControl
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", vigenereName);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", vigenereDescription);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereExplanation", vigenereExplanation);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereFacts", vigenereFacts);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", VIGENERE_NAME);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", VIGENERE_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereExplanation", VIGENERE_EXPLANATION);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereFacts", VIGENERE_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(vigenereDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(vigenereName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(VIGENERE_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(VIGENERE_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(vigenereExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(vigenereExplanation.get(0), vigenereExplanation.get(1), vigenereExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(VIGENERE_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(VIGENERE_EXPLANATION.get(0), VIGENERE_EXPLANATION.get(1), VIGENERE_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(vigenereFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(vigenereFacts.get(0), vigenereFacts.get(1), vigenereFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Getting info for {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(VIGENERE_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(VIGENERE_FACTS.get(0), VIGENERE_FACTS.get(1), VIGENERE_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeVigenere() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/encode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Encoding {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeVigenere() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeAdfgvx_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(blankNode.toString()))
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("message").value(CipherParameterUtil.PRESERVE_CAPITALS + CipherParameterUtil.PRESENT_MESSAGE));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url + "/decode");
|
||||
//Controller
|
||||
verify(vigenereLogger, times(1)).info("Decoding {}", vigenereName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,23 +32,23 @@ public class VigenereCipherControllerTest{
|
||||
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 static final String vigenereName = "vigenereName";
|
||||
private static final String vigenereDescription = "vigenereDescription";
|
||||
private static final List<String> vigenereExplanation = List.of("vigenereExplanation1", "vigenereExplanation2", "vigenereExplanation3");
|
||||
private static final List<String> vigenereFacts = List.of("vigenereFact1", "vigenereFact2", "vigenereFact3");
|
||||
private static final String VIGENERE_NAME = "vigenereName";
|
||||
private static final String VIGENERE_DESCRIPTION = "vigenereDescription";
|
||||
private static final List<String> VIGENERE_EXPLANATION = List.of("vigenereExplanation1", "vigenereExplanation2", "vigenereExplanation3");
|
||||
private static final List<String> VIGENERE_FACTS = List.of("vigenereFact1", "vigenereFact2", "vigenereFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", vigenereName);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", vigenereDescription);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereExplanation", vigenereExplanation);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereFacts", vigenereFacts);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereName", VIGENERE_NAME);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereDescription", VIGENERE_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereExplanation", VIGENERE_EXPLANATION);
|
||||
ReflectionTestUtils.setField(vigenereCipherController, "vigenereFacts", VIGENERE_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(vigenereName, vigenereDescription, vigenereExplanation, vigenereFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(VIGENERE_NAME, VIGENERE_DESCRIPTION, VIGENERE_EXPLANATION, VIGENERE_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = vigenereCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class VigenereCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(VIGENERE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(VIGENERE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class VigenereCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(VIGENERE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(VIGENERE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private BifidCipherController bifidCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.BifidCipherController")
|
||||
protected Logger bifidLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/bifid";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Mqaokne kc^vdodzd";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String bifidName = "bifidName";
|
||||
private static final String bifidDescription = "bifidDescription";
|
||||
private static final List<String> bifidExplanation = List.of("bifidExplanation1", "bifidExplanation2", "bifidExplanation3");
|
||||
private static final List<String> bifidFacts = List.of("bifidFact1", "bifidFact2", "bifidFact3");
|
||||
private static final String URL = "/bifid";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Mqaokne kc^vdodzd";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String BIFID_NAME = "bifidName";
|
||||
private static final String BIFID_DESCRIPTION = "bifidDescription";
|
||||
private static final List<String> BIFID_EXPLANATION = List.of("bifidExplanation1", "bifidExplanation2", "bifidExplanation3");
|
||||
private static final List<String> BIFID_FACTS = List.of("bifidFact1", "bifidFact2", "bifidFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class BifidCipherControllerIntegrationTest extends CipherStreamController
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidName", bifidName);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", bifidDescription);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidExplanation", bifidExplanation);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidFacts", bifidFacts);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidName", BIFID_NAME);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", BIFID_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidExplanation", BIFID_EXPLANATION);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidFacts", BIFID_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(bifidName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(bifidDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(BIFID_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(BIFID_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(bifidExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(bifidExplanation.get(0), bifidExplanation.get(1), bifidExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(BIFID_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(BIFID_EXPLANATION.get(0), BIFID_EXPLANATION.get(1), BIFID_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(bifidFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(bifidFacts.get(0), bifidFacts.get(1), bifidFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(bifidLogger, times(1)).info("Getting info for {}", bifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(BIFID_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(BIFID_FACTS.get(0), BIFID_FACTS.get(1), BIFID_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeBifid() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", bifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodebifid_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", bifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeBifid() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", bifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodebifid_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", bifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,23 +32,23 @@ public class BifidCipherControllerTest{
|
||||
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 static final String bifidName = "bifidName";
|
||||
private static final String bifidDescription = "bifidDescription";
|
||||
private static final List<String> bifidExplanation = List.of("bifidExplanation1", "bifidExplanation2", "bifidExplanation3");
|
||||
private static final List<String> bifidFacts = List.of("bifidFact1", "bifidFact2", "bifidFact3");
|
||||
private static final String BIFID_NAME = "bifidName";
|
||||
private static final String BIFID_DESCRIPTION = "bifidDescription";
|
||||
private static final List<String> BIFID_EXPLANATION = List.of("bifidExplanation1", "bifidExplanation2", "bifidExplanation3");
|
||||
private static final List<String> BIFID_FACTS = List.of("bifidFact1", "bifidFact2", "bifidFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidName", bifidName);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", bifidDescription);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidExplanation", bifidExplanation);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidFacts", bifidFacts);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidName", BIFID_NAME);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidDescription", BIFID_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidExplanation", BIFID_EXPLANATION);
|
||||
ReflectionTestUtils.setField(bifidCipherController, "bifidFacts", BIFID_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(bifidName, bifidDescription, bifidExplanation, bifidFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(BIFID_NAME, BIFID_DESCRIPTION, BIFID_EXPLANATION, BIFID_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = bifidCipherController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class BifidCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(BIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class BifidCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(BIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(BIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private ColumnarCipherController columnarCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.ColumnarCipherController")
|
||||
protected Logger columnarLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/columnar";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Edeomte ac^gosnse";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String columnarName = "columnarName";
|
||||
private static final String columnarDescription = "columnarDescription";
|
||||
private static final List<String> columnarExplanation = List.of("columnarExplanation1", "columnarExplanation2", "columnarExplanation3");
|
||||
private static final List<String> columnarFacts = List.of("columnarFact1", "columnarFact2", "columnarFact3");
|
||||
private static final String URL = "/columnar";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Edeomte ac^gosnse";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String COLUMNAR_NAME = "columnarName";
|
||||
private static final String COLUMNAR_DESCRIPTION = "columnarDescription";
|
||||
private static final List<String> COLUMNAR_EXPLANATION = List.of("columnarExplanation1", "columnarExplanation2", "columnarExplanation3");
|
||||
private static final List<String> COLUMNAR_FACTS = List.of("columnarFact1", "columnarFact2", "columnarFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class ColumnarCipherControllerIntegrationTest extends CipherStreamControl
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarName", columnarName);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", columnarDescription);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarExplanation", columnarExplanation);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarFacts", columnarFacts);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarName", COLUMNAR_NAME);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", COLUMNAR_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarExplanation", COLUMNAR_EXPLANATION);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarFacts", COLUMNAR_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(columnarName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(columnarDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(COLUMNAR_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(COLUMNAR_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(columnarExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(columnarExplanation.get(0), columnarExplanation.get(1), columnarExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(COLUMNAR_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(COLUMNAR_EXPLANATION.get(0), COLUMNAR_EXPLANATION.get(1), COLUMNAR_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(columnarFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(columnarFacts.get(0), columnarFacts.get(1), columnarFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(columnarLogger, times(1)).info("Getting info for {}", columnarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(COLUMNAR_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(COLUMNAR_FACTS.get(0), COLUMNAR_FACTS.get(1), COLUMNAR_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeColumnar() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", columnarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodecolumnar_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", columnarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeColumnar() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", columnarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodecolumnar_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", columnarName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,24 +32,24 @@ public class ColumnarCipherControllerTest{
|
||||
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 static final String columnarName = "columnarName";
|
||||
private static final String columnarDescription = "columnarDescription";
|
||||
private static final List<String> columnarExplanation = List.of("columnarExplanation1", "columnarExplanation2", "columnarExplanation3");
|
||||
private static final List<String> columnarFacts = List.of("columnarFact1", "columnarFact2", "columnarFact3");
|
||||
private static final String COLUMNAR_NAME = "columnarName";
|
||||
private static final String COLUMNAR_DESCRIPTION = "columnarDescription";
|
||||
private static final List<String> COLUMNAR_EXPLANATION = List.of("columnarExplanation1", "columnarExplanation2", "columnarExplanation3");
|
||||
private static final List<String> COLUMNAR_FACTS = List.of("columnarFact1", "columnarFact2", "columnarFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarName", columnarName);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", columnarDescription);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarExplanation", columnarExplanation);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarFacts", columnarFacts);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarName", COLUMNAR_NAME);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarDescription", COLUMNAR_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarExplanation", COLUMNAR_EXPLANATION);
|
||||
ReflectionTestUtils.setField(columnarCipherController, "columnarFacts", COLUMNAR_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(columnarName, columnarDescription, columnarExplanation, columnarFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(COLUMNAR_NAME, COLUMNAR_DESCRIPTION, COLUMNAR_EXPLANATION, COLUMNAR_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = columnarCipherController.getCipherInfo();
|
||||
@@ -66,7 +67,7 @@ public class ColumnarCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(COLUMNAR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +86,7 @@ public class ColumnarCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(COLUMNAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(COLUMNAR_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private HillCipherController hillCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.HillCipherController")
|
||||
protected Logger hillLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/hill";
|
||||
private static final String decodedString = "Message to^encoded";
|
||||
private static final String encodedString = "Mgkeqge ul^ikhisplrd";
|
||||
private static final int[][] keyArray = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
private static final String hillName = "hillName";
|
||||
private static final String hillDescription = "hillDescription";
|
||||
private static final List<String> hillExplanation = List.of("hillExplanation1", "hillExplanation2", "hillExplanation3");
|
||||
private static final List<String> hillFacts = List.of("hillFact1", "hillFact2", "hillFact3");
|
||||
private static final String URL = "/hill";
|
||||
private static final String DECODED_STRING = "Message to^encoded";
|
||||
private static final String ENCODED_STRING = "Mgkeqge ul^ikhisplrd";
|
||||
private static final int[][] KEY_ARRAY = new int[][]{{1, 4, 2}, {2, 4, 1}, {4, 1, 2}};
|
||||
private static final String HILL_NAME = "hillName";
|
||||
private static final String HILL_DESCRIPTION = "hillDescription";
|
||||
private static final List<String> HILL_EXPLANATION = List.of("hillExplanation1", "hillExplanation2", "hillExplanation3");
|
||||
private static final List<String> HILL_FACTS = List.of("hillFact1", "hillFact2", "hillFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class HillCipherControllerIntegrationTest extends CipherStreamControllerI
|
||||
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);
|
||||
decodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(KEY_ARRAY));
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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");
|
||||
encodedNode.set(CipherParameterUtil.HILL_KEY, mapper.valueToTree(KEY_ARRAY));
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING + "xx");
|
||||
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillName", hillName);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillDescription", hillDescription);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillExplanation", hillExplanation);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillFacts", hillFacts);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillName", HILL_NAME);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillDescription", HILL_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillExplanation", HILL_EXPLANATION);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillFacts", HILL_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(hillName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(hillDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(HILL_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(HILL_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(hillExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(hillExplanation.get(0), hillExplanation.get(1), hillExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(HILL_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(HILL_EXPLANATION.get(0), HILL_EXPLANATION.get(1), HILL_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(hillFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(hillFacts.get(0), hillFacts.get(1), hillFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(hillLogger, times(1)).info("Getting info for {}", hillName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(HILL_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(HILL_FACTS.get(0), HILL_FACTS.get(1), HILL_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", hillName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodehill_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", hillName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeHill() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", hillName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING + "xx"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodehill_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", hillName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -33,24 +33,24 @@ public class HillCipherControllerTest{
|
||||
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 static final String hillName = "hillName";
|
||||
private static final String hillDescription = "hillDescription";
|
||||
private static final List<String> hillExplanation = List.of("hillExplanation1", "hillExplanation2", "hillExplanation3");
|
||||
private static final List<String> hillFacts = List.of("hillFact1", "hillFact2", "hillFact3");
|
||||
private static final String HILL_NAME = "hillName";
|
||||
private static final String HILL_DESCRIPTION = "hillDescription";
|
||||
private static final List<String> HILL_EXPLANATION = List.of("hillExplanation1", "hillExplanation2", "hillExplanation3");
|
||||
private static final List<String> HILL_FACTS = List.of("hillFact1", "hillFact2", "hillFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillName", hillName);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillDescription", hillDescription);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillExplanation", hillExplanation);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillFacts", hillFacts);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillName", HILL_NAME);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillDescription", HILL_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillExplanation", HILL_EXPLANATION);
|
||||
ReflectionTestUtils.setField(hillCipherController, "hillFacts", HILL_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(hillName, hillDescription, hillExplanation, hillFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(HILL_NAME, HILL_DESCRIPTION, HILL_EXPLANATION, HILL_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = hillCipherController.getCipherInfo();
|
||||
@@ -60,7 +60,7 @@ public class HillCipherControllerTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeHill() throws JsonProcessingException{
|
||||
public void testEncodeHill(){
|
||||
ObjectNode cipherParams = generateParams(HILL_INPUT_STRING);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class HillCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(HILL_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +79,7 @@ public class HillCipherControllerTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeHill() throws JsonProcessingException{
|
||||
public void testDecodeHill(){
|
||||
ObjectNode cipherParams = generateParams(HILL_OUTPUT_STRING);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public class HillCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(HILL_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(HILL_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,136 +28,94 @@ public class MorseCodeControllerIntegrationTest extends CipherStreamControllerIn
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private MorseCodeController morseCodeController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.MorseCodeController")
|
||||
protected Logger morseLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/morse";
|
||||
private static final String decodedString = "Message to^encode123";
|
||||
private static final String encodedString = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
private static final String morseName = "morseName";
|
||||
private static final String morseDescription = "morseDescription";
|
||||
private static final List<String> morseExplanation = List.of("morseExplanation1", "morseExplanation2", "morseExplanation3");
|
||||
private static final List<String> morseFacts = List.of("morseFact1", "morseFact2", "morseFact3");
|
||||
private static final String URL = "/morse";
|
||||
private static final String DECODED_STRING = "Message to^encode123";
|
||||
private static final String ENCODED_STRING = "-- . ... ... .- --. . - --- . -. -.-. --- -.. . .---- ..--- ...--";
|
||||
private static final String MORSE_NAME = "morseName";
|
||||
private static final String MORSE_DESCRIPTION = "morseDescription";
|
||||
private static final List<String> MORSE_EXPLANATION = List.of("morseExplanation1", "morseExplanation2", "morseExplanation3");
|
||||
private static final List<String> MORSE_FACTS = List.of("morseFact1", "morseFact2", "morseFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
decodedNode = mapper.createObjectNode();
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, decodedString);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, encodedString);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
encodedNode = mapper.createObjectNode();
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, encodedString);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, decodedString.toUpperCase().replaceAll("[^A-Z0-9]", ""));
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING.toUpperCase().replaceAll("[^A-Z0-9]", ""));
|
||||
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseName", morseName);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseDescription", morseDescription);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseExplanation", morseExplanation);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseFacts", morseFacts);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseName", MORSE_NAME);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseDescription", MORSE_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseExplanation", MORSE_EXPLANATION);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseFacts", MORSE_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(morseName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(morseDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(MORSE_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(MORSE_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(morseExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(morseExplanation.get(0), morseExplanation.get(1), morseExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(MORSE_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(MORSE_EXPLANATION.get(0), MORSE_EXPLANATION.get(1), MORSE_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(morseFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(morseFacts.get(0), morseFacts.get(1), morseFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(morseLogger, times(1)).info("Getting info for {}", morseName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(MORSE_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(MORSE_FACTS.get(0), MORSE_FACTS.get(1), MORSE_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeMorse() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", morseName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodemorse_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", morseName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeMorse() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", morseName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING.toUpperCase().replaceAll("[^A-Z0-9]", "")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodemorse_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", morseName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -30,24 +31,24 @@ public class MorseCodeControllerTest{
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String MORSE_INPUT_STRING = "SOS";
|
||||
private static final String MORSE_OUTPUT_STRING = "... --- ...";
|
||||
private static final String morseName = "morseName";
|
||||
private static final String morseDescription = "morseDescription";
|
||||
private static final List<String> morseExplanation = List.of("morseExplanation1", "morseExplanation2", "morseExplanation3");
|
||||
private static final List<String> morseFacts = List.of("morseFact1", "morseFact2", "morseFact3");
|
||||
private static final String MORSE_NAME = "morseName";
|
||||
private static final String MORSE_DESCRIPTION = "morseDescription";
|
||||
private static final List<String> MORSE_EXPLANATION = List.of("morseExplanation1", "morseExplanation2", "morseExplanation3");
|
||||
private static final List<String> MORSE_FACTS = List.of("morseFact1", "morseFact2", "morseFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseName", morseName);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseDescription", morseDescription);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseExplanation", morseExplanation);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseFacts", morseFacts);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseName", MORSE_NAME);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseDescription", MORSE_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseExplanation", MORSE_EXPLANATION);
|
||||
ReflectionTestUtils.setField(morseCodeController, "morseFacts", MORSE_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(morseName, morseDescription, morseExplanation, morseFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(MORSE_NAME, MORSE_DESCRIPTION, MORSE_EXPLANATION, MORSE_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = morseCodeController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class MorseCodeControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(MORSE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class MorseCodeControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(MORSE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(MORSE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,20 +28,16 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private PlayfairCipherController playfairCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PlayfairCipherController")
|
||||
protected Logger playfairLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/playfair";
|
||||
private static final String decodedString = "Hide the gold in - the@tree+stump";
|
||||
private static final String decodedStringPadded = "Hide the gold in - the@trexe+stump";
|
||||
private static final String encodedString = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private static final String keyword = "Play-fair@Exam ple";
|
||||
private static final String playfairName = "playfairName";
|
||||
private static final String playfairDescription = "playfairDescription";
|
||||
private static final List<String> playfairExplanation = List.of("playfairExplanation1", "playfairExplanation2", "playfairExplanation3");
|
||||
private static final List<String> playfairFacts = List.of("playfairFact1", "playfairFact2", "playfairFact3");
|
||||
private static final String URL = "/playfair";
|
||||
private static final String DECODED_STRING = "Hide the gold in - the@tree+stump";
|
||||
private static final String DECODED_STRING_PADDED = "Hide the gold in - the@trexe+stump";
|
||||
private static final String ENCODED_STRING = "Bmod zbx dnab ek - udm@uixmm+ouvif";
|
||||
private static final String KEYWORD = "Play-fair@Exam ple";
|
||||
private static final String PLAYFAIR_NAME = "playfairName";
|
||||
private static final String PLAYFAIR_DESCRIPTION = "playfairDescription";
|
||||
private static final List<String> PLAYFAIR_EXPLANATION = List.of("playfairExplanation1", "playfairExplanation2", "playfairExplanation3");
|
||||
private static final List<String> PLAYFAIR_FACTS = List.of("playfairFact1", "playfairFact2", "playfairFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -55,125 +46,87 @@ public class PlayfairCipherControllerIntegrationTest extends CipherStreamControl
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING_PADDED);
|
||||
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairName", playfairName);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", playfairDescription);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairExplanation", playfairExplanation);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairFacts", playfairFacts);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairName", PLAYFAIR_NAME);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", PLAYFAIR_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairExplanation", PLAYFAIR_EXPLANATION);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairFacts", PLAYFAIR_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(playfairName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(playfairDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(PLAYFAIR_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(PLAYFAIR_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(playfairExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(playfairExplanation.get(0), playfairExplanation.get(1), playfairExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(PLAYFAIR_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(PLAYFAIR_EXPLANATION.get(0), PLAYFAIR_EXPLANATION.get(1), PLAYFAIR_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(playfairFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(playfairFacts.get(0), playfairFacts.get(1), playfairFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(playfairLogger, times(1)).info("Getting info for {}", playfairName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(PLAYFAIR_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(PLAYFAIR_FACTS.get(0), PLAYFAIR_FACTS.get(1), PLAYFAIR_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePlayfair() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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(playfairLogger, times(1)).info("Encoding {}", playfairName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeplayfair_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", playfairName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePlayfair() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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(playfairLogger, times(1)).info("Decoding {}", playfairName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING_PADDED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeplayfair_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", playfairName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -32,24 +33,24 @@ public class PlayfairCipherControllerTest{
|
||||
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 static final String playfairName = "playfairName";
|
||||
private static final String playfairDescription = "playfairDescription";
|
||||
private static final List<String> playfairExplanation = List.of("playfairExplanation1", "playfairExplanation2", "playfairExplanation3");
|
||||
private static final List<String> playfairFacts = List.of("playfairFact1", "playfairFact2", "playfairFact3");
|
||||
private static final String PLAYFAIR_NAME = "playfairName";
|
||||
private static final String PLAYFAIR_DESCRIPTION = "playfairDescription";
|
||||
private static final List<String> PLAYFAIR_EXPLANATION = List.of("playfairExplanation1", "playfairExplanation2", "playfairExplanation3");
|
||||
private static final List<String> PLAYFAIR_FACTS = List.of("playfairFact1", "playfairFact2", "playfairFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairName", playfairName);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", playfairDescription);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairExplanation", playfairExplanation);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairFacts", playfairFacts);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairName", PLAYFAIR_NAME);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairDescription", PLAYFAIR_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairExplanation", PLAYFAIR_EXPLANATION);
|
||||
ReflectionTestUtils.setField(playfairCipherController, "playfairFacts", PLAYFAIR_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(playfairName, playfairDescription, playfairExplanation, playfairFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(PLAYFAIR_NAME, PLAYFAIR_DESCRIPTION, PLAYFAIR_EXPLANATION, PLAYFAIR_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = playfairCipherController.getCipherInfo();
|
||||
@@ -67,7 +68,7 @@ public class PlayfairCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(PLAYFAIR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(PLAYFAIR_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,7 +87,7 @@ public class PlayfairCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(DECODED_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(DECODED_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private PolybiusSquareController polybiusSquareController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.PolybiusSquareController")
|
||||
protected Logger polybiusLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/polybius";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "41124545233212 5115^124225152212";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String polybiusName = "polybiusName";
|
||||
private static final String polybiusDescription = "polybiusDescription";
|
||||
private static final List<String> polybiusExplanation = List.of("polybiusExplanation1", "polybiusExplanation2", "polybiusExplanation3");
|
||||
private static final List<String> polybiusFacts = List.of("polybiusFact1", "polybiusFact2", "polybiusFact3");
|
||||
private static final String URL = "/polybius";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "41124545233212 5115^124225152212";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String POLYBIUS_NAME = "polybiusName";
|
||||
private static final String POLYBIUS_DESCRIPTION = "polybiusDescription";
|
||||
private static final List<String> POLYBIUS_EXPLANATION = List.of("polybiusExplanation1", "polybiusExplanation2", "polybiusExplanation3");
|
||||
private static final List<String> POLYBIUS_FACTS = List.of("polybiusFact1", "polybiusFact2", "polybiusFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class PolybiusSquareControllerIntegrationTest extends CipherStreamControl
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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());
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING.toUpperCase());
|
||||
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", polybiusName);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", polybiusDescription);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusExplanation", polybiusExplanation);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusFacts", polybiusFacts);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", POLYBIUS_NAME);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", POLYBIUS_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusExplanation", POLYBIUS_EXPLANATION);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusFacts", POLYBIUS_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(polybiusName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(polybiusDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(POLYBIUS_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(POLYBIUS_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(polybiusExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(polybiusExplanation.get(0), polybiusExplanation.get(1), polybiusExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(POLYBIUS_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(POLYBIUS_EXPLANATION.get(0), POLYBIUS_EXPLANATION.get(1), POLYBIUS_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(polybiusFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(polybiusFacts.get(0), polybiusFacts.get(1), polybiusFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(polybiusLogger, times(1)).info("Getting info for {}", polybiusName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(POLYBIUS_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(POLYBIUS_FACTS.get(0), POLYBIUS_FACTS.get(1), POLYBIUS_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodePolybius() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", polybiusName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodepolybius_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", polybiusName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodePolybius() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", polybiusName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING.toUpperCase()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodepolybius_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", polybiusName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,23 +32,23 @@ public class PolybiusSquareControllerTest{
|
||||
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 static final String polybiusName = "polybiusName";
|
||||
private static final String polybiusDescription = "polybiusDescription";
|
||||
private static final List<String> polybiusExplanation = List.of("PolybiusExplanation1", "PolybiusExplanation2", "PolybiusExplanation3");
|
||||
private static final List<String> polybiusFacts = List.of("PolybiusFact1", "PolybiusFact2", "PolybiusFact3");
|
||||
private static final String POLYBIUS_NAME = "polybiusName";
|
||||
private static final String POLYBIUS_DESCRIPTION = "polybiusDescription";
|
||||
private static final List<String> POLYBIUS_EXPLANATION = List.of("PolybiusExplanation1", "PolybiusExplanation2", "PolybiusExplanation3");
|
||||
private static final List<String> POLYBIUS_FACTS = List.of("PolybiusFact1", "PolybiusFact2", "PolybiusFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", polybiusName);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", polybiusDescription);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusExplanation", polybiusExplanation);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusFacts", polybiusFacts);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusName", POLYBIUS_NAME);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusDescription", POLYBIUS_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusExplanation", POLYBIUS_EXPLANATION);
|
||||
ReflectionTestUtils.setField(polybiusSquareController, "polybiusFacts", POLYBIUS_FACTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(polybiusName, polybiusDescription, polybiusExplanation, polybiusFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(POLYBIUS_NAME, POLYBIUS_DESCRIPTION, POLYBIUS_EXPLANATION, POLYBIUS_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = polybiusSquareController.getCipherInfo();
|
||||
@@ -65,7 +66,7 @@ public class PolybiusSquareControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(POLYBIUS_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ public class PolybiusSquareControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(POLYBIUS_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(POLYBIUS_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,19 +28,15 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private RailFenceController railFenceController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.RailFenceController")
|
||||
protected Logger railFenceLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/railFence";
|
||||
private static final String decodedString = "Message to^encode";
|
||||
private static final String encodedString = "Maooesg te^cdsene";
|
||||
private static final int rails = 3;
|
||||
private static final String railFenceName = "railFenceName";
|
||||
private static final String railFenceDescription = "railFenceDescription";
|
||||
private static final List<String> railFenceExplanation = List.of("railFenceExplanation1", "railFenceExplanation2", "railFenceExplanation3");
|
||||
private static final List<String> railFenceFacts = List.of("railFenceFact1", "railFenceFact2", "railFenceFact3");
|
||||
private static final String URL = "/railFence";
|
||||
private static final String DECODED_STRING = "Message to^encode";
|
||||
private static final String ENCODED_STRING = "Maooesg te^cdsene";
|
||||
private static final int RAILS = 3;
|
||||
private static final String RAIL_FENCE_NAME = "railFenceName";
|
||||
private static final String RAIL_FENCE_DESCRIPTION = "railFenceDescription";
|
||||
private static final List<String> RAIL_FENCE_EXPLANATION = List.of("railFenceExplanation1", "railFenceExplanation2", "railFenceExplanation3");
|
||||
private static final List<String> RAIL_FENCE_FACTS = List.of("railFenceFact1", "railFenceFact2", "railFenceFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -54,125 +45,87 @@ public class RailFenceControllerIntegrationTest extends CipherStreamControllerIn
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, RAILS);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.RAIL_FENCE_RAILS, RAILS);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceName", railFenceName);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceDescription", railFenceDescription);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceExplanation", railFenceExplanation);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceFacts", railFenceFacts);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceName", RAIL_FENCE_NAME);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceDescription", RAIL_FENCE_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceExplanation", RAIL_FENCE_EXPLANATION);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceFacts", RAIL_FENCE_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(railFenceName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(railFenceDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(RAIL_FENCE_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(RAIL_FENCE_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(railFenceExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(railFenceExplanation.get(0), railFenceExplanation.get(1), railFenceExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(RAIL_FENCE_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(RAIL_FENCE_EXPLANATION.get(0), RAIL_FENCE_EXPLANATION.get(1), RAIL_FENCE_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(railFenceFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(railFenceFacts.get(0), railFenceFacts.get(1), railFenceFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(railFenceLogger, times(1)).info("Getting info for {}", railFenceName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(RAIL_FENCE_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(RAIL_FENCE_FACTS.get(0), RAIL_FENCE_FACTS.get(1), RAIL_FENCE_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeRailFence() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", railFenceName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncoderailFence_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", railFenceName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeRailFence() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", railFenceName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecoderailFence_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", railFenceName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -31,24 +32,24 @@ public class RailFenceControllerTest{
|
||||
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 static final String railFenceName = "railFenceName";
|
||||
private static final String railFenceDescription = "railFenceDescription";
|
||||
private static final List<String> railFenceExplanation = List.of("railFenceExplanation1", "railFenceExplanation2", "railFenceExplanation3");
|
||||
private static final List<String> railFenceFacts = List.of("railFenceFact1", "railFenceFact2", "railFenceFact3");
|
||||
private static final String RAIL_FENCE_NAME = "railFenceName";
|
||||
private static final String RAIL_FENCE_DESCRIPTION = "railFenceDescription";
|
||||
private static final List<String> RAIL_FENCE_EXPLANATION = List.of("railFenceExplanation1", "railFenceExplanation2", "railFenceExplanation3");
|
||||
private static final List<String> RAIL_FENCE_FACTS = List.of("railFenceFact1", "railFenceFact2", "railFenceFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceName", railFenceName);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceDescription", railFenceDescription);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceExplanation", railFenceExplanation);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceFacts", railFenceFacts);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceName", RAIL_FENCE_NAME);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceDescription", RAIL_FENCE_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceExplanation", RAIL_FENCE_EXPLANATION);
|
||||
ReflectionTestUtils.setField(railFenceController, "railFenceFacts", RAIL_FENCE_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(railFenceName, railFenceDescription, railFenceExplanation, railFenceFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(RAIL_FENCE_NAME, RAIL_FENCE_DESCRIPTION, RAIL_FENCE_EXPLANATION, RAIL_FENCE_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = railFenceController.getCipherInfo();
|
||||
@@ -66,7 +67,7 @@ public class RailFenceControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(RAIL_FENCE_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +86,7 @@ public class RailFenceControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(RAIL_FENCE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(RAIL_FENCE_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.controller.polysubstitution;
|
||||
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@@ -11,16 +10,12 @@ import java.util.List;
|
||||
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.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.CipherStreamControllerIntegrationTestBase;
|
||||
import com.mattrixwv.cipherstream.utils.CipherInfoUtil;
|
||||
import com.mattrixwv.cipherstream.utils.CipherParameterUtil;
|
||||
@@ -33,21 +28,17 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private TrifidCipherController trifidCipherController;
|
||||
//Loggers
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.polysubstitution.TrifidCipherController")
|
||||
protected Logger trifidLogger;
|
||||
//Fields
|
||||
private static final ObjectNode blankNode = mapper.createObjectNode();
|
||||
private static final String url = "/trifid";
|
||||
private static final String decodedString = "Message to^encode+";
|
||||
private static final String encodedString = "Gqdokpd od^ljvflf+";
|
||||
private static final String keyword = "keyword";
|
||||
private static final String trifidFill = "=";
|
||||
private static final int grouplength = Integer.MAX_VALUE;
|
||||
private static final String trifidName = "trifidName";
|
||||
private static final String trifidDescription = "trifidDescription";
|
||||
private static final List<String> trifidExplanation = List.of("trifidExplanation1", "trifidExplanation2", "trifidExplanation3");
|
||||
private static final List<String> trifidFacts = List.of("trifidFact1", "trifidFact2", "trifidFact3");
|
||||
private static final String URL = "/trifid";
|
||||
private static final String DECODED_STRING = "Message to^encode+";
|
||||
private static final String ENCODED_STRING = "Gqdokpd od^ljvflf+";
|
||||
private static final String KEYWORD = "keyword";
|
||||
private static final String TRIFID_FILL = "=";
|
||||
private static final int GROUP_LENGTH = Integer.MAX_VALUE;
|
||||
private static final String TRIFID_NAME = "trifidName";
|
||||
private static final String TRIFID_DESCRIPTION = "trifidDescription";
|
||||
private static final List<String> TRIFID_EXPLANATION = List.of("trifidExplanation1", "trifidExplanation2", "trifidExplanation3");
|
||||
private static final List<String> TRIFID_FACTS = List.of("trifidFact1", "trifidFact2", "trifidFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@@ -56,129 +47,91 @@ public class TrifidCipherControllerIntegrationTest extends CipherStreamControlle
|
||||
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);
|
||||
decodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
decodedNode.put(CipherParameterUtil.TRIFID_FILL, TRIFID_FILL);
|
||||
decodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, GROUP_LENGTH);
|
||||
decodedNode.put(CipherParameterUtil.INPUT_STRING, DECODED_STRING);
|
||||
decodedNode.put(CipherParameterUtil.OUTPUT_STRING, ENCODED_STRING);
|
||||
|
||||
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);
|
||||
encodedNode.put(CipherParameterUtil.KEYWORD, KEYWORD);
|
||||
encodedNode.put(CipherParameterUtil.TRIFID_FILL, TRIFID_FILL);
|
||||
encodedNode.put(CipherParameterUtil.TRIFID_GROUP_LENGTH, GROUP_LENGTH);
|
||||
encodedNode.put(CipherParameterUtil.INPUT_STRING, ENCODED_STRING);
|
||||
encodedNode.put(CipherParameterUtil.OUTPUT_STRING, DECODED_STRING);
|
||||
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidName", trifidName);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", trifidDescription);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidExplanation", trifidExplanation);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidFacts", trifidFacts);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidName", TRIFID_NAME);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", TRIFID_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidExplanation", TRIFID_EXPLANATION);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidFacts", TRIFID_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetCipherInfo() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress))
|
||||
mockMvc.perform(get(URL)
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(trifidName))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(trifidDescription))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_NAME).value(TRIFID_NAME))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_DESCRIPTION).value(TRIFID_DESCRIPTION))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(trifidExplanation.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(trifidExplanation.get(0), trifidExplanation.get(1), trifidExplanation.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasSize(TRIFID_EXPLANATION.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_EXPLANATION, hasItems(TRIFID_EXPLANATION.get(0), TRIFID_EXPLANATION.get(1), TRIFID_EXPLANATION.get(2))))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS).isArray())
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(trifidFacts.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(trifidFacts.get(0), trifidFacts.get(1), trifidFacts.get(2))));
|
||||
|
||||
//Filter
|
||||
super.verifyFilter(url);
|
||||
//Controller
|
||||
verify(trifidLogger, times(1)).info("Getting info for {}", trifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasSize(TRIFID_FACTS.size())))
|
||||
.andExpect(jsonPath(CipherInfoUtil.CIPHER_FACTS, hasItems(TRIFID_FACTS.get(0), TRIFID_FACTS.get(1), TRIFID_FACTS.get(2))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeTrifid() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", trifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", decodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(ENCODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodetrifid_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/encode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/encode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", trifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodeTrifid() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", trifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
|
||||
//Cipher Aspect
|
||||
verify(aspectLogger, times(1)).info("CipherStream log {}", encodedNode);
|
||||
.andExpect(jsonPath(CipherParameterUtil.OUTPUT_STRING).value(DECODED_STRING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecodetrifid_error() throws Exception{
|
||||
mockMvc.perform(post(url + "/decode")
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddress)
|
||||
mockMvc.perform(post(URL + "/decode")
|
||||
.header("X-Request-Id", REQUEST_ID)
|
||||
.header("X-Forwarded-For", IP_ADDRESS)
|
||||
.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 {}", trifidName);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
|
||||
//Cipher Aspect
|
||||
verifyNoInteractions(aspectLogger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
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;
|
||||
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
|
||||
@Tag("unit-test")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -33,24 +34,24 @@ public class TrifidCipherControllerTest{
|
||||
private static final String TRIFID_KEYWORD = CipherParameterUtil.KEYWORD;
|
||||
private static final char TRIFID_FILL_ID = '+';
|
||||
private static final int TRIFID_GROUP_LENGTH = 3;
|
||||
private static final String trifidName = "trifidName";
|
||||
private static final String trifidDescription = "trifidDescription";
|
||||
private static final List<String> trifidExplanation = List.of("trifidExplanation1", "trifidExplanation2", "trifidExplanation3");
|
||||
private static final List<String> trifidFacts = List.of("trifidFact1", "trifidFact2", "trifidFact3");
|
||||
private static final String TRIFID_NAME = "trifidName";
|
||||
private static final String TRIFID_DESCRIPTION = "trifidDescription";
|
||||
private static final List<String> TRIFID_EXPLANATION = List.of("trifidExplanation1", "trifidExplanation2", "trifidExplanation3");
|
||||
private static final List<String> TRIFID_FACTS = List.of("trifidFact1", "trifidFact2", "trifidFact3");
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(){
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidName", trifidName);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", trifidDescription);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidExplanation", trifidExplanation);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidFacts", trifidFacts);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidName", TRIFID_NAME);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidDescription", TRIFID_DESCRIPTION);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidExplanation", TRIFID_EXPLANATION);
|
||||
ReflectionTestUtils.setField(trifidCipherController, "trifidFacts", TRIFID_FACTS);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tetGetCipherInfo(){
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(trifidName, trifidDescription, trifidExplanation, trifidFacts);
|
||||
ObjectNode infoNode = CipherInfoUtil.buildInfoNode(TRIFID_NAME, TRIFID_DESCRIPTION, TRIFID_EXPLANATION, TRIFID_FACTS);
|
||||
|
||||
|
||||
ObjectNode returnedJson = trifidCipherController.getCipherInfo();
|
||||
@@ -68,7 +69,7 @@ public class TrifidCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(TRIFID_OUTPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +88,7 @@ public class TrifidCipherControllerTest{
|
||||
|
||||
|
||||
assertEquals(cipherParams, returnedJson);
|
||||
assertEquals(TRIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asText());
|
||||
assertEquals(TRIFID_INPUT_STRING, returnedJson.get(CipherParameterUtil.OUTPUT_STRING).asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.cipherstream.exception.InvalidCipherParameterException;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user