summaryrefslogtreecommitdiffstats
path: root/security/ssl/src/test/java
diff options
context:
space:
mode:
authorPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2019-02-15 14:49:54 +0100
committerPiotr Jaszczyk <piotr.jaszczyk@nokia.com>2019-02-18 15:20:20 +0100
commit28a5b0d5b6c844ca78665bded229e67a429800b7 (patch)
treee3fad7c857de1a734027fa9ccc3e9dcbb3cc29a5 /security/ssl/src/test/java
parent244b070d680eaac727091193b0998c76c78cc230 (diff)
Remove vavr from SSL API
It is still used internally, but methods does not depend on it. The goal was to support clean integration with any JVM app, ie. apps using Kotlin are rather using Arrow or nothing at all. Issue-ID: DCAEGEN2-1069 Change-Id: I1a9151bacd287d65ca8c84057de2f3c174cf8145 Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'security/ssl/src/test/java')
-rw-r--r--security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordTest.java16
-rw-r--r--security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordsTest.java64
2 files changed, 55 insertions, 25 deletions
diff --git a/security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordTest.java b/security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordTest.java
index ede227eb..41143f61 100644
--- a/security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordTest.java
+++ b/security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordTest.java
@@ -24,10 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import io.vavr.collection.Array;
-import io.vavr.control.Try;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.security.ssl.exceptions.PasswordEvictedException;
/**
* @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
@@ -66,10 +66,10 @@ class PasswordTest {
final Password cut = new Password("ala ma kota".toCharArray());
// when & then
- useThePassword(cut).get();
+ useThePassword(cut);
- assertThatExceptionOfType(GeneralSecurityException.class).isThrownBy(() ->
- useThePassword(cut).get());
+ assertThatExceptionOfType(PasswordEvictedException.class).isThrownBy(() ->
+ useThePassword(cut));
}
@Test
@@ -80,8 +80,8 @@ class PasswordTest {
// when & then
cut.clear();
- assertThatExceptionOfType(GeneralSecurityException.class).isThrownBy(() ->
- useThePassword(cut).get());
+ assertThatExceptionOfType(PasswordEvictedException.class).isThrownBy(() ->
+ useThePassword(cut));
}
@Test
@@ -97,8 +97,8 @@ class PasswordTest {
assertAllCharsAreNull(passwordChars);
}
- private Try<Object> useThePassword(Password cut) {
- return cut.use((pass) -> Try.success(42));
+ private void useThePassword(Password cut) {
+ cut.use((pass) -> null);
}
private void assertAllCharsAreNull(char[] passwordChars) {
diff --git a/security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordsTest.java b/security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordsTest.java
index 07c5afe8..13d7f213 100644
--- a/security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordsTest.java
+++ b/security/ssl/src/test/java/org/onap/dcaegen2/services/sdk/security/ssl/PasswordsTest.java
@@ -21,15 +21,17 @@
package org.onap.dcaegen2.services.sdk.security.ssl;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import io.vavr.control.Try;
import java.io.File;
import java.net.URISyntaxException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.security.ssl.exceptions.ReadingPasswordFromFileException;
/**
* @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
@@ -38,28 +40,62 @@ import org.junit.jupiter.api.Test;
class PasswordsTest {
@Test
+ void wrap() {
+ // given
+ final char[] passwd = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
+
+ // when
+ final Password result = Passwords.wrap(passwd);
+
+ // then
+ assertThat(extractPassword(result)).isEqualTo("password");
+ assertThat(passwd).containsOnly('\0');
+ }
+
+ @Test
+ void fromString() {
+ // given
+ final String passwd = "password";
+
+ // when
+ final Password result = Passwords.fromString(passwd);
+
+ // then
+ assertThat(extractPassword(result)).isEqualTo("password");
+ }
+
+ @Test
void fromFile() {
// given
final File file = new File("./src/test/resources/password.txt");
// when
- final Try<Password> result = Passwords.fromFile(file);
+ final Password result = Passwords.fromFile(file);
// then
- assertSuccessful(result);
assertThat(extractPassword(result)).isEqualTo("ja baczewski\n2nd line");
}
@Test
+ void fromFileWhenNotExisting() {
+ // given
+ final File file = new File("./not existing file");
+
+ // when & then
+ assertThatThrownBy(() -> Passwords.fromFile(file))
+ .isInstanceOf(ReadingPasswordFromFileException.class)
+ .hasCauseInstanceOf(NoSuchFileException.class);
+ }
+
+ @Test
void fromPath() throws URISyntaxException {
// given
final Path path = Paths.get(PasswordsTest.class.getResource("/password.txt").toURI());
// when
- final Try<Password> result = Passwords.fromPath(path);
+ final Password result = Passwords.fromPath(path);
// then
- assertSuccessful(result);
assertThat(extractPassword(result)).isEqualTo("ja baczewski\n2nd line");
}
@@ -69,11 +105,10 @@ class PasswordsTest {
final Path path = Paths.get("/", UUID.randomUUID().toString());
// when
- final Try<Password> result = Passwords.fromPath(path);
+ Assertions.assertThrows(ReadingPasswordFromFileException.class, () -> {
+ Passwords.fromPath(path);
+ });
- // then
- assertThat(result.isFailure()).describedAs("Try.failure?").isTrue();
- assertThat(result.getCause()).isInstanceOf(NoSuchFileException.class);
}
@Test
@@ -82,18 +117,13 @@ class PasswordsTest {
final String resource = "/password.txt";
// when
- final Try<Password> result = Passwords.fromResource(resource);
+ final Password result = Passwords.fromResource(resource);
// then
- assertSuccessful(result);
assertThat(extractPassword(result)).isEqualTo("ja baczewski\n2nd line");
}
- private void assertSuccessful(Try<Password> result) {
- assertThat(result.isSuccess()).describedAs("Try.success?").isTrue();
- }
-
- private String extractPassword(Try<Password> result) {
- return result.flatMap(pass -> pass.useChecked(String::new)).get();
+ private String extractPassword(Password pass) {
+ return pass.use(String::new);
}
} \ No newline at end of file