Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: chrome/android/webapk/libs/client/junit/src/org/chromium/webapk/lib/client/WebApkVerifySignatureTest.java

Issue 2772483002: Commment signed webapks working and verified. (Closed)
Patch Set: Fix setting of flags. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.webapk.lib.client;
6
7 import static org.junit.Assert.assertArrayEquals;
8 import static org.junit.Assert.assertEquals;
9
10 import org.junit.Test;
11 import org.junit.runner.RunWith;
12 import org.robolectric.annotation.Config;
13
14 import org.chromium.testing.local.LocalRobolectricTestRunner;
15
16 /** Unit tests for WebApkVerifySignature for Android. */
17 @RunWith(LocalRobolectricTestRunner.class)
18 @Config(manifest = Config.NONE)
19 public class WebApkVerifySignatureTest {
20 /** Elliptical Curves, Digital Signature Algorithm */
21 private static final String KEY_FACTORY = "EC";
22
23 private static final String TEST_DATA_DIR = "/webapks/";
24
25 @Test
26 public void testHexToBytes() throws Exception {
27 byte[] empty = {};
28 assertArrayEquals(empty, WebApkVerifySignature.hexToBytes(""));
29 byte[] test = {(byte) 0xFF, (byte) 0xFE, 0x00, 0x01};
30 assertArrayEquals(test, WebApkVerifySignature.hexToBytes("fffe0001"));
31 assertArrayEquals(test, WebApkVerifySignature.hexToBytes("FFFE0001"));
32 assertEquals(null, WebApkVerifySignature.hexToBytes("f")); // Odd number of nibbles.
33 }
34
35 @Test
36 public void testCommentHash() throws Exception {
37 byte[] bytes = {(byte) 0xde, (byte) 0xca, (byte) 0xfb, (byte) 0xad};
38 assertEquals(null, WebApkVerifySignature.parseCommentSignature("weapk:de cafbad"));
39 assertEquals(null, WebApkVerifySignature.parseCommentSignature("webapk:" ));
40 assertEquals(null, WebApkVerifySignature.parseCommentSignature("webapk:d ecafbad"));
41 assertArrayEquals(
42 bytes, WebApkVerifySignature.parseCommentSignature("webapk:12345 :decafbad"));
43 assertArrayEquals(
44 bytes, WebApkVerifySignature.parseCommentSignature("XXXwebapk:00 00:decafbadXXX"));
45 assertArrayEquals(
46 bytes, WebApkVerifySignature.parseCommentSignature("\n\nwebapk:0 000:decafbad\n\n"));
47 assertArrayEquals(bytes,
48 WebApkVerifySignature.parseCommentSignature("chrome-webapk:000:d ecafbad\n\n"));
49 assertArrayEquals(bytes,
50 WebApkVerifySignature.parseCommentSignature(
51 "prefixed: chrome-webapk:000:decafbad :suffixed"));
52 }
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698