mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-05-24 08:25:00 -04:00
Support for dnsA/dnsAAAA data added to v2 index
This commit is contained in:
committed by
Torsten Grote
parent
456f91a3cc
commit
1c9570575f
@@ -9,6 +9,9 @@ import org.fdroid.index.IndexParser
|
||||
import org.fdroid.index.parseV2
|
||||
import org.fdroid.index.v2.IndexV2
|
||||
import org.fdroid.index.v2.IndexV2DiffStreamProcessor
|
||||
import org.fdroid.index.v2.MirrorV2
|
||||
import org.fdroid.index.v2.RepoV2
|
||||
import org.fdroid.test.LOCALE
|
||||
import org.fdroid.test.TestDataMaxV2
|
||||
import org.fdroid.test.TestDataMaxV2.PACKAGE_NAME_3
|
||||
import org.fdroid.test.TestDataMaxV2.app3
|
||||
@@ -85,6 +88,142 @@ internal class IndexV2DiffTest : DbTest() {
|
||||
)
|
||||
}
|
||||
|
||||
// add more dnsA/dnsAAAA results to mirrors
|
||||
@Test
|
||||
fun testAddDns() {
|
||||
val diffJson =
|
||||
"""
|
||||
{
|
||||
"repo": {
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dns-test.org/repo",
|
||||
"countryCode": "us",
|
||||
"dnsA": [
|
||||
"16.15.191.37",
|
||||
"16.15.191.44",
|
||||
"16.15.199.90",
|
||||
"16.15.219.121"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "https://dns-test.com/repo",
|
||||
"countryCode": "nl",
|
||||
"dnsAAAA": [
|
||||
"2600:1f60:80a0::100f:db9b",
|
||||
"2600:1f60:80a0::100f:df70",
|
||||
"2600:1f60:80a0::100f:df7b",
|
||||
"2600:1f60:80c0::100f:b9f4"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
testJsonDiff(
|
||||
startPath = "index-base-dns-v2.json",
|
||||
diff = diffJson,
|
||||
endIndex = TestDataAddDnsV2.index,
|
||||
)
|
||||
}
|
||||
|
||||
// remove dnsA/dnsAAAA results from mirrors
|
||||
@Test
|
||||
fun testRemoveDns() {
|
||||
val diffJson =
|
||||
"""
|
||||
{
|
||||
"repo": {
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dns-test.org/repo",
|
||||
"countryCode": "us",
|
||||
"dnsA": []
|
||||
},
|
||||
{
|
||||
"url": "https://dns-test.com/repo",
|
||||
"countryCode": "nl",
|
||||
"dnsAAAA": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
testJsonDiff(
|
||||
startPath = "index-base-dns-v2.json",
|
||||
diff = diffJson,
|
||||
endIndex = TestDataRemoveDnsV2.index,
|
||||
)
|
||||
}
|
||||
|
||||
// set dnsA/dnsAAAA results from mirrors to null
|
||||
@Test
|
||||
fun testNullDns() {
|
||||
val diffJson =
|
||||
"""
|
||||
{
|
||||
"repo": {
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dns-test.org/repo",
|
||||
"countryCode": "us",
|
||||
"dnsA": null
|
||||
},
|
||||
{
|
||||
"url": "https://dns-test.com/repo",
|
||||
"countryCode": "nl",
|
||||
"dnsAAAA": null
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
testJsonDiff(
|
||||
startPath = "index-base-dns-v2.json",
|
||||
diff = diffJson,
|
||||
endIndex = TestDataRemoveDnsV2.index,
|
||||
)
|
||||
}
|
||||
|
||||
// replace dnsA results with dnsAAAA results and vice versa
|
||||
@Test
|
||||
fun testSwapDns() {
|
||||
val diffJson =
|
||||
"""
|
||||
{
|
||||
"repo": {
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://dns-test.org/repo",
|
||||
"countryCode": "us",
|
||||
"dnsAAAA": [
|
||||
"2600:1f60:80a0::100f:db9b",
|
||||
"2600:1f60:80a0::100f:df70"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "https://dns-test.com/repo",
|
||||
"countryCode": "nl",
|
||||
"dnsA": [
|
||||
"16.15.191.37",
|
||||
"16.15.191.44"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"""
|
||||
.trimIndent()
|
||||
testJsonDiff(
|
||||
startPath = "index-base-dns-v2.json",
|
||||
diff = diffJson,
|
||||
endIndex = TestDataSwapDnsV2.index,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMinRemoveApp() {
|
||||
val diffJson =
|
||||
@@ -533,4 +672,77 @@ internal class IndexV2DiffTest : DbTest() {
|
||||
assertDbEquals(repoId, endIndex)
|
||||
return repoId
|
||||
}
|
||||
|
||||
object TestDataAddDnsV2 {
|
||||
|
||||
val repo =
|
||||
RepoV2(
|
||||
timestamp = 99,
|
||||
name = mapOf(LOCALE to "DnsTest"),
|
||||
address = "https://dns-test.org/repo",
|
||||
mirrors =
|
||||
listOf(
|
||||
MirrorV2(
|
||||
"https://dns-test.org/repo",
|
||||
"us",
|
||||
dnsA = listOf("16.15.191.37", "16.15.191.44", "16.15.199.90", "16.15.219.121"),
|
||||
),
|
||||
MirrorV2(
|
||||
"https://dns-test.com/repo",
|
||||
"nl",
|
||||
dnsAAAA =
|
||||
listOf(
|
||||
"2600:1f60:80a0::100f:db9b",
|
||||
"2600:1f60:80a0::100f:df70",
|
||||
"2600:1f60:80a0::100f:df7b",
|
||||
"2600:1f60:80c0::100f:b9f4",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val index = IndexV2(repo = repo)
|
||||
}
|
||||
|
||||
object TestDataRemoveDnsV2 {
|
||||
|
||||
val repo =
|
||||
RepoV2(
|
||||
timestamp = 99,
|
||||
name = mapOf(LOCALE to "DnsTest"),
|
||||
address = "https://dns-test.org/repo",
|
||||
mirrors =
|
||||
listOf(
|
||||
MirrorV2("https://dns-test.org/repo", "us", dnsA = emptyList()),
|
||||
MirrorV2("https://dns-test.com/repo", "nl", dnsAAAA = emptyList()),
|
||||
),
|
||||
)
|
||||
|
||||
val index = IndexV2(repo = repo)
|
||||
}
|
||||
|
||||
object TestDataSwapDnsV2 {
|
||||
|
||||
val repo =
|
||||
RepoV2(
|
||||
timestamp = 99,
|
||||
name = mapOf(LOCALE to "DnsTest"),
|
||||
address = "https://dns-test.org/repo",
|
||||
mirrors =
|
||||
listOf(
|
||||
MirrorV2(
|
||||
"https://dns-test.org/repo",
|
||||
"us",
|
||||
dnsAAAA = listOf("2600:1f60:80a0::100f:db9b", "2600:1f60:80a0::100f:df70"),
|
||||
),
|
||||
MirrorV2(
|
||||
"https://dns-test.com/repo",
|
||||
"nl",
|
||||
dnsA = listOf("16.15.191.37", "16.15.191.44"),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val index = IndexV2(repo = repo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ internal class RepositoryDiffTest : DbTest() {
|
||||
"""
|
||||
.trimIndent()
|
||||
testDiff(repo, json) { repos ->
|
||||
val expectedMirrors = setOf(Mirror(repos[0].repoId, "foo", "bar"))
|
||||
val expectedMirrors = setOf(Mirror(repos[0].repoId, "foo", "bar", emptyList(), emptyList()))
|
||||
assertEquals(expectedMirrors, repos[0].mirrors.toSet())
|
||||
assertRepoEquals(repo.copy(mirrors = listOf(MirrorV2("foo", "bar"))), repos[0])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user