Search in sources :

Example 1 with IndexV1Updater

use of org.fdroid.fdroid.IndexV1Updater in project fdroidclient by f-droid.

the class IndexV1UpdaterTest method testBadTestyJar.

private void testBadTestyJar(String jar) throws IOException, RepoUpdater.UpdateException {
    Repo repo = MultiRepoUpdaterTest.createRepo("Testy", jar, context, TESTY_CERT);
    IndexV1Updater updater = new IndexV1Updater(context, repo);
    JarFile jarFile = new JarFile(TestUtils.copyResourceToTempFile(jar), true);
    JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
    InputStream indexInputStream = jarFile.getInputStream(indexEntry);
    updater.processIndexV1(indexInputStream, indexEntry, "fakeEtag");
    // it should never reach here, it should throw a SigningException
    fail();
}
Also used : IndexV1Updater(org.fdroid.fdroid.IndexV1Updater) Repo(org.fdroid.fdroid.data.Repo) InputStream(java.io.InputStream) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry)

Example 2 with IndexV1Updater

use of org.fdroid.fdroid.IndexV1Updater in project fdroidclient by f-droid.

the class IndexV1UpdaterTest method testIndexV1Processing.

@Test
public void testIndexV1Processing() throws IOException, RepoUpdater.UpdateException {
    List<Repo> repos = RepoProvider.Helper.all(context);
    for (Repo repo : repos) {
        RepoProvider.Helper.remove(context, repo.getId());
    }
    assertEquals("No repos present", 0, RepoProvider.Helper.all(context).size());
    assertEquals("No apps present", 0, AppProvider.Helper.all(context.getContentResolver()).size());
    Repo repo = MultiRepoUpdaterTest.createRepo("Testy", TESTY_JAR, context, TESTY_CERT);
    repo.timestamp = 1481222110;
    IndexV1Updater updater = new IndexV1Updater(context, repo);
    JarFile jarFile = new JarFile(TestUtils.copyResourceToTempFile(TESTY_JAR), true);
    Log.i(TAG, "jarFile " + jarFile);
    JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
    InputStream indexInputStream = jarFile.getInputStream(indexEntry);
    updater.processIndexV1(indexInputStream, indexEntry, "fakeEtag");
    IOUtils.closeQuietly(indexInputStream);
    List<App> apps = AppProvider.Helper.all(context.getContentResolver());
    assertEquals("63 apps present", 63, apps.size());
    String[] packages = { "fake.app.one", "org.adaway", "This_does_not_exist" };
    for (String id : packages) {
        assertEquals("No apks for " + id, 0, ApkProvider.Helper.findByPackageName(context, id).size());
    }
    for (App app : apps) {
        assertTrue("Some apks for " + app.packageName, ApkProvider.Helper.findByPackageName(context, app.packageName).size() > 0);
    }
    repos = RepoProvider.Helper.all(context);
    assertEquals("One repo", 1, repos.size());
    Repo repoFromDb = repos.get(0);
    assertEquals("repo.timestamp should be set", 1497639511, repoFromDb.timestamp);
    assertEquals("repo.address should be the same", repo.address, repoFromDb.address);
    assertEquals("repo.name should be set", "non-public test repo", repoFromDb.name);
    assertEquals("repo.maxage should be set", 0, repoFromDb.maxage);
    assertEquals("repo.version should be set", 18, repoFromDb.version);
    assertEquals("repo.icon should be set", "fdroid-icon.png", repoFromDb.icon);
    // NOCHECKSTYLE LineLength
    String description = "This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/u/fdroid. ";
    assertEquals("repo.description should be set", description, repoFromDb.description);
    assertEquals("repo.mirrors should have items", 2, repo.mirrors.length);
    assertEquals("repo.mirrors first URL", "http://frkcchxlcvnb4m5a.onion/fdroid/repo", repo.mirrors[0]);
    assertEquals("repo.mirrors second URL", "http://testy.at.or.at/fdroid/repo", repo.mirrors[1]);
    // Make sure the per-apk anti features which are new in index v1 get added correctly.
    assertEquals(0, AppProvider.Helper.findInstalledAppsWithKnownVulns(context).size());
    InstalledAppTestUtils.install(context, "com.waze", 1019841, "v3.9.5.4", "362488e7be5ea0689b4e97d989ae1404", "cbbdb8c5dafeccd7dd7b642dde0477d3489e18ac366e3c8473d5c07e5f735a95");
    assertEquals(1, AppProvider.Helper.findInstalledAppsWithKnownVulns(context).size());
}
Also used : App(org.fdroid.fdroid.data.App) IndexV1Updater(org.fdroid.fdroid.IndexV1Updater) Repo(org.fdroid.fdroid.data.Repo) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) FDroidProviderTest(org.fdroid.fdroid.data.FDroidProviderTest) Test(org.junit.Test)

Example 3 with IndexV1Updater

use of org.fdroid.fdroid.IndexV1Updater in project fdroidclient by f-droid.

the class MultiRepoUpdaterTest method updateRepo.

protected void updateRepo(RepoUpdater updater, String indexJarPath) throws UpdateException {
    File indexJar = TestUtils.copyResourceToTempFile(indexJarPath);
    try {
        if (updater instanceof IndexV1Updater) {
            JarFile jarFile = new JarFile(indexJar);
            JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
            InputStream indexInputStream = jarFile.getInputStream(indexEntry);
            ((IndexV1Updater) updater).processIndexV1(indexInputStream, indexEntry, null);
        } else {
            updater.processDownloadedFile(indexJar);
        }
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    } finally {
        if (indexJar != null && indexJar.exists()) {
            indexJar.delete();
        }
    }
}
Also used : IndexV1Updater(org.fdroid.fdroid.IndexV1Updater) InputStream(java.io.InputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 4 with IndexV1Updater

use of org.fdroid.fdroid.IndexV1Updater in project fdroidclient by f-droid.

the class IndexV1UpdaterTest method testIndexV1WithOldTimestamp.

@Test(expected = RepoUpdater.UpdateException.class)
public void testIndexV1WithOldTimestamp() throws IOException, RepoUpdater.UpdateException {
    Repo repo = MultiRepoUpdaterTest.createRepo("Testy", TESTY_JAR, context, TESTY_CERT);
    repo.timestamp = System.currentTimeMillis() / 1000;
    IndexV1Updater updater = new IndexV1Updater(context, repo);
    JarFile jarFile = new JarFile(TestUtils.copyResourceToTempFile(TESTY_JAR), true);
    JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
    InputStream indexInputStream = jarFile.getInputStream(indexEntry);
    updater.processIndexV1(indexInputStream, indexEntry, "fakeEtag");
    // it should never reach here, it should throw a SigningException
    fail();
    getClass().getResourceAsStream("foo");
}
Also used : IndexV1Updater(org.fdroid.fdroid.IndexV1Updater) Repo(org.fdroid.fdroid.data.Repo) InputStream(java.io.InputStream) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) FDroidProviderTest(org.fdroid.fdroid.data.FDroidProviderTest) Test(org.junit.Test)

Example 5 with IndexV1Updater

use of org.fdroid.fdroid.IndexV1Updater in project fdroidclient by f-droid.

the class IndexV1UpdaterTest method testIndexV1WithWrongCert.

@Test(expected = RepoUpdater.SigningException.class)
public void testIndexV1WithWrongCert() throws IOException, RepoUpdater.UpdateException {
    // NOCHECKSTYLE LineLength
    String badCert = "308202ed308201d5a003020102020426ffa009300d06092a864886f70d01010b05003027310b300906035504061302444531183016060355040a130f4e4f47415050532050726f6a656374301e170d3132313030363132303533325a170d3337303933303132303533325a3027310b300906035504061302444531183016060355040a130f4e4f47415050532050726f6a65637430820122300d06092a864886f70d01010105000382010f003082010a02820101009a8d2a5336b0eaaad89ce447828c7753b157459b79e3215dc962ca48f58c2cd7650df67d2dd7bda0880c682791f32b35c504e43e77b43c3e4e541f86e35a8293a54fb46e6b16af54d3a4eda458f1a7c8bc1b7479861ca7043337180e40079d9cdccb7e051ada9b6c88c9ec635541e2ebf0842521c3024c826f6fd6db6fd117c74e859d5af4db04448965ab5469b71ce719939a06ef30580f50febf96c474a7d265bb63f86a822ff7b643de6b76e966a18553c2858416cf3309dd24278374bdd82b4404ef6f7f122cec93859351fc6e5ea947e3ceb9d67374fe970e593e5cd05c905e1d24f5a5484f4aadef766e498adf64f7cf04bddd602ae8137b6eea40722d0203010001a321301f301d0603551d0e04160414110b7aa9ebc840b20399f69a431f4dba6ac42a64300d06092a864886f70d01010b0500038201010007c32ad893349cf86952fb5a49cfdc9b13f5e3c800aece77b2e7e0e9c83e34052f140f357ec7e6f4b432dc1ed542218a14835acd2df2deea7efd3fd5e8f1c34e1fb39ec6a427c6e6f4178b609b369040ac1f8844b789f3694dc640de06e44b247afed11637173f36f5886170fafd74954049858c6096308fc93c1bc4dd5685fa7a1f982a422f2a3b36baa8c9500474cf2af91c39cbec1bc898d10194d368aa5e91f1137ec115087c31962d8f76cd120d28c249cf76f4c70f5baa08c70a7234ce4123be080cee789477401965cfe537b924ef36747e8caca62dfefdd1a6288dcb1c4fd2aaa6131a7ad254e9742022cfd597d2ca5c660ce9e41ff537e5a4041e37";
    Repo repo = MultiRepoUpdaterTest.createRepo("Testy", TESTY_JAR, context, badCert);
    IndexV1Updater updater = new IndexV1Updater(context, repo);
    JarFile jarFile = new JarFile(TestUtils.copyResourceToTempFile(TESTY_JAR), true);
    JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
    InputStream indexInputStream = jarFile.getInputStream(indexEntry);
    updater.processIndexV1(indexInputStream, indexEntry, "fakeEtag");
    // it should never reach here, it should throw a SigningException
    fail();
    getClass().getResourceAsStream("foo");
}
Also used : IndexV1Updater(org.fdroid.fdroid.IndexV1Updater) Repo(org.fdroid.fdroid.data.Repo) InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) FDroidProviderTest(org.fdroid.fdroid.data.FDroidProviderTest) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)5 JarEntry (java.util.jar.JarEntry)5 JarFile (java.util.jar.JarFile)5 IndexV1Updater (org.fdroid.fdroid.IndexV1Updater)5 Repo (org.fdroid.fdroid.data.Repo)4 FDroidProviderTest (org.fdroid.fdroid.data.FDroidProviderTest)3 Test (org.junit.Test)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 File (java.io.File)1 IOException (java.io.IOException)1 App (org.fdroid.fdroid.data.App)1