1 // Copyright 2018 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16 #include "tink/key_manager.h"
17
18 #include <memory>
19
20 #include "gmock/gmock.h"
21 #include "gtest/gtest.h"
22 #include "absl/status/status.h"
23 #include "tink/util/status.h"
24 #include "tink/util/test_matchers.h"
25 #include "proto/empty.pb.h"
26
27 namespace crypto {
28 namespace tink {
29
30 namespace {
31
32 using ::crypto::tink::test::StatusIs;
33
TEST(AlwaysFailingFactoryTest,NewKeyFromProtoLite)34 TEST(AlwaysFailingFactoryTest, NewKeyFromProtoLite) {
35 std::unique_ptr<KeyFactory> factory = KeyFactory::AlwaysFailingFactory(
36 util::Status(absl::StatusCode::kAlreadyExists, ""));
37 google::crypto::tink::Empty empty_proto;
38 EXPECT_THAT(factory->NewKey(empty_proto).status(),
39 StatusIs(absl::StatusCode::kAlreadyExists));
40 }
41
TEST(AlwaysFailingFactoryTest,NewKeyFromStringView)42 TEST(AlwaysFailingFactoryTest, NewKeyFromStringView) {
43 std::unique_ptr<KeyFactory> factory = KeyFactory::AlwaysFailingFactory(
44 util::Status(absl::StatusCode::kAlreadyExists, ""));
45 EXPECT_THAT(factory->NewKey("").status(),
46 StatusIs(absl::StatusCode::kAlreadyExists));
47 }
48
TEST(AlwaysFailingFactoryTest,NewKeyData)49 TEST(AlwaysFailingFactoryTest, NewKeyData) {
50 std::unique_ptr<KeyFactory> factory = KeyFactory::AlwaysFailingFactory(
51 util::Status(absl::StatusCode::kAlreadyExists, ""));
52 EXPECT_THAT(factory->NewKeyData("").status(),
53 StatusIs(absl::StatusCode::kAlreadyExists));
54 }
55
56 } // namespace
57 } // namespace tink
58 } // namespace crypto
59