use of org.wso2.carbon.secvault.SecureVault in project carbon-apimgt by wso2.
the class FileEncryptionUtilityTestCase method testEncryptFiles.
@Test(priority = 2, description = "Test complete flow of encrypting files")
public void testEncryptFiles() throws Exception {
FileEncryptionConfigurations config = new FileEncryptionConfigurations();
List<String> filesToEncrypt = new ArrayList<>();
filesToEncrypt.add(testFileToEncrypt);
config.setFilesToEncrypt(filesToEncrypt);
SecureVault secureVault = Mockito.mock(SecureVault.class);
FileEncryptionUtility fileEncryptionUtility = FileEncryptionUtility.getInstance();
fileEncryptionUtility.setConfig(config);
fileEncryptionUtility.setAesKeyFileLocation();
fileEncryptionUtility.setSecureVault(secureVault);
Answer nonEncryptedAesKey = invocation -> {
Object[] args = invocation.getArguments();
return args[0];
};
Mockito.when(secureVault.encrypt(Mockito.anyString().getBytes())).thenAnswer(nonEncryptedAesKey);
Mockito.when(secureVault.decrypt(Mockito.anyString().getBytes())).thenAnswer(nonEncryptedAesKey);
fileEncryptionUtility.createAndStoreAESKey();
fileEncryptionUtility.encryptFiles();
Assert.assertTrue(Files.notExists(Paths.get(originalFilePath)));
Assert.assertEquals(fileEncryptionUtility.readFromEncryptedFile(encryptedFilePath), someText);
}
Aggregations