diff --git a/storage/BUILD.gn b/storage/BUILD.gn index b4c412db4f9390c83de53e7d6e6abf92257f9145..5d8ea59bfbd091ea94e485b208742010fd635e35 100644 --- a/storage/BUILD.gn +++ b/storage/BUILD.gn @@ -20,6 +20,7 @@ group("storage") { "storagefileioerrorjstest:storagefileioerror_js_test", "storagefileiojstest:storagefileio_js_test", "storagefilejstest:storagefile_js_test", + "storagesecuritylabeljstest:storagesecuritylabel_js_test", "storagestatfsjstest:storagestatfs_js_test", ] } diff --git a/storage/storagesecuritylabeljstest/BUILD.gn b/storage/storagesecuritylabeljstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cef131ddd483d2743b0813fa3a7271a4e8a8108a --- /dev/null +++ b/storage/storagesecuritylabeljstest/BUILD.gn @@ -0,0 +1,31 @@ +# 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. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("storagesecuritylabel_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":storagesecuritylabel_js_assets", + ":storagesecuritylabel_js_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsStorageSecurityLabelJSTest" +} +ohos_js_assets("storagesecuritylabel_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("storagesecuritylabel_js_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/storage/storagesecuritylabeljstest/Test.json b/storage/storagesecuritylabeljstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..540d87082d7fc6604f9a676794ad8f9c8974591d --- /dev/null +++ b/storage/storagesecuritylabeljstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for storage securitylabel Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "60000", + "package": "ohos.acts.storage.securitylabel", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "ActsStorageSecurityLabelJSTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/storage/storagesecuritylabeljstest/signature/openharmony_sx.p7b b/storage/storagesecuritylabeljstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/storage/storagesecuritylabeljstest/signature/openharmony_sx.p7b differ diff --git a/storage/storagesecuritylabeljstest/src/main/config.json b/storage/storagesecuritylabeljstest/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..24dff049de74d4776ebad7d7cc7acd5a37000d49 --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "ohos.acts.storage.securitylabel", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.storage.securitylabel", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.storage.securitylabel.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/app.js b/storage/storagesecuritylabeljstest/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..60ee141c8dbd251c763b7b74552b5a133a774d6a --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * 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. + */ + +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/i18n/en-US.json b/storage/storagesecuritylabeljstest/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..ead52ed2e09ec82aaf7aa9f4e714ed39ea88308e --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "Test" + } +} \ No newline at end of file diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/i18n/zh-CN.json b/storage/storagesecuritylabeljstest/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..3f48f2585b24a8fe4a745e8ee2972a9e991a7803 --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "测试" + } +} \ No newline at end of file diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.css b/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.hml b/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.js b/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..61921cf3ba7d0a16a9c2edb9b9f04c1fb69a6333 --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/pages/index/index.js @@ -0,0 +1,41 @@ +/* + * 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. + */ + +import app from '@system.app' + +import {Core} from 'deccjsunit/index' + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + require('../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/test/Common.js b/storage/storagesecuritylabeljstest/src/main/js/default/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..66141751d1d079cc2a5650cab2500b89e5edd994 --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/test/Common.js @@ -0,0 +1,42 @@ +/* + * 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. + */ + +import securitylabel from '@ohos.securitylabel'; +import fileio from '@ohos.fileio'; +import featureAbility from '@ohos.ability.featureAbility'; + +import { + describe, beforeAll, beforeEach, afterEach, afterAll, it, expect +} +from 'deccjsunit/index' + +export async function nextFileName(testName) { + let context = featureAbility.getContext(); + let data = await context.getFilesDir(); + let BASE_PATH = data.substring(0, data.length - 5) + 'cache/'; + return BASE_PATH + testName; +} + +export { + describe, + beforeAll, + beforeEach, + afterEach, + afterAll, + it, + expect, + securitylabel, + fileio +}; \ No newline at end of file diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/test/List.test.js b/storage/storagesecuritylabeljstest/src/main/js/default/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..1d4d537418fcc60242afcf921a74c922d5133580 --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/test/List.test.js @@ -0,0 +1,16 @@ +/* + * 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. + */ + +require('./securitylabel.test.js'); diff --git a/storage/storagesecuritylabeljstest/src/main/js/default/test/securitylabel.test.js b/storage/storagesecuritylabeljstest/src/main/js/default/test/securitylabel.test.js new file mode 100644 index 0000000000000000000000000000000000000000..608e8f18b1bc1f358003ddd0eccfcb8847c8ac55 --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/js/default/test/securitylabel.test.js @@ -0,0 +1,409 @@ +/* + * 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. + */ + +import { + describe, it, expect, securitylabel, nextFileName, fileio +} from './Common'; + +describe('securitylabel', function () { + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0000 + * @tc.name securitylabel_test_set_security_label_async_000 + * @tc.desc Test that the setSecurityLabel() interface callback to set the data label. Test the getSecurityLabel() interface callback to get the data label. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_000', 0, async function (done) { + let fpath = await nextFileName('test.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + securitylabel.setSecurityLabel(fpath, 's0', function (err) { + securitylabel.getSecurityLabel(fpath, function (err, dataLevel) { + expect(dataLevel == 's0').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + }) + } catch (e) { + console.log('securitylabel_test_set_security_label_async_000 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0010 + * @tc.name securitylabel_test_set_security_label_async_001 + * @tc.desc Test that the setSecurityLabel() interface callback to set the data label. Test the getSecurityLabel() interface promises to get the data label. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_001', 0, async function (done) { + let fpath = await nextFileName('test1.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + securitylabel.setSecurityLabel(fpath, 's1', async function (err) { + let dataLevel = await securitylabel.getSecurityLabel(fpath); + expect(dataLevel == 's1').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + } catch (e) { + console.log('securitylabel_test_set_security_label_async_001 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0020 + * @tc.name securitylabel_test_set_security_label_async_002 + * @tc.desc Test that the setSecurityLabel() interface promises to set the data label. Test the getSecurityLabel() interface callback to get the data label. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_002', 0, async function (done) { + let fpath = await nextFileName('test2.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + await securitylabel.setSecurityLabel(fpath, 's2'); + securitylabel.getSecurityLabel(fpath, function (err, dataLevel) { + expect(dataLevel == 's2').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }) + } catch (e) { + console.log('securitylabel_test_set_security_label_async_002 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0030 + * @tc.name securitylabel_test_set_security_label_async_003 + * @tc.desc Test that the setSecurityLabel() interface promises to set the data label. Test the getSecurityLabel() interface promises to get the data label. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_003', 0, async function (done) { + let fpath = await nextFileName('test3.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + await securitylabel.setSecurityLabel(fpath, 's3'); + let dataLevel = await securitylabel.getSecurityLabel(fpath); + expect(dataLevel == 's3').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('securitylabel_test_set_security_label_async_003 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0040 + * @tc.name securitylabel_test_set_security_label_async_004 + * @tc.desc Test that the setSecurityLabel() interface promises to set the data label. Test the getSecurityLabel() interface promises to get the data label. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_004', 0, async function (done) { + let fpath = await nextFileName('test4.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + await securitylabel.setSecurityLabel(fpath, 's4'); + let dataLevel = await securitylabel.getSecurityLabel(fpath); + expect(dataLevel == 's4').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + } catch (e) { + console.log('securitylabel_test_set_security_label_async_004 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0050 + * @tc.name securitylabel_test_set_security_label_async_005 + * @tc.desc Test setSecurityLabel() interfaces. return false when path is empty string. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_005', 0, async function (done) { + try { + securitylabel.setSecurityLabel('', 's0', function (err) { + expect(err.code == '-1').assertTrue(); + done(); + }); + } catch (e) { + console.log('securitylabel_test_set_security_label_async_005 has failed for ' + e); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0060 + * @tc.name securitylabel_test_set_security_label_async_006 + * @tc.desc Test setSecurityLabel() interfaces. return false when the path is invalid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_006', 0, async function (done) { + try { + securitylabel.setSecurityLabel('/data/test.txt', 's0', function (err) { + expect(err.code == '-1').assertTrue(); + done(); + }); + } catch (e) { + console.log('securitylabel_test_set_security_label_async_006 has failed for ' + e); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0070 + * @tc.name securitylabel_test_set_security_label_async_007 + * @tc.desc Test setSecurityLabel() interfaces. Throw exception when path is empty. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_007', 0, async function (done) { + try { + await securitylabel.setSecurityLabel('s0'); + expect(null).assertFail(); + done(); + } catch (e) { + console.log('securitylabel_test_set_security_label_async_007 has failed for ' + e); + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0080 + * @tc.name securitylabel_test_set_security_label_async_008 + * @tc.desc Test setSecurityLabel() interfaces. return false when dataLevel is empty string. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_008', 0, async function (done) { + let fpath = await nextFileName('test5.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + securitylabel.setSecurityLabel(fpath, '', async function (err) { + expect(err.code == '-1').assertTrue(); + let dataLevel = await securitylabel.getSecurityLabel(fpath); + expect(dataLevel == '').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('securitylabel_test_set_security_label_async_008 has failed for ' + e); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0090 + * @tc.name securitylabel_test_set_security_label_async_009 + * @tc.desc Test setSecurityLabel() interfaces. return false when the dataLevel is invalid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_009', 0, async function (done) { + let fpath = await nextFileName('test6.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + securitylabel.setSecurityLabel(fpath, 'ss', async function (err) { + expect(err.code == '-1').assertTrue(); + let dataLevel = await securitylabel.getSecurityLabel(fpath); + expect(dataLevel == '').assertTrue(); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + done(); + }); + } catch (e) { + console.log('securitylabel_test_set_security_label_async_009 has failed for ' + e); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0100 + * @tc.name securitylabel_test_set_security_label_async_010 + * @tc.desc Test setSecurityLabel() interfaces. Throw exception when dataLevel is empty. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_010', 0, async function (done) { + let fpath = await nextFileName('test7.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + await securitylabel.setSecurityLabel(fpath); + expect(null).assertFail(); + done(); + } catch (e) { + console.log('securitylabel_test_set_security_label_async_010 has failed for ' + e); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_SET_SECURITY_LABEL_0110 + * @tc.name securitylabel_test_set_security_label_async_011 + * @tc.desc Test setSecurityLabel() interfaces. Throws an exception when passing multiple parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_set_security_label_async_011', 0, async function (done) { + let fpath = await nextFileName('test8.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + securitylabel.setSecurityLabel(fpath, 's0', '', function (err) { + done(); + }) + } catch (e) { + console.log('securitylabel_test_set_security_label_async_011 has failed for ' + e); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0000 + * @tc.name securitylabel_test_get_security_label_async_000 + * @tc.desc Test getSecurityLabel() interfaces. return empty when path is empty string. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_get_security_label_async_000', 0, async function (done) { + try { + let dataLevel = await securitylabel.getSecurityLabel(''); + expect(dataLevel == '').assertTrue(); + done(); + } catch (e) { + console.log('securitylabel_test_get_security_label_async_000 has failed for ' + e); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0010 + * @tc.name securitylabel_test_get_security_label_async_001 + * @tc.desc Test getSecurityLabel() interfaces. return empty when the path is invalid. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_get_security_label_async_001', 0, async function (done) { + try { + let dataLevel = await securitylabel.getSecurityLabel('/data/test.txt'); + expect(dataLevel == '').assertTrue(); + done(); + } catch (e) { + console.log('securitylabel_test_get_security_label_async_001 has failed for ' + e); + expect(null).assertFail(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0020 + * @tc.name securitylabel_test_get_security_label_async_002 + * @tc.desc Test getSecurityLabel() interfaces. Throw exception when path is empty. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_get_security_label_async_002', 0, async function (done) { + try { + await securitylabel.getSecurityLabel(); + expect(null).assertFail(); + done(); + } catch (e) { + console.log('securitylabel_test_get_security_label_async_002 has failed for ' + e); + expect(!!e).assertTrue(); + done(); + } + }); + + /** + * @tc.number SUB_DF_SECURITYLABEL_GET_SECURITY_LABEL_0030 + * @tc.name securitylabel_test_get_security_label_async_003 + * @tc.desc Test getSecurityLabel() interfaces. Throws an exception when passing multiple parameters. + * @tc.size MEDIUM + * @tc.type Function + * @tc.level Level 0 + * @tc.require + */ + it('securitylabel_test_get_security_label_async_003', 0, async function (done) { + let fpath = await nextFileName('test9.txt'); + fileio.openSync(fpath, 0o102, 0o666); + + try { + securitylabel.getSecurityLabel(fpath, '', function(err, dataLevel) { + done(); + }); + } catch (e) { + console.log('securitylabel_test_get_security_label_async_003 has failed for ' + e); + expect(fileio.unlinkSync(fpath) == null).assertTrue(); + expect(!!e).assertTrue(); + done(); + } + }); +}); diff --git a/storage/storagesecuritylabeljstest/src/main/resources/base/element/string.json b/storage/storagesecuritylabeljstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0d7cf2eebb9d86e29029caf4526260b501e9456a --- /dev/null +++ b/storage/storagesecuritylabeljstest/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Storagesecuritylabeljstest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/storage/storagesecuritylabeljstest/src/main/resources/base/media/icon.png b/storage/storagesecuritylabeljstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/storage/storagesecuritylabeljstest/src/main/resources/base/media/icon.png differ