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