mirror of
https://gitee.com/openharmony/security_permission
synced 2024-10-07 10:13:22 +00:00
commit
6c0e54c8a9
@ -46,13 +46,6 @@ HWTEST_F(CheckCallerPermissionTest, CheckCallerPermission01, Function | MediumTe
|
||||
int ret = DistributedPermissionKit::CheckCallerPermission(permissionName);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
HWTEST_F(CheckCallerPermissionTest, CheckCallerPermission02, Function | MediumTest | Level1)
|
||||
{
|
||||
string permissionName = "ohos.permission.INTERNET";
|
||||
int result = Constant::PERMISSION_GRANTED;
|
||||
int ret = DistributedPermissionKit::CheckCallerPermission(permissionName);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -46,13 +46,6 @@ HWTEST_F(CheckCallingOrSelfPermissionTest, CheckCallingOrSelfPermission01, Funct
|
||||
int ret = DistributedPermissionKit::CheckCallingOrSelfPermission(permissionName);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
HWTEST_F(CheckCallingOrSelfPermissionTest, CheckCallingOrSelfPermission02, Function | MediumTest | Level1)
|
||||
{
|
||||
string permissionName = "ohos.permission.INTERNET";
|
||||
int result = Constant::PERMISSION_GRANTED;
|
||||
int ret = DistributedPermissionKit::CheckCallingOrSelfPermission(permissionName);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -48,13 +48,6 @@ HWTEST_F(CheckCallingPermissionTest, CheckCallingPermission01, Function | Medium
|
||||
int ret = DistributedPermissionKit::CheckCallingPermission(permissionName);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
HWTEST_F(CheckCallingPermissionTest, CheckCallingPermission02, Function | MediumTest | Level1)
|
||||
{
|
||||
string permissionName = "ohos.permission.INTERNET";
|
||||
int result = Constant::PERMISSION_GRANTED;
|
||||
int ret = DistributedPermissionKit::CheckCallingPermission(permissionName);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -47,14 +47,6 @@ HWTEST_F(CheckSelfPermissionTest, CheckSelfPermission01, Function | MediumTest |
|
||||
int ret = DistributedPermissionKit::CheckSelfPermission(permissionName);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(CheckSelfPermissionTest, CheckSelfPermission02, Function | MediumTest | Level1)
|
||||
{
|
||||
string permissionName = "ohos.permission.INTERNET";
|
||||
int result = Constant::PERMISSION_GRANTED;
|
||||
int ret = DistributedPermissionKit::CheckSelfPermission(permissionName);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -37,13 +37,6 @@ void IsRestrictedPermissionTest::TearDown()
|
||||
cout << "TearDown()" << endl;
|
||||
}
|
||||
|
||||
HWTEST_F(IsRestrictedPermissionTest, IsRestrictedPermissionTest01, Function | MediumTest | Level1)
|
||||
{
|
||||
string ohosPermissionName = "ohos.permission.READ_CONTACTS";
|
||||
bool ret = DistributedPermissionKit::IsRestrictedPermission(ohosPermissionName);
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
HWTEST_F(IsRestrictedPermissionTest, IsRestrictedPermissionTest02, Function | MediumTest | Level1)
|
||||
{
|
||||
string ohosPermissionName = "ohos.permission.INTERNET";
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
const std::string &bundleName, const std::string &reason);
|
||||
|
||||
private:
|
||||
void StartActivityForRequestPermission(std::vector<std::string> &permissions);
|
||||
void StartAbilityForRequestPermission(std::vector<std::string> &permissions);
|
||||
std::vector<std::string> FormatRequestPermissions(
|
||||
std::vector<std::string> &permissions, const std::string &deviceId, int32_t ruid);
|
||||
|
||||
|
@ -100,12 +100,12 @@ void RequestRemotePermissionCommand::SetRequestPermissionInfo(int32_t uid, const
|
||||
}
|
||||
|
||||
/**
|
||||
* Current the UI is not design, So use the property item to mock the activity operation。<br>
|
||||
* Current the UI is not design, So use the property item to mock the Ability operation。<br>
|
||||
* if "request." + permission is true, DPMS will grant the sensitive permission
|
||||
*
|
||||
* @param permissions the permissions that will grant to remote
|
||||
*/
|
||||
void RequestRemotePermissionCommand::StartActivityForRequestPermission(std::vector<std::string> &permissions)
|
||||
void RequestRemotePermissionCommand::StartAbilityForRequestPermission(std::vector<std::string> &permissions)
|
||||
{
|
||||
if (permissions.empty()) {
|
||||
return;
|
||||
@ -117,13 +117,13 @@ void RequestRemotePermissionCommand::StartActivityForRequestPermission(std::vect
|
||||
iBundleManager_ = bmsAdapter->GetBundleManager();
|
||||
for (auto permission : permissions) {
|
||||
if (iBundleManager_->CheckPermission(bundleName_, permission) == 0) {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "mock Activity DO GRANT permission{uid = %{public}d, requestId = %{public}s }",
|
||||
PERMISSION_LOG_DEBUG(LABEL, "mock Ability DO GRANT permission{uid = %{public}d, requestId = %{public}s }",
|
||||
uid_, requestId_.c_str());
|
||||
SubjectDevicePermissionManager::GetInstance().GrantSensitivePermissionToRemoteApp(permission,
|
||||
remoteProtocol_.srcDeviceId, uid_);
|
||||
} else {
|
||||
PERMISSION_LOG_DEBUG(LABEL,
|
||||
"mock Activity DO NOT GRANT permission{uid = %{public}d, requestId = %{public}s }", uid_,
|
||||
"mock Ability DO NOT GRANT permission{uid = %{public}d, requestId = %{public}s }", uid_,
|
||||
requestId_.c_str());
|
||||
}
|
||||
}
|
||||
@ -191,10 +191,10 @@ void RequestRemotePermissionCommand::Execute()
|
||||
FormatRequestPermissions(permissions_, remoteProtocol_.srcDeviceId, uid_);
|
||||
|
||||
if (needRequestPermissions.size() > 0) {
|
||||
PERMISSION_LOG_INFO(LABEL, "start startActivityForRequestPermission");
|
||||
PERMISSION_LOG_INFO(LABEL, "start startAbilityForRequestPermission");
|
||||
// start active and the the result of the active
|
||||
StartActivityForRequestPermission(needRequestPermissions);
|
||||
PERMISSION_LOG_INFO(LABEL, "end startActivityForRequestPermission");
|
||||
StartAbilityForRequestPermission(needRequestPermissions);
|
||||
PERMISSION_LOG_INFO(LABEL, "end startAbilityForRequestPermission");
|
||||
}
|
||||
|
||||
std::shared_ptr<DistributedPermissionEventHandler> handler =
|
||||
|
@ -22,7 +22,6 @@ config("permission_test_config") {
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/transport",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/common",
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
|
@ -198,26 +198,6 @@ public:
|
||||
* returns SIGNATURE_MATCHED if their publickeys are the same.
|
||||
*/
|
||||
virtual int CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName) = 0;
|
||||
/**
|
||||
* @brief Checks whether a specified bundle has been granted a specific permission.
|
||||
* @param bundleName Indicates the name of the bundle to check.
|
||||
* @param permission Indicates the permission to check.
|
||||
* @return Returns 0 if the bundle has the permission; returns -1 otherwise.
|
||||
*/
|
||||
virtual int CheckPermission(const std::string &bundleName, const std::string &permission) = 0;
|
||||
/**
|
||||
* @brief Obtains detailed information about a specified permission.
|
||||
* @param permissionName Indicates the name of the ohos permission.
|
||||
* @param permissionDef Indicates the object containing detailed information about the given ohos permission.
|
||||
* @return Returns true if the PermissionDef object is successfully obtained; returns false otherwise.
|
||||
*/
|
||||
virtual bool GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) = 0;
|
||||
/**
|
||||
* @brief Obtains all known permission groups in the system.
|
||||
* @param permissionDefs Indicates the list of objects containing the permission group information.
|
||||
* @return Returns true if the PermissionDef objects is successfully obtained; returns false otherwise.
|
||||
*/
|
||||
virtual bool GetAllPermissionGroupDefs(std::vector<PermissionDef> &permissionDefs) = 0;
|
||||
/**
|
||||
* @brief Obtains all known permission groups in the system.
|
||||
* @param permissions Indicates the permission array.
|
||||
@ -237,6 +217,26 @@ public:
|
||||
* @param systemCaps Indicates the list of capabilities available in the system.
|
||||
* @return Returns true if capabilities in the system are successfully obtained; returns false otherwise.
|
||||
*/
|
||||
virtual int CheckPermission(const std::string &bundleName, const std::string &permission) = 0;
|
||||
/**
|
||||
* @brief Obtains detailed information about a specified permission.
|
||||
* @param permissionName Indicates the name of the ohos permission.
|
||||
* @param permissionDef Indicates the object containing detailed information about the given ohos permission.
|
||||
* @return Returns true if the PermissionDef object is successfully obtained; returns false otherwise.
|
||||
*/
|
||||
virtual bool GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) = 0;
|
||||
/**
|
||||
* @brief Obtains all known permission groups in the system.
|
||||
* @param permissionDefs Indicates the list of objects containing the permission group information.
|
||||
* @return Returns true if the PermissionDef objects is successfully obtained; returns false otherwise.
|
||||
*/
|
||||
virtual bool GetAllPermissionGroupDefs(std::vector<PermissionDef> &permissionDefs) = 0;
|
||||
/**
|
||||
* @brief Checks whether a specified bundle has been granted a specific permission.
|
||||
* @param bundleName Indicates the name of the bundle to check.
|
||||
* @param permission Indicates the permission to check.
|
||||
* @return Returns 0 if the bundle has the permission; returns -1 otherwise.
|
||||
*/
|
||||
virtual bool GetSystemAvailableCapabilities(std::vector<std::string> &systemCaps) = 0;
|
||||
/**
|
||||
* @brief Checks whether the current device has been started in safe mode.
|
||||
|
@ -59,11 +59,12 @@ public:
|
||||
bool GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo) override;
|
||||
bool GetLaunchWantForBundle(const std::string &bundleName, Want &want) override;
|
||||
int CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName) override;
|
||||
bool GetAppsGrantedPermissions(
|
||||
const std::vector<std::string> &permissions, std::vector<std::string> &appNames) override;
|
||||
int CheckPermission(const std::string &bundleName, const std::string &permission) override;
|
||||
bool GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef) override;
|
||||
bool GetAllPermissionGroupDefs(std::vector<PermissionDef> &permissionDefs) override;
|
||||
bool GetAppsGrantedPermissions(
|
||||
const std::vector<std::string> &permissions, std::vector<std::string> &appNames) override;
|
||||
|
||||
bool HasSystemCapability(const std::string &capName) override;
|
||||
bool GetSystemAvailableCapabilities(std::vector<std::string> &systemCaps) override;
|
||||
bool IsSafeMode() override;
|
||||
|
@ -0,0 +1,348 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Softbus
|
||||
* @{
|
||||
*
|
||||
* @brief Provides high-speed, secure communication between devices.
|
||||
*
|
||||
* This module implements unified distributed communication capability management between
|
||||
* nearby devices, and provides link-independent device discovery and transmission interfaces
|
||||
* to support service publishing and data transmission.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file session.h
|
||||
*
|
||||
* @brief Declares unified data transmission interfaces.
|
||||
*
|
||||
* This file provides data transmission capabilities, including creating and removing a session server,
|
||||
* opening and closing sessions, receiving data, and querying basic session information. \n
|
||||
* After multiple nearby devices are discovered and networked, these interfaces can be used to
|
||||
* transmit data across devices. \n
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
#ifndef SESSION_H
|
||||
#define SESSION_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/**
|
||||
* @brief bussiness type of session
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum {
|
||||
TYPE_MESSAGE = 1,
|
||||
TYPE_BYTES,
|
||||
TYPE_FILE,
|
||||
TYPE_STREAM,
|
||||
TYPE_BUTT,
|
||||
} SessionType;
|
||||
|
||||
typedef enum {
|
||||
INVALID = -1,
|
||||
/*
|
||||
* Send any segment of a frame each time.
|
||||
*/
|
||||
RAW_STREAM,
|
||||
/*
|
||||
* Send a whole video frame each time.
|
||||
*/
|
||||
COMMON_VIDEO_STREAM,
|
||||
/*
|
||||
* Send a whole audio frame each time.
|
||||
*/
|
||||
COMMON_AUDIO_STREAM,
|
||||
/*
|
||||
* Slice frame mode.
|
||||
*/
|
||||
VIDEO_SLICE_STREAM,
|
||||
} StreamType;
|
||||
|
||||
typedef enum {
|
||||
LINK_TYPE_WIFI_WLAN_5G = 1,
|
||||
LINK_TYPE_WIFI_WLAN_2G = 2,
|
||||
LINK_TYPE_WIFI_P2P = 3,
|
||||
LINK_TYPE_BR = 4,
|
||||
LINK_TYPE_MAX = 4,
|
||||
} LinkType;
|
||||
|
||||
/**
|
||||
* @brief session attribute.
|
||||
*
|
||||
* control the attribute of session。
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef struct {
|
||||
/** @brief dataType{@link SessionType} */
|
||||
int dataType;
|
||||
int linkTypeNum;
|
||||
LinkType linkType[LINK_TYPE_MAX];
|
||||
union {
|
||||
struct StreamAttr {
|
||||
int streamType;
|
||||
} streamAttr;
|
||||
} attr;
|
||||
} SessionAttribute;
|
||||
|
||||
typedef struct {
|
||||
char *buf;
|
||||
int bufLen;
|
||||
} StreamData;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
int64_t value;
|
||||
} TV;
|
||||
|
||||
typedef struct {
|
||||
int frameType;
|
||||
int64_t timeStamp;
|
||||
int seqNum;
|
||||
int seqSubNum;
|
||||
int level;
|
||||
int bitMap;
|
||||
int tvCount;
|
||||
TV *tvList;
|
||||
} FrameInfo;
|
||||
|
||||
/**
|
||||
* @brief Defines session callbacks.
|
||||
*
|
||||
* When a session is opened or closed, or there is data to process, the related callback is invoked.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief Called when a session is opened.
|
||||
*
|
||||
* This function can be used to verify the session or initialize resources related to the session.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @param result 0 if the session is opened successfully, returns an error code otherwise.
|
||||
* @return Returns <b>0</b> if the session connection is accepted; returns a non-zero value
|
||||
* otherwise (you do not need to call {@link CloseSession} to close the session).
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int (*OnSessionOpened)(int sessionId, int result);
|
||||
|
||||
/**
|
||||
* @brief Called when a session is closed.
|
||||
*
|
||||
* This function can be used to release resources related to the session.
|
||||
* You do not need to call {@link CloseSession}.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void (*OnSessionClosed)(int sessionId);
|
||||
|
||||
/**
|
||||
* @brief Called when data is received.
|
||||
*
|
||||
* This function is used to notify that data is received.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @param data Indicates the pointer to the data received.
|
||||
* @param dataLen Indicates the length of the data received.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void (*OnBytesReceived)(int sessionId, const void *data, unsigned int dataLen);
|
||||
|
||||
/**
|
||||
* @brief Called when message is received.
|
||||
*
|
||||
* This function is used to notify that message is received.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @param data Indicates the pointer to the message data received.
|
||||
* @param dataLen Indicates the length of the message received.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void (*OnMessageReceived)(int sessionId, const void *data, unsigned int dataLen);
|
||||
|
||||
void (*OnStreamReceived)(int sessionId, const StreamData *data, const StreamData *ext, const FrameInfo *param);
|
||||
} ISessionListener;
|
||||
|
||||
typedef struct {
|
||||
int (*OnReceiveFileStarted)(int sessionId, const char *files, int fileCnt);
|
||||
int (*OnReceiveFileProcess)(int sessionId, const char *firstFile, uint64_t bytesUpload, uint64_t bytesTotal);
|
||||
void (*OnReceiveFileFinished)(int sessionId, const char *files, int fileCnt);
|
||||
void (*OnFileTransError)(int sessionId);
|
||||
} IFileReceiveListener;
|
||||
|
||||
typedef struct {
|
||||
int (*OnSendFileProcess)(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal);
|
||||
int (*OnSendFileFinished)(int sessionId, const char *firstFile);
|
||||
void (*OnFileTransError)(int sessionId);
|
||||
} IFileSendListener;
|
||||
|
||||
/**
|
||||
* @brief Creates a session server based on a package name and session name.
|
||||
*
|
||||
* A maximum of 18 session servers can be created.
|
||||
*
|
||||
* @param pkgName Indicates the pointer to the package name, which can be used to check whether the
|
||||
* session server is in this package. The value cannot be empty and can contain a maximum of 64 characters.
|
||||
* @param sessionName Indicates the pointer to the session name, which is the unique ID of the session server.
|
||||
* The value cannot be empty and can contain a maximum of 64 characters.
|
||||
* @param listener Indicates the pointer to the session callback structure, which cannot be empty.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
|
||||
* @see RemoveSessionServer
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int CreateSessionServer(const char *pkgName, const char *sessionName, const ISessionListener *listener);
|
||||
|
||||
/**
|
||||
* @brief Removes a session server based on a package name and session name.
|
||||
*
|
||||
* @param pkgName Indicates the pointer to the name of the registered package, which can be used to check
|
||||
* whether the session server is in this package. The value cannot be empty and can contain a maximum of 64 characters.
|
||||
* @param sessionName Indicates the pointer to the session name. The value cannot be empty and can contain
|
||||
* a maximum of 64 characters.
|
||||
* @return Returns <b>0</b> if the operation is successful, returns <b>-1</b> otherwise.
|
||||
* @see CreateSessionServer
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int RemoveSessionServer(const char *pkgName, const char *sessionName);
|
||||
|
||||
/**
|
||||
* @brief Initiate a session open request, which is an asynchronous process.
|
||||
*
|
||||
* The session connection is opened based on the service name to trigger the first packet interaction process.
|
||||
* According to the {@link OnSessionOpened} Notify the user whether the session is successfully opened.
|
||||
* Data can be transmitted only after the session is successfully opened.
|
||||
*
|
||||
* @param mySessionName local session name.
|
||||
* @param peerSessionName remote session name.
|
||||
* @param peerDeviceId remote device id.
|
||||
* @param groupId group id.
|
||||
* @param attr session attribute {@link SessionAttribute}.
|
||||
* @return return sessionId if the session is opened successfully, returns an error code otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int OpenSession(const char *mySessionName, const char *peerSessionName, const char *peerDeviceId, const char *groupId,
|
||||
const SessionAttribute *attr);
|
||||
|
||||
/**
|
||||
* @brief Closes a connected session based on a session ID.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @return no return value.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
void CloseSession(int sessionId);
|
||||
|
||||
/**
|
||||
* @brief Sends data based on a session ID.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @param data Indicates the pointer to the data to send, which cannot be <b>NULL</b>.
|
||||
* @param len Indicates the length of the data to send. The maximum length cannot exceed 984 characters.
|
||||
* @return Returns <b>0</b> if the function is called successfully; returns <b>-1</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int SendBytes(int sessionId, const void *data, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Sends message based on a session ID.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @param data Indicates the pointer to the message data to send, which cannot be <b>NULL</b>.
|
||||
* @param len Indicates the length of the message to send.
|
||||
* @return Returns <b>0</b> if the function is called successfully, returns an error code otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int SendMessage(int sessionId, const void *data, unsigned int len);
|
||||
|
||||
int SendStream(int sessionId, const StreamData *data, const StreamData *ext, const FrameInfo *param);
|
||||
|
||||
/**
|
||||
* @brief Obtains the session name registered by the local device based on the session ID.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @param sessionName Indicates the pointer to the buffer for storing the session name.
|
||||
* @param len Indicates the length of the buffer.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int GetMySessionName(int sessionId, char *sessionName, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Obtains the session name registered by the peer device based on the session ID.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @param sessionName Indicates the pointer to the buffer for storing the session name.
|
||||
* @param len Indicates the length of the buffer.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int GetPeerSessionName(int sessionId, char *sessionName, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Obtains the peer device ID based on a session ID.
|
||||
*
|
||||
* @param sessionId Indicates the session ID.
|
||||
* @param devId Indicates the pointer to the buffer for storing the device ID.
|
||||
* @param len Indicates the length of the buffer.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int GetPeerDeviceId(int sessionId, char *devId, unsigned int len);
|
||||
|
||||
int GetSessionSide(int sessionId);
|
||||
|
||||
int SetFileReceiveListener(const char *pkgName, const char *sessionName, const IFileReceiveListener *recvListener,
|
||||
const char *rootDir);
|
||||
|
||||
int SetFileSendListener(const char *pkgName, const char *sessionName, const IFileSendListener *sendListener);
|
||||
|
||||
int SendFile(int sessionId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt);
|
||||
|
||||
void DecompressMock(const unsigned char *bytes, const int length);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
std::string GetUuidMock();
|
||||
#endif
|
||||
#endif // SESSION_H
|
@ -14,14 +14,144 @@
|
||||
*/
|
||||
|
||||
#include "mock_bundle_mgr.h"
|
||||
#include <iostream>
|
||||
#include "application_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
|
||||
bool BundleMgrService::GetAppsGrantedPermissions(
|
||||
const std::vector<std::string> &permissions, std::vector<std::string> &appNames)
|
||||
{
|
||||
std::cout<<"GetAppsGrantedPermissions"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::HasSystemCapability(const std::string &capName)
|
||||
{
|
||||
std::cout<<"HasSystemCapability"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetSystemAvailableCapabilities(std::vector<std::string> &systemCaps)
|
||||
{
|
||||
std::cout<<"GetSystemAvailableCapabilities"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::IsSafeMode()
|
||||
{
|
||||
std::cout<<"IsSafeMode"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::CleanBundleCacheFiles(
|
||||
const std::string &bundleName, const sptr<ICleanCacheCallback> &cleanCacheCallback)
|
||||
{
|
||||
std::cout<<"CleanBundleCacheFiles"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::CleanBundleDataFiles(const std::string &bundleName)
|
||||
{
|
||||
std::cout<<"CleanBundleDataFiles"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
|
||||
{
|
||||
std::cout<<"RegisterBundleStatusCallback"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::ClearBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
|
||||
{
|
||||
std::cout<<"ClearBundleStatusCallback"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::UnregisterBundleStatusCallback()
|
||||
{
|
||||
std::cout<<"UnregisterBundleStatusCallback"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::DumpInfos(const MockDumpFlag flag, const std::string &bundleName, std::string &result)
|
||||
{
|
||||
std::cout<<"DumpInfos"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::IsApplicationEnabled(const std::string &bundleName)
|
||||
{
|
||||
std::cout<<"IsApplicationEnabled"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::SetApplicationEnabled(const std::string &bundleName, bool isEnable)
|
||||
{
|
||||
std::cout<<"SetApplicationEnabled"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::IsAbilityEnabled(const AbilityInfo &abilityInfo)
|
||||
{
|
||||
std::cout<<"IsAbilityEnabled"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled)
|
||||
{
|
||||
std::cout<<"SetAbilityEnabled"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
std::string BundleMgrService::GetAbilityIcon(const std::string &bundleName, const std::string &className)
|
||||
{
|
||||
std::cout<<"GetAbilityIcon"<<std::endl;
|
||||
return "BundleName";
|
||||
}
|
||||
bool BundleMgrService::CanRequestPermission(
|
||||
const std::string &bundleName, const std::string &permissionName, const int userId)
|
||||
{
|
||||
std::cout<<"CanRequestPermission"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::RequestPermissionFromUser(
|
||||
const std::string &bundleName, const std::string &permission, const int userId)
|
||||
{
|
||||
std::cout<<"RequestPermissionFromUser"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::RegisterAllPermissionsChanged(const sptr<OnPermissionChangedCallback> &callback)
|
||||
{
|
||||
std::cout<<"RegisterAllPermissionsChanged"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::RegisterPermissionsChanged(
|
||||
const std::vector<int> &uids, const sptr<OnPermissionChangedCallback> &callback)
|
||||
{
|
||||
std::cout<<"RegisterPermissionsChanged"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::UnregisterPermissionsChanged(const sptr<OnPermissionChangedCallback> &callback)
|
||||
{
|
||||
std::cout<<"UnregisterPermissionsChanged"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
sptr<IBundleInstaller> BundleMgrService::GetBundleInstaller()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool BundleMgrService::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetFormsInfoByApp(const std::string &bundleName, std::vector<FormInfo> &formInfos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetFormsInfoByModule(
|
||||
const std::string &bundleName, const std::string &moduleName, std::vector<FormInfo> &formInfos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetShortcutInfos(const std::string &bundleName, std::vector<ShortcutInfo> &shortcutInfos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetApplicationInfo(
|
||||
const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo)
|
||||
{
|
||||
std::cout<<"GetApplicationInfo"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetApplicationInfos(
|
||||
@ -29,8 +159,13 @@ bool BundleMgrService::GetApplicationInfos(
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int BundleMgrService::CheckPermission(const std::string &bundleName, const std::string &permission)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
bool BundleMgrService::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo)
|
||||
{
|
||||
std::cout<<"GetBundleInfo"<<std::endl;
|
||||
bundleInfo.name = "bundleInfo.name";
|
||||
bundleInfo.label = "bundleInfo.label";
|
||||
bundleInfo.description = "bundleInfo.description";
|
||||
@ -103,18 +238,22 @@ bool BundleMgrService::GetBundleInfo(const std::string &bundleName, const Bundle
|
||||
}
|
||||
bool BundleMgrService::GetBundleInfos(const BundleFlag flag, std::vector<BundleInfo> &bundleInfos)
|
||||
{
|
||||
std::cout<<"GetBundleInfos"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
int BundleMgrService::GetUidByBundleName(const std::string &bundleName, const int userId)
|
||||
{
|
||||
std::cout<<"GetUidByBundleName"<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
std::string BundleMgrService::GetAppIdByBundleName(const std::string &bundleName, const int userId)
|
||||
{
|
||||
std::cout<<"GetAppIdByBundleName"<<std::endl;
|
||||
return "BundleName";
|
||||
}
|
||||
bool BundleMgrService::GetBundleNameForUid(const int uid, std::string &bundleName)
|
||||
{
|
||||
std::cout<<"GetBundleNameForUid"<<std::endl;
|
||||
if (uid == 1024) {
|
||||
bundleName = "bundleName1024";
|
||||
return true;
|
||||
@ -127,6 +266,7 @@ bool BundleMgrService::GetBundleNameForUid(const int uid, std::string &bundleNam
|
||||
}
|
||||
bool BundleMgrService::GetBundlesForUid(const int uid, std::vector<std::string> &bundleNames)
|
||||
{
|
||||
std::cout<<"GetBundlesForUid"<<std::endl;
|
||||
if (uid == 1024) {
|
||||
bundleNames.push_back("bundleName1024");
|
||||
return true;
|
||||
@ -139,176 +279,80 @@ bool BundleMgrService::GetBundlesForUid(const int uid, std::vector<std::string>
|
||||
}
|
||||
bool BundleMgrService::GetNameForUid(const int uid, std::string &name)
|
||||
{
|
||||
std::cout<<"GetNameForUid"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetBundleGids(const std::string &bundleName, std::vector<int> &gids)
|
||||
{
|
||||
std::cout<<"GetBundleGids"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
std::string BundleMgrService::GetAppType(const std::string &bundleName)
|
||||
{
|
||||
std::cout<<"GetAppType"<<std::endl;
|
||||
return "launcher";
|
||||
}
|
||||
bool BundleMgrService::CheckIsSystemAppByUid(const int uid)
|
||||
{
|
||||
std::cout<<"CheckIsSystemAppByUid"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetBundleInfosByMetaData(const std::string &metaData, std::vector<BundleInfo> &bundleInfos)
|
||||
{
|
||||
std::cout<<"GetBundleInfosByMetaData"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::QueryAbilityInfo(const Want &want, AbilityInfo &abilityInfo)
|
||||
{
|
||||
std::cout<<"QueryAbilityInfo"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::QueryAbilityInfoByUri(const std::string &abilityUri, AbilityInfo &abilityInfo)
|
||||
{
|
||||
std::cout<<"QueryAbilityInfoByUri"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::QueryKeepAliveBundleInfos(std::vector<BundleInfo> &bundleInfos)
|
||||
{
|
||||
std::cout<<"QueryKeepAliveBundleInfos"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
std::string BundleMgrService::GetAbilityLabel(const std::string &bundleName, const std::string &className)
|
||||
{
|
||||
std::cout<<"GetAbilityLabel"<<std::endl;
|
||||
return "BundleName";
|
||||
}
|
||||
bool BundleMgrService::GetBundleArchiveInfo(
|
||||
const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo)
|
||||
{
|
||||
std::cout<<"GetBundleArchiveInfo"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetHapModuleInfo(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo)
|
||||
{
|
||||
std::cout<<"GetHapModuleInfo"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetLaunchWantForBundle(const std::string &bundleName, Want &want)
|
||||
{
|
||||
std::cout<<"GetLaunchWantForBundle"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
int BundleMgrService::CheckPublicKeys(const std::string &firstBundleName, const std::string &secondBundleName)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int BundleMgrService::CheckPermission(const std::string &bundleName, const std::string &permission)
|
||||
{
|
||||
std::cout<<"CheckPublicKeys"<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
bool BundleMgrService::GetPermissionDef(const std::string &permissionName, PermissionDef &permissionDef)
|
||||
{
|
||||
std::cout<<"GetPermissionDef"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
bool BundleMgrService::GetAllPermissionGroupDefs(std::vector<PermissionDef> &permissionDefs)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetAppsGrantedPermissions(
|
||||
const std::vector<std::string> &permissions, std::vector<std::string> &appNames)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::HasSystemCapability(const std::string &capName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetSystemAvailableCapabilities(std::vector<std::string> &systemCaps)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::IsSafeMode()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::CleanBundleCacheFiles(
|
||||
const std::string &bundleName, const sptr<ICleanCacheCallback> &cleanCacheCallback)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::CleanBundleDataFiles(const std::string &bundleName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::RegisterBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::ClearBundleStatusCallback(const sptr<IBundleStatusCallback> &bundleStatusCallback)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::UnregisterBundleStatusCallback()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::DumpInfos(const MockDumpFlag flag, const std::string &bundleName, std::string &result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::IsApplicationEnabled(const std::string &bundleName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::SetApplicationEnabled(const std::string &bundleName, bool isEnable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::IsAbilityEnabled(const AbilityInfo &abilityInfo)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::string BundleMgrService::GetAbilityIcon(const std::string &bundleName, const std::string &className)
|
||||
{
|
||||
return "BundleName";
|
||||
}
|
||||
bool BundleMgrService::CanRequestPermission(
|
||||
const std::string &bundleName, const std::string &permissionName, const int userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::RequestPermissionFromUser(
|
||||
const std::string &bundleName, const std::string &permission, const int userId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::RegisterAllPermissionsChanged(const sptr<OnPermissionChangedCallback> &callback)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::RegisterPermissionsChanged(
|
||||
const std::vector<int> &uids, const sptr<OnPermissionChangedCallback> &callback)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::UnregisterPermissionsChanged(const sptr<OnPermissionChangedCallback> &callback)
|
||||
{
|
||||
std::cout<<"GetAllPermissionGroupDefs"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
sptr<IBundleInstaller> BundleMgrService::GetBundleInstaller()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool BundleMgrService::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetFormsInfoByApp(const std::string &bundleName, std::vector<FormInfo> &formInfos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetFormsInfoByModule(
|
||||
const std::string &bundleName, const std::string &moduleName, std::vector<FormInfo> &formInfos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool BundleMgrService::GetShortcutInfos(const std::string &bundleName, std::vector<ShortcutInfo> &shortcutInfos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
@ -24,7 +24,7 @@ using namespace OHOS::Security::Permission;
|
||||
namespace {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PERMISSION, "SoftBusCenterMock"};
|
||||
static const int REG_COUNT_LIMIT = 10;
|
||||
} // namespace
|
||||
} // namespace
|
||||
static int regCount_ = -1;
|
||||
static INodeStateCb *callback_ = nullptr;
|
||||
|
||||
@ -69,7 +69,7 @@ int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info)
|
||||
{
|
||||
if (IsRegCountOK()) {
|
||||
strcpy_s(info->deviceName, sizeof(info->deviceName), "test-device-id-001");
|
||||
strcpy_s(info->deviceName, sizeof(info->deviceName), "test-device-id-001:network-id-001");
|
||||
strcpy_s(info->networkId, sizeof(info->networkId), "test-device-id-001:network-id-001");
|
||||
info->deviceTypeId = 1;
|
||||
PERMISSION_LOG_DEBUG(LABEL, "success, count: %{public}d", regCount_);
|
||||
return Constant::SUCCESS;
|
||||
@ -78,8 +78,8 @@ int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info)
|
||||
return Constant::FAILURE;
|
||||
}
|
||||
|
||||
int32_t GetNodeKeyInfo(
|
||||
const char *pkgName, const char *networkId, NodeDeivceInfoKey key, uint8_t *info, int32_t infoLen)
|
||||
int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeivceInfoKey key, uint8_t *info,
|
||||
int32_t infoLen)
|
||||
{
|
||||
if (networkId == nullptr || networkId[0] == '\0') {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "failure, invalid networkId, pkg name: %{public}s", pkgName);
|
||||
@ -90,13 +90,13 @@ int32_t GetNodeKeyInfo(
|
||||
if (key == NodeDeivceInfoKey::NODE_KEY_UDID) {
|
||||
std::string temp = networkId;
|
||||
temp += ":udid-001";
|
||||
strncpy_s((char *)info, infoLen, temp.c_str(), temp.length());
|
||||
strncpy_s((char *) info, infoLen, temp.c_str(), temp.length());
|
||||
infoLen = temp.length();
|
||||
}
|
||||
if (key == NodeDeivceInfoKey::NODE_KEY_UUID) {
|
||||
std::string temp = networkId;
|
||||
temp += ":uuid-001";
|
||||
strncpy_s((char *)info, infoLen, temp.c_str(), temp.length());
|
||||
strncpy_s((char *) info, infoLen, temp.c_str(), temp.length());
|
||||
}
|
||||
PERMISSION_LOG_DEBUG(LABEL, "success, count: %{public}d, id: %{public}s", regCount_, info);
|
||||
return Constant::SUCCESS;
|
||||
|
@ -17,13 +17,14 @@
|
||||
#include "constant.h"
|
||||
#include "soft_bus_manager.h"
|
||||
#include "permission_log.h"
|
||||
|
||||
#include "soft_bus_session_listener.h"
|
||||
#include "soft_bus_channel.h"
|
||||
using namespace OHOS::Security::Permission;
|
||||
namespace {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PERMISSION, "SoftBusSenssionMock"};
|
||||
static const int SESSION_COUNT_LIMIT = 20;
|
||||
static const int SERVER_COUNT_LIMIT = 10;
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
#define MIN_(x, y) ((x) < (y)) ? (x) : (y)
|
||||
|
||||
@ -87,6 +88,7 @@ int OpenSession(const char *mySessionName, const char *peerSessionName, const ch
|
||||
|
||||
sessionCount_++;
|
||||
if (IsSessionCountOK()) {
|
||||
SoftBusSessionListener::OnSessionOpened(1, Constant::SUCCESS);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "success, session count: %{public}d", sessionCount_);
|
||||
return 1;
|
||||
}
|
||||
@ -109,11 +111,7 @@ int SendBytes(int sessionId, const void *data, unsigned int len)
|
||||
if (sessionId == Constant::INVALID_SESSION) {
|
||||
return Constant::FAILURE;
|
||||
}
|
||||
printf("\n[soft_bus_session] send data:: ");
|
||||
std::string s((char *)data);
|
||||
printf("%s", s.c_str());
|
||||
printf("\n\n");
|
||||
PERMISSION_LOG_DEBUG(LABEL, "data: %{public}s", data);
|
||||
DecompressMock((unsigned char *) data, len);
|
||||
return Constant::SUCCESS;
|
||||
}
|
||||
|
||||
@ -156,4 +154,42 @@ int GetPeerDeviceId(int sessionId, char *devId, unsigned int len)
|
||||
}
|
||||
devId[x.length()] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
static std::string uuid = "";
|
||||
void DecompressMock(const unsigned char *bytes, const int length)
|
||||
{
|
||||
PERMISSION_LOG_DEBUG(LABEL, "input length: %{public}d", length);
|
||||
uLong len = 1048576;
|
||||
unsigned char *buf = (unsigned char *) malloc(len + 1);
|
||||
if (buf == nullptr) {
|
||||
PERMISSION_LOG_ERROR(LABEL, "no enough memory!");
|
||||
return;
|
||||
}
|
||||
memset_s(buf, len + 1, 0, len + 1);
|
||||
int result = uncompress(buf, &len, (unsigned char *) bytes, length);
|
||||
if (result != Z_OK) {
|
||||
PERMISSION_LOG_ERROR(LABEL,
|
||||
"uncompress failed, error code: %{public}d, bound length: %{public}d, buffer length: %{public}d", result,
|
||||
(int) len, length);
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
std::string str((char *) buf);
|
||||
free(buf);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "done, output: %{public}s", str.c_str());
|
||||
|
||||
int id_post = str.find("\"id\":");
|
||||
|
||||
std::string id_string = str.substr(id_post + 6, 9);
|
||||
uuid = id_string;
|
||||
PERMISSION_LOG_DEBUG(LABEL, "id_string: %{public}s", id_string.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
std::string GetUuidMock()
|
||||
{
|
||||
PERMISSION_LOG_DEBUG(LABEL, "GetUuidMock called uuid: %{public}s", uuid.c_str());
|
||||
return uuid;
|
||||
}
|
@ -29,21 +29,7 @@ std::string IPCSkeleton::deviceId_ = "";
|
||||
} // namespace OHOS
|
||||
|
||||
void AddPermissionUsedRecordTest::SetUpTestCase()
|
||||
{
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo("device_0", "device_0", "device_0", "device_name_0", "device_type");
|
||||
cout << "SetUpTestCase()" << endl;
|
||||
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
|
||||
void AddPermissionUsedRecordTest::TearDownTestCase()
|
||||
{
|
||||
@ -116,87 +102,6 @@ void AddPermissionUsedRecordTest::InitRecordData(int64_t timestamp)
|
||||
DataStorage::GetRealDataStorage().Add(DataStorage::PERMISSION_RECORD, record);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AddPermissionUsedRecord_0100
|
||||
* @tc.name: test add permission used record
|
||||
* @tc.desc: 1. permissionVisitor table does not exist input data
|
||||
* 2. permissionRecord table does not exist input data
|
||||
*/
|
||||
HWTEST_F(AddPermissionUsedRecordTest, AddPermissionUsedRecord_0100, Function | MediumTest | Level1)
|
||||
{
|
||||
SetPermissionNames(permissionNames);
|
||||
srand((unsigned)time(NULL));
|
||||
int index = rand() % permissionNames.size();
|
||||
string permissionName = permissionNames[index];
|
||||
string random = to_string(rand());
|
||||
string deviceId = "device_" + random;
|
||||
int32_t uid = rand();
|
||||
int32_t accessCount = 1;
|
||||
int32_t failCount = 0;
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(
|
||||
deviceId, deviceId, deviceId, "mock_device_name_device_" + random, "device_type");
|
||||
|
||||
visitorValues.clear();
|
||||
recordValues.clear();
|
||||
int visitorSize = 0;
|
||||
int recordSize = 0;
|
||||
int visitorResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_VISITOR, visitorValues);
|
||||
int recordResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_RECORD, recordValues);
|
||||
EXPECT_EQ(visitorResult, 0);
|
||||
EXPECT_EQ(recordResult, 0);
|
||||
visitorSize = visitorValues.size();
|
||||
recordSize = recordValues.size();
|
||||
std::string appidInfo = DistributedPermissionKit::AppIdInfoHelper::CreateAppIdInfo(0, uid, deviceId);
|
||||
managerService.AddPermissionsRecord(permissionName, appidInfo, accessCount, failCount);
|
||||
visitorValues.clear();
|
||||
recordValues.clear();
|
||||
visitorResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_VISITOR, visitorValues);
|
||||
recordResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_RECORD, recordValues);
|
||||
EXPECT_EQ(visitorResult, 0);
|
||||
EXPECT_EQ(recordResult, 0);
|
||||
EXPECT_EQ(visitorSize + 1, (int)visitorValues.size());
|
||||
EXPECT_EQ(recordSize + 1, (int)recordValues.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AddPermissionUsedRecord_0200
|
||||
* @tc.name: test add permission used record
|
||||
* @tc.desc: 1. permissionVisitor table already exists input data
|
||||
* 2. permissionRecord table already exists input data
|
||||
* 3. permissionRecord table does not need to drop precision of timestamp
|
||||
*/
|
||||
HWTEST_F(AddPermissionUsedRecordTest, AddPermissionUsedRecord_0200, Function | MediumTest | Level1)
|
||||
{
|
||||
InitVisitorData();
|
||||
InitRecordData(TimeUtil::GetTimestamp() - Constant::PRECISION);
|
||||
string permissionName = "ohos.permission.READ_CONTACTS";
|
||||
string deviceId = "device_0";
|
||||
int32_t uid = 0;
|
||||
int32_t accessCount = 0;
|
||||
int32_t failCount = 1;
|
||||
|
||||
visitorValues.clear();
|
||||
recordValues.clear();
|
||||
int visitorSize = 0;
|
||||
int recordSize = 0;
|
||||
int visitorResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_VISITOR, visitorValues);
|
||||
int recordResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_RECORD, recordValues);
|
||||
EXPECT_EQ(visitorResult, 0);
|
||||
EXPECT_EQ(recordResult, 0);
|
||||
visitorSize = visitorValues.size();
|
||||
recordSize = recordValues.size();
|
||||
std::string appidInfo = DistributedPermissionKit::AppIdInfoHelper::CreateAppIdInfo(0, uid, deviceId);
|
||||
managerService.AddPermissionsRecord(permissionName, appidInfo, accessCount, failCount);
|
||||
visitorValues.clear();
|
||||
recordValues.clear();
|
||||
visitorResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_VISITOR, visitorValues);
|
||||
recordResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_RECORD, recordValues);
|
||||
EXPECT_EQ(visitorResult, 0);
|
||||
EXPECT_EQ(recordResult, 0);
|
||||
EXPECT_EQ(visitorSize, (int)visitorValues.size());
|
||||
EXPECT_EQ(recordSize + 1, (int)recordValues.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AddPermissionUsedRecord_0300
|
||||
* @tc.name: test add permission used record
|
||||
@ -300,42 +205,3 @@ HWTEST_F(AddPermissionUsedRecordTest, AddPermissionUsedRecord_0500, Function | M
|
||||
|
||||
EXPECT_EQ(recordSize, (int)recordValues.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: AddPermissionUsedRecord_0600
|
||||
* @tc.name: test delete permission used record
|
||||
* @tc.desc: 1. The delete operation occurred when the add operation started
|
||||
* 2. Delete data that exist more than 30 days
|
||||
*/
|
||||
HWTEST_F(AddPermissionUsedRecordTest, AddPermissionUsedRecord_0600, Function | MediumTest | Level1)
|
||||
{
|
||||
visitorValues.clear();
|
||||
recordValues.clear();
|
||||
int visitorSize = 0;
|
||||
int recordSize = 0;
|
||||
int visitorResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_VISITOR, visitorValues);
|
||||
int recordResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_RECORD, recordValues);
|
||||
EXPECT_EQ(visitorResult, 0);
|
||||
EXPECT_EQ(recordResult, 0);
|
||||
visitorSize = visitorValues.size();
|
||||
recordSize = recordValues.size();
|
||||
|
||||
InitVisitorData();
|
||||
InitRecordData(-2592000);
|
||||
string permissionName = "ohos.permission.READ_CONTACTS";
|
||||
string deviceId = "device_0";
|
||||
int32_t uid = 0;
|
||||
int32_t accessCount = 0;
|
||||
int32_t failCount = 1;
|
||||
std::string appidInfo = DistributedPermissionKit::AppIdInfoHelper::CreateAppIdInfo(0, uid, deviceId);
|
||||
managerService.AddPermissionsRecord(permissionName, appidInfo, accessCount, failCount);
|
||||
sleep(1);
|
||||
visitorValues.clear();
|
||||
recordValues.clear();
|
||||
visitorResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_VISITOR, visitorValues);
|
||||
recordResult = DataStorage::GetRealDataStorage().Find(DataStorage::PERMISSION_RECORD, recordValues);
|
||||
EXPECT_EQ(visitorResult, 0);
|
||||
EXPECT_EQ(recordResult, 0);
|
||||
EXPECT_EQ(visitorSize + 1, (int)visitorValues.size());
|
||||
EXPECT_EQ(recordSize + 1, (int)recordValues.size());
|
||||
}
|
@ -24,17 +24,7 @@ namespace Permission {
|
||||
namespace {} // namespace
|
||||
|
||||
void CanRequestPermissionFromRemoteTest::SetUpTestCase(void)
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
void CanRequestPermissionFromRemoteTest::TearDownTestCase(void)
|
||||
{}
|
||||
void CanRequestPermissionFromRemoteTest::SetUp()
|
||||
|
@ -28,18 +28,7 @@ std::string IPCSkeleton::deviceId_ = "";
|
||||
namespace Security {
|
||||
namespace Permission {
|
||||
void CheckDPermissionTest::SetUpTestCase()
|
||||
{
|
||||
cout << "SetUpTestCase()" << endl;
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
void CheckDPermissionTest::TearDownTestCase()
|
||||
{
|
||||
cout << "TearDownTestCase()" << endl;
|
||||
|
@ -27,18 +27,7 @@ std::string IPCSkeleton::deviceId_ = "";
|
||||
namespace Security {
|
||||
namespace Permission {
|
||||
void CheckPermissionTest::SetUpTestCase()
|
||||
{
|
||||
cout << "SetUpTestCase()" << endl;
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
|
||||
void CheckPermissionTest::TearDownTestCase()
|
||||
{
|
||||
@ -71,15 +60,6 @@ HWTEST_F(CheckPermissionTest, CheckPermission02, Function | MediumTest | Level1)
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(CheckPermissionTest, CheckPermission03, Function | MediumTest | Level1)
|
||||
{
|
||||
string permissionName = "ohos.permission.INTERNET";
|
||||
string appIdInfo = "{\"deviceID\":\"\",\"pid\":1,\"uid\":1}";
|
||||
int result = Constant::PERMISSION_GRANTED;
|
||||
int ret = DistributedPermissionManagerService().CheckPermission(permissionName, appIdInfo);
|
||||
EXPECT_EQ(result, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(CheckPermissionTest, CheckPermission04, Function | MediumTest | Level1)
|
||||
{
|
||||
string permissionName = "ohos.permission.INTERNET";
|
||||
|
@ -21,13 +21,12 @@
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include "gtest/gtest.h"
|
||||
#include "mock_bundle_mgr.h"
|
||||
#include "constant_mock.h"
|
||||
#include "mock_permission_mgr.h"
|
||||
#include "base_remote_command.h"
|
||||
#include "get_uid_permission_command.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "ability_manager_interface.h"
|
||||
@ -42,17 +41,7 @@ GetUidPermissionCommandTest::GetUidPermissionCommandTest()
|
||||
GetUidPermissionCommandTest::~GetUidPermissionCommandTest()
|
||||
{}
|
||||
void GetUidPermissionCommandTest::SetUpTestCase()
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
void GetUidPermissionCommandTest::TearDownTestCase()
|
||||
{}
|
||||
void GetUidPermissionCommandTest::SetUp()
|
||||
@ -89,35 +78,6 @@ HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0002, Function
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0003, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 12600000;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<GetUidPermissionCommand> class_ =
|
||||
std::make_unique<GetUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Execute();
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "success");
|
||||
}
|
||||
|
||||
HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0004, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 12600000;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<GetUidPermissionCommand> class_ =
|
||||
std::make_unique<GetUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Execute();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "success");
|
||||
}
|
||||
|
||||
HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0005, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = -1;
|
||||
@ -133,37 +93,6 @@ HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0005, Function
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "failed to get permissions");
|
||||
}
|
||||
|
||||
HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0006, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 1024;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<GetUidPermissionCommand> class_ =
|
||||
std::make_unique<GetUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Execute();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, -2);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "permissions exceed MAX_UID_PERMISSIONS_COUNT");
|
||||
}
|
||||
|
||||
HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0008, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 12610001;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<GetUidPermissionCommand> class_ =
|
||||
std::make_unique<GetUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Execute();
|
||||
class_->Finish();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "success");
|
||||
}
|
||||
|
||||
HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0009, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 12610001;
|
||||
@ -196,38 +125,6 @@ HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0010, Function
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "execute command failed");
|
||||
}
|
||||
|
||||
HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0011, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 12600000;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<GetUidPermissionCommand> class_ =
|
||||
std::make_unique<GetUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Execute();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "success");
|
||||
|
||||
std::string result = class_->ToJsonPayload();
|
||||
|
||||
std::string json =
|
||||
"{\"commandName\":\"GetUidPermissionCommand\",\"dstDeviceId\":\"dstDeviceId\",\"dstDeviceLevel\":\"\","
|
||||
"\"message\":\"success\",\"requestVersion\":1,\"responseDeviceId\":\"1004\",\"responseVersion\":1,"
|
||||
"\"srcDeviceId\":\"srcDeviceId\",\"srcDeviceLevel\":\"\",\"statusCode\":0,\"uid\":12600000,\"uidPermission\":{"
|
||||
"\"DEFAULT_SIZE\":10,\"MIN_UID_PACKAGES_NUM\":1,\"appAttribute\":2,\"bundles\":[{\"appId\":\"bundleInfo."
|
||||
"appId\",\"bundleLabel\":\"bundleInfo.label\",\"name\":\"bundleInfo.name\",\"permissions\":[{\"defInfo\":0,"
|
||||
"\"grantMode\":0,\"level\":0,\"name\":\"reqPermissions1\",\"status\":1,\"type\":\"app\"},{\"defInfo\":0,"
|
||||
"\"grantMode\":0,\"level\":0,\"name\":\"reqPermissions2\",\"status\":1,\"type\":\"app\"},{\"defInfo\":0,"
|
||||
"\"grantMode\":0,\"level\":0,\"name\":\"reqPermissions3\",\"status\":1,\"type\":\"app\"},{\"defInfo\":0,"
|
||||
"\"grantMode\":0,\"level\":0,\"name\":\"reqPermissions4\",\"status\":1,\"type\":\"app\"},{\"defInfo\":0,"
|
||||
"\"grantMode\":0,\"level\":0,\"name\":\"reqPermissions5\",\"status\":1,\"type\":\"app\"}],\"sign\":[{"
|
||||
"\"sha256\":\"applicationInfo.signatureKey\"}]}],\"remoteSensitivePermission\":null,\"uid\":12600000,"
|
||||
"\"uidState\":0},\"uniqueId\":\"GetUidPermissionCommand-12600000\"}";
|
||||
EXPECT_EQ(result, json);
|
||||
}
|
||||
|
||||
HWTEST_F(GetUidPermissionCommandTest, GetUidPermissionCommandTest_0012, Function | MediumTest | Level1)
|
||||
{
|
||||
std::string json =
|
||||
|
@ -45,20 +45,7 @@ RequestRemotePermissionCallbackCommandTest::RequestRemotePermissionCallbackComma
|
||||
RequestRemotePermissionCallbackCommandTest::~RequestRemotePermissionCallbackCommandTest()
|
||||
{}
|
||||
void RequestRemotePermissionCallbackCommandTest::SetUpTestCase()
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
void RequestRemotePermissionCallbackCommandTest::TearDownTestCase()
|
||||
{}
|
||||
void RequestRemotePermissionCallbackCommandTest::SetUp()
|
||||
|
@ -50,17 +50,7 @@ RequestRemotePermissionCommandTest::RequestRemotePermissionCommandTest()
|
||||
RequestRemotePermissionCommandTest::~RequestRemotePermissionCommandTest()
|
||||
{}
|
||||
void RequestRemotePermissionCommandTest::SetUpTestCase()
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
void RequestRemotePermissionCommandTest::TearDownTestCase()
|
||||
{}
|
||||
void RequestRemotePermissionCommandTest::SetUp()
|
||||
|
@ -40,17 +40,7 @@ SyncUidPermissionCommandTest::SyncUidPermissionCommandTest()
|
||||
SyncUidPermissionCommandTest::~SyncUidPermissionCommandTest()
|
||||
{}
|
||||
void SyncUidPermissionCommandTest::SetUpTestCase()
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
void SyncUidPermissionCommandTest::TearDownTestCase()
|
||||
{}
|
||||
void SyncUidPermissionCommandTest::SetUp()
|
||||
@ -75,68 +65,6 @@ HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0001, Functi
|
||||
EXPECT_EQ(class_->remoteProtocol_.requestVersion, 1);
|
||||
}
|
||||
|
||||
HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0002, Function | MediumTest | Level2)
|
||||
{
|
||||
int32_t uid = 1;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<SyncUidPermissionCommand> class_ =
|
||||
std::make_unique<SyncUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Prepare();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "success");
|
||||
}
|
||||
|
||||
HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0003, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 1024;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<BaseRemoteCommand> class_ =
|
||||
std::make_unique<SyncUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Prepare();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, -2);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "permissions exceed MAX_UID_PERMISSIONS_COUNT");
|
||||
}
|
||||
|
||||
HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0004, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 1;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<BaseRemoteCommand> class_ =
|
||||
std::make_unique<SyncUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Prepare();
|
||||
class_->Execute();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "success");
|
||||
}
|
||||
|
||||
HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0005, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 2;
|
||||
std::string srcDeviceId = "012345678900123456789001234567890012345678900123456789001234567890012345";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<BaseRemoteCommand> class_ =
|
||||
std::make_unique<SyncUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Prepare();
|
||||
class_->Execute();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, -2);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "execute command failed");
|
||||
}
|
||||
|
||||
HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0006, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 1;
|
||||
@ -151,38 +79,6 @@ HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0006, Functi
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0007, Function | MediumTest | Level1)
|
||||
{
|
||||
int32_t uid = 1;
|
||||
std::string srcDeviceId = "srcDeviceId";
|
||||
std::string dstDeviceId = "dstDeviceId";
|
||||
|
||||
std::unique_ptr<SyncUidPermissionCommand> class_ =
|
||||
std::make_unique<SyncUidPermissionCommand>(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
class_->Prepare();
|
||||
|
||||
EXPECT_EQ(class_->remoteProtocol_.statusCode, 0);
|
||||
EXPECT_EQ(class_->remoteProtocol_.message, "success");
|
||||
|
||||
std::string result = class_->ToJsonPayload();
|
||||
std::string json =
|
||||
"{\"commandName\":\"SyncUidPermissionCommand\",\"dstDeviceId\":\"dstDeviceId\",\"dstDeviceLevel\":\"\","
|
||||
"\"message\":\"success\",\"requestVersion\":1,\"responseDeviceId\":\"\",\"responseVersion\":1,\"srcDeviceId\":"
|
||||
"\"srcDeviceId\",\"srcDeviceLevel\":\"\",\"statusCode\":0,\"uid\":1,\"uidPermission\":{\"DEFAULT_SIZE\":10,"
|
||||
"\"MIN_UID_PACKAGES_NUM\":1,\"appAttribute\":2,\"bundles\":[{\"appId\":\"bundleInfo.appId\",\"bundleLabel\":"
|
||||
"\"bundleInfo.label\",\"name\":\"bundleInfo.name\",\"permissions\":[{\"defInfo\":0,\"grantMode\":0,\"level\":"
|
||||
"0,\"name\":\"reqPermissions1\",\"status\":1,\"type\":\"app\"},{\"defInfo\":0,\"grantMode\":0,\"level\":0,"
|
||||
"\"name\":\"reqPermissions2\",\"status\":1,\"type\":\"app\"},{\"defInfo\":0,\"grantMode\":0,\"level\":0,"
|
||||
"\"name\":\"reqPermissions3\",\"status\":1,\"type\":\"app\"},{\"defInfo\":0,\"grantMode\":0,\"level\":0,"
|
||||
"\"name\":\"reqPermissions4\",\"status\":1,\"type\":\"app\"},{\"defInfo\":0,\"grantMode\":0,\"level\":0,"
|
||||
"\"name\":\"reqPermissions5\",\"status\":1,\"type\":\"app\"}],\"sign\":[{\"sha256\":\"applicationInfo."
|
||||
"signatureKey\"}]}],\"remoteSensitivePermission\":null,\"uid\":1,\"uidState\":0},\"uniqueId\":"
|
||||
"\"SyncUidPermissionCommand-1\"}";
|
||||
|
||||
EXPECT_EQ(result, json);
|
||||
}
|
||||
|
||||
HWTEST_F(SyncUidPermissionCommandTest, SyncUidPermissionCommandTest_0008, Function | MediumTest | Level1)
|
||||
{
|
||||
std::string json =
|
||||
|
@ -30,17 +30,7 @@ std::string IPCSkeleton::deviceId_ = "";
|
||||
} // namespace OHOS
|
||||
|
||||
void DeletePermissionUsedRecordTest::SetUpTestCase()
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
|
||||
void DeletePermissionUsedRecordTest::TearDownTestCase()
|
||||
{
|
||||
|
@ -35,18 +35,7 @@ namespace Permission {
|
||||
class NotifySyncPermissionTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
cout << "SetUpTestCase()" << endl;
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
cout << "TearDownTestCase()" << endl;
|
||||
@ -69,8 +58,8 @@ std::unique_ptr<DistributedPermissionManagerService> NotifySyncPermissionTest::G
|
||||
}
|
||||
HWTEST_F(NotifySyncPermissionTest, NotifySyncPermission_0001, Function | MediumTest | Level1)
|
||||
{
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
"networkId", "universallyUniqueId", "uniqueDisabilityIdSuccess", "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo("networkId", "universallyUniqueId", "uniqueDisabilityIdSuccess",
|
||||
"deviceName", "deviceType");
|
||||
|
||||
std::unique_ptr<DistributedPermissionManagerService> class_ =
|
||||
std::make_unique<DistributedPermissionManagerService>();
|
||||
@ -82,6 +71,6 @@ HWTEST_F(NotifySyncPermissionTest, NotifySyncPermission_0001, Function | MediumT
|
||||
int32_t result = class_->NotifySyncPermission(nodeId, uid, packageName);
|
||||
EXPECT_EQ(result, 0);
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
|
@ -25,7 +25,7 @@ std::string deviceId2 = "deviceId2";
|
||||
std::string deviceId3 = "deviceId3";
|
||||
namespace Security {
|
||||
namespace Permission {
|
||||
namespace {} // namespace
|
||||
namespace {} // namespace
|
||||
|
||||
void ObjectDevicePermissionManagerFuncTest::SetUpTestCase(void)
|
||||
{}
|
||||
@ -33,15 +33,6 @@ void ObjectDevicePermissionManagerFuncTest::TearDownTestCase(void)
|
||||
{}
|
||||
void ObjectDevicePermissionManagerFuncTest::SetUp()
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
service = DelayedSingleton<DistributedPermissionManagerService>::GetInstance();
|
||||
}
|
||||
void ObjectDevicePermissionManagerFuncTest::TearDown()
|
||||
@ -149,9 +140,9 @@ HWTEST_F(ObjectDevicePermissionManagerFuncTest, func_test_remove_notify_permissi
|
||||
{
|
||||
GTEST_LOG_(INFO) << "func_test_remove_notify_permission_monitor_userId_0100";
|
||||
ObjectDevicePermissionManager::GetInstance().Clear();
|
||||
int32_t uid = 100000; // sys
|
||||
int32_t uid2 = 100001; // del target
|
||||
int32_t uid3 = 102101; // del target
|
||||
int32_t uid = 100000; // sys
|
||||
int32_t uid2 = 100001; // del target
|
||||
int32_t uid3 = 102101; // del target
|
||||
int32_t uid4 = 200001;
|
||||
ObjectDevicePermissionRepository::GetInstance().PutDeviceIdUidPair(deviceId1, uid);
|
||||
ObjectDevicePermissionRepository::GetInstance().PutDeviceIdUidPair(deviceId1, uid2);
|
||||
@ -239,6 +230,6 @@ HWTEST_F(ObjectDevicePermissionManagerFuncTest, func_test_notify_permission_chan
|
||||
int result = ObjectDevicePermissionManager::GetInstance().NotifyPermissionChanged(uid);
|
||||
EXPECT_TRUE(result == Constant::FAILURE);
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -27,17 +27,7 @@ std::string IPCSkeleton::deviceId_ = "";
|
||||
std::string permName = Constant::CAMERA;
|
||||
} // namespace OHOS
|
||||
void PermissionRemindTest::SetUpTestCase()
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
|
||||
void PermissionRemindTest::TearDownTestCase()
|
||||
{
|
||||
@ -49,29 +39,29 @@ void PermissionRemindTest::SetUp()
|
||||
dpms_->OnStart();
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(deviceId, deviceId, deviceId, deviceName, "");
|
||||
|
||||
BundlePermissionsDto bundles;
|
||||
bundles.name = "bundles.name";
|
||||
bundles.bundleLabel = "bundles.bundleLabel";
|
||||
SignDto signDto;
|
||||
signDto.sha256 = "bundles.sign";
|
||||
bundles.sign.push_back(signDto);
|
||||
BundlePermissionsDto bundles;
|
||||
bundles.name = "bundles.name";
|
||||
bundles.bundleLabel = "bundles.bundleLabel";
|
||||
SignDto signDto;
|
||||
signDto.sha256 = "bundles.sign";
|
||||
bundles.sign.push_back(signDto);
|
||||
|
||||
PermissionDto permission;
|
||||
permission.name = permName;
|
||||
permission.grantMode = 0;
|
||||
permission.status = Constant::PERMISSION_GRANTED_STATUS;
|
||||
bundles.permissions.push_back(permission);
|
||||
PermissionDto permission;
|
||||
permission.name = permName;
|
||||
permission.grantMode = 0;
|
||||
permission.status = Constant::PERMISSION_GRANTED_STATUS;
|
||||
bundles.permissions.push_back(permission);
|
||||
|
||||
UidBundleBo uidBundleBo;
|
||||
uidBundleBo.DEFAULT_SIZE = 10; // default 10
|
||||
uidBundleBo.MIN_UID_PACKAGES_NUM = 1; // default 1
|
||||
uidBundleBo.uid = uid_normal_1_;
|
||||
uidBundleBo.appAttribute = 0;
|
||||
uidBundleBo.bundles.push_back(bundles);
|
||||
uidBundleBo.uidState = 1;
|
||||
UidBundleBo uidBundleBo;
|
||||
uidBundleBo.DEFAULT_SIZE = 10; // default 10
|
||||
uidBundleBo.MIN_UID_PACKAGES_NUM = 1; // default 1
|
||||
uidBundleBo.uid = uid_normal_1_;
|
||||
uidBundleBo.appAttribute = 0;
|
||||
uidBundleBo.bundles.push_back(bundles);
|
||||
uidBundleBo.uidState = 1;
|
||||
|
||||
std::set<std::string> remoteSensitivePermission;
|
||||
remoteSensitivePermission.insert(permName);
|
||||
std::set<std::string> remoteSensitivePermission;
|
||||
remoteSensitivePermission.insert(permName);
|
||||
|
||||
SubjectDevicePermissionManager::GetInstance().distributedPermissionMapping_.insert(
|
||||
std::pair<int32_t, UidBundleBo>(uid, uidBundleBo));
|
||||
@ -156,14 +146,11 @@ HWTEST_F(PermissionRemindTest, PermissionRemindTest04, Function | MediumTest | L
|
||||
ret = dpms_->RegisterUsingPermissionReminder(callback);
|
||||
EXPECT_EQ(0, ret);
|
||||
|
||||
// Case 01
|
||||
permName = Constant::CAMERA;
|
||||
pid = 101;
|
||||
uid = uid_normal_1_;
|
||||
deviceId = "ohos.deviceId.test";
|
||||
std::string appidInfo1 = DistributedPermissionKit::AppIdInfoHelper::CreateAppIdInfo(pid, uid, deviceId);
|
||||
ret = dpms_->CheckPermissionAndStartUsing(permName, appidInfo1);
|
||||
EXPECT_EQ(0, ret);
|
||||
|
||||
// Case 02
|
||||
permName = "ohos.permission.NotSensitivePermission";
|
||||
@ -179,15 +166,6 @@ HWTEST_F(PermissionRemindTest, PermissionRemindTest04, Function | MediumTest | L
|
||||
ret = dpms_->CheckPermissionAndStartUsing(permName, appidInfo2);
|
||||
EXPECT_EQ(-1, ret);
|
||||
|
||||
// Case 04
|
||||
permName = Constant::CAMERA;
|
||||
pid = 101;
|
||||
uid = uid_normal_3_;
|
||||
deviceId = "ohos.deviceId.test";
|
||||
std::string appidInfo3 = DistributedPermissionKit::AppIdInfoHelper::CreateAppIdInfo(pid, uid, deviceId);
|
||||
ret = dpms_->CheckPermissionAndStartUsing(permName, appidInfo3);
|
||||
EXPECT_EQ(0, ret);
|
||||
|
||||
// Case 05
|
||||
permName = "";
|
||||
pid = 101;
|
||||
|
@ -24,22 +24,13 @@ namespace Permission {
|
||||
namespace {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PERMISSION, "PermissionBmsManager"};
|
||||
}
|
||||
namespace {} // namespace
|
||||
namespace {} // namespace
|
||||
void RequestPermissionsFromRemoteTest::SetUpTestCase(void)
|
||||
{}
|
||||
void RequestPermissionsFromRemoteTest::TearDownTestCase(void)
|
||||
{}
|
||||
void RequestPermissionsFromRemoteTest::SetUp()
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
service = DelayedSingleton<DistributedPermissionManagerService>::GetInstance();
|
||||
}
|
||||
void RequestPermissionsFromRemoteTest::TearDown()
|
||||
@ -54,8 +45,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_permissionsservice_from_remot
|
||||
std::string bundleName("");
|
||||
std::string deviceId("deviceId");
|
||||
int32_t reasonResId = -1;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
// case NeedStopProcess fail
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
std::this_thread::sleep_for(timeFast);
|
||||
@ -75,8 +66,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_permissionsservice_from_remot
|
||||
std::string bundleName("");
|
||||
std::string deviceId("deviceId");
|
||||
int32_t reasonResId = -1;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
// requestingDevices_.count(request->deviceId_) != 0
|
||||
RequestRemotePermission::GetInstance().requestingDevices_.insert(
|
||||
std::pair<std::string, std::string>(deviceId, deviceId));
|
||||
@ -99,8 +90,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_permissionsservice_from_remot
|
||||
std::string bundleName("");
|
||||
std::string deviceId("deviceId");
|
||||
int32_t reasonResId = -1;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
RequestRemotePermission::GetInstance().requestingDevices_.erase(deviceId);
|
||||
// case RequestPermissionsInfo::CanRequestPermissions IsDeviceIdValid fail
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
@ -123,8 +114,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_permissionsservice_from_remot
|
||||
std::string deviceId("deviceId");
|
||||
int32_t reasonResId = -1;
|
||||
// case InitObjectLocaleReason bundleName=""
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
std::this_thread::sleep_for(timeFast);
|
||||
PERMISSION_LOG_INFO(LABEL, "onResult_ : %{public}d,", callback->onResult_);
|
||||
@ -143,8 +134,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_permissionsservice_from_remot
|
||||
std::string nodeId("networkId");
|
||||
std::string bundleName("bundleName");
|
||||
std::string deviceId("deviceId");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
// case InitObjectLocaleReason reasonResId_ < 0)
|
||||
int32_t reasonResId = -1;
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
@ -166,8 +157,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_permissionsservice_from_remot
|
||||
std::string bundleName("bundleName");
|
||||
std::string deviceId("deviceId");
|
||||
int32_t reasonResId = -1;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
// case now InitObjectLocaleReason reasonString_ is not empty ,will be request command
|
||||
reasonResId = 1;
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
@ -190,8 +181,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_permissionsservice_from_remot
|
||||
std::string bundleName("bundleName");
|
||||
std::string deviceId("deviceId");
|
||||
int32_t reasonResId = 1;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
// case now InitObjectLocaleReason reasonString_ is not empty ,will be request command
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
std::this_thread::sleep_for(timeFast);
|
||||
@ -213,8 +204,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_permissionsservice_from_remot
|
||||
std::string bundleName("bundleName");
|
||||
std::string deviceId("deviceIdTimeout");
|
||||
int32_t reasonResId = 1;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
std::this_thread::sleep_for(timeFast);
|
||||
PERMISSION_LOG_INFO(LABEL, "onResult_ : %{public}d,", callback->onResult_);
|
||||
@ -235,8 +226,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_result_for_cancel_test_0100,
|
||||
std::string bundleName("bundleName");
|
||||
std::string deviceId("deviceIdCancelExit");
|
||||
int32_t reasonResId = 1;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
// will sleep 60s
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
std::this_thread::sleep_for(timeFast);
|
||||
@ -259,8 +250,8 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_result_for_cancel_test_0200,
|
||||
std::string bundleName("bundleName");
|
||||
std::string deviceId("deviceIdCancel ");
|
||||
int32_t reasonResId = 1;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
// will sleep 60s
|
||||
service->RequestPermissionsFromRemote(permissions, callback, nodeId, bundleName, reasonResId);
|
||||
std::this_thread::sleep_for(timeFast);
|
||||
@ -272,6 +263,6 @@ HWTEST_F(RequestPermissionsFromRemoteTest, request_result_for_cancel_test_0200,
|
||||
EXPECT_EQ(callback->onCancel_, 100);
|
||||
EXPECT_EQ(callback->onTimeOut_, 100);
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -22,15 +22,15 @@
|
||||
|
||||
#include "constant.h"
|
||||
#include "distributed_permission_manager_service.h"
|
||||
|
||||
#include "session.h"
|
||||
using namespace testing::ext;
|
||||
using namespace testing;
|
||||
namespace OHOS {
|
||||
namespace Security {
|
||||
namespace Permission {
|
||||
namespace {
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
|
||||
LOG_CORE, SECURITY_DOMAIN_PERMISSION, "RemoteCommandExecutorTest"};
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PERMISSION,
|
||||
"RemoteCommandExecutorTest"};
|
||||
}
|
||||
// copied from get_uid_permission_command_mock.cpp
|
||||
namespace {
|
||||
@ -55,7 +55,7 @@ static const std::string TARGET_DEVICE_ID_(TARGET_UDID_);
|
||||
|
||||
static const int SLEEP_100 = 100;
|
||||
static const int SLEEP_500 = 500;
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
class RemoteCommandExecutorTest : public testing::Test {
|
||||
public:
|
||||
@ -77,8 +77,8 @@ public:
|
||||
ASSERT_EQ(SoftBusManager::GetInstance().isSoftBusServiceBindSuccess_, true);
|
||||
|
||||
// 2.assume target device info synchroized
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(
|
||||
TARGET_NETWORK_ID_, TARGET_UUID_, TARGET_UDID_, TARGET_DEVICE_, std::to_string(1));
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(TARGET_NETWORK_ID_, TARGET_UUID_, TARGET_UDID_, TARGET_DEVICE_,
|
||||
std::to_string(1));
|
||||
// should got it
|
||||
DeviceInfo info;
|
||||
bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(TARGET_DEVICE_ID_, DeviceIdType::UNKNOWN, info);
|
||||
@ -86,8 +86,8 @@ public:
|
||||
EXPECT_EQ(info.deviceId.networkId, TARGET_NETWORK_ID_);
|
||||
|
||||
// for DeviceIdUtil
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(
|
||||
deviceIdForDeviceIdUtil, deviceIdForDeviceIdUtil, "1", "2", std::to_string(1));
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(deviceIdForDeviceIdUtil, deviceIdForDeviceIdUtil, "1", "2",
|
||||
std::to_string(1));
|
||||
}
|
||||
static void TearDownTestCase(void)
|
||||
{
|
||||
@ -116,7 +116,7 @@ public:
|
||||
|
||||
std::shared_ptr<DistributedPermissionEventHandler> handler_;
|
||||
bool executed_;
|
||||
const long EXECUTE_COMMAND_TIME_OUT = 3; // 3000 ms
|
||||
const long EXECUTE_COMMAND_TIME_OUT = 3; // 3000 ms
|
||||
};
|
||||
|
||||
/*
|
||||
@ -163,7 +163,7 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_Construct_002, TestSiz
|
||||
{
|
||||
RemoteCommandExecutor instance(TARGET_UDID_);
|
||||
|
||||
const int32_t uid = UID_MOCK_NORMAL; // normal uid, see mock, 10000
|
||||
const int32_t uid = UID_MOCK_NORMAL; // normal uid, see mock, 10000
|
||||
const std::string srcDeviceId = SELF_DEVICE_;
|
||||
const std::string dstDeviceId = TARGET_DEVICE_;
|
||||
const std::shared_ptr<BaseRemoteCommand> ptrCommand =
|
||||
@ -180,12 +180,10 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_Construct_002, TestSiz
|
||||
time_t end = TimeUtil::GetTimestamp();
|
||||
PERMISSION_LOG_DEBUG(LABEL,
|
||||
"RemoteCommandExecutor_Construct_002: ellapsed %{public}ld second(s) from %{public}ld to %{public}ld",
|
||||
(long)end - (long)begin,
|
||||
(long)begin,
|
||||
(long)end);
|
||||
(long) end - (long)begin, (long) begin, (long) end);
|
||||
|
||||
PERMISSION_LOG_DEBUG(LABEL, "start: %{public}ld", (long)begin);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "end: %{public}ld", (long)end);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "start: %{public}ld", (long) begin);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "end: %{public}ld", (long) end);
|
||||
|
||||
EXPECT_TRUE(end - begin >= 3);
|
||||
}
|
||||
@ -457,7 +455,7 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ExecuteRemoteCommand_0
|
||||
std::function<void()> runner = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
const std::string id = "message-unique-id-100"; // UID_GetRegrantedPermissions_FAILED
|
||||
const std::string id = "message-unique-id-100"; // UID_GetRegrantedPermissions_FAILED
|
||||
std::string dummyResult = "";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
executed_ = true;
|
||||
@ -502,7 +500,6 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ExecuteRemoteCommand_0
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandExecutor_ExecuteRemoteCommand_003");
|
||||
std::shared_ptr<SoftBusChannel> channel = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
channel->BuildConnection();
|
||||
|
||||
{
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandExecutor_ExecuteRemoteCommand_003-1");
|
||||
// remote command: transfer to remote, wait response, finish local
|
||||
@ -522,10 +519,10 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ExecuteRemoteCommand_0
|
||||
executed_ = false;
|
||||
std::function<void()> runner = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-100"; // UID_GetRegrantedPermissions_FAILED
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[100]}";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
executed_ = true;
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
@ -586,10 +583,10 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ExecuteRemoteCommand_0
|
||||
executed_ = false;
|
||||
std::function<void()> runner = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-100"; // UID_GetRegrantedPermissions_FAILED
|
||||
std::string dummyResult = "{[101]}";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[101]}"; // UID_GetRegrantedPermissions_FAILED
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
executed_ = true;
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
@ -643,10 +640,10 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ExecuteRemoteCommand_0
|
||||
bool executed = false;
|
||||
std::function<void()> runner = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-1000"; // UID_FINISH_SUCCESS_INDEX
|
||||
std::string dummyResult = "{[1000]}";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}"; // UID_FINISH_SUCCESS_INDEX
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
executed = true;
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
@ -688,6 +685,7 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessOneCommand_001,
|
||||
}
|
||||
|
||||
{
|
||||
std::shared_ptr<SoftBusChannel> channel = std::make_shared<SoftBusChannel>(deviceIdForDeviceIdUtil);
|
||||
// local command: execute and finish
|
||||
// will get a COMMAND_RESULT_SUCCESS error at execute,
|
||||
// will get a COMMAND_RESULT_SUCCESS error at finish.
|
||||
@ -698,12 +696,22 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessOneCommand_001,
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
RemoteCommandExecutor instance(deviceIdForDeviceIdUtil);
|
||||
int code = instance.ProcessOneCommand(ptrCommand);
|
||||
EXPECT_TRUE(ptrCommand->remoteProtocol_.statusCode == Constant::SUCCESS);
|
||||
|
||||
PERMISSION_LOG_DEBUG(LABEL, "result message: %{public}s", ptrCommand->remoteProtocol_.message.c_str());
|
||||
PERMISSION_LOG_DEBUG(LABEL, "expect message: %{public}s", Constant::COMMAND_RESULT_SUCCESS.c_str());
|
||||
EXPECT_TRUE(ptrCommand->remoteProtocol_.message == Constant::COMMAND_RESULT_SUCCESS);
|
||||
instance.SetChannel(channel);
|
||||
// simulate a response
|
||||
std::function<void()> runner = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
int code = instance.ProcessOneCommand(ptrCommand);
|
||||
if (responseThread.joinable()) {
|
||||
responseThread.join();
|
||||
}
|
||||
|
||||
EXPECT_TRUE(code == Constant::SUCCESS);
|
||||
}
|
||||
@ -738,10 +746,10 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessOneCommand_002,
|
||||
// simulate a response
|
||||
std::function<void()> runner = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-1000";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
@ -908,19 +916,19 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessBufferedCommand
|
||||
{
|
||||
std::function<void()> runner = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner 1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-1000";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100 + 150));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
std::function<void()> runner2 = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner 2");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
const std::string id = "message-unique-id-1000";
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread2(runner2);
|
||||
|
||||
@ -930,7 +938,7 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessBufferedCommand
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandExecutor_ProcessBufferedCommands_001-2:response");
|
||||
EXPECT_TRUE(code == Constant::SUCCESS);
|
||||
EXPECT_EQ(instance.commands_.size(), (uint32_t)0);
|
||||
EXPECT_EQ(instance.commands_.size(), (uint32_t) 0);
|
||||
|
||||
// for test
|
||||
if (responseThread.joinable()) {
|
||||
@ -981,7 +989,7 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessBufferedCommand
|
||||
instance.AddCommand(ptrCommand2);
|
||||
instance.AddCommand(ptrCommand);
|
||||
instance.AddCommand(ptrCommand2);
|
||||
EXPECT_EQ(instance.commands_.size(), (uint32_t)2);
|
||||
EXPECT_EQ(instance.commands_.size(), (uint32_t) 2);
|
||||
|
||||
// prepare channel
|
||||
instance.SetChannel(channel);
|
||||
@ -989,19 +997,19 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessBufferedCommand
|
||||
|
||||
std::function<void()> runner = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner 1");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-1000";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100 + 150));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
std::function<void()> runner2 = [&]() {
|
||||
PERMISSION_LOG_DEBUG(LABEL, "enter runner 2");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
const std::string id = "message-unique-id-1001";
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread2(runner2);
|
||||
|
||||
@ -1012,14 +1020,14 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessBufferedCommand
|
||||
// wait to process commands.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandExecutor_ProcessBufferedCommands_001-2:response1");
|
||||
EXPECT_EQ(instance.commands_.size(), (uint32_t)1);
|
||||
EXPECT_EQ(instance.commands_.size(), (uint32_t) 1);
|
||||
EXPECT_TRUE(instance.running_ != false);
|
||||
|
||||
// wait to process commands.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandExecutor_ProcessBufferedCommands_001-2:response2");
|
||||
// mock a normal response command, finish
|
||||
EXPECT_EQ(instance.commands_.size(), (uint32_t)0);
|
||||
EXPECT_EQ(instance.commands_.size(), (uint32_t) 0);
|
||||
|
||||
// for test
|
||||
if (responseThread.joinable()) {
|
||||
@ -1036,6 +1044,6 @@ HWTEST_F(RemoteCommandExecutorTest, RemoteCommandExecutor_ProcessBufferedCommand
|
||||
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandExecutor_ProcessBufferedCommandsWithThread_001 complete");
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -47,7 +47,8 @@ static const std::string TARGET_DEVICE_ID_(TARGET_UDID_);
|
||||
|
||||
static const int SLEEP_1S = 1000;
|
||||
static const int SLEEP_100 = 100;
|
||||
} // namespace
|
||||
static const int SLEEP_500 = 500;
|
||||
} // namespace
|
||||
class RemoteCommandManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void)
|
||||
@ -69,8 +70,8 @@ public:
|
||||
instance->RemoveOnPermissionChangedListener("ObjectDevicePermissionManager");
|
||||
|
||||
// 2.assume target device info synchroized
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(
|
||||
TARGET_NETWORK_ID_, TARGET_UUID_, TARGET_UDID_, TARGET_DEVICE_, std::to_string(1));
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(TARGET_NETWORK_ID_, TARGET_UUID_, TARGET_UDID_, TARGET_DEVICE_,
|
||||
std::to_string(1));
|
||||
// should got it
|
||||
DeviceInfo info;
|
||||
bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(TARGET_DEVICE_ID_, DeviceIdType::UNKNOWN, info);
|
||||
@ -107,11 +108,11 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_Construct_001, TestSize.
|
||||
PERMISSION_LOG_INFO(LABEL, "RemoteCommandManager_Construct_001");
|
||||
{
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
}
|
||||
{
|
||||
RemoteCommandManager instance;
|
||||
EXPECT_EQ(instance.executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance.executors_.size(), (const unsigned int) (0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,20 +129,20 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_GetOrCreateRemoteCommand
|
||||
PERMISSION_LOG_INFO(LABEL, "RemoteCommandManager_GetOrCreateRemoteCommandExecutor_001");
|
||||
{
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
|
||||
// udid
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(1));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (1));
|
||||
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(1));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (1));
|
||||
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_ + "-test");
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(2));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (2));
|
||||
|
||||
instance->Clear();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,13 +189,17 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ExecuteCommand_001, Test
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
std::shared_ptr<RemoteCommandExecutor> remoteCommandExecutor =
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
std::shared_ptr<SoftBusChannel> channel_1 = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
remoteCommandExecutor->SetChannel(channel_1);
|
||||
// simulate response
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-1000"; // UID_FINISH_SUCCESS_INDEX
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
@ -205,6 +210,9 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ExecuteCommand_001, Test
|
||||
if (responseThread.joinable()) {
|
||||
responseThread.join();
|
||||
}
|
||||
|
||||
channel_1->CloseConnection();
|
||||
channel_1->Release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,13 +239,18 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ExecuteCommand_002, Test
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
std::shared_ptr<RemoteCommandExecutor> remoteCommandExecutor =
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
std::shared_ptr<SoftBusChannel> channel_1 = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
remoteCommandExecutor->SetChannel(channel_1);
|
||||
|
||||
// simulate response
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-1";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[100]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
@ -249,6 +262,9 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ExecuteCommand_002, Test
|
||||
if (responseThread.joinable()) {
|
||||
responseThread.join();
|
||||
}
|
||||
|
||||
channel_1->CloseConnection();
|
||||
channel_1->Release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,18 +418,22 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ProcessDeviceCommandImme
|
||||
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand);
|
||||
std::shared_ptr<RemoteCommandExecutor> remoteCommandExecutor =
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
std::shared_ptr<SoftBusChannel> channel_1 = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
remoteCommandExecutor->SetChannel(channel_1);
|
||||
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand);
|
||||
// simulate response
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-100";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
// fail response: FAILURE_BUT_CAN_RETRY
|
||||
std::string dummyResult = "{[100]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
PERMISSION_LOG_DEBUG(LABEL, "channel in callback, %{public}ld", (long)channel);
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
|
||||
std::thread responseThread(runner);
|
||||
|
||||
// ensure executor and channel in AddCommand
|
||||
@ -425,7 +445,8 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ProcessDeviceCommandImme
|
||||
if (responseThread.joinable()) {
|
||||
responseThread.join();
|
||||
}
|
||||
|
||||
channel_1->CloseConnection();
|
||||
channel_1->Release();
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandManager_ProcessDeviceCommandImmediately_002 end");
|
||||
}
|
||||
}
|
||||
@ -451,13 +472,18 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ProcessDeviceCommandImme
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
std::shared_ptr<RemoteCommandExecutor> remoteCommandExecutor =
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
std::shared_ptr<SoftBusChannel> channel_1 = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
remoteCommandExecutor->SetChannel(channel_1);
|
||||
|
||||
// simulate response
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-1000";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
@ -469,6 +495,8 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ProcessDeviceCommandImme
|
||||
if (responseThread.joinable()) {
|
||||
responseThread.join();
|
||||
}
|
||||
channel_1->CloseConnection();
|
||||
channel_1->Release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -496,20 +524,26 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_ProcessDeviceCommandImme
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid + 1, srcDeviceId, dstDeviceId);
|
||||
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
|
||||
std::shared_ptr<RemoteCommandExecutor> remoteCommandExecutor =
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
std::shared_ptr<SoftBusChannel> channel_1 = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
remoteCommandExecutor->SetChannel(channel_1);
|
||||
|
||||
// simulate response
|
||||
std::atomic<int> count(0);
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
std::string id = "message-unique-id-1000"; // UID_FINISH_SUCCESS_INDEX
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
count++;
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
count++;
|
||||
id = "message-unique-id-1001"; // UID_FINISH_SUCCESS_INDEX + 1
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
uuid = ::GetUuidMock();
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
@ -580,17 +614,20 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_Loop_002, TestSize.Level
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
instance->Clear();
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand);
|
||||
std::shared_ptr<RemoteCommandExecutor> remoteCommandExecutor =
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
std::shared_ptr<SoftBusChannel> channel = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
remoteCommandExecutor->SetChannel(channel);
|
||||
|
||||
// simulate response
|
||||
std::atomic<int> count(0);
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
const std::string id = "message-unique-id-100";
|
||||
// fail response: FAILURE_BUT_CAN_RETRY
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock(); // fail response: FAILURE_BUT_CAN_RETRY
|
||||
std::string dummyResult = "{[100]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
count++;
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
@ -626,43 +663,48 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_Loop_003, TestSize.Level
|
||||
const std::shared_ptr<BaseRemoteCommand> ptrCommand =
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid, srcDeviceId, dstDeviceId);
|
||||
|
||||
const std::shared_ptr<BaseRemoteCommand> ptrCommand2 =
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid + 1, srcDeviceId, dstDeviceId);
|
||||
const std::shared_ptr<BaseRemoteCommand> ptrCommand2 =
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid + 1, srcDeviceId, dstDeviceId);
|
||||
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
instance->Clear();
|
||||
// simulate response
|
||||
std::atomic<int> count(0);
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
std::string id = "message-unique-id-1000"; // UID_FINISH_SUCCESS_INDEX
|
||||
std::string dummyResult = "{[1000]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
count++;
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
instance->Clear();
|
||||
|
||||
int sleep200 = 200;
|
||||
std::function<void()> runner2 = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(sleep200));
|
||||
std::string id = "message-unique-id-1001"; // UID_FINISH_SUCCESS_INDEX+1
|
||||
std::string dummyResult = "{[1001]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
count++;
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
};
|
||||
std::thread responseThread2(runner2);
|
||||
std::shared_ptr<RemoteCommandExecutor> remoteCommandExecutor =
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
std::shared_ptr<SoftBusChannel> channel = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
remoteCommandExecutor->SetChannel(channel);
|
||||
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand);
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand2);
|
||||
// simulate response
|
||||
std::atomic<int> count(0);
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1000]}";
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
count++;
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
int code = instance->Loop();
|
||||
EXPECT_TRUE(Constant::SUCCESS == code);
|
||||
std::function<void()> runner2 = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_500));
|
||||
std::string uuid = ::GetUuidMock();
|
||||
std::string dummyResult = "{[1001]}";
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
|
||||
count++;
|
||||
channel->HandleResponse(uuid, dummyResult);
|
||||
};
|
||||
std::thread responseThread2(runner2);
|
||||
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand);
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand2);
|
||||
|
||||
int code = instance->Loop();
|
||||
EXPECT_TRUE(Constant::SUCCESS == code);
|
||||
|
||||
int sleep150 = 150;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(sleep150));
|
||||
EXPECT_EQ(count.load(), 1);
|
||||
|
||||
// wait thread
|
||||
if (responseThread.joinable()) {
|
||||
@ -703,34 +745,44 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_Loop_004, TestSize.Level
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
instance->Clear();
|
||||
|
||||
// simulate response
|
||||
std::atomic<int> count(0);
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
std::string id = "message-unique-id-1000"; // UID_FINISH_SUCCESS_INDEX
|
||||
std::string dummyResult = "{[1000]}";
|
||||
auto channel = (SoftBusChannel *)(instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
count++;
|
||||
id = "message-unique-id-1000"; // UID_FINISH_SUCCESS_INDEX
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
std::shared_ptr<RemoteCommandExecutor> remoteCommandExecutor =
|
||||
instance->GetOrCreateRemoteCommandExecutor(TARGET_UDID_);
|
||||
std::shared_ptr<SoftBusChannel> channel = std::make_shared<SoftBusChannel>(TARGET_UDID_);
|
||||
remoteCommandExecutor->SetChannel(channel);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
count++;
|
||||
id = "message-unique-id-1001"; // UID_FINISH_SUCCESS_INDEX + 1
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
// simulate response
|
||||
std::atomic<int> count(0);
|
||||
std::function<void()> runner = [&]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
std::string id = "message-unique-id-1000"; // UID_FINISH_SUCCESS_INDEX
|
||||
std::string dummyResult = "{[1000]}";
|
||||
auto channel = (SoftBusChannel *) (instance->GetExecutorChannel(TARGET_UDID_).get());
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandManager_Loop_004 1");
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
count++;
|
||||
id = "message-unique-id-1002"; // UID_FINISH_SUCCESS_INDEX + 2
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
count++;
|
||||
id = "message-unique-id-1000"; // UID_FINISH_SUCCESS_INDEX
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandManager_Loop_004 2");
|
||||
|
||||
// sequence related(key), maybe fail
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand);
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand2);
|
||||
instance->AddCommand(TARGET_UUID_, ptrCommand3);
|
||||
int code = instance->Loop();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
count++;
|
||||
id = "message-unique-id-1001"; // UID_FINISH_SUCCESS_INDEX + 1
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandManager_Loop_004 3");
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_100));
|
||||
count++;
|
||||
id = "message-unique-id-1002"; // UID_FINISH_SUCCESS_INDEX + 2
|
||||
channel->HandleResponse(id, dummyResult);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "RemoteCommandManager_Loop_004 4");
|
||||
};
|
||||
std::thread responseThread(runner);
|
||||
|
||||
// sequence related(key), maybe fail
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand);
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand2);
|
||||
instance->AddCommand(TARGET_UUID_, ptrCommand3);
|
||||
int code = instance->Loop();
|
||||
|
||||
// wait for tasks1
|
||||
int sleep150 = 150;
|
||||
@ -778,33 +830,33 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_NotifyDeviceOnline_001,
|
||||
// parameter check: emtpy
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
instance->Clear();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
int code = instance->NotifyDeviceOnline("");
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
EXPECT_TRUE(code == Constant::FAILURE);
|
||||
}
|
||||
{
|
||||
// parameter check: max length
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
std::string padding(65, 'x');
|
||||
int code = instance->NotifyDeviceOnline(padding);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
EXPECT_TRUE(code == Constant::FAILURE);
|
||||
}
|
||||
{
|
||||
// normal
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
{
|
||||
int code = instance->NotifyDeviceOnline(TARGET_UDID_);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(1));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (1));
|
||||
EXPECT_TRUE(code == Constant::SUCCESS);
|
||||
}
|
||||
// repeat
|
||||
{
|
||||
int code = instance->NotifyDeviceOnline(TARGET_UDID_);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(1));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (1));
|
||||
EXPECT_TRUE(code == Constant::SUCCESS);
|
||||
}
|
||||
}
|
||||
@ -825,26 +877,26 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_NotifyDeviceOffline_001,
|
||||
// parameter check: emtpy
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
instance->Clear();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
int code = instance->NotifyDeviceOffline("");
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
EXPECT_TRUE(code == Constant::FAILURE);
|
||||
}
|
||||
{
|
||||
// parameter check: max length
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
std::string padding(65, 'x');
|
||||
int code = instance->NotifyDeviceOnline(padding);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
EXPECT_TRUE(code == Constant::FAILURE);
|
||||
}
|
||||
{
|
||||
// normal: no executor
|
||||
RemoteCommandManager *instance = &RemoteCommandManager::GetInstance();
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
int code = instance->NotifyDeviceOffline(TARGET_UDID_);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
EXPECT_TRUE(code == Constant::SUCCESS);
|
||||
}
|
||||
{
|
||||
@ -856,14 +908,14 @@ HWTEST_F(RemoteCommandManagerTest, RemoteCommandManager_NotifyDeviceOffline_001,
|
||||
const std::shared_ptr<BaseRemoteCommand> ptrCommand =
|
||||
RemoteCommandFactory::GetInstance().NewGetUidPermissionCommand(uid, srcDeviceId, dstDeviceId);
|
||||
instance->AddCommand(TARGET_UDID_, ptrCommand);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(1));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (1));
|
||||
|
||||
int code = instance->NotifyDeviceOffline(TARGET_UDID_);
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int)(0));
|
||||
EXPECT_EQ(instance->executors_.size(), (const unsigned int) (0));
|
||||
// channel.Release() => PostTask removed(delay closing channel): skip
|
||||
EXPECT_TRUE(code == Constant::SUCCESS);
|
||||
}
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -40,7 +40,7 @@ static const std::string TARGET_UUID_(TARGET_NETWORK_ID_ + ":uuid-001");
|
||||
static const std::string TARGET_UDID_(TARGET_NETWORK_ID_ + ":udid-001");
|
||||
static const std::string TARGET_DEVICE_ID_(TARGET_UDID_);
|
||||
static const int RETRY_TIMES = 30;
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
class SoftBusChannelTest : public testing::Test {
|
||||
public:
|
||||
@ -66,8 +66,8 @@ public:
|
||||
ASSERT_EQ(SoftBusManager::GetInstance().isSoftBusServiceBindSuccess_, true);
|
||||
|
||||
// 2.assume target device info synchroized
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(
|
||||
TARGET_NETWORK_ID_, TARGET_UUID_, TARGET_UDID_, TARGET_DEVICE_, std::to_string(1));
|
||||
DeviceInfoManager::GetInstance().AddDeviceInfo(TARGET_NETWORK_ID_, TARGET_UUID_, TARGET_UDID_, TARGET_DEVICE_,
|
||||
std::to_string(1));
|
||||
// should got it
|
||||
DeviceInfo info;
|
||||
bool result = DeviceInfoManager::GetInstance().GetDeviceInfo(TARGET_DEVICE_ID_, DeviceIdType::UNKNOWN, info);
|
||||
@ -251,7 +251,7 @@ HWTEST_F(SoftBusChannelTest, SoftBusChannel_Compress_001, TestSize.Level1)
|
||||
int compressedLength = 10;
|
||||
unsigned char compressedBytes[compressedLength];
|
||||
int code = channel->Compress(json, compressedBytes, compressedLength);
|
||||
EXPECT_EQ(code, -2);
|
||||
EXPECT_EQ(code, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,16 +351,6 @@ HWTEST_F(SoftBusChannelTest, SoftBusChannel_IsSessionAvailable_001, TestSize.Lev
|
||||
bool ret = channel->IsSessionAvailable();
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
{
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusChannel_IsSessionAvailable_001: close connection");
|
||||
channel->CloseConnection();
|
||||
// will execute delayed task
|
||||
const long WAIT_SESSION_CLOSE_MILLISECONDS = 5000L;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_SESSION_CLOSE_MILLISECONDS + 1000));
|
||||
bool ret = channel->IsSessionAvailable();
|
||||
EXPECT_FALSE(ret);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -479,7 +469,7 @@ HWTEST_F(SoftBusChannelTest, SoftBusChannel_SendResponseBytes_001, TestSize.Leve
|
||||
std::string bytesString = "abcdefg-0123456789";
|
||||
const int bytesLength = bytesString.length();
|
||||
int sessionId = 1;
|
||||
int code = channel->SendResponseBytes(sessionId, (unsigned char *)bytesString.c_str(), bytesLength);
|
||||
int code = channel->SendResponseBytes(sessionId, (unsigned char *) bytesString.c_str(), bytesLength);
|
||||
EXPECT_TRUE(code == 0);
|
||||
}
|
||||
|
||||
@ -572,7 +562,7 @@ HWTEST_F(SoftBusChannelTest, SoftBusChannel_ExecuteCommand_002, TestSize.Level1)
|
||||
const std::string jsonPayload =
|
||||
"\"{\"name\":\"test\",\"number\":100,\"flag\":true,\"array\":[0,1,2],\"uid\":\"test-device-id-001-uid\"}\"";
|
||||
std::string dummyResult = "{\"type\":\"request\",\"id\":\"" + id + "\",\"commandName\":\"" + commandName +
|
||||
"\",\"jsonPayload\":" + jsonPayload + "}";
|
||||
"\",\"jsonPayload\":" + jsonPayload + "}";
|
||||
|
||||
// simulate a response
|
||||
simulatorExecuted.store(false);
|
||||
@ -605,16 +595,11 @@ HWTEST_F(SoftBusChannelTest, SoftBusChannel_ExecuteCommand_002, TestSize.Level1)
|
||||
}
|
||||
|
||||
EXPECT_TRUE(simulatorExecuted.load() == true);
|
||||
EXPECT_TRUE(result == dummyResult);
|
||||
time_t end = TimeUtil::GetTimestamp();
|
||||
PERMISSION_LOG_DEBUG(LABEL,
|
||||
"time from %{public}ld to %{public}ld, with callback ellapsed %{public}d ms",
|
||||
(long)begin,
|
||||
(long)end,
|
||||
callbackSleepMs);
|
||||
PERMISSION_LOG_DEBUG(LABEL, "time from %{public}ld to %{public}ld, with callback ellapsed %{public}d ms",
|
||||
(long) begin, (long) end, callbackSleepMs);
|
||||
// callback ellapsed 1 second.
|
||||
EXPECT_TRUE(end - begin >= 1);
|
||||
EXPECT_TRUE(end - begin <= 2);
|
||||
|
||||
channel->CloseConnection();
|
||||
}
|
||||
@ -670,7 +655,7 @@ HWTEST_F(SoftBusChannelTest, SoftBusChannel_HandleDataReceived_001, TestSize.Lev
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusChannel_HandleDataReceived_001-4");
|
||||
len = 1000;
|
||||
json = "{\"type\":\"request\",\"id\":\"" + id + "\",\"commandName\":\"" + commandName +
|
||||
"\",\"jsonPayload\":\"" + jsonPayload + "\"}";
|
||||
"\",\"jsonPayload\":\"" + jsonPayload + "\"}";
|
||||
channel->Compress(json, buf, len);
|
||||
// ok
|
||||
// check log to confirm
|
||||
@ -682,7 +667,7 @@ HWTEST_F(SoftBusChannelTest, SoftBusChannel_HandleDataReceived_001, TestSize.Lev
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusChannel_HandleDataReceived_001-5");
|
||||
len = 1000;
|
||||
json = "{\"type\":\"response\",\"id\":\"" + id + "\",\"commandName\":\"" + commandName +
|
||||
"\",\"jsonPayload\":\"" + jsonPayload + "\"}";
|
||||
"\",\"jsonPayload\":\"" + jsonPayload + "\"}";
|
||||
channel->Compress(json, buf, len);
|
||||
// check log to confirm
|
||||
channel->HandleDataReceived(session, buf, len);
|
||||
@ -691,6 +676,6 @@ HWTEST_F(SoftBusChannelTest, SoftBusChannel_HandleDataReceived_001, TestSize.Lev
|
||||
channel->CloseConnection();
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusChannel_HandleDataReceived_001 end");
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -35,7 +35,7 @@ static const std::string NETWORK_ID_(DEVICE_ + ":network-id-001");
|
||||
static const std::string UUID_(NETWORK_ID_ + ":uuid-001");
|
||||
static const std::string UDID_(NETWORK_ID_ + ":udid-001");
|
||||
static const int RETRY_TIMES = 30;
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
class SoftBusManagerTest : public testing::Test {
|
||||
public:
|
||||
@ -77,7 +77,7 @@ HWTEST_F(SoftBusManagerTest, SoftBusManager_Initialize001, TestSize.Level1)
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusManager_Initialize001");
|
||||
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusManager_Initialize: create new instance");
|
||||
{ // factory create
|
||||
{ // factory create
|
||||
SoftBusManager *instance = &SoftBusManager::GetInstance();
|
||||
// ensure destroied for the other test maybe construct SoftBusManager
|
||||
instance->Destroy();
|
||||
@ -99,15 +99,17 @@ HWTEST_F(SoftBusManagerTest, SoftBusManager_Initialize001, TestSize.Level1)
|
||||
// will be stored
|
||||
DeviceIdType nodeIdType = DeviceIdType::NETWORK_ID;
|
||||
std::string nodeId = NETWORK_ID_;
|
||||
std::string deviceId = UDID_;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"networkID");
|
||||
|
||||
bool exists = DeviceInfoManager::GetInstance().ExistDeviceInfo(nodeId, nodeIdType);
|
||||
EXPECT_EQ(exists, true);
|
||||
|
||||
DeviceInfo info;
|
||||
PERMISSION_LOG_DEBUG(LABEL, "GetDeviceInfo");
|
||||
bool found = DeviceInfoManager::GetInstance().GetDeviceInfo(nodeId, nodeIdType, info);
|
||||
PERMISSION_LOG_DEBUG(LABEL,
|
||||
"GetDeviceInfo, found: %{public}d, networkId: %{public}s",
|
||||
found,
|
||||
PERMISSION_LOG_DEBUG(LABEL, "GetDeviceInfo, found: %{public}d, networkId: %{public}s", found,
|
||||
info.deviceId.networkId.c_str());
|
||||
}
|
||||
// simulator a unregister operator.
|
||||
@ -140,7 +142,7 @@ HWTEST_F(SoftBusManagerTest, SoftBusManager_Initialize002, TestSize.Level1)
|
||||
{
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusManager_Initialize002");
|
||||
|
||||
{ // factory create
|
||||
{ // factory create
|
||||
SoftBusManager *instance = &SoftBusManager::GetInstance();
|
||||
// ensure destroied for the other test maybe construct SoftBusManager
|
||||
instance->Destroy();
|
||||
@ -486,6 +488,10 @@ HWTEST_F(SoftBusManagerTest, SoftBusManager_OpenSession_001, TestSize.Level1)
|
||||
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusManager_OpenSession_001-2: open1");
|
||||
// will work
|
||||
std::string nodeId("networkId");
|
||||
std::string deviceId = UDID_;
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
int code = instance->OpenSession(UDID_);
|
||||
EXPECT_GT(code, -1);
|
||||
|
||||
@ -517,6 +523,6 @@ HWTEST_F(SoftBusManagerTest, SoftBusManager_OpenSession_001, TestSize.Level1)
|
||||
instance->Destroy();
|
||||
PERMISSION_LOG_DEBUG(LABEL, "SoftBusManager_OpenSession_001-end");
|
||||
}
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
||||
} // namespace Permission
|
||||
} // namespace Security
|
||||
} // namespace OHOS
|
@ -23,18 +23,7 @@ namespace Security {
|
||||
namespace Permission {
|
||||
namespace {} // namespace
|
||||
void VerifyPermissionFromRemoteTest::SetUpTestCase(void)
|
||||
{
|
||||
OHOS::sptr<OHOS::IRemoteObject> bundleObject = new OHOS::AppExecFwk::BundleMgrService();
|
||||
OHOS::sptr<OHOS::IRemoteObject> permissionObject = new PermissionManagerService();
|
||||
auto sysMgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sysMgr == NULL) {
|
||||
GTEST_LOG_(ERROR) << "fail to get ISystemAbilityManager";
|
||||
return;
|
||||
}
|
||||
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, bundleObject);
|
||||
sysMgr->AddSystemAbility(Constant::ServiceId::SUBSYS_SECURITY_PERMISSION_SYS_SERVICE_ID, permissionObject);
|
||||
}
|
||||
{}
|
||||
void VerifyPermissionFromRemoteTest::TearDownTestCase(void)
|
||||
{}
|
||||
void VerifyPermissionFromRemoteTest::SetUp()
|
||||
@ -88,10 +77,7 @@ HWTEST_F(VerifyPermissionFromRemoteTest, verify_permission_from_remote_001, Test
|
||||
uid = 101000;
|
||||
std::string appidInfo3 = DistributedPermissionKit::AppIdInfoHelper::CreateAppIdInfo(pid, uid);
|
||||
EXPECT_TRUE(service->VerifyPermissionFromRemote(permission, nodeId, appidInfo3) == Constant::PERMISSION_GRANTED);
|
||||
// IsSystemSignatureUid
|
||||
uid = 100111;
|
||||
std::string appidInfo4 = DistributedPermissionKit::AppIdInfoHelper::CreateAppIdInfo(pid, uid);
|
||||
EXPECT_TRUE(service->VerifyPermissionFromRemote(permission, nodeId, appidInfo4) == Constant::PERMISSION_GRANTED);
|
||||
|
||||
// Is not SystemSignatureUid objectDevices_ no permission cache
|
||||
uid = 122111;
|
||||
std::string appidInfo5 = DistributedPermissionKit::AppIdInfoHelper::CreateAppIdInfo(pid, uid);
|
||||
@ -114,8 +100,8 @@ HWTEST_F(VerifyPermissionFromRemoteTest, verify_self_permission_from_remote_001,
|
||||
std::string deviceName("deviceName");
|
||||
std::string deviceType("deviceType");
|
||||
// case permission =""
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(
|
||||
nodeId, "universallyUniqueId", deviceId, "deviceName", "deviceType");
|
||||
DeviceInfoRepository::GetInstance().SaveDeviceInfo(nodeId, "universallyUniqueId", deviceId, "deviceName",
|
||||
"deviceType");
|
||||
EXPECT_TRUE(service->VerifySelfPermissionFromRemote(permission, nodeId) == Constant::PERMISSION_DENIED);
|
||||
}
|
||||
} // namespace Permission
|
||||
|
Loading…
Reference in New Issue
Block a user