Updated on 2026-08-14

This commit is contained in:
Tangem 2024-12-23 14:19:34 +04:00
parent 00e275b605
commit 352043ab4f
5 changed files with 90 additions and 1 deletions

View file

@ -1,4 +1,26 @@
plugins {
alias(deps.plugins.kotlin.jvm)
alias(deps.plugins.android.library)
alias(deps.plugins.kotlin.android)
id("configuration")
}
android {
namespace = "com.tangem.common"
}
dependencies {
// region Firebase libraries
implementation(platform(deps.firebase.bom))
implementation(deps.firebase.analytics)
implementation(deps.firebase.crashlytics)
implementation(deps.firebase.messaging)
// end
implementation(deps.timber)
implementation(deps.arrow.core)
implementation(deps.test.junit)
implementation(deps.test.truth)
}

View file

@ -0,0 +1,31 @@
package com.tangem.common.uri
import com.google.firebase.crashlytics.FirebaseCrashlytics
import timber.log.Timber
import java.net.URI
/**
* External url validator
*
[REDACTED_AUTHOR]
*/
object ExternalUrlValidator {
private val trustedHost: List<String> = listOf("tangem.com")
/** Check if [externalUri] is trusted */
fun isUriTrusted(externalUri: String): Boolean {
return try {
val uri = URI.create(externalUri)
uri.scheme == "https" && uri.host in trustedHost
} catch (e: Exception) {
val exception = IllegalStateException("Failed to validate URI: $externalUri", e)
Timber.e(exception)
FirebaseCrashlytics.getInstance().recordException(exception)
false
}
}
}

View file

@ -0,0 +1,36 @@
package com.tangem.common.uri
import com.google.common.truth.Truth
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
/**
[REDACTED_AUTHOR]
*/
@RunWith(Parameterized::class)
class ExternalUrlValidatorTest(private val model: Model) {
@Test
fun test() {
val actual = ExternalUrlValidator.isUriTrusted(externalUri = model.url)
Truth.assertThat(actual).isEqualTo(model.expected)
}
companion object {
@JvmStatic
@Parameterized.Parameters
fun data(): Collection<Model> = listOf(
Model(url = "https://tangem.com", expected = true),
Model(url = "https://tange.com", expected = false),
Model(url = "https://fake.tangem.com", expected = false),
Model(url = "http://tangem.com", expected = false),
Model(url = "http://tandem.com", expected = false),
Model(url = "adawdawdassdw", expected = false),
)
data class Model(val url: String, val expected: Boolean)
}
}