Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

Fix provider URL protocol auto-detection

David Nashash892a2a5168fd
diff --git a/data/src/main/java/com/streamvault/data/repository/ProviderRepositoryImpl.kt b/data/src/main/java/com/streamvault/data/repository/ProviderRepositoryImpl.kt
index 1dffd609..c9268045 100644
--- a/data/src/main/java/com/streamvault/data/repository/ProviderRepositoryImpl.kt
+++ b/data/src/main/java/com/streamvault/data/repository/ProviderRepositoryImpl.kt
@@ -181,24 +181,25 @@ class ProviderRepositoryImpl @Inject constructor(
val normalizedServerUrl = ProviderInputSanitizer.normalizeUrl(serverUrl)
val normalizedUsername = ProviderInputSanitizer.normalizeUsername(username)
val normalizedName = ProviderInputSanitizer.normalizeProviderName(name)
+ val resolvedServerUrl = ProviderInputSanitizer.resolveUrlProtocol(normalizedServerUrl)
- ProviderInputSanitizer.validateUrl(normalizedServerUrl)?.let { message ->
+ ProviderInputSanitizer.validateUrl(resolvedServerUrl)?.let { message ->
return Result.error(message)
}
- UrlSecurityPolicy.validateXtreamServerUrl(normalizedServerUrl)?.let { message ->
+ UrlSecurityPolicy.validateXtreamServerUrl(resolvedServerUrl)?.let { message ->
return Result.error(message)
}
onProgress?.invoke("Authenticating...")
val existingProvider = if (id != null) {
// Edit path: check that the new normalized identity does not collide with a
// different provider before we commit the update.
- val collision = providerDao.getByUrlAndUser(normalizedServerUrl, normalizedUsername)
+ val collision = providerDao.getByUrlAndUser(resolvedServerUrl, normalizedUsername)
if (collision != null && collision.id != id) {
return Result.error("A provider with this server URL and username already exists.")
}
providerDao.getById(id)
} else {
- providerDao.getByUrlAndUser(normalizedServerUrl, normalizedUsername)
+ providerDao.getByUrlAndUser(resolvedServerUrl, normalizedUsername)
}
val effectivePassword = try {
password.takeIf { it.isNotBlank() }
@@ -207,10 +208,9 @@ class ProviderRepositoryImpl @Inject constructor(
} catch (e: CredentialDecryptionException) {
return Result.error(e.message ?: CredentialDecryptionException.MESSAGE, e)
}
- val resolvedUrl = ProviderInputSanitizer.resolveUrlProtocol(normalizedServerUrl)
val provider = createXtreamProvider(
providerId = 0,
- serverUrl = resolvedUrl,
+ serverUrl = resolvedServerUrl,
username = normalizedUsername,
password = effectivePassword,
httpUserAgent = httpUserAgent,
@@ -223,7 +223,7 @@ class ProviderRepositoryImpl @Inject constructor(
val updated = authResult.data.copy(
id = existingProvider.id,
name = normalizedName.ifBlank { existingProvider.name },
- serverUrl = resolvedUrl,
+ serverUrl = resolvedServerUrl,
username = normalizedUsername,
password = effectivePassword,
httpUserAgent = httpUserAgent,
@@ -368,6 +368,7 @@ class ProviderRepositoryImpl @Inject constructor(
val normalizedMacAddress = ProviderInputSanitizer.normalizeMacAddress(macAddress)
val normalizedName = ProviderInputSanitizer.normalizeProviderName(name)
val normalizedUsername = ProviderInputSanitizer.normalizeUsername(username)
+ val resolvedPortalUrl = ProviderInputSanitizer.resolveUrlProtocol(normalizedPortalUrl)
val normalizedDeviceProfile = ProviderInputSanitizer.normalizeDeviceProfile(deviceProfile)
val normalizedTimezone = ProviderInputSanitizer.normalizeTimezone(timezone)
val normalizedLocale = ProviderInputSanitizer.normalizeLocale(locale)
@@ -376,10 +377,10 @@ class ProviderRepositoryImpl @Inject constructor(
val normalizedDeviceId2 = ProviderInputSanitizer.normalizeStalkerDeviceId(deviceId2)
val normalizedSignature = ProviderInputSanitizer.normalizeStalkerSignature(signature)
- ProviderInputSanitizer.validateUrl(normalizedPortalUrl)?.let { message ->
+ ProviderInputSanitizer.validateUrl(resolvedPortalUrl)?.let { message ->
return Result.error(message)
}
- UrlSecurityPolicy.validateStalkerPortalUrl(normalizedPortalUrl)?.let { message ->
+ UrlSecurityPolicy.validateStalkerPortalUrl(resolvedPortalUrl)?.let { message ->
return Result.error(message)
}
if (normalizedMacAddress.isNotBlank()) {
@@ -392,13 +393,13 @@ class ProviderRepositoryImpl @Inject constructor(
val existingProvider = if (id != null) {
// Edit path: check that the new normalized identity does not collide with a
// different provider before we commit the update.
- val collision = providerDao.getByUrlAndUser(normalizedPortalUrl, normalizedUsername, normalizedMacAddress)
+ val collision = providerDao.getByUrlAndUser(resolvedPortalUrl, normalizedUsername, normalizedMacAddress)
if (collision != null && collision.id != id) {
return Result.error("A Stalker provider with this portal URL and identity already exists.")
}
providerDao.getById(id)
} else {
- providerDao.getByUrlAndUser(normalizedPortalUrl, normalizedUsername, normalizedMacAddress)
+ providerDao.getByUrlAndUser(resolvedPortalUrl, normalizedUsername, normalizedMacAddress)
}
val effectivePassword = try {
password.takeIf { it.isNotBlank() }
@@ -410,7 +411,7 @@ class ProviderRepositoryImpl @Inject constructor(
val provider = createStalkerProvider(
providerId = 0L,
- portalUrl = normalizedPortalUrl,
+ portalUrl = resolvedPortalUrl,
macAddress = normalizedMacAddress,
authMode = authMode,
username = normalizedUsername,
@@ -431,7 +432,7 @@ class ProviderRepositoryImpl @Inject constructor(
val updated = authResult.data.copy(
id = existingProvider.id,
name = normalizedName.ifBlank { existingProvider.name },
- serverUrl = normalizedPortalUrl,
+ serverUrl = resolvedPortalUrl,
username = normalizedUsername,
password = effectivePassword,
stalkerMacAddress = normalizedMacAddress,
@@ -456,7 +457,7 @@ class ProviderRepositoryImpl @Inject constructor(
} else {
val newData = authResult.data.copy(
name = normalizedName.ifBlank { authResult.data.name },
- serverUrl = normalizedPortalUrl,
+ serverUrl = resolvedPortalUrl,
username = normalizedUsername,
password = effectivePassword,
stalkerMacAddress = normalizedMacAddress,
diff --git a/data/src/test/java/com/streamvault/data/util/ProviderInputSanitizerTest.kt b/data/src/test/java/com/streamvault/data/util/ProviderInputSanitizerTest.kt
index 193cb9a7..f93fb09c 100644
--- a/data/src/test/java/com/streamvault/data/util/ProviderInputSanitizerTest.kt
+++ b/data/src/test/java/com/streamvault/data/util/ProviderInputSanitizerTest.kt
@@ -1,6 +1,8 @@
package com.streamvault.data.util
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.runBlocking
+import java.net.ServerSocket
import org.junit.Test
class ProviderInputSanitizerTest {
@@ -28,4 +30,21 @@ class ProviderInputSanitizerTest {
.isEqualTo("URLs cannot contain spaces or line breaks.")
assertThat(ProviderInputSanitizer.validateUrl("https://example.com/a.m3u")).isNull()
}
+
+ @Test
+ fun `resolveUrlProtocol keeps explicit scheme unchanged`() = runBlocking {
+ val value = ProviderInputSanitizer.resolveUrlProtocol("https://example.com:8080")
+
+ assertThat(value).isEqualTo("https://example.com:8080")
+ }
+
+ @Test
+ fun `resolveUrlProtocol falls back to http for bare host when https probe fails`() = runBlocking {
+ val port = ServerSocket(0).use { it.localPort }
+ val host = "127.0.0.1:$port"
+
+ val value = ProviderInputSanitizer.resolveUrlProtocol(host)
+
+ assertThat(value).isEqualTo("http://$host")
+ }
}
\ No newline at end of file