blob: 646b04ddfd5b07dfe9bbe3182a3696f401b6d0f6 [file] [log] [blame]
Tao Baoc9c1b862019-06-26 14:54:14 -07001#
2# Copyright (C) 2019 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
17import os.path
18
19import common
20import sign_apex
21import test_utils
22
23
24class SignApexTest(test_utils.ReleaseToolsTestCase):
25
26 def setUp(self):
27 self.testdata_dir = test_utils.get_testdata_dir()
28 self.assertTrue(os.path.exists(self.testdata_dir))
29
30 common.OPTIONS.search_path = test_utils.get_search_path()
31
32 @test_utils.SkipIfExternalToolsUnavailable()
33 def test_SignApexFile(self):
34 foo_apex = os.path.join(self.testdata_dir, 'foo.apex')
35 payload_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key')
36 container_key = os.path.join(self.testdata_dir, 'testkey')
37 signed_foo_apex = sign_apex.SignApexFile(
Tao Bao1ac886e2019-06-26 11:58:22 -070038 'avbtool',
Tao Baoc9c1b862019-06-26 14:54:14 -070039 foo_apex,
40 payload_key,
Baligh Uddinac936fd2019-12-04 08:30:32 -080041 container_key,
42 False)
Tao Baoc9c1b862019-06-26 14:54:14 -070043 self.assertTrue(os.path.exists(signed_foo_apex))
Tianjie Xu88a759d2020-01-23 10:47:54 -080044
45 @test_utils.SkipIfExternalToolsUnavailable()
46 def test_SignApexWithApk(self):
47 test_apex = os.path.join(self.testdata_dir, 'has_apk.apex')
48 payload_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key')
49 container_key = os.path.join(self.testdata_dir, 'testkey')
50 apk_keys = {'wifi-service-resources.apk': os.path.join(
51 self.testdata_dir, 'testkey')}
52 signed_test_apex = sign_apex.SignApexFile(
53 'avbtool',
54 test_apex,
55 payload_key,
56 container_key,
57 False,
58 apk_keys)
59 self.assertTrue(os.path.exists(signed_test_apex))
Nikita Ioffe36081482021-01-20 01:32:28 +000060
61 @test_utils.SkipIfExternalToolsUnavailable()
62 def test_SignCompressedApexFile(self):
63 apex = os.path.join(test_utils.get_current_dir(), 'com.android.apex.compressed.v1.capex')
64 payload_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key')
65 container_key = os.path.join(self.testdata_dir, 'testkey')
66 signed_apex = sign_apex.SignApexFile(
67 'avbtool',
68 apex,
69 payload_key,
70 container_key,
71 False,
72 codename_to_api_level_map={'S': 31})
73 self.assertTrue(os.path.exists(signed_apex))