Add test for sqlite chipher compatibility

GitOrigin-RevId: 7b458dd4208166391071bc64dcb9204ff2da1df7
This commit is contained in:
Arseny Smirnov 2020-08-12 18:36:26 +03:00
parent 0e4e1268ac
commit 10c619053e
3 changed files with 122 additions and 0 deletions

View File

@ -66,4 +66,92 @@ static const char gzip_bomb_arr[] =
"TLGznukoHjpzn3qgqJTV2ogJXaK6ctqTgxKUoPyfUeqmx4szeRJuj3josnbUu0O57kcXXX-bi25IozxSONDzF5jalI4";
const char *gzip_bomb = gzip_bomb_arr;
const size_t gzip_bomb_size = sizeof(gzip_bomb_arr) - 1;
static const char sqlite_sample_db_arr[] =
"olFZ1MdfY0Abj+LtR9ft6DTZgEHW7/"
"z7yAhC07NKr7pBAHWkbQyMPtyVSIW7PLdVaQIHYwLgd7ovQSzD7eTINxZh6Nxpwa8HTynvjhHIdQhtysRL9m3mTEj4mbjU48zq+jcFdsnzG+"
"GJAzk5MQRCi+NyDWGYnBoPhiiPc4QBoFgKoYGIhQwfVci5kf2fYIQrCM1H7QQZ8RHoqCuQ3IjMpZjt/Gzqy+P8kn2PXKWHG8/y5eDc5nQCk/"
"XhkY7A9Wl7ZUsgK7mkA1O1VHp9X0Kz/WCuWhsULuUSeshXmJ1zKciUmTMhS3T7/"
"mc2jVrR00SyT22XwpL6dRwaNtUXVJKJwtzxrTHTxWq33KdxKXFlMr5ffbWsOfpkEHlpeKybJF70bzOgKUF5pmCHOll+3gfZcJOVFI4DvHFSnt/"
"Y3XlhJDrHliXeXcfsSUNzpBsBO+/+O/MMGLi2m/kJ9GHXGpieJsHPSQG1RMNqe84QIymLEwnGptg/"
"I+gw6xqFsUqBo2Z3Hllgz0t9GqvI1ENZr16nwf9hUGMEpj2pdKGR+eSSHMac3BJaiGgoKE7BfUjaaXzI5a8FfZTyl+"
"JUMf3ou2YBuO9fiuR1AhpAyydLSAn93OdbIF+VUHea8944nyUQB2k6idA9zfOFOVPZlaWC8/KxJeLDIAYYv3s+aK3kz/"
"EyU4SSRvDLX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db_size = sizeof(sqlite_sample_db_arr) - 1;
} // namespace td

View File

@ -16,4 +16,7 @@ extern const size_t thumbnail_size;
extern const char *gzip_bomb;
extern const size_t gzip_bomb_size;
extern const char *sqlite_sample_db;
extern const size_t sqlite_sample_db_size;
} // namespace td

View File

@ -17,7 +17,9 @@
#include "td/actor/actor.h"
#include "td/utils/base64.h"
#include "td/utils/common.h"
#include "td/utils/filesystem.h"
#include "td/utils/logging.h"
#include "td/utils/port/FileFd.h"
#include "td/utils/port/thread.h"
@ -26,6 +28,8 @@
#include "td/utils/Status.h"
#include "td/utils/tests.h"
#include "data.h"
#include <limits>
#include <map>
#include <memory>
@ -191,6 +195,33 @@ TEST(DB, sqlite_encryption) {
SqliteDb::open_with_key(path, cucumber).ensure_error();
}
TEST(DB, sqlite_encryption_migrate) {
string path = "test_sqlite_db";
SqliteDb::destroy(path).ignore();
auto cucumber = DbKey::password("cucumber");
auto empty = DbKey::empty();
if (0) {
// sqlite_sample_db was generated by the following code
{
SqliteDb::change_key(path, cucumber, empty).ensure();
auto db = SqliteDb::open_with_key(path, cucumber).move_as_ok();
db.set_user_version(123).ensure();
auto kv = SqliteKeyValue();
kv.init_with_connection(db.clone(), "kv").ensure();
kv.set("hello", "world");
}
LOG(ERROR) << base64_encode(read_file(path).move_as_ok());
}
write_file(path, base64_decode(Slice(sqlite_sample_db, sqlite_sample_db_size)).move_as_ok()).ensure();
{
auto db = SqliteDb::open_with_key(path, cucumber).move_as_ok();
auto kv = SqliteKeyValue();
kv.init_with_connection(db.clone(), "kv").ensure();
CHECK(kv.get("hello") == "world");
CHECK(db.user_version().ok() == 123);
}
}
using SeqNo = uint64;
struct DbQuery {
enum class Type { Get, Set, Erase } type = Type::Get;