mirror of
https://gitee.com/openharmony/testfwk_xdevice
synced 2024-11-27 01:20:53 +00:00
commit
64ec023a4d
@ -26,6 +26,25 @@ __all__ = ["Constant", "ComType", "HostDrivenTestType",
|
||||
class Constant:
|
||||
PRODUCT_PARAM_START = r"To Obtain Product Params Start"
|
||||
PRODUCT_PARAM_END = r"To Obtain Product Params End"
|
||||
TRUSTED_ROOT_CA = "trusted_root_ca.json"
|
||||
TRUSTED_ROOT_CA_PATH = "/system/etc/security/trusted_root_ca.json"
|
||||
TRUSTED_ROOT_CA_KEY = "C=CN, O=OpenHarmony, OU=OpenHarmony Team, CN=OpenHarmony Application Root CA"
|
||||
TRUSTED_ROOT_CA_VAL = """-----BEGIN CERTIFICATE-----
|
||||
MIICRDCCAcmgAwIBAgIED+E4izAMBggqhkjOPQQDAwUAMGgxCzAJBgNVBAYTAkNO
|
||||
MRQwEgYDVQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVh
|
||||
bTEoMCYGA1UEAxMfT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gUm9vdCBDQTAeFw0y
|
||||
MTAyMDIxMjE0MThaFw00OTEyMzExMjE0MThaMGgxCzAJBgNVBAYTAkNOMRQwEgYD
|
||||
VQQKEwtPcGVuSGFybW9ueTEZMBcGA1UECxMQT3Blbkhhcm1vbnkgVGVhbTEoMCYG
|
||||
A1UEAxMfT3Blbkhhcm1vbnkgQXBwbGljYXRpb24gUm9vdCBDQTB2MBAGByqGSM49
|
||||
AgEGBSuBBAAiA2IABE023XmRaw2DnO8NSsb+KG/uY0FtS3u5LQucdr3qWVnRW5ui
|
||||
QIL6ttNZBEeLTUeYcJZCpayg9Llf+1SmDA7dY4iP2EcRo4UN3rilovtfFfsmH4ty
|
||||
3SApHVFzWUl+NwdH8KNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC
|
||||
AQYwHQYDVR0OBBYEFBc6EKGrGXzlAE+s0Zgnsphadw7NMAwGCCqGSM49BAMDBQAD
|
||||
ZwAwZAIwd1p3JzHN93eoPped1li0j64npgqNzwy4OrkehYAqNXpcpaEcLZ7UxW8E
|
||||
I2lZJ3SbAjAkqySHb12sIwdSFKSN9KCMMEo/eUT5dUXlcKR2nZz0MJdxT5F51qcX
|
||||
1CumzkcYhgU=
|
||||
-----END CERTIFICATE-----
|
||||
"""
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -15,6 +15,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
import os
|
||||
@ -47,7 +48,9 @@ from xdevice import get_file_absolute_path
|
||||
from xdevice import Platform
|
||||
from xdevice import AppInstallError
|
||||
from xdevice import RpcNotRunningError
|
||||
from xdevice import Variables
|
||||
|
||||
from ohos.constants import Constant
|
||||
from ohos.environment.dmlib import HdcHelper
|
||||
from ohos.environment.dmlib import CollectingOutputReceiver
|
||||
from ohos.utils import parse_strings_key_value
|
||||
@ -211,15 +214,43 @@ class Device(IDevice):
|
||||
def init_description(self):
|
||||
if self.device_description:
|
||||
return
|
||||
desc = {
|
||||
DeviceProperties.sn: convert_serial(self.device_sn),
|
||||
DeviceProperties.model: self.get_property("const.product.model"),
|
||||
DeviceProperties.type_: self.get_device_type(),
|
||||
DeviceProperties.platform: "OpenHarmony",
|
||||
DeviceProperties.version: self.get_property("const.product.software.version"),
|
||||
DeviceProperties.others: self.device_props
|
||||
}
|
||||
self.device_description.update(desc)
|
||||
try:
|
||||
self.__add_trusted_root_ca()
|
||||
desc = {
|
||||
DeviceProperties.sn: convert_serial(self.device_sn),
|
||||
DeviceProperties.model: self.get_property("const.product.model"),
|
||||
DeviceProperties.type_: self.get_device_type(),
|
||||
DeviceProperties.platform: "OpenHarmony",
|
||||
DeviceProperties.version: self.get_property("const.product.software.version"),
|
||||
DeviceProperties.others: self.device_props
|
||||
}
|
||||
self.device_description.update(desc)
|
||||
except Exception as e:
|
||||
LOG.error("init device description error")
|
||||
LOG.error(e, exc_info=True)
|
||||
|
||||
def __add_trusted_root_ca(self):
|
||||
self.execute_shell_command("mount -o rw,remount /")
|
||||
local = os.path.join(Variables.temp_dir, Constant.TRUSTED_ROOT_CA)
|
||||
remote = Constant.TRUSTED_ROOT_CA_PATH
|
||||
self.pull_file(remote, local)
|
||||
data = {}
|
||||
if os.path.exists(local):
|
||||
try:
|
||||
with open(local, encoding="utf-8") as json_f:
|
||||
data = json.load(json_f)
|
||||
except ValueError:
|
||||
pass
|
||||
if Constant.TRUSTED_ROOT_CA_KEY in data.keys():
|
||||
LOG.debug("trusted root ca already exists")
|
||||
return
|
||||
LOG.debug("trusted root ca does not exist, push it")
|
||||
data.update({Constant.TRUSTED_ROOT_CA_KEY: Constant.TRUSTED_ROOT_CA_VAL})
|
||||
content = json.dumps(data, indent=4, separators=(",", ":"))
|
||||
json_fd = os.open(local, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, FilePermission.mode_644)
|
||||
with os.fdopen(json_fd, mode="w", encoding="utf-8") as json_f:
|
||||
json_f.write(content)
|
||||
self.push_file(local, remote)
|
||||
|
||||
def __set_serial__(self, device_sn=""):
|
||||
self.device_sn = device_sn
|
||||
|
@ -24,7 +24,8 @@ __all__ = ["DeviceOsType", "ProductForm", "TestType", "TestExecType",
|
||||
"TEST_DRIVER_SET", "LogType", "CKit",
|
||||
"DeviceLabelType", "GTestConst", "ManagerType",
|
||||
"ModeType", "ConfigConst", "FilePermission", "CommonParserType",
|
||||
"DeviceConnectorType", "AdvanceDeviceOption", "DeviceProperties", "ReportConst"]
|
||||
"DeviceConnectorType", "AdvanceDeviceOption", "DeviceProperties", "ReportConst",
|
||||
"LifeStage", "Platform"]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
Loading…
Reference in New Issue
Block a user