blob: 22faba4c0b9c903e03d69b4a29d6d6ee098a04b0 [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
Andrew Walbran117cd5e2021-08-13 11:42:13 +000017use apkverify::{testing::assert_contains, verify};
Jooyung Hancee6de62021-08-11 15:52:07 +090018use 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]
Andrew Scullc208eb42022-05-22 16:17:52 +000026fn test_verify_v3_ecdsa_sha256_p256() {
27 assert!(verify("tests/data/v3-only-with-ecdsa-sha256-p256.apk").is_ok());
28}
29
30#[test]
Jooyung Hand8397852021-08-10 16:29:36 +090031fn test_verify_v3_digest_mismatch() {
32 let res = verify("tests/data/v3-only-with-rsa-pkcs1-sha512-8192-digest-mismatch.apk");
33 assert!(res.is_err());
Andrew Walbran117cd5e2021-08-13 11:42:13 +000034 assert_contains(&res.unwrap_err().to_string(), "Digest mismatch");
Jooyung Han543e7122021-08-11 01:48:45 +090035}
36
37#[test]
Andrew Walbran117cd5e2021-08-13 11:42:13 +000038fn test_verify_v3_cert_and_public_key_mismatch() {
Jooyung Han543e7122021-08-11 01:48:45 +090039 let res = verify("tests/data/v3-only-cert-and-public-key-mismatch.apk");
40 assert!(res.is_err());
Andrew Walbran117cd5e2021-08-13 11:42:13 +000041 assert_contains(&res.unwrap_err().to_string(), "Public key mismatch");
Jooyung Hand8397852021-08-10 16:29:36 +090042}
Jooyung Hancee6de62021-08-11 15:52:07 +090043
44#[test]
45fn test_verify_truncated_cd() {
46 use zip::result::ZipError;
47 let res = verify("tests/data/v2-only-truncated-cd.apk");
48 // TODO(jooyung): consider making a helper for err assertion
49 assert!(matches!(
Andrew Walbran117cd5e2021-08-13 11:42:13 +000050 res.unwrap_err().root_cause().downcast_ref::<ZipError>().unwrap(),
Jooyung Hancee6de62021-08-11 15:52:07 +090051 ZipError::InvalidArchive(_),
52 ));
53}