This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AUT-374 - Validate country against allowed country codes list and val… (
#121) * AUT-374 - Validate country against allowed country codes list and validate configured country codes against regex during application startup * AUT-374 - update translation
- Loading branch information
1 parent
c2b5028
commit 33f98d1
Showing
8 changed files
with
118 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ee.ria.sso.utils; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class CountryCodeUtil { | ||
|
||
private static final Pattern COUNTRY_CODE_PATTERN = Pattern.compile("^[A-Z]{2,2}$"); | ||
|
||
public static boolean isValidCountryCode(String countryCode) { | ||
if (StringUtils.isBlank(countryCode)) { | ||
return false; | ||
} | ||
return COUNTRY_CODE_PATTERN.matcher(countryCode).matches(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ee.ria.sso.utils; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class CountryCodeUtilTest { | ||
|
||
@Test | ||
public void validCountryCodesFormat() { | ||
assertTrue(CountryCodeUtil.isValidCountryCode("EE")); | ||
assertTrue(CountryCodeUtil.isValidCountryCode("EN")); | ||
assertTrue(CountryCodeUtil.isValidCountryCode("LT")); | ||
assertTrue(CountryCodeUtil.isValidCountryCode("RU")); | ||
assertTrue(CountryCodeUtil.isValidCountryCode("TT")); | ||
assertTrue(CountryCodeUtil.isValidCountryCode("XX")); | ||
} | ||
|
||
@Test | ||
public void invalidCountryCodeFormat() { | ||
assertFalse(CountryCodeUtil.isValidCountryCode("E")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("EEE")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("ee")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("Ee")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("E E")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode(" EE")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("EE ")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("--")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("##")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("E2")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode("")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode(" ")); | ||
assertFalse(CountryCodeUtil.isValidCountryCode(null)); | ||
} | ||
} |