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 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( 38 'avbtool', 39 foo_apex, 40 payload_key, 41 container_key, 42 False) 43 self.assertTrue(os.path.exists(signed_foo_apex)) 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)) 60