Jooyung Han | 12a0b70 | 2021-08-05 23:20:31 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | use apkverify::verify; |
| 18 | |
Jooyung Han | d839785 | 2021-08-10 16:29:36 +0900 | [diff] [blame] | 19 | macro_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 Han | 12a0b70 | 2021-08-05 23:20:31 +0900 | [diff] [blame] | 34 | #[test] |
| 35 | fn test_verify_v3() { |
| 36 | assert!(verify("tests/data/test.apex").is_ok()); |
| 37 | } |
Jooyung Han | d839785 | 2021-08-10 16:29:36 +0900 | [diff] [blame] | 38 | |
| 39 | #[test] |
| 40 | fn 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()); |
Jooyung Han | 543e712 | 2021-08-11 01:48:45 +0900 | [diff] [blame] | 43 | assert_contains!(res.err().unwrap().to_string(), "Digest mismatch"); |
| 44 | } |
| 45 | |
| 46 | #[test] |
| 47 | fn test_verify_v3_cert_and_publick_key_mismatch() { |
| 48 | let res = verify("tests/data/v3-only-cert-and-public-key-mismatch.apk"); |
| 49 | assert!(res.is_err()); |
| 50 | assert_contains!(res.err().unwrap().to_string(), "Public key mismatch"); |
Jooyung Han | d839785 | 2021-08-10 16:29:36 +0900 | [diff] [blame] | 51 | } |