Release 0.1.66
[platform/core/security/key-manager.git] / unit-tests / test_generic-backend.cpp
1 /*
2  *  Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16 #include <generic-backend/gobj.h>
17 #include <generic-backend/gstore.h>
18 #include <generic-backend/algo-validation.h>
19 #include <generic-backend/encryption-params.h>
20
21 #include <boost_macros_wrapper.h>
22
23 using namespace CKM;
24
25 namespace {
26
27 class GObjTest : public Crypto::GObj {
28 public:
29         GObjTest() : Crypto::GObj(CryptoBackend::None) {}
30 };
31
32 struct TestException : public std::exception {};
33
34 class ThrowingHandlerTest {
35 public:
36         static void Handle(const std::string &)
37         {
38                 throw TestException();
39         }
40 };
41
42 } // namespace anonymous
43
44 BOOST_AUTO_TEST_SUITE(GENERIC_BACKEND_TEST)
45
46 NEGATIVE_TEST_CASE(gobj)
47 {
48         GObjTest obj;
49
50         BOOST_REQUIRE_THROW(obj.getBinary(), Exc::Crypto::OperationNotSupported);
51         BOOST_REQUIRE_THROW(obj.encrypt(CryptoAlgorithm(), RawBuffer()),
52                                                 Exc::Crypto::OperationNotSupported);
53         BOOST_REQUIRE_THROW(obj.decrypt(CryptoAlgorithm(), RawBuffer()),
54                                                 Exc::Crypto::OperationNotSupported);
55         BOOST_REQUIRE_THROW(obj.sign(CryptoAlgorithm(), RawBuffer()),
56                                                 Exc::Crypto::OperationNotSupported);
57         BOOST_REQUIRE_THROW(obj.verify(CryptoAlgorithm(), RawBuffer(), RawBuffer()),
58                                                 Exc::Crypto::OperationNotSupported);
59 }
60
61 BOOST_AUTO_TEST_SUITE_END()