diff options
author | rich cannings <richc@google.com> | 2012-08-20 13:20:14 -0700 |
---|---|---|
committer | rich cannings <richc@google.com> | 2012-08-20 13:20:14 -0700 |
commit | 706e8ba26bf0de19ad5f736516dae40c4c88c2d7 (patch) | |
tree | 2c45b61e1420f9a7442de8517b1eca6802d507c0 /core/tests/coretests | |
parent | 99de2459e200e0c86d55d5eee7ea000fd030990f (diff) | |
download | frameworks_base-706e8ba26bf0de19ad5f736516dae40c4c88c2d7.zip frameworks_base-706e8ba26bf0de19ad5f736516dae40c4c88c2d7.tar.gz frameworks_base-706e8ba26bf0de19ad5f736516dae40c4c88c2d7.tar.bz2 |
Pass URLs to package verifiers
This change passes the originating URL and accompanied referrer to
package verifiers, when available.
Bug: 6544677
Change-Id: I9ebc71bc13f549bd88267e444816151a99bda000
Diffstat (limited to 'core/tests/coretests')
-rw-r--r-- | core/tests/coretests/src/android/content/pm/VerificationParamsTest.java | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/content/pm/VerificationParamsTest.java b/core/tests/coretests/src/android/content/pm/VerificationParamsTest.java new file mode 100644 index 0000000..b814e2d --- /dev/null +++ b/core/tests/coretests/src/android/content/pm/VerificationParamsTest.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.content.pm; + +import android.content.pm.ManifestDigest; +import android.content.pm.VerificationParams; +import android.net.Uri; +import android.os.Parcel; +import android.test.AndroidTestCase; + +/** + * Tests the android.content.pm.VerificationParams class + * + * To test run: + * ./development/testrunner/runtest.py frameworks-core -c android.content.pm.VerificationParamsTest + */ +public class VerificationParamsTest extends AndroidTestCase { + + private final static String VERIFICATION_URI_STRING = "http://verification.uri/path"; + private final static String ORIGINATING_URI_STRING = "http://originating.uri/path"; + private final static String REFERRER_STRING = "http://referrer.uri/path"; + private final static byte[] DIGEST_BYTES = "fake digest".getBytes(); + + private final static Uri VERIFICATION_URI = Uri.parse(VERIFICATION_URI_STRING); + private final static Uri ORIGINATING_URI = Uri.parse(ORIGINATING_URI_STRING); + private final static Uri REFERRER = Uri.parse(REFERRER_STRING); + + private final static ManifestDigest MANIFEST_DIGEST = new ManifestDigest(DIGEST_BYTES); + + public void testParcel() throws Exception { + VerificationParams expected = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + Parcel parcel = Parcel.obtain(); + expected.writeToParcel(parcel, 0); + parcel.setDataPosition(0); + + VerificationParams actual = VerificationParams.CREATOR.createFromParcel(parcel); + + assertEquals(VERIFICATION_URI, actual.getVerificationURI()); + + assertEquals(ORIGINATING_URI, actual.getOriginatingURI()); + + assertEquals(REFERRER, actual.getReferrer()); + + assertEquals(MANIFEST_DIGEST, actual.getManifestDigest()); + } + + public void testEquals_Success() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING), + Uri.parse(REFERRER_STRING), new ManifestDigest(DIGEST_BYTES)); + + assertEquals(params1, params2); + } + + public void testEquals_VerificationUri_Failure() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse("http://a.different.uri/"), Uri.parse(ORIGINATING_URI_STRING), + Uri.parse(REFERRER_STRING), new ManifestDigest(DIGEST_BYTES)); + + assertFalse(params1.equals(params2)); + } + + public void testEquals_OriginatingUri_Failure() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse(VERIFICATION_URI_STRING), Uri.parse("http://a.different.uri/"), + Uri.parse(REFERRER_STRING), new ManifestDigest(DIGEST_BYTES)); + + assertFalse(params1.equals(params2)); + } + + public void testEquals_Referrer_Failure() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING), + Uri.parse("http://a.different.uri/"), new ManifestDigest(DIGEST_BYTES)); + + assertFalse(params1.equals(params2)); + } + + public void testEquals_ManifestDigest_Failure() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING), + Uri.parse(REFERRER_STRING), new ManifestDigest("a different digest".getBytes())); + + assertFalse(params1.equals(params2)); + } + + public void testHashCode_Success() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING), + Uri.parse(REFERRER_STRING), new ManifestDigest(DIGEST_BYTES)); + + assertEquals(params1.hashCode(), params2.hashCode()); + } + + public void testHashCode_VerificationUri_Failure() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams(null, Uri.parse(ORIGINATING_URI_STRING), + Uri.parse(REFERRER_STRING), new ManifestDigest(DIGEST_BYTES)); + + assertFalse(params1.hashCode() == params2.hashCode()); + } + + public void testHashCode_OriginatingUri_Failure() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse(VERIFICATION_URI_STRING), Uri.parse("http://a.different.uri/"), + Uri.parse(REFERRER_STRING), new ManifestDigest(DIGEST_BYTES)); + + assertFalse(params1.hashCode() == params2.hashCode()); + } + + public void testHashCode_Referrer_Failure() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING), null, + new ManifestDigest(DIGEST_BYTES)); + + assertFalse(params1.hashCode() == params2.hashCode()); + } + + public void testHashCode_ManifestDigest_Failure() throws Exception { + VerificationParams params1 = new VerificationParams(VERIFICATION_URI, ORIGINATING_URI, + REFERRER, MANIFEST_DIGEST); + + VerificationParams params2 = new VerificationParams( + Uri.parse(VERIFICATION_URI_STRING), Uri.parse(ORIGINATING_URI_STRING), + Uri.parse(REFERRER_STRING), new ManifestDigest("a different digest".getBytes())); + + assertFalse(params1.hashCode() == params2.hashCode()); + } +} |