[PM-22441] Refactor DigitalAssetLinkService to use source website (#5351)

This commit is contained in:
Patrick Honkonen
2025-06-13 12:03:27 -04:00
committed by GitHub
parent 861a4281fa
commit 7de770ca03
13 changed files with 494 additions and 72 deletions

View File

@@ -13,19 +13,22 @@ import retrofit2.http.Query
internal interface DigitalAssetLinkApi {
/**
* Checks if the given [relation] exists in a digital asset link file.
* Checks if the given [relations] are declared in the digital asset link file for the given
* [sourceWebSite] for the given [targetPackageName] with a [targetCertificateFingerprint].
*
* @param sourceWebSite The host of the source digital asset links file.
* @param targetPackageName The package name of the target application.
* @param targetCertificateFingerprint The certificate fingerprint of the target application.
*/
@GET("v1/assetlinks:check")
suspend fun checkDigitalAssetLinksRelations(
@Query("source.androidApp.packageName")
sourcePackageName: String,
@Query("source.androidApp.certificate.sha256Fingerprint")
sourceCertificateFingerprint: String,
@Query("source.web.site")
sourceWebSite: String,
@Query("target.androidApp.packageName")
targetPackageName: String,
@Query("target.androidApp.certificate.sha256Fingerprint")
targetCertificateFingerprint: String,
@Query("relation")
relation: String,
relations: List<String>,
): NetworkResult<DigitalAssetLinkCheckResponseJson>
}

View File

@@ -7,12 +7,17 @@ import com.bitwarden.network.model.DigitalAssetLinkCheckResponseJson
*/
interface DigitalAssetLinkService {
/**
* Checks if the given [packageName] with a given [certificateFingerprint] has the given
* [relation].
* Checks if the given [relations] are declared in the digital asset link file for the given
* [sourceWebSite] for the given [targetPackageName] with a [targetCertificateFingerprint].
*
* @param sourceWebSite The host of the source digital asset links file.
* @param targetPackageName The package name of the target application.
* @param targetCertificateFingerprint The certificate fingerprint of the target application.
*/
suspend fun checkDigitalAssetLinksRelations(
packageName: String,
certificateFingerprint: String,
relation: String,
sourceWebSite: String,
targetPackageName: String,
targetCertificateFingerprint: String,
relations: List<String>,
): Result<DigitalAssetLinkCheckResponseJson>
}

View File

@@ -12,16 +12,16 @@ internal class DigitalAssetLinkServiceImpl(
) : DigitalAssetLinkService {
override suspend fun checkDigitalAssetLinksRelations(
packageName: String,
certificateFingerprint: String,
relation: String,
sourceWebSite: String,
targetPackageName: String,
targetCertificateFingerprint: String,
relations: List<String>,
): Result<DigitalAssetLinkCheckResponseJson> = digitalAssetLinkApi
.checkDigitalAssetLinksRelations(
sourcePackageName = packageName,
sourceCertificateFingerprint = certificateFingerprint,
targetPackageName = packageName,
targetCertificateFingerprint = certificateFingerprint,
relation = relation,
sourceWebSite = sourceWebSite,
targetPackageName = targetPackageName,
targetCertificateFingerprint = targetCertificateFingerprint,
relations = relations,
)
.toResult()
}

View File

@@ -28,10 +28,11 @@ class DigitalAssetLinkServiceTest : BaseServiceTest() {
)
.asSuccess(),
digitalAssetLinkService.checkDigitalAssetLinksRelations(
packageName = "com.x8bit.bitwarden",
certificateFingerprint =
sourceWebSite = "https://www.bitwarden.com",
targetPackageName = "com.x8bit.bitwarden",
targetCertificateFingerprint =
"00:01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F:10:11:12:13",
relation = "delegate_permission/common.handle_all_urls",
relations = listOf("delegate_permission/common.handle_all_urls"),
),
)
}
@@ -42,4 +43,5 @@ private val CHECK_DIGITAL_ASSET_LINKS_RELATIONS_SUCCESS_JSON = """
"linked": true,
"maxAge": "47.535162130s"
}
""".trimIndent()
"""
.trimIndent()