Added tests for "orphaned apks" that must be removed after disabling a repo.
This commit is contained in:
parent
d3f9cfbdfa
commit
81910bf749
@ -199,11 +199,13 @@ public class RepoUpdater {
|
||||
reader.setContentHandler(repoXMLHandler);
|
||||
reader.parse(new InputSource(indexInputStream));
|
||||
|
||||
if (repoDetailsToSave.containsKey(RepoTable.Cols.TIMESTAMP)) {
|
||||
long timestamp = repoDetailsToSave.getAsLong(RepoTable.Cols.TIMESTAMP);
|
||||
if (timestamp < repo.timestamp) {
|
||||
throw new UpdateException(repo, "index.jar is older that current index! "
|
||||
+ timestamp + " < " + repo.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
signingCertFromJar = getSigningCertFromJar(indexEntry);
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
|
||||
package org.fdroid.fdroid;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.RepoUpdater.UpdateException;
|
||||
@ -14,6 +17,7 @@ import org.robolectric.annotation.Config;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@Config(constants = BuildConfig.class)
|
||||
@RunWith(RobolectricGradleTestRunner.class)
|
||||
@ -79,4 +83,52 @@ public class AcceptableMultiRepoUpdaterTest extends MultiRepoUpdaterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Repo getMainRepo() {
|
||||
Repo repo = RepoProvider.Helper.findByAddress(context, REPO_MAIN_URI);
|
||||
assertNotNull(repo);
|
||||
return repo;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Repo getArchiveRepo() {
|
||||
Repo repo = RepoProvider.Helper.findByAddress(context, REPO_ARCHIVE_URI);
|
||||
assertNotNull(repo);
|
||||
return repo;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Repo getConflictingRepo() {
|
||||
Repo repo = RepoProvider.Helper.findByAddress(context, REPO_CONFLICTING_URI);
|
||||
assertNotNull(repo);
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrphanedApps() throws UpdateException {
|
||||
assertEmpty();
|
||||
|
||||
updateArchive();
|
||||
updateMain();
|
||||
updateConflicting();
|
||||
|
||||
assertSomewhatAcceptable();
|
||||
|
||||
disableRepo(getArchiveRepo());
|
||||
disableRepo(getMainRepo());
|
||||
disableRepo(getConflictingRepo());
|
||||
|
||||
RepoProvider.Helper.purgeApps(context, getArchiveRepo());
|
||||
RepoProvider.Helper.purgeApps(context, getMainRepo());
|
||||
RepoProvider.Helper.purgeApps(context, getConflictingRepo());
|
||||
|
||||
assertEmpty();
|
||||
}
|
||||
|
||||
private void disableRepo(Repo repo) {
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(RepoProvider.DataColumns.IN_USE, 0);
|
||||
RepoProvider.Helper.update(context, repo, values);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
||||
protected static final String REPO_ARCHIVE = "Test F-Droid repo (Archive)";
|
||||
protected static final String REPO_CONFLICTING = "Test F-Droid repo with different apps";
|
||||
|
||||
protected RepoUpdater conflictingRepoUpdater;
|
||||
protected RepoUpdater mainRepoUpdater;
|
||||
protected RepoUpdater archiveRepoUpdater;
|
||||
protected static final String REPO_MAIN_URI = "https://f-droid.org/repo";
|
||||
protected static final String REPO_ARCHIVE_URI = "https://f-droid.org/archive";
|
||||
protected static final String REPO_CONFLICTING_URI = "https://example.com/conflicting/fdroid/repo";
|
||||
|
||||
private static final String PUB_KEY =
|
||||
"3082050b308202f3a003020102020420d8f212300d06092a864886f70d01010b050030363110300e0603" +
|
||||
@ -79,10 +79,6 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
||||
RepoProvider.Helper.remove(context, 3);
|
||||
RepoProvider.Helper.remove(context, 4);
|
||||
|
||||
conflictingRepoUpdater = createUpdater(REPO_CONFLICTING, context);
|
||||
mainRepoUpdater = createUpdater(REPO_MAIN, context);
|
||||
archiveRepoUpdater = createUpdater(REPO_ARCHIVE, context);
|
||||
|
||||
Preferences.setup(context);
|
||||
}
|
||||
|
||||
@ -157,10 +153,10 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
||||
}
|
||||
}
|
||||
|
||||
private RepoUpdater createUpdater(String name, Context context) {
|
||||
private RepoUpdater createUpdater(String name, String uri, Context context) {
|
||||
Repo repo = new Repo();
|
||||
repo.signingCertificate = PUB_KEY;
|
||||
repo.address = "https://fake.url/" + UUID.randomUUID().toString() + "/fdroid/repo";
|
||||
repo.address = uri;
|
||||
repo.name = name;
|
||||
|
||||
ContentValues values = new ContentValues(2);
|
||||
@ -176,15 +172,15 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
||||
}
|
||||
|
||||
protected boolean updateConflicting() throws UpdateException {
|
||||
return updateRepo(conflictingRepoUpdater, "multiRepo.conflicting.jar");
|
||||
return updateRepo(createUpdater(REPO_CONFLICTING, REPO_CONFLICTING_URI, context), "multiRepo.conflicting.jar");
|
||||
}
|
||||
|
||||
protected boolean updateMain() throws UpdateException {
|
||||
return updateRepo(mainRepoUpdater, "multiRepo.normal.jar");
|
||||
return updateRepo(createUpdater(REPO_MAIN, REPO_MAIN_URI, context), "multiRepo.normal.jar");
|
||||
}
|
||||
|
||||
protected boolean updateArchive() throws UpdateException {
|
||||
return updateRepo(archiveRepoUpdater, "multiRepo.archive.jar");
|
||||
return updateRepo(createUpdater(REPO_ARCHIVE, REPO_ARCHIVE_URI, context), "multiRepo.archive.jar");
|
||||
}
|
||||
|
||||
private boolean updateRepo(RepoUpdater updater, String indexJarPath) throws UpdateException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user