blob: b40c435839f601eca8bdfefc8ffee3d24273d7ac [file] [log] [blame]
Jooyung Han12a0b702021-08-05 23:20:31 +09001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use apkverify::verify;
18
Jooyung Hand8397852021-08-10 16:29:36 +090019macro_rules! assert_contains {
20 ($haystack:expr,$needle:expr $(,)?) => {
21 match (&$haystack, &$needle) {
22 (haystack_value, needle_value) => {
23 assert!(
24 haystack_value.contains(needle_value),
25 "{} is not found in {}",
26 needle_value,
27 haystack_value
28 );
29 }
30 }
31 };
32}
33
Jooyung Han12a0b702021-08-05 23:20:31 +090034#[test]
35fn test_verify_v3() {
36 assert!(verify("tests/data/test.apex").is_ok());
37}
Jooyung Hand8397852021-08-10 16:29:36 +090038
39#[test]
40fn test_verify_v3_digest_mismatch() {
41 let res = verify("tests/data/v3-only-with-rsa-pkcs1-sha512-8192-digest-mismatch.apk");
42 assert!(res.is_err());
43 assert_contains!(res.err().unwrap().to_string(), "digest mismatch");
44}