From e3bc131604f5e1290ca64ae8eef64325d14bee97 Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Fri, 6 Sep 2024 10:04:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=8D=E5=90=88=E7=90=86=E4=BB=A3=E7=A0=81=E5=9B=9E=E9=80=80?= =?UTF-8?q?=20Signed-off-by:=20cuiruibin=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/common/src/common_func.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/interfaces/common/src/common_func.cpp b/interfaces/common/src/common_func.cpp index 8cc7572b0..8cdb66b62 100644 --- a/interfaces/common/src/common_func.cpp +++ b/interfaces/common/src/common_func.cpp @@ -15,7 +15,6 @@ #include "common_func.h" -#include #include #include "bundle_mgr_proxy.h" @@ -36,8 +35,6 @@ namespace { const char BACKFLASH = '/'; const std::string FILE_MANAGER_URI_HEAD = "/storage/"; const std::string FILE_MANAGER_AUTHORITY = "docs"; - std::string g_bundleName = ""; - std::mutex g_globalMutex; } static sptr GetBundleMgrProxy() { @@ -91,13 +88,7 @@ string CommonFunc::GetUriFromPath(const string &path) string realPath = path; NormalizePath(realPath); - { - std::lock_guard lock(g_globalMutex); - if (g_bundleName == "") { - g_bundleName = GetSelfBundleName(); - } - } - string packageName = (path.find(FILE_MANAGER_URI_HEAD) == 0) ? FILE_MANAGER_AUTHORITY : g_bundleName; + string packageName = (path.find(FILE_MANAGER_URI_HEAD) == 0) ? FILE_MANAGER_AUTHORITY : GetSelfBundleName(); realPath = FILE_SCHEME_PREFIX + packageName + SandboxHelper::Encode(realPath); return realPath; } -- Gitee From eac78e800a651791891bcacea9388bd18d33726a Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Sat, 14 Sep 2024 17:49:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8Djs=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=20Signed-off-by:=20cuiruibin=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unittest/js_file_permission_test/BUILD.gn | 1 - .../nopermission/BUILD.gn | 21 -- .../nopermission/FilePermission.test.js | 222 ------------------ .../nopermission/config.json | 62 ----- .../nopermission/signature/openharmony_sx.p7b | Bin 3417 -> 0 bytes .../unittest/js_file_uri_test/FileUri.test.js | 26 +- 6 files changed, 10 insertions(+), 322 deletions(-) delete mode 100644 test/unittest/js_file_permission_test/nopermission/BUILD.gn delete mode 100644 test/unittest/js_file_permission_test/nopermission/FilePermission.test.js delete mode 100644 test/unittest/js_file_permission_test/nopermission/config.json delete mode 100644 test/unittest/js_file_permission_test/nopermission/signature/openharmony_sx.p7b diff --git a/test/unittest/js_file_permission_test/BUILD.gn b/test/unittest/js_file_permission_test/BUILD.gn index 61b4f7ca2..5e505e405 100644 --- a/test/unittest/js_file_permission_test/BUILD.gn +++ b/test/unittest/js_file_permission_test/BUILD.gn @@ -18,6 +18,5 @@ group("unittest") { deps = [] deps += [ "permission:FileShareTestPermission" ] - deps += [ "nopermission:FileShareTestNoPermission" ] } ############################################################################### diff --git a/test/unittest/js_file_permission_test/nopermission/BUILD.gn b/test/unittest/js_file_permission_test/nopermission/BUILD.gn deleted file mode 100644 index 2ca47563a..000000000 --- a/test/unittest/js_file_permission_test/nopermission/BUILD.gn +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (C) 2024 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. -import("//build/test.gni") - -ohos_js_unittest("FileShareTestNoPermission") { - module_out_path = "filemanagement/app_file_service" - - hap_profile = "./config.json" - - certificate_profile = "./signature/openharmony_sx.p7b" -} diff --git a/test/unittest/js_file_permission_test/nopermission/FilePermission.test.js b/test/unittest/js_file_permission_test/nopermission/FilePermission.test.js deleted file mode 100644 index 44937de0a..000000000 --- a/test/unittest/js_file_permission_test/nopermission/FilePermission.test.js +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (C) 2024 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. - */ - - -import {describe, beforeAll, afterAll, it, expect} from 'deccjsunit/index' -import fileShare from '@ohos.fileshare' -import fileuri from '@ohos.file.fileuri' -import fs from '@ohos.file.fs' - -const DEVICE_TYPE_ERR = 801; -const PERMISSION_ERR = 201; - -describe('FileShareJSTest', function () { - beforeAll(async function () { - console.info('beforeAll'); - }) - - afterAll(async function () { - console.info('afterAll'); - }) - - /** - * @tc.name: persist_permission_test - * @tc.desc: Test persistPermission without system capability - * @tc.type: FUNC test - * @tc.require: issueI#I956FN - */ - it('persist_permission_test', 0, async function (done) { - console.info(`persist_permission_test start`); - let filePath = "/data/storage/el2/base/persist_permission_test.txt"; - let uriObject = new fileuri.FileUri(filePath); - let uri = uriObject.toString(); - let fd = await fs.open(uri, fs.OpenMode.CREATE); - await fs.close(fd); - let policyInfo = { uri: uri, operationMode: fileShare.OperationMode.READ_MODE }; - let policies = [policyInfo]; - try { - fileShare.persistPermission(policies).then(() => { - expect(false).assertTrue(); - done(); - }).catch((err) => { - console.info(`persist_permission_test err : ${err.code}`); - expect(false).assertTrue(); - }) - } catch (error) { - console.info(`persist_permission_test error : ${error.code}`); - if (error.code == DEVICE_TYPE_ERR) { - expect(true).assertTrue(); - } else if (error.code == PERMISSION_ERR) { - expect(true).assertTrue(); - } else { - expect(false).assertTrue(); - } - done(); - } - console.info(`persist_permission_test end`); - }) - - /** - * @tc.name: revoke_permission_test - * @tc.desc: Test revokePermission without system capability - * @tc.type: FUNC test - * @tc.require: issueI#I956FN - */ - it('revoke_permission_test', 0, async function (done) { - console.info(`revoke_permission_test start`); - let filePath = "/data/storage/el2/base/revoke_permission_test.txt"; - let uriObject = new fileuri.FileUri(filePath); - let uri = uriObject.toString(); - let fd = await fs.open(uri, fs.OpenMode.CREATE); - await fs.close(fd); - let policyInfo = { uri: uri, operationMode: fileShare.OperationMode.READ_MODE }; - let policies = [policyInfo]; - try { - fileShare.revokePermission(policies).then(() => { - expect(false).assertTrue(); - done(); - }).catch((err) => { - console.info(`revoke_permission_test err : ${err.code}`); - expect(false).assertTrue(); - done(); - }) - } catch (error) { - console.info(`revoke_permission_test error : ${error.code}`); - if (error.code == DEVICE_TYPE_ERR) { - expect(true).assertTrue(); - } else if (error.code == PERMISSION_ERR) { - expect(true).assertTrue(); - } else { - expect(false).assertTrue(); - } - done(); - } - console.info(`revoke_permission_test end`); - }) - - /** - * @tc.name: activate_permission_test - * @tc.desc: Test activatePermission without system capability - * @tc.type: FUNC test - * @tc.require: issueI#I956FN - */ - it('activate_permission_test', 0, async function (done) { - console.info(`activate_permission_test start`); - let filePath = "/data/storage/el2/base/activate_permission_test.txt"; - let uriObject = new fileuri.FileUri(filePath); - let uri = uriObject.toString(); - let fd = await fs.open(uri, fs.OpenMode.CREATE); - await fs.close(fd); - let policyInfo = { uri: uri, operationMode: fileShare.OperationMode.READ_MODE }; - let policies = [policyInfo]; - try { - fileShare.activatePermission(policies).then(() => { - expect(false).assertTrue(); - done(); - }).catch((err) => { - console.info(`activate_permission_test err : ${err.code}`); - expect(false).assertTrue(); - done(); - }) - } catch (error) { - console.info(`activate_permission_test error : ${error.code}`); - if (error.code == DEVICE_TYPE_ERR) { - expect(true).assertTrue(); - } else if (error.code == PERMISSION_ERR) { - expect(true).assertTrue(); - } else { - expect(false).assertTrue(); - } - done(); - } - console.info(`activate_permission_test end`); - }) - - /** - * @tc.name: deactivate_permission_test - * @tc.desc: Test deactivatePermission without system capability - * @tc.type: FUNC test - * @tc.require: issueI#I956FN - */ - it('deactivate_permission_test', 0, async function (done) { - console.info(`deactivate_permission_test start`); - let filePath = "/data/storage/el2/base/deactivate_permission_test.txt"; - let uriObject = new fileuri.FileUri(filePath); - let uri = uriObject.toString(); - let fd = await fs.open(uri, fs.OpenMode.CREATE); - await fs.close(fd); - let policyInfo = { uri: uri, operationMode: fileShare.OperationMode.READ_MODE }; - let policies = [policyInfo]; - try { - fileShare.deactivatePermission(policies).then(() => { - expect(false).assertTrue(); - done(); - }).catch((err) => { - console.info(`deactivate_permission_test err : ${err.code}`); - expect(false).assertTrue(); - done(); - }) - } catch (error) { - console.info(`deactivate_permission_test error : ${error.code}`); - if (error.code == DEVICE_TYPE_ERR) { - expect(true).assertTrue(); - } else if (error.code == PERMISSION_ERR) { - expect(true).assertTrue(); - } else { - expect(false).assertTrue(); - } - done(); - } - console.info(`deactivate_permission_test end`); - }) - - /** - * @tc.name: check_persistent_permission_test - * @tc.desc: Test checkPersistentPermission without system capability - * @tc.type: FUNC test - * @tc.require: issueI#I956FN - */ - it('check_persistent_permission_test', 0, async function (done) { - console.info(`check_persistent_permission_test start`); - let filePath = "/data/storage/el2/base/check_persistent_permission_test.txt"; - let uriObject = new fileuri.FileUri(filePath); - let uri = uriObject.toString(); - let fd = await fs.open(uri, fs.OpenMode.CREATE); - await fs.close(fd); - let policyInfo = { uri: uri, operationMode: fileShare.OperationMode.READ_MODE }; - let policies = [policyInfo]; - try { - fileShare.checkPersistentPermission(policies).then(() => { - expect(false).assertTrue(); - done(); - }).catch((err) => { - console.info(`check_persistent_permission_test err : ${err.code}`); - expect(false).assertTrue(); - done(); - }) - } catch (error) { - console.info(`check_persistent_permission_test error : ${error.code}`); - if (error.code == DEVICE_TYPE_ERR) { - expect(true).assertTrue(); - } else if (error.code == PERMISSION_ERR) { - expect(true).assertTrue(); - } else { - expect(false).assertTrue(); - } - done(); - } - console.info(`check_persistent_permission_test end`); - }) -}); \ No newline at end of file diff --git a/test/unittest/js_file_permission_test/nopermission/config.json b/test/unittest/js_file_permission_test/nopermission/config.json deleted file mode 100644 index 8f6634538..000000000 --- a/test/unittest/js_file_permission_test/nopermission/config.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "app": { - "bundleName": "ohos.file.share.nopermission.test", - "vendor": "acts", - "version": { - "code": 1000000, - "name": "1.0.0" - }, - "apiVersion": { - "compatible": 8, - "target": 9 - } - }, - "deviceConfig": {}, - "module": { - "package": "ohos.file.share.nopermission.test", - "name": ".MainAbility", - "deviceType": [ - "default", - "tablet", - "2in1" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry" - }, - "abilities": [ - { - "visible": true, - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "ohos.file.share.nopermission.test.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:app_name", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } -} \ No newline at end of file diff --git a/test/unittest/js_file_permission_test/nopermission/signature/openharmony_sx.p7b b/test/unittest/js_file_permission_test/nopermission/signature/openharmony_sx.p7b deleted file mode 100644 index 3528762252387c3678f5b3218daefb7a353c5f78..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3417 zcmcgvdstKF87CK@h!GS8#S0jzI5F^@+(>9`JtueI1QHTRA`VZIljJ}+C*;COa9SHz zCR%l_o3eVt8)}PoQ(I(vYFjsDwpM3r-PVeo7q;qbU8k+CKDwO)OuH z{UI8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nd^^Ao_@}9;iNxx-|3BIUyA*_?Fblk|0L(~wLs0yoltaZ zIW{Hjv&r+dFJ|VUE6;E4T~xf{w_DcSs*UzeO@57=8|htrqTtsTrI$aMJg#WT-=<|) U+q(jPF`v+FJbEwXz0K$T3#7VA&j0`b diff --git a/test/unittest/js_file_uri_test/FileUri.test.js b/test/unittest/js_file_uri_test/FileUri.test.js index 81419286c..b275622d3 100644 --- a/test/unittest/js_file_uri_test/FileUri.test.js +++ b/test/unittest/js_file_uri_test/FileUri.test.js @@ -100,11 +100,12 @@ describe('FileShareJSTest', function () { console.info(`get_path_from_uri_test_002 start`); try { let uri = "file://com.example.filesharea/data/storage/el2/base/files/getpathtest002.txt"; - let resultPath = "/data/storage/el2/share/r/com.example.filesharea/data/storage/el2/base/files/getpathtest002.txt"; + let resultSharePath = "/data/storage/el2/share/r/com.example.filesharea/data/storage/el2/base/files/getpathtest002.txt"; + let resultPath = "/storage/Users/currentUser/appdata/el2/base/com.example.filesharea/files/getpathtest002.txt"; let fileUriObject = new fileuri.FileUri(uri); let realPath = fileUriObject.path; console.info(`getPathFromUri success: ${JSON.stringify(realPath)}`); - expect(resultPath == realPath).assertTrue(); + expect(resultSharePath == realPath || realPath == resultPath).assertTrue(); } catch (error) { console.error(`getPathFromUri failed:${JSON.stringify(error)}`); expect(false).assertTrue(); @@ -121,20 +122,13 @@ describe('FileShareJSTest', function () { it('get_path_from_uri_test_003', 0, async function () { console.info(`get_path_from_uri_test_003 start`); try { - let uri = "file://docs/storage/Users/currentUser/Documents/getpathtest003.txt"; - if (deviceInfo.deviceType != '2in1') { - let resultPath = "/data/storage/el2/share/r/docs/storage/Users/currentUser/Documents/getpathtest003.txt"; - let fileUriObject = new fileuri.FileUri(uri); - let realPath = fileUriObject.path; - console.info(`getPathFromUri success: ${JSON.stringify(realPath)}`); - expect(resultPath == realPath).assertTrue(); - } else { - let resultPath = "/storage/Users/currentUser/Documents/getpathtest003.txt"; - let fileUriObject = new fileuri.FileUri(uri); - let realPath = fileUriObject.path; - console.info(`getPathFromUri success: ${JSON.stringify(realPath)}`); - expect(resultPath == realPath).assertTrue(); - } + let uri = "file://com.example.demo/data/storage/el2/base/files/test002.txt"; + let resultSharePath = "/data/storage/el2/share/r/com.example.demo/data/storage/el2/base/files/test002.txt"; + let resultPath = "/storage/Users/currentUser/appdata/el2/base/com.example.demo/files/test002.txt"; + let fileUriObject = new fileuri.FileUri(uri); + let realPath = fileUriObject.path; + console.info(`getPathFromUri success: ${JSON.stringify(realPath)}`); + expect(resultSharePath == realPath || realPath == resultPath).assertTrue(); } catch (error) { console.error(`getPathFromUri failed:${JSON.stringify(error)}`); expect(false).assertTrue(); -- Gitee