Search in sources :

Example 21 with Repo

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

the class IndexV1UpdaterTest method testInstanceVariablesAreProperlyMarked.

@Test
public void testInstanceVariablesAreProperlyMarked() throws IOException {
    ObjectMapper mapper = IndexV1Updater.getObjectMapperInstance(FAKE_REPO_ID);
    JsonFactory f = mapper.getFactory();
    JsonParser parser = f.createParser(TestUtils.copyResourceToTempFile("all_fields_index-v1.json"));
    Repo repo = null;
    App[] apps = null;
    Map<String, List<Apk>> packages = null;
    // go into the main object block
    parser.nextToken();
    while (true) {
        String fieldName = parser.nextFieldName();
        if (fieldName == null) {
            break;
        }
        switch(fieldName) {
            case "repo":
                repo = parseRepo(mapper, parser);
                break;
            case "apps":
                apps = parseApps(mapper, parser);
                break;
            case "packages":
                packages = parsePackages(mapper, parser);
                break;
        }
    }
    // ensure resources get cleaned up timely and properly
    parser.close();
    assertEquals(1, apps.length);
    assertEquals(1, packages.size());
    assertEquals(1488828510109L, repo.timestamp);
    assertEquals("GPLv3", apps[0].license);
    Set<String> appFields = getFields(apps[0]);
    for (String field : appFields) {
        assertNotEquals("secret", field);
    }
    Apk apk = packages.get("info.guardianproject.cacert").get(0);
    assertEquals("e013db095e8da843fae5ac44be6152e51377ee717e5c8a7b6d913d7720566b5a", apk.hash);
    Set<String> packageFields = getFields(apk);
    for (String field : packageFields) {
        assertNotEquals("secret", field);
    }
}
Also used : App(org.fdroid.fdroid.data.App) Repo(org.fdroid.fdroid.data.Repo) JsonFactory(com.fasterxml.jackson.core.JsonFactory) List(java.util.List) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Apk(org.fdroid.fdroid.data.Apk) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) FDroidProviderTest(org.fdroid.fdroid.data.FDroidProviderTest) Test(org.junit.Test)

Example 22 with Repo

use of org.fdroid.fdroid.data.Repo 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)

Example 23 with Repo

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

the class MultiRepoUpdaterTest method findRepo.

@NonNull
protected Repo findRepo(@NonNull String name, List<Repo> allRepos) {
    Repo repo = null;
    for (Repo r : allRepos) {
        if (TextUtils.equals(name, r.getName())) {
            repo = r;
            break;
        }
    }
    assertNotNull("Repo " + allRepos, repo);
    return repo;
}
Also used : Repo(org.fdroid.fdroid.data.Repo) NonNull(android.support.annotation.NonNull)

Example 24 with Repo

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

the class ProperMultiRepoUpdaterTest method assertMainRepo.

/**
 * + 2048 (com.uberspot.a2048)
 * - Version 1.96 (19)
 * - Version 1.95 (18)
 * + AdAway (org.adaway)
 * - Version 3.0.2 (54)
 * - Version 3.0.1 (53)
 * - Version 3.0 (52)
 * + adbWireless (siir.es.adbWireless)
 * - Version 1.5.4 (12)
 */
private void assertMainRepo(List<Repo> allRepos) {
    Repo repo = findRepo(REPO_MAIN, allRepos);
    List<Apk> apks = ApkProvider.Helper.findByRepo(context, repo, Schema.ApkTable.Cols.ALL);
    assertEquals("Apks for main repo", apks.size(), 6);
    assertApksExist(apks, "com.uberspot.a2048", new int[] { 18, 19 });
    assertApksExist(apks, "org.adaway", new int[] { 52, 53, 54 });
    assertApksExist(apks, "siir.es.adbWireless", new int[] { 12 });
    assert2048Metadata(repo, "Normal");
    assertAdAwayMetadata(repo, "Normal");
    assertAdbMetadata(repo, "Normal");
}
Also used : Repo(org.fdroid.fdroid.data.Repo) Apk(org.fdroid.fdroid.data.Apk)

Example 25 with Repo

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

the class ProperMultiRepoUpdaterTest method assertConflictingRepo.

/**
 * + AdAway (org.adaway)
 * - Version 3.0.1 (53) *
 * - Version 3.0 (52) *
 * - Version 2.9.2 (51) *
 * - Version 2.2.1 (50) *
 * + Add to calendar (org.dgtale.icsimport)
 * - Version 1.2 (3)
 * - Version 1.1 (2)
 */
private void assertConflictingRepo(List<Repo> allRepos) {
    Repo repo = findRepo(REPO_CONFLICTING, allRepos);
    List<Apk> apks = ApkProvider.Helper.findByRepo(context, repo, Schema.ApkTable.Cols.ALL);
    assertEquals("Apks for conflicting repo", 6, apks.size());
    assertApksExist(apks, "org.adaway", new int[] { 50, 51, 52, 53 });
    assertApksExist(apks, "org.dgtale.icsimport", new int[] { 2, 3 });
    assertAdAwayMetadata(repo, "Conflicting");
    assertCalendarMetadata(repo, "Conflicting");
}
Also used : Repo(org.fdroid.fdroid.data.Repo) Apk(org.fdroid.fdroid.data.Apk)

Aggregations

Repo (org.fdroid.fdroid.data.Repo)30 Test (org.junit.Test)14 RepoDetails (org.fdroid.fdroid.mock.RepoDetails)8 ArrayList (java.util.ArrayList)5 FDroidProviderTest (org.fdroid.fdroid.data.FDroidProviderTest)5 NonNull (android.support.annotation.NonNull)4 InputStream (java.io.InputStream)4 List (java.util.List)4 JarEntry (java.util.jar.JarEntry)4 JarFile (java.util.jar.JarFile)4 IndexV1Updater (org.fdroid.fdroid.IndexV1Updater)4 Apk (org.fdroid.fdroid.data.Apk)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 ContentValues (android.content.ContentValues)3 App (org.fdroid.fdroid.data.App)3 RepoPushRequest (org.fdroid.fdroid.data.RepoPushRequest)3 Uri (android.net.Uri)2 View (android.view.View)2 TextView (android.widget.TextView)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2