aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java
blob: 6779784a2568caf7112754ffc7ca27c6866962a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (C) Art O Cathain
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.sufficientlysecure.keychain.provider;

import java.util.Collections;
import java.util.Arrays;
import java.util.Collection;
import java.util.ArrayList;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.*;
import org.robolectric.annotation.Config;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
import org.sufficientlysecure.keychain.support.KeyringTestingHelper;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = WorkaroundBuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")
public class ProviderHelperKeyringTest {

    @Test
    public void testSavePublicKeyring() throws Exception {
        Assert.assertTrue(new KeyringTestingHelper(RuntimeEnvironment.application).addKeyring(Collections.singleton(
                "/public-key-for-sample.blob"
        )));
    }

    // @Test
    public void testSavePublicKeyringRsa() throws Exception {
        Assert.assertTrue(new KeyringTestingHelper(RuntimeEnvironment.application).addKeyring(prependResourcePath(Arrays.asList(
                        "000001-006.public_key",
                        "000002-013.user_id",
                        "000003-002.sig",
                        "000004-012.ring_trust",
                        "000005-002.sig",
                        "000006-012.ring_trust",
                        "000007-002.sig",
                        "000008-012.ring_trust",
                        "000009-002.sig",
                        "000010-012.ring_trust",
                        "000011-002.sig",
                        "000012-012.ring_trust",
                        "000013-014.public_subkey",
                        "000014-002.sig",
                        "000015-012.ring_trust"
                ))));
    }

    // @Test
    public void testSavePublicKeyringDsa() throws Exception {
        Assert.assertTrue(new KeyringTestingHelper(RuntimeEnvironment.application).addKeyring(prependResourcePath(Arrays.asList(
                        "000016-006.public_key",
                        "000017-002.sig",
                        "000018-012.ring_trust",
                        "000019-013.user_id",
                        "000020-002.sig",
                        "000021-012.ring_trust",
                        "000022-002.sig",
                        "000023-012.ring_trust",
                        "000024-014.public_subkey",
                        "000025-002.sig",
                        "000026-012.ring_trust"
                ))));
    }

    // @Test
    public void testSavePublicKeyringDsa2() throws Exception {
        Assert.assertTrue(new KeyringTestingHelper(RuntimeEnvironment.application).addKeyring(prependResourcePath(Arrays.asList(
                        "000027-006.public_key",
                        "000028-002.sig",
                        "000029-012.ring_trust",
                        "000030-013.user_id",
                        "000031-002.sig",
                        "000032-012.ring_trust",
                        "000033-002.sig",
                        "000034-012.ring_trust"
                ))));
    }

    private static Collection<String> prependResourcePath(Collection<String> files) {
        Collection<String> prependedFiles = new ArrayList<String>();
        for (String file: files) {
            prependedFiles.add("/OpenPGP-Haskell/tests/data/" + file);
        }
        return prependedFiles;
    }
}