aboutsummaryrefslogtreecommitdiffstats
path: root/certServiceClient/src
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2020-03-18 07:59:14 +0100
committerBogumil Zebek <bogumil.zebek@nokia.com>2020-03-18 11:41:56 +0000
commit0d4320e07d220219876e77f5faf301be3a8a8a49 (patch)
tree1aa87db719864a79597eb181267fcd6c74efa6a3 /certServiceClient/src
parentc16d738408ceef496be1d8bb1b22f6c0d868e6fc (diff)
Improve validation of country code
Issue-ID: AAF-1107 Signed-off-by: pwielebs <piotr.wielebski@nokia.com> Change-Id: Id8c1ca149fd65746a02ee480cfc8abbb6b9f7b5c
Diffstat (limited to 'certServiceClient/src')
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java13
-rw-r--r--certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java6
2 files changed, 12 insertions, 7 deletions
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
index a914891f..092cd3c3 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
@@ -24,6 +24,10 @@ import org.onap.aaf.certservice.client.configuration.exception.ClientConfigurati
import org.onap.aaf.certservice.client.configuration.exception.CsrConfigurationException;
import org.onap.aaf.certservice.client.configuration.model.ConfigurationModel;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Set;
import java.util.regex.Pattern;
public abstract class AbstractConfigurationFactory<T extends ConfigurationModel> {
@@ -38,10 +42,6 @@ public abstract class AbstractConfigurationFactory<T extends ConfigurationModel>
return caName.matches("^[a-zA-Z0-9]*$");
}
- public boolean isCountryValid(String country) {
- return country.matches("^([A-Z][A-Z])$");
- }
-
public boolean isCommonNameValid(String commonName) {
return !isSpecialCharsPresent(commonName) &&
!isHttpProtocolsPresent(commonName) &&
@@ -64,4 +64,9 @@ public abstract class AbstractConfigurationFactory<T extends ConfigurationModel>
private boolean isHttpProtocolsPresent(String stringToCheck) {
return Pattern.compile("[h][t][t][p][:][/][/]|[h][t][t][p][s][:][/][/]").matcher(stringToCheck).find();
}
+
+ public boolean isCountryValid(String country) {
+ Set<String> countryNames = new HashSet<>(Arrays.asList(Locale.getISOCountries()));
+ return countryNames.contains(country);
+ }
}
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java
index edefc4de..c5955555 100644
--- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java
+++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactoryTest.java
@@ -43,13 +43,13 @@ public class AbstractConfigurationFactoryTest {
}
@ParameterizedTest
- @ValueSource(strings = {"PL", "DE", "PT", "US"})
+ @ValueSource(strings = {"PL", "DE", "PN", "US", "IO", "CA", "KH", "CO", "DK", "EC", "CZ", "CN", "BR", "BD", "BE"})
public void shouldAcceptValidCountryCode(String countryCode) {
assertThat(cut.isCountryValid(countryCode)).isTrue();
}
@ParameterizedTest
- @ValueSource(strings = {"1P", "PLP", "P#", "&*"})
+ @ValueSource(strings = {"", "QQ", "AFG", "D", "&*", "!", "ONAP", "p", "pl", "us", "afg"})
public void shouldRejectInvalidCountryCode(String countryCode) {
assertThat(cut.isCountryValid(countryCode)).isFalse();
}
@@ -77,4 +77,4 @@ public class AbstractConfigurationFactoryTest {
public void shouldRejectInvalidCommonName(String commonName) {
assertThat(cut.isCommonNameValid(commonName)).isFalse();
}
-} \ No newline at end of file
+}