Skip to content
Snippets Groups Projects
Commit 8e960306 authored by Martin Vogel's avatar Martin Vogel
Browse files

refactor: cleanup tests (planning#667)

parent 2b226732
No related branches found
No related tags found
1 merge request!321Draft: planning#667 Derive VPKI Certs from PKCS KeyStore
......@@ -29,12 +29,11 @@ class KeyStoreReaderTest {
void loadKeyStore(@TempDir final Path tempDir) throws IOException, KeyStoreException {
// Given
var path = "/badssl.com-client.p12";
byte[] bytes = getClass().getResourceAsStream(path).readAllBytes();
var configPath = Files.write(Path.of(tempDir.toString(), "badssl.com-client.p12"), bytes);
final byte[] resourceAsBytes = getResourceAsBytes("/badssl.com-client.p12");
var storePath = Files.write(Path.of(tempDir.toString(), "badssl.com-client.p12"), resourceAsBytes);
// When
final KeyStore keyStore = uut.loadKeyStore(configPath.toString(), "badssl.com");
final KeyStore keyStore = uut.loadKeyStore(storePath.toString(), "badssl.com");
// Then
assertNotNull(keyStore);
......@@ -45,12 +44,11 @@ class KeyStoreReaderTest {
void loadKeyStoreWithWrongPassword(@TempDir final Path tempDir) throws IOException {
// Given
var path = "/badssl.com-client.p12";
byte[] bytes = getClass().getResourceAsStream(path).readAllBytes();
var configPath = Files.write(Path.of(tempDir.toString(), "badssl.com-client.p12"), bytes);
final byte[] resourceAsBytes = getResourceAsBytes("/badssl.com-client.p12");
var storePath = Files.write(Path.of(tempDir.toString(), "badssl.com-client.p12"), resourceAsBytes);
// When
var exception = assertThrows(FitConnectCertificateException.class, () -> uut.loadKeyStore(configPath.toString(), "wrongPass"));
var exception = assertThrows(FitConnectCertificateException.class, () -> uut.loadKeyStore(storePath.toString(), "wrongPass"));
// Then
assertThat(exception.getMessage(), containsString("keystore password was incorrect"));
......@@ -65,4 +63,8 @@ class KeyStoreReaderTest {
// Then
assertThat(exception.getCause().getMessage(), containsString(Path.of("/wrong/path").toString()));
}
private byte[] getResourceAsBytes(String name) throws IOException {
return getClass().getResourceAsStream(name).readAllBytes();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment