Tao Bao | c9c1b86 | 2019-06-26 14:54:14 -0700 | [diff] [blame] | 1 | # |
| 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 | |
| 17 | import os.path |
| 18 | |
| 19 | import common |
| 20 | import sign_apex |
| 21 | import test_utils |
| 22 | |
| 23 | |
| 24 | class 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 Bao | 1ac886e | 2019-06-26 11:58:22 -0700 | [diff] [blame] | 38 | 'avbtool', |
Tao Bao | c9c1b86 | 2019-06-26 14:54:14 -0700 | [diff] [blame] | 39 | foo_apex, |
| 40 | payload_key, |
Baligh Uddin | ac936fd | 2019-12-04 08:30:32 -0800 | [diff] [blame] | 41 | container_key, |
| 42 | False) |
Tao Bao | c9c1b86 | 2019-06-26 14:54:14 -0700 | [diff] [blame] | 43 | self.assertTrue(os.path.exists(signed_foo_apex)) |
Tianjie Xu | 88a759d | 2020-01-23 10:47:54 -0800 | [diff] [blame] | 44 | |
| 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 Ioffe | 3608148 | 2021-01-20 01:32:28 +0000 | [diff] [blame] | 60 | |
| 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)) |