aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
+}