Decrypt import only if password is given

This commit is contained in:
René Pfeuffer
2021-02-25 16:26:49 +01:00
parent 1ffeeb035d
commit ff4d9224f9
3 changed files with 24 additions and 4 deletions

View File

@@ -112,10 +112,9 @@ class FullScmRepositoryImporterTest {
}
@BeforeEach
void initRepositoryService() throws IOException {
void initRepositoryService() {
lenient().when(serviceFactory.create(REPOSITORY)).thenReturn(service);
lenient().when(service.getUnbundleCommand()).thenReturn(unbundleCommandBuilder);
lenient().when(repositoryImportExportEncryption.decrypt(any(), any())).thenAnswer(invocation -> invocation.getArgument(0));
}
@Test
@@ -196,5 +195,15 @@ class FullScmRepositoryImporterTest {
verify(unbundleCommandBuilder).unbundle((InputStream) argThat(argument -> argument.getClass().equals(NoneClosingInputStream.class)));
verify(workdirProvider, never()).createNewWorkdir(REPOSITORY.getId());
}
@Test
void shouldDecryptStreamWhenPasswordSet() throws IOException {
InputStream stream = Resources.getResource("sonia/scm/repository/import/scm-import.tar.gz").openStream();
when(repositoryImportExportEncryption.decrypt(any(), eq("hg2tg"))).thenAnswer(invocation -> invocation.getArgument(0));
fullImporter.importFromStream(REPOSITORY, stream, "hg2tg");
verify(updateEngine).update(REPOSITORY.getId());
}
}
}