blob: 33665245a1e6d0e5ca1f0e7e0b6cf4ef0133239a [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
Jooyung Hancee6de62021-08-11 15:52:07 +090017use apkverify::{assert_contains, verify};
18use std::matches;
Jooyung Hand8397852021-08-10 16:29:36 +090019
Jooyung Han12a0b702021-08-05 23:20:31 +090020#[test]
21fn test_verify_v3() {
22 assert!(verify("tests/data/test.apex").is_ok());
23}
Jooyung Hand8397852021-08-10 16:29:36 +090024
25#[test]
26fn 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 Han543e7122021-08-11 01:48:45 +090029 assert_contains!(res.err().unwrap().to_string(), "Digest mismatch");
30}
31
32#[test]
33fn 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 Hand8397852021-08-10 16:29:36 +090037}
Jooyung Hancee6de62021-08-11 15:52:07 +090038
39#[test]
40fn 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}