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

Unified Diff: content/public/android/junit/src/org/chromium/content/browser/installedapp/PackageHashTest.java

Issue 2802603002: getInstalledRelatedApps: Introduce random delay to stop timing attacks. (Closed)
Patch Set: Added tests for PackageHash and the delay in InstalledAppProviderImpl. 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 side-by-side diff with in-line comments
Download patch
Index: content/public/android/junit/src/org/chromium/content/browser/installedapp/PackageHashTest.java
diff --git a/content/public/android/junit/src/org/chromium/content/browser/installedapp/PackageHashTest.java b/content/public/android/junit/src/org/chromium/content/browser/installedapp/PackageHashTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..865e174a8b5faff1155b0fa228e3794aa8d78cd1
--- /dev/null
+++ b/content/public/android/junit/src/org/chromium/content/browser/installedapp/PackageHashTest.java
@@ -0,0 +1,32 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser.installedapp;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+
+import org.chromium.base.test.util.Feature;
+
+/**
+ * Tests that PackageHash generates correct hashes.
+ */
+@RunWith(BlockJUnit4ClassRunner.class)
+public class PackageHashTest {
+ @Test
+ @Feature({"InstalledApp"})
+ public void testPackageHash() {
+ PackageHash.setGlobalSaltForTesting("5797896c-e292-4d6f-b0a4-0aee1f89b9ed");
+ // These expectations are based on the salt + ':' + packageName, encoded in UTF-8, hashed
+ // with SHA-256, and looking at the first two bytes of the result.
+ Assert.assertEquals((short) 0x41b2, PackageHash.hashForPackage("com.example.test1"));
+ Assert.assertEquals((short) 0xe0e8, PackageHash.hashForPackage("com.example.t\u00e9st2"));
+
+ PackageHash.setGlobalSaltForTesting("66e36020-efa2-4ab7-a7fc-21762e98dcb4");
+ Assert.assertEquals((short) 0x2beb, PackageHash.hashForPackage("com.example.test1"));
+ Assert.assertEquals((short) 0xe112, PackageHash.hashForPackage("com.example.t\u00e9st2"));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698