1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# 4# Copyright (c) 2024 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from devicetest.core.test_case import TestCase, Step 18 19# @tc.number: G-SOFTWARE-0501 20# @tc.name: testBundleInstallVerify 21# @tc.desc: 【G-SOFTWARE-0501】不应修改包管理服务对应用安装的校验规则,包括应用版本号升级校验、包名长度校验、 22# ExtensionAbility 类型校验、同应用内多 hap 包名/版本号/签名/包类型一致性校验规则。 23class testBundleInstallVerify(TestCase): 24 25 def __init__(self, controllers): 26 self.TAG = self.__class__.__name__ 27 super().__init__(self.TAG, controllers) 28 29 def setup(self): 30 Step("Setup") 31 32 def process(self): 33 Step("Process") 34 errorList = [] 35 errorList = self.versionCodeVerify(errorList) 36 errorList = self.multipleHapsVerify(errorList) 37 if len(errorList) > 0: 38 self.log.info('errorList: [' + ', '.join(errorList) + ']') 39 assert False 40 41 def versionCodeVerify(self, errorList): 42 installResult = self.device1.execute_shell_command("bm install -p /data/local/tmp/bundle_first.hap") 43 if 'install bundle successfully' not in installResult.strip(): 44 errorList.append('install application failed') 45 return errorList 46 dumpResult = self.device1.execute_shell_command("bm dump -n com.pcs.software.bundle.first") 47 if dumpResult.count('\"versionCode\": 1100000') < 1: 48 errorList.append('get version code failed') 49 return errorList 50 installResult = self.device1.execute_shell_command("bm install -p /data/local/tmp/bundle_second.hap") 51 if 'error: install version downgrade' not in installResult.strip(): 52 errorList.append('version code downgrade verify failed') 53 return errorList 54 dumpResult = self.device1.execute_shell_command("bm dump -n com.pcs.software.bundle.first") 55 if dumpResult.count('\"versionCode\": 1100000') < 1: 56 errorList.append('get version code failed') 57 return errorList 58 installResult = self.device1.execute_shell_command("bm install -p /data/local/tmp/bundle_third.hap") 59 if 'install bundle successfully' not in installResult.strip(): 60 errorList.append('version code upgrade verify failed') 61 return errorList 62 dumpResult = self.device1.execute_shell_command("bm dump -n com.pcs.software.bundle.first") 63 if dumpResult.count('\"versionCode\": 1200000') < 1: 64 errorList.append('get version code failed') 65 return errorList 66 return errorList 67 68 def multipleHapsVerify(self, errorList): 69 installResult = self.device1.execute_shell_command("bm install -p /data/local/tmp/bundle_fourth.hap") 70 if 'install bundle successfully' not in installResult.strip(): 71 errorList.append('install application failed') 72 return errorList 73 installResult = self.device1.execute_shell_command("bm install -p /data/local/tmp/feature_first.hap") 74 if 'install bundle successfully' not in installResult.strip(): 75 errorList.append('install multiple haps failed') 76 return errorList 77 installResult = self.device1.execute_shell_command("bm install -p /data/local/tmp/feature_second.hap") 78 if 'error: install version not compatible' not in installResult.strip(): 79 errorList.append('install multiple haps versioncode verify failed') 80 return errorList 81 installResult = self.device1.execute_shell_command("bm install -p /data/local/tmp/feature_third.hap") 82 if 'error: verify signature failed' not in installResult.strip(): 83 errorList.append('install multiple haps signature verify failed') 84 return errorList 85 return errorList 86 87 def teardown(self): 88 Step("Teardown")