aboutsummaryrefslogtreecommitdiffstats
path: root/quantum/visualizer
diff options
context:
space:
mode:
authorThierry Michel Philippe Kleist <thierry@kle.ist>2020-09-21 20:12:22 +0200
committerGitHub <noreply@github.com>2020-09-21 11:12:22 -0700
commit0384237544a1d377ff0946e59f564529a717e341 (patch)
treecddc8c711703311ba3d532809c03297fac99eac7 /quantum/visualizer
parentbc7a745227d453dd68ae2f40b0c4ff98c082212f (diff)
downloadfirmware-0384237544a1d377ff0946e59f564529a717e341.tar.gz
firmware-0384237544a1d377ff0946e59f564529a717e341.tar.bz2
firmware-0384237544a1d377ff0946e59f564529a717e341.zip
[Keyboard] knife66 added (#9877)
* feat: keyboard knife66 added * fix: requested changes applied * docs: updated readme * feat: added support for ws2812 * fix: adjusted headers and readme * fix: moved to LAYOUT_all
Diffstat (limited to 'quantum/visualizer')
0 files changed, 0 insertions, 0 deletions
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
/*
 * Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
 *
 * 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.pgp;


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.security.Security;
import java.util.ArrayList;

import android.app.Application;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;

import junit.framework.Assert;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openintents.openpgp.OpenPgpMetadata;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;
import org.sufficientlysecure.keychain.WorkaroundBuildConfig;
import org.sufficientlysecure.keychain.operations.InputDataOperation;
import org.sufficientlysecure.keychain.operations.results.InputDataResult;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.InputDataParcel;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;


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

    static PrintStream oldShadowStream;

    @BeforeClass
    public static void setUpOnce() throws Exception {

        Security.insertProviderAt(new BouncyCastleProvider(), 1);
        oldShadowStream = ShadowLog.stream;
        // ShadowLog.stream = System.out;

    }

    @Before
    public void setUp() {
        // don't log verbosely here, we're not here to test imports
        ShadowLog.stream = oldShadowStream;

        // ok NOW log verbosely!
        ShadowLog.stream = System.out;
    }

    @Test
    public void testMimeDecoding() throws Exception {

        String mimeMail =
            "Content-Type: multipart/mixed; boundary=\"=-26BafqxfXmhVNMbYdoIi\"\n" +
            "\n" +
            "--=-26BafqxfXmhVNMbYdoIi\n" +
            "Content-Type: text/plain; charset=utf-8\n" +
            "Content-Transfer-Encoding: quoted-printable\n" +
            "Content-Disposition: attachment; filename=data.txt\n" +
            "\n" +
            "message part 1\n" +
            "\n" +
            "--=-26BafqxfXmhVNMbYdoIi\n" +
            "Content-Type: text/testvalue; charset=iso-8859-1\n" +
            "Content-Description: Dummy content description\n" +
            "\n" +
            "message part 2.1\n" +
            "message part 2.2\n" +
            "\n" +
            "--=-26BafqxfXmhVNMbYdoIi--";


        ByteArrayOutputStream outStream1 = new ByteArrayOutputStream();
        ByteArrayOutputStream outStream2 = new ByteArrayOutputStream();
        ContentResolver mockResolver = mock(ContentResolver.class);

        // fake openOutputStream first and second
        when(mockResolver.openOutputStream(any(Uri.class), eq("w")))
                .thenReturn(outStream1, outStream2);

        // fake openInputStream
        Uri fakeInputUri = Uri.parse("content://fake/1");
        when(mockResolver.openInputStream(fakeInputUri)).thenReturn(
                new ByteArrayInputStream(mimeMail.getBytes()));

        Uri fakeOutputUri1 = Uri.parse("content://fake/out/1");
        Uri fakeOutputUri2 = Uri.parse("content://fake/out/2");
        when(mockResolver.insert(eq(TemporaryFileProvider.CONTENT_URI), any(ContentValues.class)))
                .thenReturn(fakeOutputUri1, fakeOutputUri2);

        // application which returns mockresolver
        Application spyApplication = spy(RuntimeEnvironment.application);
        when(spyApplication.getContentResolver()).thenReturn(mockResolver);

        InputDataOperation op = new InputDataOperation(spyApplication,
                new ProviderHelper(RuntimeEnvironment.application), null);

        InputDataParcel input = new InputDataParcel(fakeInputUri, null);

        InputDataResult result = op.execute(input, new CryptoInputParcel());

        // must be successful, no verification, have two output URIs
        Assert.assertTrue(result.success());
        Assert.assertNull(result.mDecryptVerifyResult);

        ArrayList<Uri> outUris = result.getOutputUris();
        Assert.assertEquals("must have two output URIs", 2, outUris.size());
        Assert.assertEquals("first uri must be the one we provided", fakeOutputUri1, outUris.get(0));
        verify(mockResolver).openOutputStream(result.getOutputUris().get(0), "w");
        Assert.assertEquals("second uri must be the one we provided", fakeOutputUri2, outUris.get(1));
        verify(mockResolver).openOutputStream(result.getOutputUris().get(1), "w");

        ContentValues contentValues = new ContentValues();
        contentValues.put("name", "data.txt");
        contentValues.put("mimetype", "text/plain");
        verify(mockResolver).insert(TemporaryFileProvider.CONTENT_URI, contentValues);
        contentValues.put("name", (String) null);