-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Siarhei_Kakichau
committed
Jul 5, 2024
1 parent
563e803
commit cb8be41
Showing
14 changed files
with
161 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
artifact-processor/src/main/java/org/student/api/factories/ConsumerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n/java/org/student/api/OperationType.java → .../org/student/api/utils/OperationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g/student/api/ProcessMessageFunction.java → ...ent/api/utils/ProcessMessageFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
artifact-processor/src/test/java/archiver/ArchiverServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package archiver; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.student.archiver.ArchiverService; | ||
import org.student.archiver.ArchiverServiceImpl; | ||
import org.student.configs.KeyStoreConfig; | ||
import org.student.models.Artifact; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ArchiverServiceTest { | ||
|
||
private static final String RSA_ALIAS = "RSAAlias"; | ||
private static final String ROOT_PASSWORD = "P@55w0rd"; | ||
private static final String PATH_TO_KEY_STORE = "src/test/resources"; | ||
private ArchiverService archiverService; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
|
||
KeyStoreConfig config = new KeyStoreConfig(); | ||
config.setDefaultRSAAlias(RSA_ALIAS); | ||
config.setRootPassword(ROOT_PASSWORD); | ||
config.setPathToKeyStore(PATH_TO_KEY_STORE); | ||
|
||
archiverService = new ArchiverServiceImpl(config); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
Path path = Paths.get(PATH_TO_KEY_STORE + "/keystore.jks"); | ||
try { | ||
Files.deleteIfExists(path); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Test | ||
void testEncrypt() { | ||
byte[] rawArtifactMessage = "Test message".getBytes(); | ||
Artifact artifact = archiverService.encrypt(rawArtifactMessage); | ||
|
||
assertNotNull(artifact, "Artifact should not be null"); | ||
assertNotEquals(rawArtifactMessage[0], artifact.getArtifactData()[0]); | ||
} | ||
|
||
@Test | ||
void testDecrypt() { | ||
var testStr = "Test message"; | ||
byte[] rawArtifactMessage = testStr.getBytes(); | ||
Artifact encryptedArtifact = archiverService.encrypt(rawArtifactMessage); | ||
Artifact decryptedArtifact = archiverService.decrypt(encryptedArtifact); | ||
|
||
var actualStr = new String(decryptedArtifact.getArtifactData()); | ||
|
||
assertNotNull(decryptedArtifact, "Decrypted artifact should not be null"); | ||
assertEquals(actualStr, testStr); | ||
|
||
} | ||
|
||
} |