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

!3018 【Distributeddatamgr】【Master】用例同步 RdbstoreChangeEncryptKeyJsunit.test.js

Merge pull request !3018 from Maowen/master
......@@ -27,5 +27,6 @@ require('./DataAbilityPredicatesJsunit.test.js')
require('./RdbstoreTransactionJsunit.test.js')
require('./RdbstorePredicatesJoinJsunit.test.js')
require('./RdbStoreDistributedJsunit.test.js')
require('./RdbstoreChangeEncryptKeyJsunit.test.js')
// @ts-nocheck
/*
* 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, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import dataRdb from '@ohos.data.rdb';
const TAG = "[RDB_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {
name: "EncryptNoKeyInsertTest.db",
encryptKey: new Uint8Array([1, 2, 3])
}
const STORE_CONFIG_NO_KEY = {
name: "EncryptNoKeyInsertTest.db"
}
var i = 1;
var rdbStore = undefined;
describe('rdbStoreInsertTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
beforeEach(async function () {
if ( i== 2){
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG_NO_KEY, 1);
}
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST);
console.info(TAG + 'beforeEach')
})
afterEach(async function () {
i ++;
console.info(TAG + 'afterEach')
rdbStore = null
await dataRdb.deleteRdbStore("EncryptNoKeyInsertTest.db");
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.name testRdbStoreChangeEncryptKey0001
* @tc.number SUB_DDM_Encrypt_ChangeKey0001
* @tc.desc encrypt the db at start, then change the encrypt key
*/
it('testRdbStoreChangeEncryptKey0001', 0, async function (done) {
console.log(TAG + "************* testRdbStoreChangeEncryptKey0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
var newKey = new Uint8Array([1, 2])
await rdbStore.changeEncryptKey(newKey);
let predicates = new dataRdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
console.log(TAG + "resultSet query done");
resultSet.goToFirstRow()
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
expect(1).assertEqual(id);
} catch (e) {
console.log("insert1 error " + e);
}
done()
console.log(TAG + "************* testRdbStoreChangeEncryptKey0001 end *************");
})
/**
* @tc.name testRdbStoreChangeEncryptKey0002
* @tc.number SUB_DDM_Encrypt_ChangeKey0002
* @tc.desc encrypt the db at start, then change the encrypt key
*/
it('testRdbStoreChangeEncryptKey0002', 0, async function (done) {
console.log(TAG + "************* testRdbStoreChangeEncryptKey0002 start *************");
var u8 = new Uint8Array([1, 2, 3])
let result = 1;
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
try {
let result = await rdbStore.changeEncryptKey(new Uint8Array([1, 2]));
} catch (e) {
expect(1).assertEqual(result);
console.log(TAG + "can not change encrypt key, since config with no key");
}
done()
console.log(TAG + "************* testRdbStoreChangeEncryptKey0002 end *************");
})
/**
* @tc.name testRdbStoreChangeEncryptKey0003
* @tc.number SUB_DDM_Encrypt_ChangeKey0003
* @tc.desc encrypt the db at start, then clear the encrypt key
* now sqlite does not support this feature, switch encrypt to non-encrypt.
*/
it('testRdbStoreChangeEncryptKey0003', 0, async function (done) {
console.log(TAG + "************* testRdbStoreChangeEncryptKey0003 start *************");
let result = -1;
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
try{
result = await rdbStore.changeEncryptKey(new Uint8Array());
} catch (e) {
expect(-1).assertEqual(result);
console.log(TAG + "can not clear encrypt key 2");
}
done()
console.log(TAG + "************* testRdbStoreChangeEncryptKey0003 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
......@@ -113,9 +113,8 @@ describe('rdbStorePredicatesJoinTest', function () {
/**
* @tc.name: testRdbJoin001
* @tc.desc: SUB_DDM_AppDataFWK_Rdb_Inner_Join
* @tc.type: FUNC
* @tc.require: I4NZP6
* @tc.number: SUB_DDM_AppDataFWK_Rdb_Inner_Join
* @tc.desc: sql query inner join test
*/
it('testRdbJoin001', 0, async function (done) {
console.log(TAG + "testRdbJoin001 begin.");
......@@ -137,9 +136,8 @@ describe('rdbStorePredicatesJoinTest', function () {
/**
* @tc.name: testRdbJoin002
* @tc.desc: SUB_DDM_AppDataFWK_Rdb_Cross_Join
* @tc.type: FUNC
* @tc.require: I4NZP6
* @tc.number: SUB_DDM_AppDataFWK_Rdb_Cross_Join
* @tc.desc: sql query cross join test
*/
it('testRdbJoin002', 0, async function (done) {
console.log(TAG + "testRdbJoin002 begin.");
......@@ -163,9 +161,8 @@ describe('rdbStorePredicatesJoinTest', function () {
/**
* @tc.name: testRdbJoin003
* @tc.desc: SUB_DDM_AppDataFWK_Rdb_Left_Outer_Join
* @tc.type: FUNC
* @tc.require: I4NZP6
* @tc.number: SUB_DDM_AppDataFWK_Rdb_Left_Outer_Join
* @tc.desc: sql query left outer join test
*/
it('testRdbJoin003', 0, async function (done) {
console.log(TAG + "testRdbJoin003 begin.");
......
......@@ -51,7 +51,7 @@ describe('rdbStoreInsertTest', function () {
/**
* @tc.name rdb transaction insert test
* @tc.number SUB_DDM_AppDataFWK_testRdbTransactionInsert0001
* @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0001
* @tc.desc rdb transaction insert & commit, the result comes out is 3 items;
*/
it('testRdbTransactionInsert0001', 0, async function (done) {
......@@ -86,7 +86,7 @@ describe('rdbStoreInsertTest', function () {
/**
* @tc.name rdb transaction insert test
* @tc.number SUB_DDM_AppDataFWK_testRdbTransactionInsert0002
* @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0002
* @tc.desc rdb transaction insert & commit, the result comes out is 3 items;
*/
it('testRdbTransactionInsert0002', 0, async function (done) {
......@@ -137,7 +137,7 @@ describe('rdbStoreInsertTest', function () {
/**
* @tc.name rdb transaction insert test
* @tc.number SUB_DDM_AppDataFWK_testRdbTransactionInsert0003
* @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0003
* @tc.desc while using transaction to insert values, querying the db,
* the result comes out is 0;
*/
......
......@@ -1568,7 +1568,7 @@ describe('DeviceKvStorePromiseTest', function () {
try {
var count = 0;
kvStore.on('dataChange', 0, function (data) {
console.log('testDeviceKvStoreOnChange001 0' + JSON.stringify(data))
console.log('testDeviceKvStorestartTransaction001' + JSON.stringify(data))
count++;
});
await kvStore.startTransaction().then(async (err) => {
......@@ -1621,7 +1621,7 @@ describe('DeviceKvStorePromiseTest', function () {
try {
var count = 0;
kvStore.on('dataChange', 0, function (data) {
console.log('testDeviceKvStoreOnChange001 0' + JSON.stringify(data))
console.log('testDeviceKvStorestartTransaction002' + JSON.stringify(data))
count++;
});
await kvStore.startTransaction().then(async (err) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册