-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge(#21): feat: validate config url and intent origin check
- Loading branch information
Showing
7 changed files
with
110 additions
and
32 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
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
25 changes: 25 additions & 0 deletions
25
rampsdk/src/main/java/network/ramp/sdk/utils/UrlSafeChecker.kt
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,25 @@ | ||
package network.ramp.sdk.utils | ||
|
||
object UrlSafeChecker { | ||
|
||
private val listOfSafeUrls = listOf( | ||
"https://ri-widget-dev2.firebaseapp.com", | ||
"https://ri-widget-staging.firebaseapp.com", | ||
"https://buy.ramp.network" | ||
) | ||
private val listOfSafeRegex = listOf("^https://ri-widget-dev-(\\d+)\\.firebaseapp\\.com$") | ||
|
||
fun isUrlSafe(url: String) = checkStaticUrls(url) || checkRegexList(url) | ||
|
||
private fun checkStaticUrls(url: String): Boolean = listOfSafeUrls.contains(url) | ||
|
||
private fun checkRegexList(url: String): Boolean { | ||
var isMatch = false | ||
listOfSafeRegex.forEach { | ||
val regex = Regex(pattern = it, options = setOf(RegexOption.IGNORE_CASE)) | ||
if (regex.matches(url)) | ||
isMatch = true | ||
} | ||
return isMatch | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
rampsdk/src/test/java/network/ramp/sdk/utils/UrlSafeCheckerTest.kt
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,51 @@ | ||
package network.ramp.sdk.utils | ||
|
||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
|
||
internal class UrlSafeCheckerTest { | ||
|
||
@Test | ||
fun `isUrlSafe should return true fore safe urls`() { | ||
val safeUrl1 = "https://ri-widget-dev2.firebaseapp.com" | ||
val safeUrl2 = "https://ri-widget-staging.firebaseapp.com" | ||
val safeUrl3 = "https://buy.ramp.network" | ||
val safeUrl4 = "https://ri-widget-dev-5.firebaseapp.com" | ||
val safeUrl5 = "https://ri-widget-dev-42.firebaseapp.com" | ||
|
||
|
||
Assertions.assertAll( | ||
{ Assertions.assertTrue(UrlSafeChecker.isUrlSafe(safeUrl1)) }, | ||
{ Assertions.assertTrue(UrlSafeChecker.isUrlSafe(safeUrl2)) }, | ||
{ Assertions.assertTrue(UrlSafeChecker.isUrlSafe(safeUrl3)) }, | ||
{ Assertions.assertTrue(UrlSafeChecker.isUrlSafe(safeUrl4)) }, | ||
{ Assertions.assertTrue(UrlSafeChecker.isUrlSafe(safeUrl5)) } | ||
) | ||
} | ||
|
||
@Test | ||
fun `isUrlSafe should return false fore unsafe urls`() { | ||
|
||
val unsafeUrl1 = "https://ri-widget-devs2.firebaseapp.com" | ||
val unsafeUrl2 = "ri-widget-staging.firebaseapp.com" | ||
val unsafeUrl3 = "https://ngrok.io/buy.ramp.network" | ||
val unsafeUrl4 = "https://ri-widget-dev-5.firebaseapp.com/sadasd" | ||
val unsafeUrl5 = "https://ri-widget-dev.com/?https://ri-widget-devs2.firebaseapp.com" | ||
val unsafeUrl6 = "https://ri-widget-dev-s.firebaseapp.com" | ||
val unsafeUrl7 = "https://ri-widget-dev-10.firebaseapp.comsd" | ||
val unsafeUrl8 = "https://ri-widget-dev-.firebaseapp.com" | ||
|
||
|
||
Assertions.assertAll( | ||
{ Assertions.assertFalse(UrlSafeChecker.isUrlSafe(unsafeUrl1)) }, | ||
{ Assertions.assertFalse(UrlSafeChecker.isUrlSafe(unsafeUrl2)) }, | ||
{ Assertions.assertFalse(UrlSafeChecker.isUrlSafe(unsafeUrl3)) }, | ||
{ Assertions.assertFalse(UrlSafeChecker.isUrlSafe(unsafeUrl4)) }, | ||
{ Assertions.assertFalse(UrlSafeChecker.isUrlSafe(unsafeUrl5)) }, | ||
{ Assertions.assertFalse(UrlSafeChecker.isUrlSafe(unsafeUrl6)) }, | ||
{ Assertions.assertFalse(UrlSafeChecker.isUrlSafe(unsafeUrl7)) }, | ||
{ Assertions.assertFalse(UrlSafeChecker.isUrlSafe(unsafeUrl8)) } | ||
) | ||
} | ||
} |