Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
1d2ed0153a
|
|||
|
3fec7b2755
|
|||
|
0d49fbe0da
|
|||
|
00e4882c2a
|
|||
|
e184b00ef5
|
|||
|
1fe4fc2d82
|
|||
|
e646d6c888
|
|||
| 18593fcfc5 | |||
| b869f6bc28 | |||
| d7c2591dab | |||
| b6bfcc0290 | |||
| 4e34267856 | |||
| 5f246d79a6 |
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>
|
||||
366
pom.xml
366
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.1.9</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.5.4</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.38</version>
|
||||
<version>1.18.42</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -73,7 +99,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-layout-template-json</artifactId>
|
||||
<version>2.25.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.24</version>
|
||||
<version>1.9.25.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--My libraries-->
|
||||
<dependency>
|
||||
<groupId>com.mattrixwv</groupId>
|
||||
<artifactId>cipher-stream-java</artifactId>
|
||||
<version>1.3.8</version>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--Tests-->
|
||||
@@ -105,166 +131,51 @@
|
||||
<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.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<!--Ensure maven is the correct version-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-maven</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>3.8.6</version>
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.0</version>
|
||||
<configuration>
|
||||
<compilerArgs>
|
||||
<arg>-Xlint:all</arg>
|
||||
</compilerArgs>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.3</version>
|
||||
<configuration>
|
||||
<skipTests>${skip.unit.tests}</skipTests>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
</excludes>
|
||||
<classpathDependencyExcludes>
|
||||
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j2-impl</classpathDependencyExclude>
|
||||
</classpathDependencyExcludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.4.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.1.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.1.4</version>
|
||||
<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>
|
||||
<version>3.5.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
<skipITs>${skip.integration.tests}</skipITs>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
</includes>
|
||||
<classpathDependencyExcludes>
|
||||
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j2-impl</classpathDependencyExclude>
|
||||
</classpathDependencyExcludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.21.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.9.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>versions-maven-plugin</artifactId>
|
||||
<version>2.18.0</version>
|
||||
<configuration>
|
||||
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!--Sonarqube-->
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>5.1.0.4751</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.13</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/CipherStreamAPI*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.owasp</groupId>
|
||||
<artifactId>dependency-check-maven</artifactId>
|
||||
<version>12.1.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>none</phase>
|
||||
@@ -273,15 +184,170 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<formats>
|
||||
<format>json</format>
|
||||
<format>html</format>
|
||||
</formats>
|
||||
<nvdApiServerId>nvd</nvdApiServerId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<!--Ensure maven is the correct version-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.6.2</version>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>3.8.6</version>
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</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.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<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>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.4</version>
|
||||
<configuration>
|
||||
<skipTests>${skip.unit.tests}</skipTests>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
</excludes>
|
||||
<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.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.1.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.1.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>3.5.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<configuration>
|
||||
<skipITs>${skip.integration.tests}</skipITs>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
</includes>
|
||||
<argLine>@{argLine} -Xshare:off -javaagent:${org.mockito:mockito-core:jar}</argLine>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.21.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.9.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>versions-maven-plugin</artifactId>
|
||||
<version>2.21.0</version>
|
||||
<configuration>
|
||||
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--Sonarqube-->
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>5.5.0.6356</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.14</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/CipherStreamAPI*</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jacoco-initialize</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>jacoco-site</id>
|
||||
<phase>none</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.owasp</groupId>
|
||||
<artifactId>dependency-check-maven</artifactId>
|
||||
<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>
|
||||
|
||||
@@ -7,9 +7,8 @@ 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
|
||||
@@ -38,8 +37,8 @@ public class CipherStreamLoggingAspect{
|
||||
public void getCipherInfo(ObjectNode returnedJson){
|
||||
//Extract JSON to MDC
|
||||
returnedJson.properties().forEach(entry -> {
|
||||
if(entry.getValue().isTextual()){
|
||||
MDC.put(entry.getKey(), entry.getValue().asText());
|
||||
if(entry.getValue().isString()){
|
||||
MDC.put(entry.getKey(), entry.getValue().asString());
|
||||
}
|
||||
else{
|
||||
MDC.put(entry.getKey(), entry.getValue().toString());
|
||||
|
||||
@@ -6,7 +6,6 @@ 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;
|
||||
|
||||
@@ -21,7 +20,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.mattrixwv.cipherstream.config;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
@@ -17,7 +16,7 @@ public class WebConfig implements WebMvcConfigurer{
|
||||
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(@NonNull CorsRegistry registry){
|
||||
public void addCorsMappings(CorsRegistry registry){
|
||||
registry.addMapping("/**")
|
||||
.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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Server options
|
||||
server.error.include-stacktrace=always
|
||||
spring.web.error.include-stacktrace=always
|
||||
server.port=8001
|
||||
server.shutdown=graceful
|
||||
spring.lifecycle.timeoutPerShutdownPhase=10s
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -6,20 +6,16 @@ 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.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
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.aspect.CipherStreamLoggingAspect;
|
||||
import com.mattrixwv.cipherstream.controller.monosubstitution.CaesarCipherController;
|
||||
|
||||
|
||||
@@ -29,13 +25,10 @@ public class FullFilterIntegrationTest{
|
||||
//HTTP
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//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}")
|
||||
@@ -44,7 +37,7 @@ public class FullFilterIntegrationTest{
|
||||
|
||||
@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")
|
||||
@@ -53,36 +46,22 @@ public class FullFilterIntegrationTest{
|
||||
.param("_", "value3"))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verify(logger, times(1)).info(eq("Request parameters: {}"), any(StringJoiner.class));
|
||||
verifyNoMoreInteractions(logger);
|
||||
verify(mdc, times(1)).put("requestId", requestId.toString());
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).put("url", url);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
verify(mdc, times(1)).clear();
|
||||
verifyNoMoreInteractions(mdc);
|
||||
verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_noParameters() throws Exception{
|
||||
mockMvc.perform(get(url)
|
||||
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));
|
||||
verifyNoMoreInteractions(logger);
|
||||
verify(mdc, times(1)).put("requestId", requestId.toString());
|
||||
verify(mdc, times(1)).put("ip", "192.168.1.1");
|
||||
verify(mdc, times(1)).put("url", url);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
verify(mdc, times(1)).clear();
|
||||
verifyNoMoreInteractions(mdc);
|
||||
verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoFilterInternal_options() throws Exception{
|
||||
mockMvc.perform(options(url)
|
||||
mockMvc.perform(options(URL)
|
||||
.header("X-Request-Id", requestId)
|
||||
.header("X-Forwarded-For", ipAddresses)
|
||||
.param("param1", "value1")
|
||||
@@ -91,8 +70,6 @@ public class FullFilterIntegrationTest{
|
||||
.param("_", "value3"))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
verifyNoInteractions(logger);
|
||||
verify(mdc, times(1)).clear();
|
||||
verifyNoMoreInteractions(mdc);
|
||||
verify(fullFilter, times(1)).doFilterInternal(any(), any(), any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,70 +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;
|
||||
|
||||
|
||||
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();
|
||||
@BeforeEach
|
||||
public void setupJson(){
|
||||
mapper = new ObjectMapper();
|
||||
blankNode = mapper.createObjectNode();
|
||||
}
|
||||
|
||||
protected void verifyAspectLogging(ObjectNode jsonNode){
|
||||
//Verify the MDC
|
||||
jsonNode.properties().forEach(entry -> {
|
||||
if(entry.getValue().isTextual()){
|
||||
verify(mdc, times(1)).put(entry.getKey(), entry.getValue().asText());
|
||||
}
|
||||
else{
|
||||
verify(mdc, times(1)).put(entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
});
|
||||
verifyNoMoreInteractions(mdc);
|
||||
|
||||
//Verify the logger
|
||||
verify(aspectLogger, times(1)).info("CipherStream log");
|
||||
verifyNoMoreInteractions(aspectLogger);
|
||||
@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
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
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.mockito.Mock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
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)
|
||||
@@ -26,28 +33,29 @@ import com.mattrixwv.cipherstream.config.FullFilter;
|
||||
public class HealthCheckControllerIntegrationTest{
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
//MDC
|
||||
@Mock
|
||||
private MDCAdapter mdc;
|
||||
//Logging
|
||||
@Mock(name = "com.mattrixwv.cipherstream.controller.HealthCheckController")
|
||||
private Logger healthLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.config.FullFilter")
|
||||
private Logger filterLogger;
|
||||
@Mock(name = "com.mattrixwv.cipherstream.aspect.CipherStreamLoggingAspect")
|
||||
protected Logger aspectLogger;
|
||||
@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());
|
||||
|
||||
//Verify results
|
||||
verify(healthLogger, times(1)).debug("Health check");
|
||||
verifyNoInteractions(filterLogger);
|
||||
verifyNoInteractions(aspectLogger);
|
||||
verify(mdc, times(1)).clear();
|
||||
verifyNoMoreInteractions(mdc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,132 +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);
|
||||
verifyNoMoreInteractions(adfgvxLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(adfgvxLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(adfgvxLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(adfgvxLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgvxName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(adfgvxLogger);
|
||||
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,132 +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);
|
||||
verifyNoMoreInteractions(adfgxLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(adfgxLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(adfgxLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(adfgxLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, adfgxName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(adfgxLogger);
|
||||
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,132 +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);
|
||||
verifyNoMoreInteractions(affineLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(affineLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(affineLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(affineLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, affineName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(affineLogger);
|
||||
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,128 +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);
|
||||
verifyNoMoreInteractions(atbashLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(atbashLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(atbashLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(atbashLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, atbashName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(atbashLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(autokeyLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(autokeyLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(autokeyLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(autokeyLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, autokeyName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(autokeyLogger);
|
||||
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,128 +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);
|
||||
verifyNoMoreInteractions(baconianLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(baconianLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(baconianLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(baconianLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baconianName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(baconianLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(baseXLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(baseXLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(baseXLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(baseXLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, baseXName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(baseXLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(beaufortLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(beaufortLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(beaufortLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(beaufortLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, beaufortName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(beaufortLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(caesarLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(caesarLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(caesarLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(caesarLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, caesarName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(caesarLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(oneTimePadLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(oneTimePadLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(oneTimePadLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(oneTimePadLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, oneTimePadName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(oneTimePadLogger);
|
||||
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,138 +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);
|
||||
verifyNoMoreInteractions(portaLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(portaLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(portaLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(portaLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, portaName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(portaLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(substitutionLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(substitutionLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(substitutionLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(substitutionLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, substitutionName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(substitutionLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(vigenereLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(vigenereLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(vigenereLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(vigenereLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, vigenereName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(vigenereLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(bifidLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(bifidLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(bifidLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(bifidLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, bifidName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(bifidLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(columnarLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(columnarLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(columnarLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(columnarLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, columnarName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(columnarLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(hillLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(hillLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(hillLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(hillLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, hillName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(hillLogger);
|
||||
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,141 +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);
|
||||
verifyNoMoreInteractions(morseLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(morseLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(morseLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(morseLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, morseName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(morseLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(playfairLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(playfairLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(playfairLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(playfairLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, playfairName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(playfairLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(polybiusLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(polybiusLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(polybiusLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(polybiusLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, polybiusName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(polybiusLogger);
|
||||
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,130 +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);
|
||||
verifyNoMoreInteractions(railFenceLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(railFenceLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(railFenceLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(railFenceLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, railFenceName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(railFenceLogger);
|
||||
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,134 +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);
|
||||
verifyNoMoreInteractions(trifidLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(trifidLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(trifidLogger);
|
||||
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);
|
||||
verifyNoMoreInteractions(trifidLogger);
|
||||
verify(mdc, times(1)).put(CipherStreamLoggingAspect.CIPHER_NAME_LOGGING, trifidName);
|
||||
//Cipher Aspect
|
||||
verifyAspectLogging(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);
|
||||
verifyNoMoreInteractions(trifidLogger);
|
||||
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