/Users/deen/code/yugabyte-db/src/yb/util/crypt-test.cc
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include <glog/logging.h> |
15 | | #include <gtest/gtest.h> |
16 | | |
17 | | #include "yb/util/crypt.h" |
18 | | #include "yb/util/test_util.h" |
19 | | |
20 | | namespace yb { |
21 | | namespace util { |
22 | | |
23 | | class CryptTest: public YBTest { |
24 | | }; |
25 | | |
26 | 1 | TEST_F(CryptTest, TestHashing) { |
27 | 1 | char salt[kBcryptHashSize]; |
28 | 1 | char hash[kBcryptHashSize]; |
29 | 1 | int ret; |
30 | | |
31 | 1 | const char pass[] = "hi,mom"; |
32 | 1 | const char hash1[] = "$2a$10$VEVmGHy4F4XQMJ3eOZJAUeb.MedU0W10pTPCuf53eHdKJPiSE8sMK"; |
33 | 1 | const char hash2[] = "$2a$10$3F0BVk5t8/aoS.3ddaB3l.fxg5qvafQ9NybxcpXLzMeAt.nVWn.NO"; |
34 | | |
35 | 1 | ret = bcrypt_gensalt(12, salt); |
36 | 1 | EXPECT_EQ(0, ret); |
37 | | |
38 | 1 | ret = bcrypt_hashpw("testtesttest", salt, hash); |
39 | 1 | EXPECT_EQ(0, ret); |
40 | | |
41 | 1 | ret = bcrypt_hashpw(pass, hash1, hash); |
42 | 1 | EXPECT_EQ(0, ret); |
43 | 1 | EXPECT_EQ(*hash1, *hash); |
44 | | |
45 | 1 | ret = bcrypt_hashpw(pass, hash2, hash); |
46 | 1 | EXPECT_EQ(0, ret); |
47 | 1 | EXPECT_EQ(*hash2, *hash); |
48 | 1 | } |
49 | | |
50 | | } // namespace util |
51 | | } // namespace yb |