mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-01-24 06:47:44 -05:00
[db] Catch NotFoundException in RepoAdder
This commit is contained in:
committed by
Michael Pöhn
parent
b5c8f2c92c
commit
7b52db331c
@@ -177,6 +177,10 @@ internal class RepoAdder(
|
||||
log.error(e) { "Error fetching repo." }
|
||||
addRepoState.value = AddRepoError(INVALID_INDEX, e)
|
||||
return
|
||||
} catch (e: NotFoundException) { // v1 repos can also have 404
|
||||
log.error(e) { "Error fetching repo." }
|
||||
addRepoState.value = AddRepoError(INVALID_INDEX, e)
|
||||
return
|
||||
}
|
||||
// set final result
|
||||
val finalRepo = receivedRepo
|
||||
|
||||
@@ -559,6 +559,54 @@ internal class RepoAdderTest {
|
||||
assertEquals(63, addRepoState.apps.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDownloadV1ThrowsNotFoundException() = runTest {
|
||||
val url = "https://example.org/repo"
|
||||
val jarFile = folder.newFile()
|
||||
|
||||
every { tempFileProvider.createTempFile() } returns jarFile
|
||||
every {
|
||||
downloaderFactory.create(
|
||||
repo = match { it.address == url && it.formatVersion == IndexFormatVersion.TWO },
|
||||
uri = Uri.parse("$url/entry.jar"),
|
||||
indexFile = any(),
|
||||
destFile = jarFile,
|
||||
)
|
||||
} returns downloader
|
||||
every { downloader.download() } throws NotFoundException()
|
||||
|
||||
every {
|
||||
downloaderFactory.create(
|
||||
repo = match { it.address == url && it.formatVersion == IndexFormatVersion.ONE },
|
||||
uri = Uri.parse("$url/index-v1.jar"),
|
||||
indexFile = any(),
|
||||
destFile = jarFile,
|
||||
)
|
||||
} returns downloader
|
||||
every { downloader.download() } throws NotFoundException()
|
||||
|
||||
repoAdder.addRepoState.test {
|
||||
assertIs<None>(awaitItem())
|
||||
|
||||
repoAdder.fetchRepository(
|
||||
url = url,
|
||||
username = null,
|
||||
password = null,
|
||||
proxy = null
|
||||
)
|
||||
|
||||
val state1 = awaitItem()
|
||||
assertIs<Fetching>(state1)
|
||||
assertNull(state1.repo)
|
||||
assertTrue(state1.apps.isEmpty())
|
||||
assertFalse(state1.canAdd)
|
||||
|
||||
val state2 = awaitItem()
|
||||
assertTrue(state2 is AddRepoError, "$state2")
|
||||
assertEquals(INVALID_INDEX, state2.errorType)
|
||||
}
|
||||
}
|
||||
|
||||
private fun expectDownloadOfMinRepo(url: String) {
|
||||
val urlTrimmed = url.trimEnd('/')
|
||||
val jarFile = folder.newFile()
|
||||
|
||||
Reference in New Issue
Block a user