1 /******************************************************************************
2 *
3 * Copyright 2019 Google, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include <binder/ProcessState.h>
20 #include <gtest/gtest.h>
21 #include <fstream>
22
23 #include "btif/include/btif_keystore.h"
24
25 using namespace bluetooth;
26
27 class BtifKeystoreTest : public ::testing::Test {
28 protected:
29 std::unique_ptr<BtifKeystore> btif_keystore_;
SetUp()30 void SetUp() override {
31 android::ProcessState::self()->startThreadPool();
32 btif_keystore_ =
33 std::make_unique<BtifKeystore>(static_cast<keystore::KeystoreClient*>(
34 new keystore::KeystoreClientImpl));
35 };
TearDown()36 void TearDown() override { btif_keystore_ = nullptr; };
37 };
38
TEST_F(BtifKeystoreTest,test_encrypt_decrypt)39 TEST_F(BtifKeystoreTest, test_encrypt_decrypt) {
40 std::string hash = "test";
41
42 std::string encrypted_hash = btif_keystore_->Encrypt(hash, 0);
43 std::string decrypted_hash = btif_keystore_->Decrypt(encrypted_hash);
44
45 EXPECT_FALSE(encrypted_hash.empty());
46 EXPECT_EQ(hash, decrypted_hash);
47 }
48
TEST_F(BtifKeystoreTest,test_encrypt_empty_hash)49 TEST_F(BtifKeystoreTest, test_encrypt_empty_hash) {
50 std::string hash = "";
51
52 std::string encrypted_hash = btif_keystore_->Encrypt(hash, 0);
53
54 EXPECT_TRUE(encrypted_hash.empty());
55 }
56
TEST_F(BtifKeystoreTest,test_decrypt_empty_hash)57 TEST_F(BtifKeystoreTest, test_decrypt_empty_hash) {
58 std::string hash = "";
59
60 std::string decrypted_hash = btif_keystore_->Decrypt(hash);
61
62 EXPECT_TRUE(decrypted_hash.empty());
63 }
64