Make index file name constants public and replace their string usages

This commit is contained in:
Torsten Grote
2022-11-18 13:37:52 -03:00
committed by Hans-Christoph Steiner
parent fc4aee206e
commit 2edfaf7933
16 changed files with 53 additions and 40 deletions

View File

@@ -13,6 +13,7 @@ import org.fdroid.download.Mirror;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.ProgressListener;
import org.fdroid.fdroid.Utils;
import org.fdroid.index.v1.IndexV1UpdaterKt;
import org.junit.Test;
import java.io.File;
@@ -38,20 +39,20 @@ public class HttpDownloaderTest {
// https://developer.android.com/reference/javax/net/ssl/SSLContext
static {
ArrayList<Pair<String, String>> tempUrls = new ArrayList<>(Arrays.asList(
new Pair<>("https://f-droid.org/repo", "index-v1.jar"),
new Pair<>("https://f-droid.org/repo", IndexV1UpdaterKt.SIGNED_FILE_NAME),
// sites that use SNI for HTTPS
new Pair<>("https://mirrors.edge.kernel.org/", "debian/dists/stable/Release"),
new Pair<>("https://fdroid.tetaneutral.net/fdroid/repo/", "index-v1.jar"),
new Pair<>("https://ftp.fau.de/fdroid/repo/", "index-v1.jar"),
new Pair<>("https://fdroid.tetaneutral.net/fdroid/repo/", IndexV1UpdaterKt.SIGNED_FILE_NAME),
new Pair<>("https://ftp.fau.de/fdroid/repo/", IndexV1UpdaterKt.SIGNED_FILE_NAME),
new Pair<>("https://ftp.fau.de/fdroid/repo", "dev.lonami.klooni/en-US/phoneScreenshots/1-game.jpg"),
//new Pair<>("https://microg.org/fdroid/repo/index-v1.jar"),
//new Pair<>("https://grobox.de/fdroid/repo/index.jar"),
new Pair<>("https://guardianproject.info/fdroid/repo", "index-v1.jar")
new Pair<>("https://guardianproject.info/fdroid/repo", IndexV1UpdaterKt.SIGNED_FILE_NAME)
));
if (Build.VERSION.SDK_INT >= 22) {
tempUrls.addAll(Arrays.asList(
new Pair<>("https://en.wikipedia.org", "/wiki/Index.html"), // no SNI but weird ipv6 lookup issues
new Pair<>("https://mirror.cyberbits.eu/fdroid/repo/", "index-v1.jar") // TLSv1.2 only and SNI
new Pair<>("https://mirror.cyberbits.eu/fdroid/repo/", IndexV1UpdaterKt.SIGNED_FILE_NAME) // TLSv1.2 only and SNI
));
}
URLS = tempUrls;

View File

@@ -16,6 +16,8 @@ import org.fdroid.fdroid.data.SanitizedFile;
import org.fdroid.index.v1.AppV1;
import org.fdroid.index.v1.IndexV1;
import org.fdroid.index.v1.IndexV1Creator;
import org.fdroid.index.v1.IndexV1UpdaterKt;
import org.fdroid.index.v1.IndexV1VerifierKt;
import org.fdroid.index.v1.PackageV1;
import org.fdroid.index.v1.RepoV1;
@@ -94,7 +96,7 @@ public final class LocalRepoManager {
fdroidDirCaps = new SanitizedFile(webRoot, "FDROID");
repoDir = new SanitizedFile(fdroidDir, "repo");
repoDirCaps = new SanitizedFile(fdroidDirCaps, "REPO");
indexJar = new SanitizedFile(repoDir, "index-v1.jar");
indexJar = new SanitizedFile(repoDir, IndexV1UpdaterKt.SIGNED_FILE_NAME);
indexJarUnsigned = new SanitizedFile(repoDir, "index-v1.unsigned.jar");
if (!fdroidDir.exists() && !fdroidDir.mkdir()) {
@@ -257,7 +259,7 @@ public final class LocalRepoManager {
IndexV1 indexV1 = creator.createRepo();
cacheApps(indexV1);
writeIndexPage(address);
SanitizedFile indexJson = new SanitizedFile(repoDir, "index-v1.json");
SanitizedFile indexJson = new SanitizedFile(repoDir, IndexV1VerifierKt.JSON_FILE_NAME);
writeIndexJar(indexJson);
}

View File

@@ -33,6 +33,7 @@ import org.fdroid.index.IndexParser;
import org.fdroid.index.IndexParserKt;
import org.fdroid.index.SigningException;
import org.fdroid.index.v1.IndexV1;
import org.fdroid.index.v1.IndexV1UpdaterKt;
import org.fdroid.index.v1.IndexV1Verifier;
import org.fdroid.index.v2.FileV2;
@@ -131,8 +132,11 @@ public class SwapService extends Service {
private void updateRepo(@NonNull Peer peer, Repository repo)
throws IOException, InterruptedException, SigningException, NotFoundException {
Uri uri = Uri.parse(repo.getAddress()).buildUpon().appendPath("index-v1.jar").build();
FileV2 indexFile = FileV2.fromPath("/index-v1.jar");
Uri uri = Uri.parse(repo.getAddress())
.buildUpon()
.appendPath(IndexV1UpdaterKt.SIGNED_FILE_NAME)
.build();
FileV2 indexFile = FileV2.fromPath("/" + IndexV1UpdaterKt.SIGNED_FILE_NAME);
File swapJarFile =
File.createTempFile("swap", "", getApplicationContext().getCacheDir());
try {

View File

@@ -1,12 +1,15 @@
package org.fdroid.fdroid.nearby;
import org.fdroid.index.v1.IndexV1UpdaterKt;
import org.fdroid.index.v1.IndexV1VerifierKt;
/**
* @see <a href="https://stackoverflow.com/a/36162691">Android 5.0 DocumentFile from tree URI</a>
*/
public final class TreeUriUtils {
public static final String TAG = "TreeUriUtils";
static final String SIGNED_FILE_NAME = "index-v1.jar";
static final String DATA_FILE_NAME = "index-v1.json";
static final String SIGNED_FILE_NAME = IndexV1UpdaterKt.SIGNED_FILE_NAME;
static final String DATA_FILE_NAME = IndexV1VerifierKt.JSON_FILE_NAME;
}

View File

@@ -63,6 +63,7 @@ import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.data.DBHelper;
import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.index.v1.IndexV1UpdaterKt;
import java.io.File;
import java.io.IOException;
@@ -621,7 +622,7 @@ public class ManageReposActivity extends AppCompatActivity implements RepoAdapte
}
// check for v1 index as this is the last one we can still handle
final Uri uri = builder.appendPath("index-v1.jar").build();
final Uri uri = builder.appendPath(IndexV1UpdaterKt.SIGNED_FILE_NAME).build();
try {
final URL url = new URL(uri.toString());

View File

@@ -20,6 +20,7 @@
package org.fdroid.fdroid;
import org.fdroid.fdroid.data.Apk;
import org.fdroid.index.v1.IndexV1UpdaterKt;
import org.fdroid.index.v2.FileV1;
import org.junit.Before;
import org.junit.Test;
@@ -125,8 +126,8 @@ public class RepoUrlsTest {
@Test
public void testIndexV1Urls() {
testReposWithFile("index-v1.jar", tr ->
Utils.getUri(tr.repoUrl, "index-v1.jar").toString()
testReposWithFile(IndexV1UpdaterKt.SIGNED_FILE_NAME, tr ->
Utils.getUri(tr.repoUrl, IndexV1UpdaterKt.SIGNED_FILE_NAME).toString()
);
}

View File

@@ -2,6 +2,7 @@ package org.fdroid.index
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.fdroid.database.Repository
import org.fdroid.index.v2.SIGNED_FILE_NAME
import org.junit.Test
import org.junit.runner.RunWith
import kotlin.test.assertEquals
@@ -21,8 +22,8 @@ internal class IndexUpdaterTest {
weight = 0,
lastUpdated = 23L,
)
val uri = defaultRepoUriBuilder.getUri(repo, "entry.jar")
assertEquals("http://example.org/entry.jar", uri.toString())
val uri = defaultRepoUriBuilder.getUri(repo, SIGNED_FILE_NAME)
assertEquals("http://example.org/$SIGNED_FILE_NAME", uri.toString())
}
}

View File

@@ -191,8 +191,8 @@ internal class IndexV1UpdaterTest : DbTest() {
@Suppress("DEPRECATION")
private fun downloadIndex(repo: Repository, jar: String) {
val uri = Uri.parse("${repo.address}/index-v1.jar")
val indexFile = FileV2.fromPath("/index-v1.jar")
val uri = Uri.parse("${repo.address}/$SIGNED_FILE_NAME")
val indexFile = FileV2.fromPath("/$SIGNED_FILE_NAME")
val jarFile = tmpFolder.newFile()
assets.open(jar).use { inputStream ->

View File

@@ -60,7 +60,7 @@ internal class IndexV2UpdaterTest : DbTest() {
val repoId = repoDao.insertEmptyRepo("http://example.org")
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-min/entry.jar",
entryPath = "diff-empty-min/$SIGNED_FILE_NAME",
jsonPath = "index-min-v2.json",
indexFileV2 = TestDataEntry.emptyToMin.index
)
@@ -80,7 +80,7 @@ internal class IndexV2UpdaterTest : DbTest() {
val repoId = repoDao.insertEmptyRepo("http://example.org")
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-mid/entry.jar",
entryPath = "diff-empty-mid/$SIGNED_FILE_NAME",
jsonPath = "index-mid-v2.json",
indexFileV2 = TestDataEntry.emptyToMid.index
)
@@ -95,7 +95,7 @@ internal class IndexV2UpdaterTest : DbTest() {
val repoId = repoDao.insertEmptyRepo("http://example.org")
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-max/entry.jar",
entryPath = "diff-empty-max/$SIGNED_FILE_NAME",
jsonPath = "index-max-v2.json",
indexFileV2 = TestDataEntry.emptyToMax.index
)
@@ -110,7 +110,7 @@ internal class IndexV2UpdaterTest : DbTest() {
val repoId = streamIndexV2IntoDb("index-min-v2.json")
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-mid/entry.jar",
entryPath = "diff-empty-mid/$SIGNED_FILE_NAME",
jsonPath = "diff-empty-mid/42.json",
indexFileV2 = TestDataEntry.emptyToMid.diffs["42"] ?: fail()
)
@@ -126,7 +126,7 @@ internal class IndexV2UpdaterTest : DbTest() {
repoDao.updateRepository(repoId, CERTIFICATE)
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-min/entry.jar",
entryPath = "diff-empty-min/$SIGNED_FILE_NAME",
jsonPath = "diff-empty-min/23.json",
indexFileV2 = TestDataEntry.emptyToMin.diffs["23"] ?: fail()
)
@@ -142,7 +142,7 @@ internal class IndexV2UpdaterTest : DbTest() {
repoDao.updateRepository(repoId, CERTIFICATE)
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-max/entry.jar",
entryPath = "diff-empty-max/$SIGNED_FILE_NAME",
jsonPath = "diff-empty-max/1337.json",
indexFileV2 = TestDataEntry.emptyToMax.diffs["1337"] ?: fail()
)
@@ -158,7 +158,7 @@ internal class IndexV2UpdaterTest : DbTest() {
repoDao.updateRepository(repoId, CERTIFICATE)
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-min/entry.jar",
entryPath = "diff-empty-min/$SIGNED_FILE_NAME",
jsonPath = "diff-empty-min/23.json",
indexFileV2 = TestDataEntry.emptyToMin.diffs["23"] ?: fail()
)
@@ -174,7 +174,7 @@ internal class IndexV2UpdaterTest : DbTest() {
repoDao.updateRepository(repoId, CERTIFICATE)
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-min/entry.jar",
entryPath = "diff-empty-min/$SIGNED_FILE_NAME",
jsonPath = "diff-empty-min/23.json",
indexFileV2 = TestDataEntry.emptyToMin.diffs["23"] ?: fail()
)
@@ -192,7 +192,7 @@ internal class IndexV2UpdaterTest : DbTest() {
repoDao.updateRepository(newRepo)
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-min/entry.jar",
entryPath = "diff-empty-min/$SIGNED_FILE_NAME",
jsonPath = "index-min-v2.json",
indexFileV2 = TestDataEntry.emptyToMin.index
)
@@ -206,7 +206,7 @@ internal class IndexV2UpdaterTest : DbTest() {
val repoId = repoDao.insertEmptyRepo("http://example.org")
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-min/entry.jar",
entryPath = "diff-empty-min/$SIGNED_FILE_NAME",
jsonPath = "index-min-v2.json",
indexFileV2 = TestDataEntry.emptyToMin.index
)
@@ -220,7 +220,7 @@ internal class IndexV2UpdaterTest : DbTest() {
val repoId = repoDao.insertEmptyRepo("http://example.org")
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-min/entry.jar",
entryPath = "diff-empty-min/$SIGNED_FILE_NAME",
jsonPath = "index-min-v2.json",
indexFileV2 = TestDataEntry.emptyToMin.index
)
@@ -238,7 +238,7 @@ internal class IndexV2UpdaterTest : DbTest() {
val repoId = streamIndexV1IntoDb("index-min-v1.json")
val repo = prepareUpdate(
repoId = repoId,
entryPath = "diff-empty-mid/entry.jar",
entryPath = "diff-empty-mid/$SIGNED_FILE_NAME",
jsonPath = "index-mid-v2.json",
indexFileV2 = TestDataEntry.emptyToMid.index,
)
@@ -261,7 +261,7 @@ internal class IndexV2UpdaterTest : DbTest() {
val entryFile = tmpFolder.newFile()
val indexFile = tmpFolder.newFile()
val repo = repoDao.getRepository(repoId) ?: fail()
val entryUri = Uri.parse("${repo.address}/entry.jar")
val entryUri = Uri.parse("${repo.address}/$SIGNED_FILE_NAME")
val indexUri = Uri.parse("${repo.address}/${indexFileV2.name.trimStart('/')}")
assets.open(entryPath).use { inputStream ->

View File

@@ -20,7 +20,7 @@ import org.fdroid.index.defaultRepoUriBuilder
import org.fdroid.index.setIndexUpdateListener
import org.fdroid.index.v2.FileV2
internal const val SIGNED_FILE_NAME = "index-v1.jar"
public const val SIGNED_FILE_NAME: String = "index-v1.jar"
public class IndexV1Updater(
database: FDroidDatabase,

View File

@@ -20,7 +20,7 @@ import org.fdroid.index.defaultRepoUriBuilder
import org.fdroid.index.parseEntry
import org.fdroid.index.setIndexUpdateListener
internal const val SIGNED_FILE_NAME = "entry.jar"
public const val SIGNED_FILE_NAME: String = "entry.jar"
public class IndexV2Updater(
database: FDroidDatabase,

View File

@@ -5,7 +5,7 @@ import org.fdroid.index.SigningException
import java.io.File
import java.util.jar.Attributes
internal const val JSON_FILE_NAME = "index-v1.json"
public const val JSON_FILE_NAME: String = "index-v1.json"
private const val SUPPORTED_DIGEST = "SHA1-Digest"
/**

View File

@@ -5,7 +5,7 @@ import org.fdroid.index.SigningException
import java.io.File
import java.util.jar.Attributes
private const val JSON_FILE_NAME = "entry.json"
public const val JSON_FILE_NAME: String = "entry.json"
private val FORBIDDEN_DIGESTS = listOf(
"MD5-Digest",
"SHA1-Digest",

View File

@@ -113,7 +113,7 @@ internal class IndexV1VerifierTest {
assertEquals("foo\n", inputStream.readBytes().decodeToString())
}
}
assertTrue(e.message!!.contains("index-v1.json"))
assertTrue(e.message!!.contains(JSON_FILE_NAME))
}
@Test

View File

@@ -120,7 +120,7 @@ internal class EntryVerifierTest {
val e = assertFailsWith<SigningException> {
verifier.getStreamAndVerify { }
}
assertTrue(e.message!!.contains("entry.json"))
assertTrue(e.message!!.contains(JSON_FILE_NAME))
}
@Test

View File

@@ -19,17 +19,17 @@ internal class EntryTest {
@Test
fun testEmptyToMin() {
testEntryEquality("$assetPath/diff-empty-min/entry.json", TestDataEntry.emptyToMin)
testEntryEquality("$assetPath/diff-empty-min/$JSON_FILE_NAME", TestDataEntry.emptyToMin)
}
@Test
fun testEmptyToMid() {
testEntryEquality("$assetPath/diff-empty-mid/entry.json", TestDataEntry.emptyToMid)
testEntryEquality("$assetPath/diff-empty-mid/$JSON_FILE_NAME", TestDataEntry.emptyToMid)
}
@Test
fun testEmptyToMax() {
testEntryEquality("$assetPath/diff-empty-max/entry.json", TestDataEntry.emptyToMax)
testEntryEquality("$assetPath/diff-empty-max/$JSON_FILE_NAME", TestDataEntry.emptyToMax)
}
@Test