Skip to content

Commit 15500df

Browse files
authored
Localhost url validation (#46)
* Implement extra seed parameters * Added automatic migration * Handle persistent SQL defaults * Added translations * Localhost URL validation
1 parent 70b0015 commit 15500df

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

core/validation/src/main/java/com/shifthackz/aisdv1/core/validation/url/UrlValidator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ interface UrlValidator {
1010
object Empty : Error
1111
object BadScheme : Error
1212
object Invalid : Error
13+
object Localhost : Error
1314
}
1415
}

core/validation/src/main/java/com/shifthackz/aisdv1/core/validation/url/UrlValidatorImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class UrlValidatorImpl : UrlValidator {
1919
isValid = false,
2020
validationError = UrlValidator.Error.BadScheme,
2121
)
22+
input.contains(LOCALHOST_IPV4) -> ValidationResult(
23+
isValid = false,
24+
validationError = UrlValidator.Error.Localhost,
25+
)
2226
!URLUtil.isValidUrl(input) -> ValidationResult(
2327
isValid = false,
2428
validationError = UrlValidator.Error.Invalid,
@@ -33,5 +37,6 @@ class UrlValidatorImpl : UrlValidator {
3337
companion object {
3438
private const val SCHEME_HTTPS = "https://"
3539
private const val SCHEME_HTTP = "http://"
40+
private const val LOCALHOST_IPV4 = "127.0.0.1"
3641
}
3742
}

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/setup/ServerSetupContract.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@ fun ValidationResult<UrlValidator.Error>.mapToUi(): UiText? {
6767
UrlValidator.Error.BadScheme -> R.string.error_invalid_scheme
6868
UrlValidator.Error.Empty -> R.string.error_empty_url
6969
UrlValidator.Error.Invalid -> R.string.error_invalid_url
70+
UrlValidator.Error.Localhost -> R.string.error_localhost_url
7071
}.asUiText()
7172
}

presentation/src/main/res/values-uk/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<string name="error_invalid">Неправильні дані</string>
145145
<string name="error_invalid_scheme">URL має починатися з <b>http://</b> або <b>https://</b></string>
146146
<string name="error_invalid_url">Недійсна URL-адреса сервера</string>
147+
<string name="error_localhost_url">Ви не можете використовувати localhost (127.0.0.1) URL-адресу для підключення до сервера.</string>
147148
<string name="error_min_size">Мінімальний розмір %1$s</string>
148149
<string name="error_max_size">Максимальний розмір %1$s</string>
149150
</resources>

presentation/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<string name="error_invalid">Invalid input</string>
145145
<string name="error_invalid_scheme">Server URL should start with <b>http://</b> or <b>https://</b></string>
146146
<string name="error_invalid_url">Invalid Server URL</string>
147+
<string name="error_localhost_url">You can not use localhost (127.0.0.1) URL to connect to server.</string>
147148
<string name="error_min_size">Minimum size is %1$s</string>
148149
<string name="error_max_size">Maximum size is %1$s</string>
149150
</resources>

0 commit comments

Comments
 (0)