mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-23 15:11:33 +00:00
commit
a62d210ee0
@ -46,7 +46,7 @@ private:
|
||||
using Info = DistributedRdb::RdbDebugInfo;
|
||||
int ProcessOpenCallback(RdbStore &rdbStore,
|
||||
const RdbStoreConfig &config, int version, RdbOpenCallback &openCallback);
|
||||
bool IsConfigInvalidChanged(const std::string &path, const RdbStoreConfig &config);
|
||||
bool IsConfigInvalidChanged(const std::string &path, RdbStoreConfig &config);
|
||||
int32_t GetParamFromService(DistributedRdb::RdbSyncerParam ¶m);
|
||||
static Param GetSyncParam(const RdbStoreConfig &config);
|
||||
static std::map<std::string, Info> Collector(const RdbStoreConfig &config);
|
||||
|
@ -15,6 +15,8 @@
|
||||
#define LOG_TAG "RdbStoreConfig"
|
||||
#include "rdb_store_config.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "logger.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_security_manager.h"
|
||||
@ -630,4 +632,25 @@ bool RdbStoreConfig::CryptoParam::IsValid() const
|
||||
(cryptoPageSize & (cryptoPageSize - 1)) == 0;
|
||||
}
|
||||
|
||||
std::string RdbStoreConfig::Format(const RdbStoreConfig &cacheConfig, const RdbStoreConfig &incomingConfig)
|
||||
{
|
||||
std::stringstream oss;
|
||||
oss << " isEncrypt:" << static_cast<int32_t>(cacheConfig.IsEncrypt()) << "->"
|
||||
<< static_cast<int32_t>(incomingConfig.IsEncrypt()) << ",";
|
||||
oss << " securityLevel:" << static_cast<int32_t>(cacheConfig.securityLevel_) << "->"
|
||||
<< static_cast<int32_t>(incomingConfig.securityLevel_) << ",";
|
||||
oss << " area:" << cacheConfig.area_ << "->" << incomingConfig.area_ << ",";
|
||||
oss << " storageMode:" << static_cast<int32_t>(cacheConfig.storageMode_) << "->"
|
||||
<< static_cast<int32_t>(incomingConfig.storageMode_) << ",";
|
||||
oss << " journalMode:" << cacheConfig.journalMode_ << "->" << incomingConfig.journalMode_ << ",";
|
||||
oss << " syncMode:" << cacheConfig.syncMode_ << "->" << incomingConfig.syncMode_ << ",";
|
||||
oss << " databaseFileType:" << cacheConfig.databaseFileType << "->" << incomingConfig.databaseFileType << ",";
|
||||
oss << " journalSize:" << cacheConfig.journalSize_ << "->" << incomingConfig.journalSize_ << ",";
|
||||
oss << " pageSize:" << cacheConfig.pageSize_ << "->" << incomingConfig.pageSize_ << ",";
|
||||
oss << " customDir:" << cacheConfig.customDir_ << "->" << incomingConfig.customDir_ << ",";
|
||||
oss << " haMode:" << cacheConfig.haMode_ << "->" << incomingConfig.haMode_ << ",";
|
||||
oss << " dbType:" << cacheConfig.dbType_ << "->" << incomingConfig.dbType_ << ",";
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
} // namespace OHOS::NativeRdb
|
||||
|
@ -70,15 +70,18 @@ std::shared_ptr<RdbStoreImpl> RdbStoreManager::GetStoreFromCache(const RdbStoreC
|
||||
storeCache_.erase(path);
|
||||
// If rdbStore is not null, it means that the config has changed.
|
||||
if (rdbStore != nullptr) {
|
||||
auto pool = TaskExecutor::GetInstance().GetExecutor();
|
||||
pool->Schedule(std::chrono::seconds(RETRY_INTERVAL), [config, rdbStore]() {
|
||||
Reportor::Report(Reportor::Create(config, E_CONFIG_INVALID_CHANGE,
|
||||
"ErrorType:Config diff!" + RdbStoreConfig::Format(rdbStore->GetConfig(), config)));
|
||||
});
|
||||
LOG_INFO("app[%{public}s:%{public}s] path[%{public}s]"
|
||||
" cfg[%{public}d,%{public}d,%{public}d,%{public}d,%{public}d,%{public}d,%{public}d,%{public}s]"
|
||||
" %{public}s",
|
||||
config.GetBundleName().c_str(), config.GetModuleName().c_str(), SqliteUtils::Anonymous(path).c_str(),
|
||||
config.GetDBType(), config.GetHaMode(), config.IsEncrypt(), config.GetArea(),
|
||||
config.GetSecurityLevel(), config.GetRoleType(), config.IsReadOnly(), config.GetCustomDir().c_str(),
|
||||
RdbFaultHiViewReporter::FormatBrief(
|
||||
Connection::Collect(config), SqliteUtils::Anonymous(config.GetName()))
|
||||
.c_str());
|
||||
Reportor::FormatBrief(Connection::Collect(config), SqliteUtils::Anonymous(config.GetName())).c_str());
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@ -87,42 +90,42 @@ std::shared_ptr<RdbStoreImpl> RdbStoreManager::GetStoreFromCache(const RdbStoreC
|
||||
std::shared_ptr<RdbStore> RdbStoreManager::GetRdbStore(
|
||||
const RdbStoreConfig &config, int &errCode, int version, RdbOpenCallback &openCallback)
|
||||
{
|
||||
RdbStoreConfig modifyConfig = config;
|
||||
// TOD this lock should only work on storeCache_, add one more lock for connectionpool
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto path = config.GetRoleType() == VISITOR ? config.GetVisitorDir() : config.GetPath();
|
||||
auto pool = TaskExecutor::GetInstance().GetExecutor();
|
||||
pool->Schedule(std::chrono::seconds(RETRY_INTERVAL), [path, config, this]() {
|
||||
if (IsConfigInvalidChanged(path, config)) {
|
||||
Reportor::Report(Reportor::Create(config, E_CONFIG_INVALID_CHANGE, "ErrorType:Encrypt diff"));
|
||||
}
|
||||
});
|
||||
std::shared_ptr<RdbStoreImpl> rdbStore = GetStoreFromCache(config, path);
|
||||
auto path = modifyConfig.GetRoleType() == VISITOR ? modifyConfig.GetVisitorDir() : modifyConfig.GetPath();
|
||||
bundleName_ = modifyConfig.GetBundleName();
|
||||
std::shared_ptr<RdbStoreImpl> rdbStore = GetStoreFromCache(modifyConfig, path);
|
||||
if (rdbStore != nullptr) {
|
||||
return rdbStore;
|
||||
}
|
||||
rdbStore = std::make_shared<RdbStoreImpl>(config, errCode);
|
||||
if (modifyConfig.GetRoleType() == OWNER && IsConfigInvalidChanged(path, modifyConfig)) {
|
||||
errCode = E_CONFIG_INVALID_CHANGE;
|
||||
return nullptr;
|
||||
}
|
||||
rdbStore = std::make_shared<RdbStoreImpl>(modifyConfig, errCode);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("RdbStoreManager GetRdbStore fail to open RdbStore as memory issue, rc=%{public}d", errCode);
|
||||
LOG_ERROR("GetRdbStore fail path:%{public}s, rc=%{public}d", SqliteUtils::Anonymous(path).c_str(), errCode);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (config.GetRoleType() == OWNER && !config.IsReadOnly()) {
|
||||
errCode = SetSecurityLabel(config);
|
||||
if (modifyConfig.GetRoleType() == OWNER && !modifyConfig.IsReadOnly()) {
|
||||
errCode = SetSecurityLabel(modifyConfig);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("fail, storeName:%{public}s security %{public}d errCode:%{public}d",
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(), config.GetSecurityLevel(), errCode);
|
||||
SqliteUtils::Anonymous(modifyConfig.GetName()).c_str(), modifyConfig.GetSecurityLevel(), errCode);
|
||||
return nullptr;
|
||||
}
|
||||
if (config.IsVector()) {
|
||||
if (modifyConfig.IsVector()) {
|
||||
storeCache_[path] = rdbStore;
|
||||
return rdbStore;
|
||||
}
|
||||
(void)rdbStore->ExchangeSlaverToMaster();
|
||||
errCode = ProcessOpenCallback(*rdbStore, config, version, openCallback);
|
||||
errCode = ProcessOpenCallback(*rdbStore, modifyConfig, version, openCallback);
|
||||
if (errCode != E_OK) {
|
||||
LOG_ERROR("fail, storeName:%{public}s path:%{public}s ProcessOpenCallback errCode:%{public}d",
|
||||
SqliteUtils::Anonymous(config.GetName()).c_str(), SqliteUtils::Anonymous(config.GetPath()).c_str(),
|
||||
errCode);
|
||||
SqliteUtils::Anonymous(modifyConfig.GetName()).c_str(),
|
||||
SqliteUtils::Anonymous(modifyConfig.GetPath()).c_str(), errCode);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -131,11 +134,11 @@ std::shared_ptr<RdbStore> RdbStoreManager::GetRdbStore(
|
||||
return rdbStore;
|
||||
}
|
||||
|
||||
bool RdbStoreManager::IsConfigInvalidChanged(const std::string &path, const RdbStoreConfig &config)
|
||||
bool RdbStoreManager::IsConfigInvalidChanged(const std::string &path, RdbStoreConfig &config)
|
||||
{
|
||||
Param param = GetSyncParam(config);
|
||||
Param tempParam;
|
||||
if (bundleName_.empty()) {
|
||||
if (config.GetBundleName().empty()) {
|
||||
LOG_WARN("Config has no bundleName, path: %{public}s", SqliteUtils::Anonymous(path).c_str());
|
||||
return false;
|
||||
}
|
||||
@ -148,14 +151,20 @@ bool RdbStoreManager::IsConfigInvalidChanged(const std::string &path, const RdbS
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
if (tempParam.level_ != param.level_ || tempParam.area_ != param.area_ ||
|
||||
tempParam.isEncrypt_ != param.isEncrypt_) {
|
||||
LOG_ERROR("Store config invalid change, storeName %{public}s, securitylevel: %{public}d -> %{public}d, "
|
||||
"area: %{public}d -> %{public}d, isEncrypt: %{public}d -> %{public}d",
|
||||
bool isLevelInvalidChange = (tempParam.level_ > param.level_);
|
||||
bool isEncryptInvalidChange = (tempParam.isEncrypt_ != param.isEncrypt_);
|
||||
bool isAreaInvalidChange = (tempParam.area_ != param.area_);
|
||||
if (isLevelInvalidChange || isEncryptInvalidChange || isAreaInvalidChange) {
|
||||
LOG_WARN("Store config invalid change, storePath %{public}s, securitylevel: %{public}d -> %{public}d, "
|
||||
"area: %{public}d -> %{public}d, isEncrypt: %{public}d -> %{public}d",
|
||||
SqliteUtils::Anonymous(path).c_str(), tempParam.level_, param.level_, tempParam.area_, param.area_,
|
||||
tempParam.isEncrypt_, param.isEncrypt_);
|
||||
return true;
|
||||
if (isLevelInvalidChange) {
|
||||
return true;
|
||||
}
|
||||
if (isEncryptInvalidChange) {
|
||||
config.SetEncryptStatus(tempParam.isEncrypt_);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -672,6 +672,8 @@ public:
|
||||
|
||||
void EnableRekey(bool enable);
|
||||
|
||||
static std::string Format(const RdbStoreConfig &cacheConfig, const RdbStoreConfig &IncomingConfig);
|
||||
|
||||
private:
|
||||
void ClearEncryptKey();
|
||||
int32_t GenerateEncryptedKey() const;
|
||||
|
@ -252,6 +252,7 @@ public:
|
||||
CryptoParam GetCryptoParam() const;
|
||||
void SetJournalMode(const std::string &journalMode);
|
||||
void EnableRekey(bool enable);
|
||||
static std::string Format(const RdbStoreConfig &cacheConfig, const RdbStoreConfig &IncomingConfig);
|
||||
|
||||
private:
|
||||
void ClearEncryptKey();
|
||||
|
@ -167,21 +167,43 @@ describe('rdbEncryptTest', function () {
|
||||
* @tc.number SUB_DDM_RDB_JS_RdbEncryptTest_0040
|
||||
* @tc.desc RDB encrypt function test
|
||||
*/
|
||||
it('RdbEncryptTest_0040', 0, async function () {
|
||||
await console.log(TAG + "************* RdbEncryptTest_0040 start *************")
|
||||
context = ability_featureAbility.getContext()
|
||||
|
||||
await CreateRdbStore(context, STORE_CONFIG_ENCRYPT)
|
||||
it('RdbEncryptTest_0040', 0, async function (done) {
|
||||
console.log(TAG + "************* RdbEncryptTest_0040 start *************");
|
||||
context = ability_featureAbility.getContext();
|
||||
await CreateRdbStore(context, STORE_CONFIG_ENCRYPT);
|
||||
try {
|
||||
await CreateRdbStore(context, STORE_CONFIG_WRONG)
|
||||
expect().assertFail()
|
||||
let rdbStore = await CreateRdbStore(context, STORE_CONFIG_WRONG);
|
||||
expect(rdbStore !== null).assertTrue();
|
||||
} catch (err) {
|
||||
console.log(TAG + `failed, errcode:${JSON.stringify(err)}.`);
|
||||
console.log(TAG + `failed, errcode:${JSON.stringify(err)}.`);
|
||||
expect().assertFail();
|
||||
}
|
||||
|
||||
await console.log(TAG + "************* RdbEncryptTest_0040 end *************")
|
||||
done();
|
||||
console.log(TAG + "************* RdbEncryptTest_0040 end *************");
|
||||
})
|
||||
|
||||
/**
|
||||
* @tc.name RdbEncryptTest_0041
|
||||
* @tc.number SUB_DDM_RDB_JS_RdbEncryptTest_0041
|
||||
* @tc.desc RDB Encrypt function test
|
||||
* @tc.size MediumTest
|
||||
* @tc.type Function
|
||||
* @tc.level Level 1
|
||||
*/
|
||||
it('RdbEncryptTest_0041', 0, async function (done) {
|
||||
console.log(TAG + "************* RdbEncryptTest_0041 start *************");
|
||||
context = ability_featureAbility.getContext();
|
||||
await CreateRdbStore(context, STORE_CONFIG_WRONG);
|
||||
try {
|
||||
let rdbStore = await CreateRdbStore(context, STORE_CONFIG_ENCRYPT);
|
||||
expect(rdbStore !== null).assertTrue();
|
||||
} catch (err) {
|
||||
console.log(TAG + `failed, errcode:${JSON.stringify(err)}.`);
|
||||
expect().assertFail();
|
||||
}
|
||||
done();
|
||||
console.log(TAG + "************* RdbEncryptTest_0041 end *************");
|
||||
})
|
||||
/**
|
||||
* @tc.name Scenario testcase of RDB, get correct encrypt file when open database
|
||||
* @tc.number SUB_DDM_RDB_JS_RdbEncryptTest_0050
|
||||
@ -200,7 +222,7 @@ describe('rdbEncryptTest', function () {
|
||||
rdbStore1 = await CreateRdbStore(context, STORE_CONFIG_ENCRYPT);
|
||||
} catch (err) {
|
||||
expect().assertFail()
|
||||
console.error(`CreatRdbStore1 failed, error code: ${err.code}, err message: ${err.message}`);
|
||||
console.error(`CreateRdbStore1 failed, error code: ${err.code}, err message: ${err.message}`);
|
||||
}
|
||||
|
||||
// query 'rdbstore1'
|
||||
@ -218,7 +240,7 @@ describe('rdbEncryptTest', function () {
|
||||
rdbStore2 = await CreateRdbStore(context, STORE_CONFIG_ENCRYPT2)
|
||||
} catch (err) {
|
||||
expect().assertFail()
|
||||
console.error(`CreatRdbStore2 failed, error code: ${err.code}, err message: ${err.message}`);
|
||||
console.error(`CreateRdbStore2 failed, error code: ${err.code}, err message: ${err.message}`);
|
||||
}
|
||||
|
||||
// create table and query 'rdbStore1'
|
||||
|
@ -48,7 +48,7 @@ function CREATE_UINT8_ARRAY(len) {
|
||||
|
||||
const CONST_UINT8_ARRAY = CREATE_UINT8_ARRAY(127);
|
||||
|
||||
const DB_NAME = "resultSetPerf.db";
|
||||
const DB_NAME = "GetValuesBucketPerf.db";
|
||||
const STORE_CONFIG = {
|
||||
name: DB_NAME,
|
||||
securityLevel: dataRdb.SecurityLevel.S3
|
||||
|
@ -70,7 +70,7 @@ const STORE_CONFIG_NON_DEFAULT = {
|
||||
}
|
||||
}
|
||||
|
||||
async function CreatRdbStore(context, STORE_CONFIG) {
|
||||
async function CreateRdbStore(context, STORE_CONFIG) {
|
||||
let rdbStore = await data_relationalStore.getRdbStore(context, STORE_CONFIG)
|
||||
await rdbStore.executeSql(CREATE_TABLE_TEST, null)
|
||||
let u8 = new Uint8Array([1, 2, 3])
|
||||
@ -211,7 +211,7 @@ describe('rdbEncryptTest', function () {
|
||||
*/
|
||||
it('RdbEncryptTest_0030', 0, async function (done) {
|
||||
await console.log(TAG + "************* RdbEncryptTest_0030 start *************")
|
||||
let rdbStore = await CreatRdbStore(context, STORE_CONFIG_ENCRYPT)
|
||||
let rdbStore = await CreateRdbStore(context, STORE_CONFIG_ENCRYPT)
|
||||
let predicates = new data_relationalStore.RdbPredicates("test")
|
||||
predicates.equalTo("name", "zhangsan")
|
||||
let resultSet = await rdbStore.query(predicates)
|
||||
@ -239,19 +239,42 @@ describe('rdbEncryptTest', function () {
|
||||
* @tc.number SUB_DDM_RDB_JS_RdbEncryptTest_0040
|
||||
* @tc.desc RDB Encrypt function test
|
||||
*/
|
||||
it('RdbEncryptTest_0040', 0, async function () {
|
||||
await console.log(TAG + "************* RdbEncryptTest_0040 start *************")
|
||||
let rdbStore = await CreatRdbStore(context, STORE_CONFIG_ENCRYPT)
|
||||
rdbStore = null
|
||||
|
||||
it('RdbEncryptTest_0040', 0, async function (done) {
|
||||
console.log(TAG + "************* RdbEncryptTest_0040 start *************");
|
||||
context = ability_featureAbility.getContext();
|
||||
await CreateRdbStore(context, STORE_CONFIG_ENCRYPT);
|
||||
try {
|
||||
rdbStore = await CreatRdbStore(context, STORE_CONFIG_WRONG)
|
||||
expect(false).assertTrue()
|
||||
let rdbStore = await CreateRdbStore(context, STORE_CONFIG_WRONG);
|
||||
expect(rdbStore !== null).assertTrue();
|
||||
} catch (err) {
|
||||
expect(err.code).assertEqual(14800011);
|
||||
console.log(TAG + `failed, errcode:${JSON.stringify(err)}.`);
|
||||
expect().assertFail();
|
||||
}
|
||||
done();
|
||||
console.log(TAG + "************* RdbEncryptTest_0040 end *************");
|
||||
})
|
||||
|
||||
await console.log(TAG + "************* RdbEncryptTest_0040 end *************")
|
||||
/**
|
||||
* @tc.name RdbEncryptTest_0041
|
||||
* @tc.number SUB_DDM_RDB_JS_RdbEncryptTest_0041
|
||||
* @tc.desc RDB Encrypt function test
|
||||
* @tc.size MediumTest
|
||||
* @tc.type Function
|
||||
* @tc.level Level 1
|
||||
*/
|
||||
it('RdbEncryptTest_0041', 0, async function (done) {
|
||||
console.log(TAG + "************* RdbEncryptTest_0041 start *************");
|
||||
context = ability_featureAbility.getContext();
|
||||
await CreateRdbStore(context, STORE_CONFIG_WRONG);
|
||||
try {
|
||||
let rdbStore = await CreateRdbStore(context, STORE_CONFIG_ENCRYPT);
|
||||
expect(rdbStore !== null).assertTrue();
|
||||
} catch (err) {
|
||||
console.log(TAG + `failed, errcode:${JSON.stringify(err)}.`);
|
||||
expect().assertFail();
|
||||
}
|
||||
done();
|
||||
console.log(TAG + "************* RdbEncryptTest_0041 end *************");
|
||||
})
|
||||
|
||||
/**
|
||||
@ -297,10 +320,10 @@ describe('rdbEncryptTest', function () {
|
||||
let rdbStore2;
|
||||
// create 'rdbstore1'
|
||||
try {
|
||||
rdbStore1 = await CreatRdbStore(context, STORE_CONFIG_ENCRYPT);
|
||||
rdbStore1 = await CreateRdbStore(context, STORE_CONFIG_ENCRYPT);
|
||||
} catch (err) {
|
||||
expect().assertFail()
|
||||
console.error(`CreatRdbStore1 failed, error code: ${err.code}, err message: ${err.message}`);
|
||||
console.error(`CreateRdbStore1 failed, error code: ${err.code}, err message: ${err.message}`);
|
||||
}
|
||||
|
||||
// query 'rdbstore1'
|
||||
@ -315,10 +338,10 @@ describe('rdbEncryptTest', function () {
|
||||
|
||||
// create 'rdbStore2'
|
||||
try {
|
||||
rdbStore2 = await CreatRdbStore(context, STORE_CONFIG_ENCRYPT2)
|
||||
rdbStore2 = await CreateRdbStore(context, STORE_CONFIG_ENCRYPT2)
|
||||
} catch (err) {
|
||||
expect().assertFail()
|
||||
console.error(`CreatRdbStore2 failed, error code: ${err.code}, err message: ${err.message}`);
|
||||
console.error(`CreateRdbStore2 failed, error code: ${err.code}, err message: ${err.message}`);
|
||||
}
|
||||
|
||||
// create table and query 'rdbStore1'
|
||||
|
@ -337,6 +337,59 @@ HWTEST_F(RdbEncryptTest, RdbStore_Encrypt_009, TestSize.Level1)
|
||||
EXPECT_EQ(ret, E_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_Encrypt_010
|
||||
* @tc.desc: test create encrypted Rdb and open in non encrypted mode ,then E_OK
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbEncryptTest, RdbStore_Encrypt_010, TestSize.Level1)
|
||||
{
|
||||
RdbStoreConfig config(RdbEncryptTest::ENCRYPTED_DATABASE_NAME);
|
||||
config.SetEncryptStatus(true);
|
||||
config.SetBundleName("com.example.TestEncrypt10");
|
||||
|
||||
EncryptTestOpenCallback helper;
|
||||
int errCode;
|
||||
std::shared_ptr<RdbStore> store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
EXPECT_EQ(errCode, E_OK);
|
||||
|
||||
std::string keyPath = RDB_TEST_PATH + "key/encrypted.pub_key";
|
||||
int ret = access(keyPath.c_str(), F_OK);
|
||||
EXPECT_EQ(ret, 0);
|
||||
|
||||
config.SetEncryptStatus(false);
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
EXPECT_EQ(errCode, E_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_Encrypt_011
|
||||
* @tc.desc: test create unencrypted Rdb and open in encrypted mode ,then E_OK
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbEncryptTest, RdbStore_Encrypt_011, TestSize.Level1)
|
||||
{
|
||||
RdbStoreConfig config(RdbEncryptTest::UNENCRYPTED_DATABASE_NAME);
|
||||
config.SetEncryptStatus(false);
|
||||
config.SetBundleName("com.example.TestEncrypt11");
|
||||
EncryptTestOpenCallback helper;
|
||||
int errCode;
|
||||
std::shared_ptr<RdbStore> store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
EXPECT_EQ(errCode, E_OK);
|
||||
|
||||
std::string keyPath = RDB_TEST_PATH + "key/unencrypted.pub_key";
|
||||
int ret = access(keyPath.c_str(), F_OK);
|
||||
EXPECT_EQ(ret, -1);
|
||||
|
||||
config.SetEncryptStatus(true);
|
||||
store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_NE(store, nullptr);
|
||||
EXPECT_EQ(errCode, E_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStore_RdbPassword_001
|
||||
* @tc.desc: Abnomal test RdbStore RdbPassword class
|
||||
|
@ -167,7 +167,6 @@ HWTEST_F(RdbHelperTest, GetDatabase_002, TestSize.Level0)
|
||||
RdbStoreConfig config(dbPath);
|
||||
std::string bundleName = "com.ohos.config.GetDatabase";
|
||||
config.SetBundleName(bundleName);
|
||||
config.SetSecurityLevel(SecurityLevel::S1);
|
||||
config.SetArea(1);
|
||||
config.SetEncryptStatus(true);
|
||||
|
||||
@ -193,7 +192,6 @@ HWTEST_F(RdbHelperTest, GetDatabase_003, TestSize.Level0)
|
||||
RdbStoreConfig config(dbPath);
|
||||
std::string bundleName = "com.ohos.config.GetDatabase";
|
||||
config.SetBundleName(bundleName);
|
||||
config.SetSecurityLevel(SecurityLevel::S1);
|
||||
config.SetArea(1);
|
||||
config.SetEncryptStatus(true);
|
||||
|
||||
@ -206,7 +204,7 @@ HWTEST_F(RdbHelperTest, GetDatabase_003, TestSize.Level0)
|
||||
EXPECT_EQ(errCode, E_OK);
|
||||
EXPECT_NE(rdbStore1, nullptr);
|
||||
|
||||
config.SetSecurityLevel(SecurityLevel::S2);
|
||||
config.SetEncryptStatus(false);
|
||||
std::shared_ptr<RdbStore> rdbStore2 = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_EQ(errCode, E_OK);
|
||||
EXPECT_NE(rdbStore2, nullptr);
|
||||
|
@ -918,7 +918,7 @@ HWTEST_F(RdbStoreConfigTest, RdbStoreConfig_029, TestSize.Level1)
|
||||
|
||||
std::string bundleName = "com.ohos.config.test30";
|
||||
config.SetBundleName(bundleName);
|
||||
config.SetSecurityLevel(SecurityLevel::S1);
|
||||
config.SetSecurityLevel(SecurityLevel::S2);
|
||||
config.SetArea(0);
|
||||
config.SetEncryptStatus(false);
|
||||
|
||||
@ -931,10 +931,10 @@ HWTEST_F(RdbStoreConfigTest, RdbStoreConfig_029, TestSize.Level1)
|
||||
store = nullptr;
|
||||
|
||||
auto invalidConfig = config;
|
||||
invalidConfig.SetSecurityLevel(SecurityLevel::S2);
|
||||
invalidConfig.SetSecurityLevel(SecurityLevel::S1);
|
||||
store = RdbHelper::GetRdbStore(invalidConfig, 1, helper, errCode);
|
||||
EXPECT_EQ(errCode, E_OK);
|
||||
EXPECT_NE(store, nullptr);
|
||||
EXPECT_EQ(errCode, E_CONFIG_INVALID_CHANGE);
|
||||
EXPECT_EQ(store, nullptr);
|
||||
store = nullptr;
|
||||
|
||||
RdbHelper::DeleteRdbStore(dbPath);
|
||||
@ -1009,6 +1009,38 @@ HWTEST_F(RdbStoreConfigTest, RdbStoreConfig_032, TestSize.Level1)
|
||||
EXPECT_EQ(300, config.GetWriteTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStoreConfig_033
|
||||
* @tc.desc: test RdbStoreConfig SetSecurityLevel S2->S1
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RdbStoreConfigTest, RdbStoreConfig_033, TestSize.Level1)
|
||||
{
|
||||
const std::string dbPath = RDB_TEST_PATH + "config_test_33.db";
|
||||
RdbStoreConfig config(dbPath);
|
||||
|
||||
std::string bundleName = "com.ohos.config.test33";
|
||||
config.SetBundleName(bundleName);
|
||||
config.SetSecurityLevel(SecurityLevel::S2);
|
||||
|
||||
ConfigTestOpenCallback helper;
|
||||
int errCode = E_ERROR;
|
||||
std::shared_ptr<RdbStore> store = RdbHelper::GetRdbStore(config, 1, helper, errCode);
|
||||
EXPECT_EQ(errCode, E_OK);
|
||||
EXPECT_NE(store, nullptr);
|
||||
|
||||
store = nullptr;
|
||||
|
||||
auto invalidConfig = config;
|
||||
invalidConfig.SetSecurityLevel(SecurityLevel::S1);
|
||||
store = RdbHelper::GetRdbStore(invalidConfig, 1, helper, errCode);
|
||||
EXPECT_EQ(errCode, E_CONFIG_INVALID_CHANGE);
|
||||
EXPECT_EQ(store, nullptr);
|
||||
store = nullptr;
|
||||
|
||||
RdbHelper::DeleteRdbStore(dbPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RdbStoreConfigVisitor_001
|
||||
* @tc.desc: test RdbStoreConfigVisitor
|
||||
|
Loading…
Reference in New Issue
Block a user