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 | |
Jooyung Han | cee6de6 | 2021-08-11 15:52:07 +0900 | [diff] [blame^] | 17 | use apkverify::{assert_contains, verify}; |
| 18 | use std::matches; |
Jooyung Han | d839785 | 2021-08-10 16:29:36 +0900 | [diff] [blame] | 19 | |
Jooyung Han | 12a0b70 | 2021-08-05 23:20:31 +0900 | [diff] [blame] | 20 | #[test] |
| 21 | fn test_verify_v3() { |
| 22 | assert!(verify("tests/data/test.apex").is_ok()); |
| 23 | } |
Jooyung Han | d839785 | 2021-08-10 16:29:36 +0900 | [diff] [blame] | 24 | |
| 25 | #[test] |
| 26 | fn test_verify_v3_digest_mismatch() { |
| 27 | let res = verify("tests/data/v3-only-with-rsa-pkcs1-sha512-8192-digest-mismatch.apk"); |
| 28 | assert!(res.is_err()); |
Jooyung Han | 543e712 | 2021-08-11 01:48:45 +0900 | [diff] [blame] | 29 | assert_contains!(res.err().unwrap().to_string(), "Digest mismatch"); |
| 30 | } |
| 31 | |
| 32 | #[test] |
| 33 | fn test_verify_v3_cert_and_publick_key_mismatch() { |
| 34 | let res = verify("tests/data/v3-only-cert-and-public-key-mismatch.apk"); |
| 35 | assert!(res.is_err()); |
| 36 | assert_contains!(res.err().unwrap().to_string(), "Public key mismatch"); |
Jooyung Han | d839785 | 2021-08-10 16:29:36 +0900 | [diff] [blame] | 37 | } |
Jooyung Han | cee6de6 | 2021-08-11 15:52:07 +0900 | [diff] [blame^] | 38 | |
| 39 | #[test] |
| 40 | fn test_verify_truncated_cd() { |
| 41 | use zip::result::ZipError; |
| 42 | let res = verify("tests/data/v2-only-truncated-cd.apk"); |
| 43 | // TODO(jooyung): consider making a helper for err assertion |
| 44 | assert!(matches!( |
| 45 | res.err().unwrap().root_cause().downcast_ref::<ZipError>().unwrap(), |
| 46 | ZipError::InvalidArchive(_), |
| 47 | )); |
| 48 | } |