未验证 提交 f2e73260 编写于 作者: O openharmony_ci 提交者: Gitee

!5380 FA模型支持dataability权限校验需求xts用例

Merge pull request !5380 from mingxihua/master
......@@ -69,6 +69,18 @@
"type": "data",
"visible": true,
"uri": "dataability://com.example.myapplication.DataAbility2"
},
{
"srcPath": "TestDataAbility3",
"name": ".TestDataAbility3",
"icon": "$media:icon",
"srcLanguage": "ets",
"description": "$string:description_testdataability",
"type": "data",
"visible": true,
"uri": "dataability://com.example.myapplication.DataAbility3",
"readPermission": "ohos.permission.READ_CONTACTS",
"writePermission": "ohos.permission.WRITE_CONTACTS"
}
],
"js": [
......
/*
* Copyright (C) 2022 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 dataAbility from '@ohos.data.dataAbility'
import featureAbility from '@ohos.ability.featureAbility'
import fileio from '@ohos.fileio'
import dataRdb from '@ohos.data.rdb'
const TABLE_NAME = 'book'
const STORE_CONFIG = {name: 'book.db'}
const SQL_CREATE_TABLE = 'CREATE TABLE IF NOT EXISTS book' +
'(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER, introduction TEXT NOT NULL)'
let rdbStore: any = undefined
const TAG = 'ACTS_ DataAbility.data'
const context = featureAbility.getContext()
let defaultReturn = 1;
let returnError = 0;
let returnError1 = -1;
let returnError2 = -2;
let returnError3 = -3;
let dataAbilityUri = ("dataability:///com.example.myapplication.DataAbility3");
export default {
onInitialized(abilityInfo) {
console.debug('ACTS_ DataAbility onInitialized,abilityInfo=' + abilityInfo.bundleName)
dataRdb.getRdbStore(context, STORE_CONFIG, 1, (err, store) => {
console.debug('ACTS_ [data]getRdbStoreThen')
store.executeSql(SQL_CREATE_TABLE, [])
rdbStore = store
});
},
insert(uri, valueBucket, callback) {
console.debug(TAG + ' insert start 1121')
console.debug(TAG + ' valueBucket json=>' + JSON.stringify(valueBucket))
let err = "Error Uri"
if (uri != dataAbilityUri) {
console.debug(TAG + ' uri != dataAbilityUri')
callback(err, returnError1);
}
console.debug(TAG + ' valueBucket.age =>' + valueBucket.age)
console.debug(TAG + ' valueBucket.name =>' + valueBucket.name)
console.debug(TAG + ' valueBucket.salary =>' + valueBucket.salary)
if (valueBucket.age != 24) {
err = "Error age"
callback(err, returnError2);
}
if (valueBucket.name != "ActsDataAbilityHelperPermissionTest") {
err = "Error name"
callback(err, returnError2);
}
if (valueBucket.salary != 2024.20) {
err = "Error salary"
callback(err, returnError2);
}
err = "Error insert"
console.debug(TAG + ' rdbStore.insert ')
rdbStore.insert(TABLE_NAME, valueBucket, function (err, resultSet) {
console.log(TAG + "insert callback resultSet:" + resultSet
+ " ,json=" + JSON.stringify(resultSet) + ' ,err' + err)
callback(err, defaultReturn);
})
},
query(uri, columns, predicates, callback) {
console.debug(TAG + ' query start')
let err = "Error Uri"
if (uri != dataAbilityUri) {
console.debug(TAG + ' uri != dataAbilityUri')
callback(err, returnError1);
}
let rdbPredicates = dataAbility.createRdbPredicates(TABLE_NAME, predicates)
rdbStore.query(rdbPredicates, columns, callback)
},
update(uri, valueBucket, predicates, callback) {
console.debug(TAG + 'update start')
let err = "Error Uri"
if (uri != dataAbilityUri) {
console.debug(TAG + ' uri != dataAbilityUri')
callback(err, returnError1);
}
console.debug(TAG + ' valueBucket.age =>' + valueBucket.age)
console.debug(TAG + ' valueBucket.name =>' + valueBucket.name)
console.debug(TAG + ' valueBucket.salary =>' + valueBucket.salary)
if (valueBucket.age != 24) {
err = "Error age"
callback(err, returnError2);
}
if (valueBucket.name != "ActsDataAbilityHelperPermissionTest") {
err = "Error name"
callback(err, returnError2);
}
if (valueBucket.salary != 2024.20) {
err = "Error salary"
callback(err, returnError2);
}
err = "Error update"
let rdbPredicates = dataAbility.createRdbPredicates(TABLE_NAME, predicates)
rdbStore.update(valueBucket, rdbPredicates, function (err, resultSet) {
console.log(TAG + "insert callback resultSet:" + resultSet
+ " ,json=" + JSON.stringify(resultSet) + ' ,err' + err)
callback(err, defaultReturn);
})
},
delete(uri, predicates, callback) {
console.debug(TAG + 'delete start')
let err = "Error Uri"
if (uri != dataAbilityUri) {
console.debug(TAG + ' uri != dataAbilityUri')
callback(err, returnError1);
}
let rdbPredicates = dataAbility.createRdbPredicates(TABLE_NAME, predicates)
rdbStore.delete(rdbPredicates, function (err, resultSet) {
console.log(TAG + "insert callback resultSet:" + resultSet
+ " ,json=" + JSON.stringify(resultSet) + ' ,err' + err)
callback(err, defaultReturn);
})
},
call(uri, method, arg, extras, callback) {
console.debug(TAG + 'call start')
console.debug(TAG + 'uri---->' + uri)
console.debug(TAG + 'method---->' + uri)
},
batchInsert(uri, values, callback) {
let err = "Error Uri"
if (uri != dataAbilityUri) {
console.debug(TAG + ' uri != dataAbilityUri')
callback(err, returnError1);
}
for (var j = 0; j < values.length; j++) {
rdbStore.insert("EMPLOYEE", values[j], function (err, ret) {
console.log(TAG + "batchInsert callback ret:" + JSON.stringify(ret))
})
}
console.log(TAG + "batchInsert values.length:" + values.length + ' ,json=' + JSON.stringify(values.length))
callback(err, values.length);
},
openFile(uri, mode, callback) {
console.info(TAG + '==================== DataAbility test interface by openFile ================');
let defaultReturn = 1;
let returnError1 = -1;
let err = "Error Uri"
if (uri != dataAbilityUri) {
console.debug(TAG + ' uri != dataAbilityUri')
callback(err, returnError1);
}
if (!(mode == ("r") || mode == ("w") || mode == ("wt") || mode == ("wa") ||
mode == ("rw") || mode == ("rwt"))) {
if (mode == ("A1@k#4%$,.<>)(oioiu*((*&(&*giIGT^%&^Ug;sdfk;losd*7873iug8%&^$&%]ERFUy&^%&&R7")) {
defaultReturn = returnError2;
} else
defaultReturn = returnError3;
}
console.info(TAG + " path = /data/test ");
let path = "/data/test"
fileio.stat(path).then(function (stat) {
console.info(TAG + "openFile getFileInfo successfully callback ret:" + JSON.stringify(stat));
}).catch(function (err) {
console.info(TAG + "openFile getFileInfo failed with error callback ret:" + err);
defaultReturn = returnError1;
});
console.info(TAG + " path ==>" + path);
callback("success", defaultReturn);
},
normalizeUri(uri, callback) {
console.info(TAG + '==================== DataAbility test interface by normalizeUri ================');
let err = "Error Uri"
if (uri != dataAbilityUri) {
console.debug(TAG + ' uri != dataAbilityUri')
callback(err, "");
}
callback("success", uri);
},
denormalizeUri(uri, callback) {
console.info(TAG + '==================== DataAbility test interface by denormalizeUri ================');
console.info(TAG + "denormalizeUri uri:" + JSON.stringify(uri));
let err = "Error Uri"
if (uri != dataAbilityUri) {
console.debug(TAG + ' uri != dataAbilityUri')
callback(err, "");
}
callback("success", uri);
}
};
\ No newline at end of file
/*
* Copyright (C) 2022 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-1.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 featureAbility from '@ohos.ability.featureAbility'
import ohosDataAbility from '@ohos.data.dataAbility'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
export default function ActsDataAbilityHelperPermissionTest() {
describe('ActsDataAbilityHelperPermissionTest', function () {
let dataAbilityUri = ("dataability:///com.example.myapplication.DataAbility3");
let DAHelper;
beforeAll(async (done) => {
console.debug('= ACTS_beforeAll ====<begin');
try {
DAHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri);
console.debug('ACTS_beforeAll DAHelper ====>: ' + DAHelper + " ,JSON. " + JSON.stringify(DAHelper));
if(DAHelper == null){
console.debug('ACTS_beforeAll DAHelper ====>: DAHelper == null');
}
} catch (err) {
console.error('=ACTS_beforeAll acquireDataAbilityHelper catch(err)====>:' + err);
}
console.debug('= ACTS_beforeAll ====<end');
done();
})
afterAll((done) => {
console.debug('= ACTS_afterAll ====<begin');
console.debug('= ACTS_afterAll ====<end');
done();
})
/*
* @tc.number: ACTS_AcquireDataAbilityHelper_0100
* @tc.name: GetDataAbilityHelper : Connects an ability to a Service ability
* @tc.desc: Check the return value of the interface ()
*/
it('ACTS_AcquireDataAbilityHelper_0100', 0, async function (done) {
console.log('ACTS_AcquireDataAbilityHelper_0100====<begin');
console.debug("=ACTS_AcquireDataAbilityHelper_0100 dataAbilityUri====>" + dataAbilityUri)
try {
if(DAHelper == null){
var abilityHelper = featureAbility.acquireDataAbilityHelper(dataAbilityUri)
console.log('ACTS_AcquireDataAbilityHelper_0100 abilityHelper ====>: '
+ abilityHelper + " ,JSON. " + JSON.stringify(abilityHelper))
DAHelper = abilityHelper;
}
expect(typeof (DAHelper)).assertEqual("object");
} catch (err) {
console.error('=ACTS_GetDataAbilityHelper_0100 acquireDataAbilityHelper catch(err)====>:' + err);
expect(false).assertTrue();
}
expect(true).assertTrue();
console.log('ACTS_AcquireDataAbilityHelper_0100====<end')
done();
})
/*
* @tc.number: ACTS_Insert_0100
* @tc.name: Insert : Indicates the path of the data to operate
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_Insert_0100', 0, async function (done) {
console.log('ACTS_Insert_0100====<begin');
expect(typeof (DAHelper)).assertEqual("object");
console.log('Insert_0100 DAHelper ====>: ' + DAHelper)
let valueBucketM;
try {
DAHelper.insert(dataAbilityUri, valueBucketM)
.then(function (data) {
console.debug("=ACTS_Insert_0100 then data====>"
+ ("json data 【") + JSON.stringify(data) + (""));
expect(JSON.stringify(data)).assertEqual("-1")
console.log('ACTS_Insert_0100====<end');
done();
}).catch(function (err) {
console.debug("=ACTS_Insert_0100 catch err ====>"
+ ("json err 【") + JSON.stringify(err) + (""));
expect(false).assertTrue();
console.log('ACTS_Insert_0100====<end .catch');
done();
});
} catch (err) {
console.error('=ACTS_Insert_0100 catch(err)====>:' + err);
expect(false).assertTrue();
console.log('ACTS_Insert_0100====<end catch');
done();
}
})
/*
* @tc.number: ACTS_BatchInsert_0100
* @tc.name: Inserts multiple data records into the database
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_BatchInsert_0100', 0, async function (done) {
console.log('ACTS_BatchInsert_0100====<begin');
expect(typeof (DAHelper)).assertEqual("object");
console.log('featureAbility BatchInsert getDataAbilityHelper ====>: ' + DAHelper)
var valueBucketM;
try {
DAHelper.batchInsert(
dataAbilityUri,
valueBucketM
).then((data) => {
console.debug("=ACTS_BatchInsert_0100 then data====>"
+ ("json data 【") + JSON.stringify(data) + (" 】; ====>"));
expect(JSON.stringify(data)).assertEqual("-1")
console.log('ACTS_BatchInsert_0100====<end');
done();
}).catch((err) => {
console.debug("=ACTS_BatchInsert_0100 catch err ====>"
+ ("json err 【") + JSON.stringify(err) + (""));
console.log('ACTS_BatchInsert_0100====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error('=ACTS_BatchInsert_0100 catch(err)====>:' + err);
console.log('ACTS_BatchInsert_0100====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_Query_0100
* @tc.name: Queries one or more data records in the database
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_Query_0100', 0, async function (done) {
console.log('ACTS_Query_0100====<begin');
expect(typeof (DAHelper)).assertEqual("object");
var columnsArray = new Array("");
try {
let predicates = new ohosDataAbility.DataAbilityPredicates();
DAHelper.query(
dataAbilityUri,
columnsArray,
predicates
).then((data) => {
console.debug("=ACTS_Query_0100 then data====>"
+ ("json data 【") + JSON.stringify(data) + (""));
expect(data).assertEqual(null);
console.log('ACTS_Query_0100====<end');
done();
}).catch(err => {
console.debug("=ACTS_Query_0100 catch err ====>"
+ ("json err 【") + JSON.stringify(err) + (""));
console.log('ACTS_Query_0100====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error('=ACTS_Query_0100 catch(err)====>:' + err);
console.log('ACTS_Query_0100====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_Update_0100
* @tc.name: Updates one or more data records in the database.
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_Update_0100', 0, async function (done) {
console.log('ACTS_Update_0100====<begin');
expect(typeof (DAHelper)).assertEqual("object");
console.log('featureAbility Update getDataAbilityHelper ====>: ' + DAHelper)
try {
let valueBucketNull = {};
let predicates = new ohosDataAbility.DataAbilityPredicates();
console.debug("=ACTS_Update_0100 predicates====>"
+ ("json predicates 【") + JSON.stringify(predicates) + ("") + " , " + predicates);
DAHelper.update(
dataAbilityUri,
valueBucketNull,
predicates
).then((data) => {
console.debug("=ACTS_Update_0100 then data====>"
+ ("json data 【") + JSON.stringify(data) + (""));
expect(JSON.stringify(data)).assertEqual("-1")
console.log('ACTS_Update_0100====<end');
done();
}).catch((err) => {
console.debug("=ACTS_Update_0100 catch err ====>"
+ ("json err 【") + JSON.stringify(err) + (""));
expect(false).assertTrue();
console.log('ACTS_Update_0100====<end .catch');
done();
});
} catch (err) {
console.error('=ACTS_Update_0100 catch(err)====>:' + err);
expect(false).assertTrue();
console.log('ACTS_Update_0100====<end catch');
done();
}
})
/*
* @tc.number: ACTS_Delete_0100
* @tc.name: Deletes one or more data records. This method should be implemented by a Data ability.
* @tc.desc: Check the return value of the interface (by Promise)
*/
it('ACTS_Delete_0100', 0, async function (done) {
console.log('ACTS_Delete_0100====<begin');
expect(typeof (DAHelper)).assertEqual("object");
console.log('featureAbility getDataAbilityHelper ====>: ' + DAHelper);
try {
let predicates = new ohosDataAbility.DataAbilityPredicates();
console.debug("=ACTS_Delete_0100 predicates====>"
+ ("json predicates 【") + JSON.stringify(predicates) + ("") + " , " + predicates);
DAHelper.delete(
dataAbilityUri,
predicates
).then((data) => {
console.debug("=ACTS_Delete_0100 then data====>"
+ ("json data 【") + JSON.stringify(data) + (""));
expect(JSON.stringify(data)).assertEqual("-1")
console.log('ACTS_Delete_0100====<end');
done();
}).catch((err) => {
console.debug("=ACTS_Delete_0100 catch err ====>"
+ ("json err 【") + JSON.stringify(err) + (""));
expect(false).assertTrue();
console.log('ACTS_Delete_0100====<end .catch');
done();
});
} catch (err) {
console.error('=ACTS_Delete_0100 catch(err)====>:' + err);
expect(false).assertTrue();
console.log('ACTS_Delete_0100====<end catch');
done();
}
})
/*
* @tc.number: ACTS_OpenFile_0100
* @tc.name: Opens a file. This method should be implemented by a Data ability.
* @tc.desc: Check the return value of the interface (by promise)
*/
it('ACTS_OpenFile_0100', 0, async function (done) {
console.log('ACTS_OpenFile_0100====<begin');
var mode = "r";
try {
DAHelper.openFile(
dataAbilityUri,
mode,
).then((data) => {
console.debug("=ACTS_OpenFile_0100 then data====>"
+ ("json data 【") + JSON.stringify(data) + (""));
expect(JSON.stringify(data)).assertEqual("-1")
done();
}).catch(err => {
console.debug("=ACTS_OpenFile_0100 catch err ====>"
+ ("json err 【") + JSON.stringify(err) + (""));
expect(false).assertTrue();
done();
});
} catch (err) {
console.error('=ACTS_OpenFile_0100 getType catch(err)====>:' + err);
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_NormalizeUri_0100
* @tc.name: Converts the given uri that refer to the Data ability into a normalized URI.
* @tc.desc: Check the return value of the interface (by promise)
*/
it('ACTS_NormalizeUri_0100', 0, async function (done) {
console.log('ACTS_NormalizeUri_0100====<begin');
let ret = false;
expect(typeof (DAHelper)).assertEqual("object");
console.log('featureAbility normalizeUri getDataAbilityHelper ====>: ' + DAHelper);
try {
DAHelper.normalizeUri(
dataAbilityUri,
).then((data) => {
console.debug("=ACTS_NormalizeUri_0100 then data====>"
+ ("json data 【") + JSON.stringify(data) + (""));
expect(data.length).assertEqual(0);
console.log('ACTS_NormalizeUri_0100====<end');
done();
}).catch(err => {
console.debug("=ACTS_NormalizeUri_0100 catch err ====>"
+ ("json err 【") + JSON.stringify(err) + (""));
console.log('ACTS_NormalizeUri_0100====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error('=ACTS_NormalizeUri_0100 normalizeUri promise catch(err)====>:' + err);
console.log('ACTS_NormalizeUri_0100====<end catch');
expect(false).assertTrue();
done();
}
})
/*
* @tc.number: ACTS_DenormalizeUri_0100
* @tc.name: Converts the given normalized uri generated by normalizeUri into a denormalized one.
* @tc.desc: Check the return value of the interface (by promise)
*/
it('ACTS_DenormalizeUri_0100', 0, async function (done) {
console.log('ACTS_DenormalizeUri_0100====<begin');
let ret = false;
expect(typeof (DAHelper)).assertEqual("object");
console.log('featureAbility DenormalizeUri getDataAbilityHelper ====>: ' + DAHelper);
try {
DAHelper.denormalizeUri(
dataAbilityUri,
).then((data) => {
console.debug("=ACTS_DenormalizeUri_0100 then data====>"
+ ("json data 【") + JSON.stringify(data) + (""));
expect(data.length).assertEqual(0);
console.log('ACTS_DenormalizeUri_0100====<end');
done();
}).catch(err => {
console.debug("=ACTS_DenormalizeUri_0100 catch err ====>"
+ ("json err 【") + JSON.stringify(err) + (""));
console.log('ACTS_DenormalizeUri_0100====<end .catch');
expect(false).assertTrue();
done();
});
} catch (err) {
console.error('=ACTS_DenormalizeUri_0100 denormalizeUri promise catch(err)====>:' + err);
console.log('ACTS_DenormalizeUri_0100====<end catch');
expect(false).assertTrue();
done();
}
})
})}
\ No newline at end of file
......@@ -13,6 +13,8 @@
* limitations under the License.
*/
import ActsDataAbilityHelperTest from './DataAbilityHelperJsSt.test.js'
import ActsDataAbilityHelperPermissionTest from './DataAbilityHelperJsStPermission.test.js'
export default function testsuite() {
ActsDataAbilityHelperTest()
ActsDataAbilityHelperPermissionTest()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册