Add internal test cases 65/111965/2
authorKyungwook Tak <k.tak@samsung.com>
Fri, 13 Jan 2017 11:06:41 +0000 (20:06 +0900)
committerkyungwook tak <k.tak@samsung.com>
Fri, 3 Feb 2017 06:39:16 +0000 (22:39 -0800)
Change-Id: Ifd6b70245a8210f17097cd47d7739c8d19ab1819
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
(cherry picked from commit 925c8d123fd9ece130ccf359446ad9e0e63906e3)

19 files changed:
packaging/key-manager.spec
tests/CMakeLists.txt
tests/test_async-observer.cpp [new file with mode: 0644]
tests/test_binary-queue.cpp [new file with mode: 0644]
tests/test_certificate.cpp [new file with mode: 0644]
tests/test_common.cpp
tests/test_common.h
tests/test_crypto-logic.cpp [new file with mode: 0644]
tests/test_dpl-db.cpp [new file with mode: 0644]
tests/test_dpl-exception.cpp [new file with mode: 0644]
tests/test_exception.cpp [new file with mode: 0644]
tests/test_generic-backend.cpp [new file with mode: 0644]
tests/test_key-provider.cpp [moved from tests/test-key-provider.cpp with 78% similarity]
tests/test_key.cpp [new file with mode: 0644]
tests/test_log-provider.cpp [new file with mode: 0644]
tests/test_ss-crypto.cpp [new file with mode: 0644]
tests/test_stringify.cpp [new file with mode: 0644]
tests/test_sw-backend.cpp [new file with mode: 0644]
tests/test_tz-backend.cpp [new file with mode: 0644]

index 8ec74d6..8e40485 100644 (file)
@@ -45,7 +45,7 @@ Requires: libkey-manager-common = %{version}-%{release}
 %global old_rw_data_dir /opt/data/ckm
 %global rw_data_dir %{?TZ_SYS_DATA:%TZ_SYS_DATA/ckm}%{!?TZ_SYS_DATA:%old_rw_data_dir}
 %global ro_data_dir %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE/ckm}%{!?TZ_SYS_RO_SHARE:%_datadir/ckm}
-%global db_test_dir %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE/ckm-db-test}%{!?TZ_SYS_RO_SHARE:%_datadir/ckm-db-test}
+%global test_dir %{?TZ_SYS_DATA:%TZ_SYS_DATA/ckm-tests-internal}%{!?TZ_SYS_DATA:%/opt/data/ckm-tests-internal}
 %global bin_dir %{?TZ_SYS_BIN:%TZ_SYS_BIN}%{!?TZ_SYS_BIN:%_bindir}
 # image creation error occured if /usr/sbin used for ldconfig
 #%global sbin_dir %{?TZ_SYS_SBIN:%TZ_SYS_SBIN}%{!?TZ_SYS_SBIN:%_sbindir}
@@ -150,7 +150,7 @@ export LDFLAGS+="-Wl,--rpath=%{_libdir},-Bsymbolic-functions "
         -DRO_ETC_DIR=%{ro_etc_dir} \
         -DBIN_DIR=%{bin_dir} \
         -DINITIAL_VALUES_DIR=%{initial_values_dir} \
-        -DDB_TEST_DIR=%{db_test_dir} \
+        -DTEST_DIR=%{test_dir} \
         -DCA_CERTS_DIR=%{ca_certs_dir} \
 %if 0%{?watchdog_enabled}
         -DWATCHDOG_ENABLED=%{watchdog_enabled} \
@@ -313,4 +313,4 @@ fi
 %{bin_dir}/ckm_so_loader
 %{bin_dir}/ckm_db_tool
 %{bin_dir}/ckm_generate_db
-%db_test_dir
+%test_dir
index 186a659..5431f8e 100644 (file)
@@ -4,8 +4,13 @@ PKG_CHECK_MODULES(KEY_MANAGER_TEST_DEP
     )
 
 FIND_PACKAGE(Threads REQUIRED)
-ADD_DEFINITIONS( "-DBOOST_TEST_DYN_LINK" )
+ADD_DEFINITIONS("-DBOOST_TEST_DYN_LINK")
+
+SET(DB_TEST_DIR ${TEST_DIR}/db)
+SET(SS_TEST_DIR ${TEST_DIR}/secure-storage)
+
 ADD_DEFINITIONS("-DDB_TEST_DIR=\"${DB_TEST_DIR}\"")
+ADD_DEFINITIONS("-DSS_TEST_DIR=\"${SS_TEST_DIR}\"")
 
 SET(KEY_MANAGER_SRC_PATH ${PROJECT_SOURCE_DIR}/src)
 SET(KEY_MANAGER_PATH ${PROJECT_SOURCE_DIR}/src/manager)
@@ -26,44 +31,72 @@ INCLUDE_DIRECTORIES(
     ${KEY_MANAGER_PATH}/service
     ${KEY_MANAGER_PATH}/initial-values
     ${KEY_MANAGER_PATH}/main
-    ${KEY_MANAGER_PATH}/common/
-    ${KEY_MANAGER_PATH}/client-async/
+    ${KEY_MANAGER_PATH}/common
+    ${KEY_MANAGER_PATH}/crypto
+    ${KEY_MANAGER_PATH}/client-async
     ${KEY_MANAGER_SRC_PATH}/include
-    ${KEY_MANAGER_TEST_MERGED_SRC}/
-    ${KEY_MANAGER_TEST_MERGED_SRC}/encryption-scheme/
+    ${KEY_MANAGER_TEST_MERGED_SRC}
+    ${KEY_MANAGER_TEST_MERGED_SRC}/encryption-scheme
     )
 
 SET(TEST_MERGED_SOURCES
     ${KEY_MANAGER_TEST_MERGED_SRC}/colour_log_formatter.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/DBFixture.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/main.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_async-observer.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_base64.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_binary-queue.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_certificate.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_comm-manager.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_common.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_crypto-logic.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_data-type.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_db_crypto.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_descriptor-set.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_dpl-db.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_dpl-exception.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_encryption-scheme.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_exception.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_for-each-file.cpp
-    ${KEY_MANAGER_TEST_MERGED_SRC}/test-key-provider.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_generic-backend.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_key.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_key-provider.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_log-provider.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_safe-buffer.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_serialization.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_sql.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_stringify.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_ss-crypto.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_sw-backend.cpp
+    ${KEY_MANAGER_TEST_MERGED_SRC}/test_tz-backend.cpp
     ${KEY_MANAGER_TEST_MERGED_SRC}/test_xml-parser.cpp
 
     # duplicated srcs to test hidden symbols
     ${KEY_MANAGER_PATH}/client-async/descriptor-set.cpp
+    ${KEY_MANAGER_PATH}/crypto/platform/decider.cpp
+    ${KEY_MANAGER_PATH}/crypto/sw-backend/internals.cpp
+    ${KEY_MANAGER_PATH}/crypto/sw-backend/obj.cpp
+    ${KEY_MANAGER_PATH}/crypto/sw-backend/store.cpp
+    ${KEY_MANAGER_PATH}/crypto/tz-backend/obj.cpp
+    ${KEY_MANAGER_PATH}/crypto/tz-backend/store.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/assert.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/colors.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/errno_string.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/naive_synchronization_object.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/sql_connection.cpp
+    ${KEY_MANAGER_PATH}/dpl/log/src/abstract_log_provider.cpp
+    ${KEY_MANAGER_PATH}/dpl/log/src/dlog_log_provider.cpp
+    ${KEY_MANAGER_PATH}/dpl/log/src/journal_log_provider.cpp
+    ${KEY_MANAGER_PATH}/dpl/log/src/log.cpp
+    ${KEY_MANAGER_PATH}/dpl/log/src/old_style_log_provider.cpp
     ${KEY_MANAGER_PATH}/initial-values/parser.cpp
+    ${KEY_MANAGER_PATH}/initial-values/SWKeyFile.cpp
     ${KEY_MANAGER_PATH}/initial-values/xml-utils.cpp
+    ${KEY_MANAGER_PATH}/service/crypto-logic.cpp
     ${KEY_MANAGER_PATH}/service/db-crypto.cpp
     ${KEY_MANAGER_PATH}/service/for-each-file.cpp
     ${KEY_MANAGER_PATH}/service/key-provider.cpp
-    ${KEY_MANAGER_PATH}/sqlcipher/sqlcipher.c
+    ${KEY_MANAGER_PATH}/service/ss-crypto.cpp
     )
 
 LINK_DIRECTORIES(${KEY_MANAGER_DEP_LIBRARY_DIRS})
@@ -102,5 +135,6 @@ INSTALL(
     )
 
 INSTALL(DIRECTORY resources/traverse DESTINATION ${DB_TEST_DIR})
+INSTALL(DIRECTORY secure-storage-old-data/ DESTINATION ${SS_TEST_DIR})
 
 ADD_SUBDIRECTORY(encryption-scheme)
diff --git a/tests/test_async-observer.cpp b/tests/test_async-observer.cpp
new file mode 100644 (file)
index 0000000..7479605
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <ckm/ckm-manager-async.h>
+#include <boost/test/unit_test.hpp>
+#include <stdexcept>
+
+using namespace CKM;
+
+namespace {
+
+class TestObserver : public ManagerAsync::Observer {
+public:
+       void ReceivedError(int) { throw std::invalid_argument("test observer recv err"); }
+};
+
+const std::string CERT_PEM =
+       "-----BEGIN CERTIFICATE-----\n"
+       "MIIDnzCCAoegAwIBAgIJAMH/ADkC5YSTMA0GCSqGSIb3DQEBBQUAMGYxCzAJBgNV\n"
+       "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMQ0wCwYDVQQKDARBQ01FMRAwDgYD\n"
+       "VQQLDAdUZXN0aW5nMSEwHwYDVQQDDBhUZXN0IHJvb3QgY2EgY2VydGlmaWNhdGUw\n"
+       "HhcNMTQxMjMwMTcyMTUyWhcNMjQxMjI3MTcyMTUyWjBmMQswCQYDVQQGEwJBVTET\n"
+       "MBEGA1UECAwKU29tZS1TdGF0ZTENMAsGA1UECgwEQUNNRTEQMA4GA1UECwwHVGVz\n"
+       "dGluZzEhMB8GA1UEAwwYVGVzdCByb290IGNhIGNlcnRpZmljYXRlMIIBIjANBgkq\n"
+       "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7QxvDKzyFCF3w9vC\n"
+       "9IDE/Yr12w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh7xk8qfEgH3da\n"
+       "eDoV59IZ9r543KM+g8jm6KffYGX1bIJVVY5OhBRbO9nY6byYpd5kbCIUB6dCf7/W\n"
+       "rQl1aIdLGFIegAzPGFPXDcU6F192686x54bxt/itMX4agHJ9ZC/rrTBIZghVsjJo\n"
+       "5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY+Cgw1Yoz+HHv31AllgFs\n"
+       "BquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsqGQIDAQABo1Aw\n"
+       "TjAdBgNVHQ4EFgQUt6pkzFt1PZlfYRL/HGnufF4frdwwHwYDVR0jBBgwFoAUt6pk\n"
+       "zFt1PZlfYRL/HGnufF4frdwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC\n"
+       "AQEAld7Qwq0cdzDQ51w1RVLwTR8Oy25PB3rzwEHcSGJmdqlMi3xOdaz80S1R1BBX\n"
+       "ldvGBG5Tn0vT7xSuhmSgI2/HnBpy9ocHVOmhtNB4473NieEpfTYrnGXrFxu46Wus\n"
+       "9m/ZnugcQ2G6C54A/NFtvgLmaC8uH8M7gKdS6uYUwJFQEofkjmd4UpOYSqmcRXhS\n"
+       "Jzd5FYFWkJhKJYp3nlENSOD8CUFFVGekm05nFN2gRVc/qaqQkEX77+XYvhodLRsV\n"
+       "qMn7nf7taidDKLO2T4bhujztnTYOhhaXKgPy7AtZ28N2wvX96VyAPB/vrchGmyBK\n"
+       "kOg11TpPdNDkhb1J4ZCh2gupDg==\n"
+       "-----END CERTIFICATE-----\n";
+
+}
+
+BOOST_AUTO_TEST_SUITE(ASYNC_OBSERVER_TEST)
+
+BOOST_AUTO_TEST_CASE(base)
+{
+       TestObserver o;
+
+       BOOST_REQUIRE_THROW(o.ReceivedError(0), std::invalid_argument);
+
+       BOOST_REQUIRE_NO_THROW(o.ReceivedSaveKey());
+       BOOST_REQUIRE_NO_THROW(o.ReceivedSaveCertificate());
+       BOOST_REQUIRE_NO_THROW(o.ReceivedSaveData());
+       BOOST_REQUIRE_NO_THROW(o.ReceivedSavePKCS12());
+       BOOST_REQUIRE_NO_THROW(o.ReceivedRemovedAlias());
+
+       BOOST_REQUIRE_NO_THROW(o.ReceivedKey(std::move(*Key::createAES(RawBuffer({
+               0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+               0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
+               })))));
+       BOOST_REQUIRE_NO_THROW(o.ReceivedCertificate(std::move(*Certificate::create(
+               RawBuffer(CERT_PEM.begin(), CERT_PEM.end()), DataFormat::FORM_PEM))));
+       BOOST_REQUIRE_NO_THROW(o.ReceivedData(RawBuffer()));
+       BOOST_REQUIRE_NO_THROW(o.ReceivedPKCS12(PKCS12ShPtr()));
+
+       BOOST_REQUIRE_NO_THROW(o.ReceivedKeyAliasVector(AliasVector()));
+       BOOST_REQUIRE_NO_THROW(o.ReceivedCertificateAliasVector(AliasVector()));
+       BOOST_REQUIRE_NO_THROW(o.ReceivedDataAliasVector(AliasVector()));
+
+       BOOST_REQUIRE_NO_THROW(o.ReceivedCreateKeyAES());
+       BOOST_REQUIRE_NO_THROW(o.ReceivedCreateKeyPair());
+
+       BOOST_REQUIRE_NO_THROW(o.ReceivedGetCertificateChain(CertificateShPtrVector()));
+
+       BOOST_REQUIRE_NO_THROW(o.ReceivedCreateSignature(RawBuffer()));
+       BOOST_REQUIRE_NO_THROW(o.ReceivedVerifySignature());
+       BOOST_REQUIRE_NO_THROW(o.ReceivedOCSPCheck(0));
+       BOOST_REQUIRE_NO_THROW(o.ReceivedSetPermission());
+       BOOST_REQUIRE_NO_THROW(o.ReceivedEncrypted(RawBuffer()));
+       BOOST_REQUIRE_NO_THROW(o.ReceivedDecrypted(RawBuffer()));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_binary-queue.cpp b/tests/test_binary-queue.cpp
new file mode 100644 (file)
index 0000000..5180ded
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <boost/test/unit_test.hpp>
+
+#include <dpl/binary_queue.h>
+#include <ckm/ckm-raw-buffer.h>
+
+using namespace CKM;
+
+namespace {
+
+RawBuffer buf({0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07});
+
+} // namespace anonymous
+
+BOOST_AUTO_TEST_SUITE(BINARY_QUEUE_TEST)
+
+BOOST_AUTO_TEST_CASE(copy_assignment)
+{
+       BinaryQueue bq1;
+       bq1.AppendCopy(buf.data(), buf.size());
+
+       BinaryQueue bq2;
+       bq2 = bq1;
+
+       BOOST_REQUIRE(bq1.Size() == bq2.Size() && bq1.Size() == buf.size());
+
+       RawBuffer buf1(bq1.Size(), 0x00);
+       RawBuffer buf2(bq2.Size(), 0x00);
+
+       bq1.Flatten(buf1.data(), buf1.size());
+       bq2.Flatten(buf2.data(), buf2.size());
+
+       BOOST_REQUIRE(buf1 == buf2);
+}
+
+BOOST_AUTO_TEST_CASE(append_copy_to)
+{
+       BinaryQueue bq1;
+       bq1.AppendCopy(buf.data(), buf.size());
+
+       BinaryQueue bq2;
+       bq1.AppendCopyTo(bq2);
+
+       BOOST_REQUIRE(bq1.Size() == bq2.Size() && bq1.Size() == buf.size());
+
+       RawBuffer buf1(bq1.Size(), 0x00);
+       RawBuffer buf2(bq2.Size(), 0x00);
+
+       bq1.Flatten(buf1.data(), buf1.size());
+       bq2.Flatten(buf2.data(), buf2.size());
+
+       BOOST_REQUIRE(buf1 == buf2);
+}
+
+BOOST_AUTO_TEST_CASE(append_move_to)
+{
+       BinaryQueue bq1;
+       bq1.AppendCopy(buf.data(), buf.size());
+
+       BinaryQueue bq2;
+       bq1.AppendMoveTo(bq2);
+
+       BOOST_REQUIRE(bq2.Size() == buf.size() && bq1.Empty());
+
+       RawBuffer buf2(bq2.Size(), 0x00);
+       bq2.Flatten(buf2.data(), buf2.size());
+       BOOST_REQUIRE(buf == buf2);
+}
+
+BOOST_AUTO_TEST_CASE(read)
+{
+       BinaryQueue bq1;
+       bq1.AppendCopy(buf.data(), buf.size());
+
+       auto bq2 = bq1.Read(buf.size());
+       BOOST_REQUIRE(bq1.Empty());
+
+       RawBuffer buf2(bq2->Size(), 0x00);
+       bq2->Flatten(buf2.data(), buf2.size());
+       BOOST_REQUIRE(buf == buf2);
+}
+
+BOOST_AUTO_TEST_CASE(write)
+{
+       BinaryQueue bq1;
+       bq1.AppendCopy(buf.data(), buf.size());
+
+       BinaryQueue bq2;
+       bq2.Write(bq1, bq1.Size());
+
+       RawBuffer buf1(bq1.Size(), 0x00);
+       RawBuffer buf2(bq2.Size(), 0x00);
+
+       bq1.Flatten(buf1.data(), buf1.size());
+       bq2.Flatten(buf2.data(), buf2.size());
+
+       BOOST_REQUIRE(buf1 == buf2);
+}
+
+BOOST_AUTO_TEST_CASE(bucket_visitor)
+{
+       static std::vector<unsigned char> globalBuf;
+
+       class BucketVisitorTest : public BinaryQueue::BucketVisitor {
+       public:
+               virtual void OnVisitBucket(const void *buffer, size_t bufferSize) override
+               {
+                       for (size_t i = 0; i < bufferSize; ++i)
+                               globalBuf.push_back(static_cast<const unsigned char *>(buffer)[i]);
+               }
+       };
+
+       BucketVisitorTest visitor;
+
+       constexpr size_t BucketNum = 3;
+       BinaryQueue bq;
+       for (size_t i = 0; i < BucketNum; ++i)
+               bq.AppendCopy(buf.data(), buf.size());
+
+       bq.VisitBuckets(&visitor);
+
+       BOOST_REQUIRE(globalBuf.size() == buf.size() * BucketNum);
+       for (size_t i = 0; i < BucketNum; ++i)
+               for (size_t j = 0; j < buf.size(); ++j)
+                       BOOST_REQUIRE(globalBuf[i * buf.size() + j] == buf[j]);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_certificate.cpp b/tests/test_certificate.cpp
new file mode 100644 (file)
index 0000000..8c7695a
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <certificate-impl.h>
+
+#include <boost/test/unit_test.hpp>
+
+namespace {
+const std::string CERT_PEM =
+       "-----BEGIN CERTIFICATE-----\n"
+       "MIIDnzCCAoegAwIBAgIJAMH/ADkC5YSTMA0GCSqGSIb3DQEBBQUAMGYxCzAJBgNV\n"
+       "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMQ0wCwYDVQQKDARBQ01FMRAwDgYD\n"
+       "VQQLDAdUZXN0aW5nMSEwHwYDVQQDDBhUZXN0IHJvb3QgY2EgY2VydGlmaWNhdGUw\n"
+       "HhcNMTQxMjMwMTcyMTUyWhcNMjQxMjI3MTcyMTUyWjBmMQswCQYDVQQGEwJBVTET\n"
+       "MBEGA1UECAwKU29tZS1TdGF0ZTENMAsGA1UECgwEQUNNRTEQMA4GA1UECwwHVGVz\n"
+       "dGluZzEhMB8GA1UEAwwYVGVzdCByb290IGNhIGNlcnRpZmljYXRlMIIBIjANBgkq\n"
+       "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7QxvDKzyFCF3w9vC\n"
+       "9IDE/Yr12w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh7xk8qfEgH3da\n"
+       "eDoV59IZ9r543KM+g8jm6KffYGX1bIJVVY5OhBRbO9nY6byYpd5kbCIUB6dCf7/W\n"
+       "rQl1aIdLGFIegAzPGFPXDcU6F192686x54bxt/itMX4agHJ9ZC/rrTBIZghVsjJo\n"
+       "5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY+Cgw1Yoz+HHv31AllgFs\n"
+       "BquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsqGQIDAQABo1Aw\n"
+       "TjAdBgNVHQ4EFgQUt6pkzFt1PZlfYRL/HGnufF4frdwwHwYDVR0jBBgwFoAUt6pk\n"
+       "zFt1PZlfYRL/HGnufF4frdwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC\n"
+       "AQEAld7Qwq0cdzDQ51w1RVLwTR8Oy25PB3rzwEHcSGJmdqlMi3xOdaz80S1R1BBX\n"
+       "ldvGBG5Tn0vT7xSuhmSgI2/HnBpy9ocHVOmhtNB4473NieEpfTYrnGXrFxu46Wus\n"
+       "9m/ZnugcQ2G6C54A/NFtvgLmaC8uH8M7gKdS6uYUwJFQEofkjmd4UpOYSqmcRXhS\n"
+       "Jzd5FYFWkJhKJYp3nlENSOD8CUFFVGekm05nFN2gRVc/qaqQkEX77+XYvhodLRsV\n"
+       "qMn7nf7taidDKLO2T4bhujztnTYOhhaXKgPy7AtZ28N2wvX96VyAPB/vrchGmyBK\n"
+       "kOg11TpPdNDkhb1J4ZCh2gupDg==\n"
+       "-----END CERTIFICATE-----\n";
+
+const std::string CERT_BASE64 =
+       "MIIDnzCCAoegAwIBAgIJAMH/ADkC5YSTMA0GCSqGSIb3DQEBBQUAMGYxCzAJBgNV\n"
+       "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMQ0wCwYDVQQKDARBQ01FMRAwDgYD\n"
+       "VQQLDAdUZXN0aW5nMSEwHwYDVQQDDBhUZXN0IHJvb3QgY2EgY2VydGlmaWNhdGUw\n"
+       "HhcNMTQxMjMwMTcyMTUyWhcNMjQxMjI3MTcyMTUyWjBmMQswCQYDVQQGEwJBVTET\n"
+       "MBEGA1UECAwKU29tZS1TdGF0ZTENMAsGA1UECgwEQUNNRTEQMA4GA1UECwwHVGVz\n"
+       "dGluZzEhMB8GA1UEAwwYVGVzdCByb290IGNhIGNlcnRpZmljYXRlMIIBIjANBgkq\n"
+       "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7QxvDKzyFCF3w9vC\n"
+       "9IDE/Yr12w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh7xk8qfEgH3da\n"
+       "eDoV59IZ9r543KM+g8jm6KffYGX1bIJVVY5OhBRbO9nY6byYpd5kbCIUB6dCf7/W\n"
+       "rQl1aIdLGFIegAzPGFPXDcU6F192686x54bxt/itMX4agHJ9ZC/rrTBIZghVsjJo\n"
+       "5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY+Cgw1Yoz+HHv31AllgFs\n"
+       "BquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsqGQIDAQABo1Aw\n"
+       "TjAdBgNVHQ4EFgQUt6pkzFt1PZlfYRL/HGnufF4frdwwHwYDVR0jBBgwFoAUt6pk\n"
+       "zFt1PZlfYRL/HGnufF4frdwwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC\n"
+       "AQEAld7Qwq0cdzDQ51w1RVLwTR8Oy25PB3rzwEHcSGJmdqlMi3xOdaz80S1R1BBX\n"
+       "ldvGBG5Tn0vT7xSuhmSgI2/HnBpy9ocHVOmhtNB4473NieEpfTYrnGXrFxu46Wus\n"
+       "9m/ZnugcQ2G6C54A/NFtvgLmaC8uH8M7gKdS6uYUwJFQEofkjmd4UpOYSqmcRXhS\n"
+       "Jzd5FYFWkJhKJYp3nlENSOD8CUFFVGekm05nFN2gRVc/qaqQkEX77+XYvhodLRsV\n"
+       "qMn7nf7taidDKLO2T4bhujztnTYOhhaXKgPy7AtZ28N2wvX96VyAPB/vrchGmyBK\n"
+       "kOg11TpPdNDkhb1J4ZCh2gupDg==\n";
+
+const std::string CERT_PUBKEY_PEM =
+       "-----BEGIN PUBLIC KEY-----\n"
+       "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7Qxv\n"
+       "DKzyFCF3w9vC9IDE/Yr12w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh\n"
+       "7xk8qfEgH3daeDoV59IZ9r543KM+g8jm6KffYGX1bIJVVY5OhBRbO9nY6byYpd5k\n"
+       "bCIUB6dCf7/WrQl1aIdLGFIegAzPGFPXDcU6F192686x54bxt/itMX4agHJ9ZC/r\n"
+       "rTBIZghVsjJo5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY+Cgw1Yoz\n"
+       "+HHv31AllgFsBquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsq\n"
+       "GQIDAQAB\n"
+       "-----END PUBLIC KEY-----\n";
+}
+
+using namespace CKM;
+
+BOOST_AUTO_TEST_SUITE(CERTIFICATE_TEST)
+
+BOOST_AUTO_TEST_CASE(constructors)
+{
+       RawBuffer certpem(CERT_PEM.begin(), CERT_PEM.end());
+       BOOST_REQUIRE_NO_THROW(CertificateImpl(certpem, DataFormat::FORM_PEM));
+
+       RawBuffer certbase64(CERT_BASE64.begin(), CERT_BASE64.end());
+       BOOST_REQUIRE_NO_THROW(CertificateImpl(certbase64, DataFormat::FORM_DER_BASE64));
+
+       RawBuffer dummy({0x0a, 0x0b, 0x0c, 0x0d});
+       BOOST_REQUIRE(!Certificate::create(dummy, DataFormat::FORM_PEM));
+}
+
+BOOST_AUTO_TEST_CASE(move_semantics)
+{
+       RawBuffer certbuf(CERT_PEM.begin(), CERT_PEM.end());
+
+       CertificateImpl cert1(certbuf, DataFormat::FORM_PEM);
+       CertificateImpl cert2(cert1.getX509(), true);
+       CertificateImpl moveAssigned(cert1.getX509(), true);
+
+       moveAssigned = std::move(cert2);
+       BOOST_REQUIRE(cert1.getDER() == moveAssigned.getDER());
+
+       CertificateImpl moveConstructed(std::move(moveAssigned));
+       BOOST_REQUIRE(cert1.getDER() == moveConstructed.getDER());
+}
+
+BOOST_AUTO_TEST_CASE(get_evp_sh_ptr)
+{
+       RawBuffer certbuf(CERT_PEM.begin(), CERT_PEM.end());
+       RawBuffer pubkeybuf(CERT_PUBKEY_PEM.begin(), CERT_PUBKEY_PEM.end());
+
+       CertificateImpl cert(certbuf, DataFormat::FORM_PEM);
+       KeyImpl pubkey(pubkeybuf);
+
+       KeyImpl pubkeyFromCert(cert.getEvpShPtr(), KeyType::KEY_RSA_PUBLIC);
+
+       BOOST_REQUIRE(pubkeyFromCert.getDER() == pubkey.getDER());
+}
+
+BOOST_AUTO_TEST_CASE(get_ocsp_url)
+{
+       RawBuffer certbuf(CERT_PEM.begin(), CERT_PEM.end());
+       CertificateImpl cert(certbuf, DataFormat::FORM_PEM);
+
+       BOOST_REQUIRE(cert.getOCSPURL().empty());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
index ec2b242..d01b92a 100644 (file)
@@ -22,6 +22,8 @@
  */
 #include <test_common.h>
 #include <iostream>
+#include <cstdlib>
+#include <time.h>
 
 using namespace CKM;
 
@@ -45,6 +47,17 @@ RawBuffer createBigBlob(std::size_t size)
        return createPass(0, size);
 }
 
+RawBuffer createRandom(std::size_t size)
+{
+       static unsigned int seed = ::time(nullptr);
+
+       RawBuffer buf(size, 0x00);
+       for (size_t i = 0; i < size; ++i)
+               buf[i] = static_cast<RawBuffer::value_type>(::rand_r(&seed) % 256);
+
+       return buf;
+}
+
 //raw to hex string conversion from SqlConnection
 std::string rawToHexString(const RawBuffer &raw)
 {
index 07aae64..49eb8b7 100644 (file)
@@ -32,6 +32,7 @@
 CKM::RawBuffer createDefaultPass();
 CKM::RawBuffer createPass(std::size_t from, std::size_t to);
 CKM::RawBuffer createBigBlob(std::size_t size);
+CKM::RawBuffer createRandom(std::size_t size);
 
 const CKM::RawBuffer defaultPass = createDefaultPass();
 const std::string pattern =
diff --git a/tests/test_crypto-logic.cpp b/tests/test_crypto-logic.cpp
new file mode 100644 (file)
index 0000000..ffe67ff
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <crypto-logic.h>
+#include <platform/decider.h>
+#include <generic-backend/gstore.h>
+#include <db-row.h>
+
+#include <utility>
+#include <cstdlib>
+#include <time.h>
+#include <boost/test/unit_test.hpp>
+
+#include "test_common.h"
+
+using namespace CKM;
+
+namespace {
+
+Password createRandomPass(size_t size)
+{
+       static unsigned int seed = ::time(nullptr);
+
+       Password buf(size, 0x00);
+       for (size_t i = 0; i < size; ++i)
+               buf[i] = static_cast<Password::value_type>(::rand_r(&seed) % 256);
+
+       return buf;
+}
+
+} // namespace anonymous
+
+BOOST_AUTO_TEST_SUITE(CRYPTO_LOGIC_TEST)
+
+BOOST_AUTO_TEST_CASE(move_semantics)
+{
+       CryptoLogic logic;
+
+       const std::string label = "test_label";
+       BOOST_REQUIRE_NO_THROW(logic.pushKey(label, createRandom(10)));
+
+       CryptoLogic moved(std::move(logic));
+       BOOST_REQUIRE(!logic.haveKey(label));
+       BOOST_REQUIRE(moved.haveKey(label));
+
+       CryptoLogic moveAssigned = std::move(moved);
+       BOOST_REQUIRE(!moved.haveKey(label));
+       BOOST_REQUIRE(moveAssigned.haveKey(label));
+
+       moveAssigned = std::move(moveAssigned);
+       BOOST_REQUIRE(moveAssigned.haveKey(label));
+}
+
+BOOST_AUTO_TEST_CASE(push_key)
+{
+       CryptoLogic logic;
+
+       const std::string label = "test_label";
+       BOOST_REQUIRE_THROW(logic.pushKey(std::string(), createRandom(10)),
+                                               Exc::InternalError);
+       BOOST_REQUIRE_THROW(logic.pushKey(label, RawBuffer()),
+                                               Exc::InternalError);
+
+       BOOST_REQUIRE_NO_THROW(logic.pushKey(label, createRandom(10)));
+       BOOST_REQUIRE_THROW(logic.pushKey(label, createRandom(10)),
+                                               Exc::InternalError);
+
+       std::string increasingLabel = "a";
+       for (size_t i = 0; i < 20; ++i, increasingLabel.push_back('a')) {
+               BOOST_REQUIRE_NO_THROW(logic.pushKey(increasingLabel, createRandom(10)));
+               BOOST_REQUIRE_THROW(logic.pushKey(increasingLabel, createRandom(10)),
+                                                       Exc::InternalError);
+       }
+}
+
+BOOST_AUTO_TEST_CASE(row_encryption)
+{
+       Policy policy(Password(), true);
+       Crypto::Data data(DataType(DataType::Type::BINARY_DATA), createRandom(10));
+       Crypto::Decider decider;
+       Crypto::GStore &store = decider.getStore(data.type, true);
+       Token token = store.import(data, policy.password);
+
+       Name name = "test_data";
+       Label label = "test_owner";
+       DB::Row row(token, name, label, static_cast<int>(policy.extractable));
+
+       CryptoLogic logic;
+
+       BOOST_REQUIRE_THROW(logic.encryptRow(row), Exc::InternalError);
+
+       auto key = createRandom(32);
+       BOOST_REQUIRE_NO_THROW(logic.pushKey(label, key));
+       BOOST_REQUIRE_NO_THROW(logic.encryptRow(row));
+       BOOST_REQUIRE_NO_THROW(logic.decryptRow(policy.password, row));
+}
+
+BOOST_AUTO_TEST_CASE(row_encryption_negatives)
+{
+       Policy policy(Password(), true);
+       Crypto::Data data(DataType(DataType::Type::BINARY_DATA), createRandom(10));
+       Crypto::Decider decider;
+       Crypto::GStore &store = decider.getStore(data.type, true);
+       Token token = store.import(data, policy.password);
+
+       Name name = "test_data";
+       Label label = "test_owner";
+       DB::Row row(token, name, label, static_cast<int>(policy.extractable));
+
+       CryptoLogic logic;
+
+       auto key = createRandom(32);
+       BOOST_REQUIRE_NO_THROW(logic.pushKey(label, key));
+       BOOST_REQUIRE_NO_THROW(logic.encryptRow(row));
+
+       BOOST_REQUIRE_THROW(logic.decryptRow(createRandomPass(10), row),
+                                               Exc::AuthenticationFailed);
+
+       BOOST_REQUIRE_NO_THROW(logic.removeKey(label));
+       BOOST_REQUIRE_THROW(logic.decryptRow(Password(), row),
+                                               Exc::AuthenticationFailed);
+       BOOST_REQUIRE_NO_THROW(logic.pushKey(label, key));
+
+       row.algorithmType = DBCMAlgType::NONE;
+       BOOST_REQUIRE_THROW(logic.decryptRow(Password(), row),
+                                               Exc::AuthenticationFailed);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // CRYPTO_LOGIC_TEST
diff --git a/tests/test_dpl-db.cpp b/tests/test_dpl-db.cpp
new file mode 100644 (file)
index 0000000..610c9ad
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <boost/test/unit_test.hpp>
+
+#include <dpl/db/naive_synchronization_object.h>
+
+using namespace CKM;
+using namespace CKM::DB;
+
+BOOST_AUTO_TEST_SUITE(DPL_DB_TEST)
+
+BOOST_AUTO_TEST_SUITE(NAIVE_SYNCHRONIZATION_OBJECT)
+
+BOOST_AUTO_TEST_CASE(base)
+{
+       NaiveSynchronizationObject obj;
+
+       BOOST_REQUIRE_NO_THROW(obj.Synchronize());
+       BOOST_REQUIRE_NO_THROW(obj.NotifyAll());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(SQL_CONNECTION)
+
+BOOST_AUTO_TEST_CASE(connection_broken)
+{
+       BOOST_REQUIRE_THROW(
+               SqlConnection("test-db", static_cast<SqlConnection::Flag::Option>(999999)),
+               SqlConnection::Exception::ConnectionBroken);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_dpl-exception.cpp b/tests/test_dpl-exception.cpp
new file mode 100644 (file)
index 0000000..35214e5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <boost/test/unit_test.hpp>
+
+#include <dpl/exception.h>
+
+using namespace CKM;
+
+BOOST_AUTO_TEST_SUITE(DPL_EXCEPTION_TEST)
+
+BOOST_AUTO_TEST_CASE(dpl_exception)
+{
+       try {
+               throw Exception(__FILE__, __func__, __LINE__, "message");
+       } catch (const Exception &e) {
+               BOOST_REQUIRE_NO_THROW(e.DumpToString());
+               BOOST_REQUIRE_NO_THROW(e.Dump());
+               BOOST_REQUIRE_NO_THROW(Exception::DisplayKnownException(e));
+               BOOST_REQUIRE_NO_THROW(Exception::DisplayUnknownException());
+       } catch (...) {
+               BOOST_REQUIRE_MESSAGE(false, "Unknown exception catched.");
+       }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_exception.cpp b/tests/test_exception.cpp
new file mode 100644 (file)
index 0000000..009b2d2
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <exception.h>
+
+#include <boost/test/unit_test.hpp>
+#include <string>
+
+using namespace CKM;
+
+#define CHECK_EXCEPTION(exception, ec, isDebug) \
+do { \
+       const std::string errmsg = "test exception string"; \
+       BOOST_REQUIRE_THROW(ThrowErr(exception, errmsg), exception); \
+       try { \
+               ThrowErr(exception, errmsg); \
+       } catch (const exception &e) { \
+               checkExceptionInternal(e, ec, isDebug ? std::string() : errmsg); \
+       } \
+} while (false)
+
+namespace {
+
+void checkExceptionInternal(const Exc::Exception &e, int ec, const std::string &msg)
+{
+       BOOST_REQUIRE_MESSAGE(e.error() == ec,
+               "ec(" << ec << ") not matched(" << e.error() << ")");
+
+       BOOST_REQUIRE_MESSAGE(msg == e.what(),
+               "msg(" << msg << ") isn't matched(" << e.what() << ")");
+
+       BOOST_REQUIRE_MESSAGE(e.message().find(msg) != std::string::npos,
+               "msg(" << msg << ") isn't contained from message("
+               << e.message() << ")");
+}
+
+} // namespace anonymous
+
+BOOST_AUTO_TEST_SUITE(EXCEPTION_TEST)
+
+BOOST_AUTO_TEST_CASE(internal_error)
+{
+       CHECK_EXCEPTION(Exc::InternalError, CKM_API_ERROR_SERVER_ERROR, false);
+}
+
+BOOST_AUTO_TEST_CASE(database_locked)
+{
+       CHECK_EXCEPTION(Exc::DatabaseLocked, CKM_API_ERROR_DB_LOCKED, false);
+}
+
+BOOST_AUTO_TEST_CASE(database_failed)
+{
+       CHECK_EXCEPTION(Exc::DatabaseFailed, CKM_API_ERROR_DB_ERROR, false);
+}
+
+BOOST_AUTO_TEST_CASE(filesystem_failed)
+{
+       CHECK_EXCEPTION(Exc::FileSystemFailed, CKM_API_ERROR_FILE_SYSTEM, false);
+}
+
+BOOST_AUTO_TEST_CASE(inputparam)
+{
+       CHECK_EXCEPTION(Exc::InputParam, CKM_API_ERROR_INPUT_PARAM, true);
+}
+
+BOOST_AUTO_TEST_CASE(authentication_failed)
+{
+       CHECK_EXCEPTION(Exc::AuthenticationFailed, CKM_API_ERROR_AUTHENTICATION_FAILED, true);
+}
+
+BOOST_AUTO_TEST_CASE(transaction_failed)
+{
+       CHECK_EXCEPTION(Exc::TransactionFailed, CKM_API_ERROR_DB_ERROR, false);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_generic-backend.cpp b/tests/test_generic-backend.cpp
new file mode 100644 (file)
index 0000000..c2e80a0
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <generic-backend/gobj.h>
+#include <generic-backend/gstore.h>
+//#include <generic-backend/algo-validation.h>
+
+#include <boost/test/unit_test.hpp>
+
+using namespace CKM;
+
+namespace {
+
+class GObjTest : public Crypto::GObj {
+public:
+       GObjTest() : Crypto::GObj() {}
+};
+
+class GStoreTest : public Crypto::GStore {
+public:
+       GStoreTest(CryptoBackend backendId) : Crypto::GStore(backendId) {}
+};
+
+struct TestException : public std::exception {};
+
+class ThrowingHandlerTest {
+public:
+       static void Handle(const std::string &)
+       {
+               throw TestException();
+       }
+};
+
+} // namespace anonymous
+
+BOOST_AUTO_TEST_SUITE(GENERIC_BACKEND_TEST)
+
+BOOST_AUTO_TEST_CASE(gobj)
+{
+       GObjTest obj;
+
+       BOOST_REQUIRE_THROW(obj.getBinary(), Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(obj.encrypt(CryptoAlgorithm(), RawBuffer()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(obj.decrypt(CryptoAlgorithm(), RawBuffer()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(obj.sign(CryptoAlgorithm(), RawBuffer()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(obj.verify(CryptoAlgorithm(), RawBuffer(), RawBuffer()),
+                                               Exc::Crypto::OperationNotSupported);
+}
+
+BOOST_AUTO_TEST_CASE(gstore)
+{
+       GStoreTest store(static_cast<CryptoBackend>(0));
+
+       BOOST_REQUIRE_THROW(store.getObject(Token(), Password()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(store.generateAKey(CryptoAlgorithm(), Password(), Password()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(store.generateSKey(CryptoAlgorithm(), Password()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(store.import(Crypto::Data(), Password()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(store.importEncrypted(Crypto::Data(), Password(),
+                                                                                         Crypto::DataEncryption()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(store.destroy(Token()),
+                                               Exc::Crypto::OperationNotSupported);
+}
+
+#if 0
+BOOST_AUTO_TEST_CASE(algo_validation_not_mandatory)
+{
+       constexpr ParamName pn = ParamName::ALGO_TYPE;
+       using Checker = Crypto::ParamCheck<
+                       pn, int, false, Crypto::Type<int>::Equals<0, 1, 2, 3, 4>,
+                       Crypto::DefaultGetter<int>>;
+
+       Checker checker;
+       CryptoAlgorithm ca;
+
+       BOOST_REQUIRE_NO_THROW(checker.Check(ca));
+
+       for (int i = 0; i < 5; ++i) {
+               ca.setParam(pn, i);
+               BOOST_REQUIRE_NO_THROW(checker.Check(ca));
+       }
+
+       for (int i = 5; i < 10; ++i) {
+               ca.setParam(pn, i);
+               BOOST_REQUIRE_THROW(checker.Check(ca), Exc::Crypto::InputParam);
+       }
+}
+
+BOOST_AUTO_TEST_CASE(algo_validation_mandatory)
+{
+       constexpr ParamName pn = ParamName::ALGO_TYPE;
+       using Checker = Crypto::ParamCheck<
+                       pn, int, true, Crypto::Type<int>::Equals<0, 1, 2, 3, 4>,
+                       Crypto::DefaultGetter<int>>;
+
+       Checker checker;
+       CryptoAlgorithm ca;
+
+       BOOST_REQUIRE_THROW(checker.Check(ca), Exc::Crypto::InputParam);
+
+       for (int i = 0; i < 5; ++i) {
+               ca.setParam(pn, i);
+               BOOST_REQUIRE_NO_THROW(checker.Check(ca));
+       }
+
+       for (int i = 5; i < 10; ++i) {
+               ca.setParam(pn, i);
+               BOOST_REQUIRE_THROW(checker.Check(ca), Exc::Crypto::InputParam);
+       }
+}
+
+BOOST_AUTO_TEST_CASE(algo_validation_throwing_handler)
+{
+       constexpr ParamName pn = ParamName::ALGO_TYPE;
+       using Checker = Crypto::ParamCheck<
+                       pn, int, true, Crypto::Type<int>::Equals<0, 1, 2, 3, 4>,
+                       Crypto::DefaultGetter<int>, ThrowingHandlerTest>;
+
+       Checker checker;
+       CryptoAlgorithm ca;
+       BOOST_REQUIRE_THROW(checker.Check(ca), TestException);
+
+       for (int i = 0; i < 5; ++i) {
+               ca.setParam(pn, i);
+               BOOST_REQUIRE_NO_THROW(checker.Check(ca));
+       }
+
+       for (int i = 5; i < 10; ++i) {
+               ca.setParam(pn, i);
+               BOOST_REQUIRE_THROW(checker.Check(ca), TestException);
+       }
+}
+#endif
+
+BOOST_AUTO_TEST_SUITE_END()
similarity index 78%
rename from tests/test-key-provider.cpp
rename to tests/test_key-provider.cpp
index 2186304..274080d 100644 (file)
@@ -15,7 +15,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License
  *
- * @file        test-key-provider.cpp
+ * @file        test_key-provider.cpp
  * @author      Kyungwook Tak (k.tak@samsung.com)
  * @version
  * @brief
@@ -163,5 +163,54 @@ BOOST_AUTO_TEST_CASE(KeyGetPureDEK_after_reencrypt)
        BOOST_REQUIRE_NO_THROW(keyProvider.getPureDEK(rb_DEK1));
 }
 
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_CASE(wrapped_container)
+{
+       CKM::WrappedKeyAndInfoContainer wrappedContainer;
+
+       auto salt = createRandom(20);
+       BOOST_REQUIRE_NO_THROW(wrappedContainer.setKeyInfoSalt(salt.data(), salt.size()));
+       BOOST_REQUIRE_NO_THROW(wrappedContainer.setKeyInfoLabel("key_info_label"));
+
+       CKM::WrappedKeyAndInfoContainer wrappedContainer2;
+       BOOST_REQUIRE_NO_THROW(
+               wrappedContainer2.setKeyInfo(&wrappedContainer.getWrappedKeyAndInfo().keyInfo));
+
+       BOOST_REQUIRE(
+               wrappedContainer.getWrappedKeyAndInfo().keyInfo.keyLength ==
+                       wrappedContainer2.getWrappedKeyAndInfo().keyInfo.keyLength);
+       BOOST_REQUIRE(memcmp(
+               wrappedContainer.getWrappedKeyAndInfo().keyInfo.salt,
+               wrappedContainer2.getWrappedKeyAndInfo().keyInfo.salt,
+               sizeof(wrappedContainer.getWrappedKeyAndInfo().keyInfo.salt)) == 0);
+       BOOST_REQUIRE(memcmp(
+               wrappedContainer.getWrappedKeyAndInfo().keyInfo.label,
+               wrappedContainer2.getWrappedKeyAndInfo().keyInfo.label,
+               sizeof(wrappedContainer.getWrappedKeyAndInfo().keyInfo.label)) == 0);
+}
+
+BOOST_AUTO_TEST_CASE(container)
+{
+       CKM::KeyAndInfoContainer container;
+       BOOST_REQUIRE_NO_THROW(container.setKeyInfoKeyLength(10));
 
+       CKM::KeyAndInfoContainer container2;
+       BOOST_REQUIRE_NO_THROW(container2.setKeyInfo(&container.getKeyAndInfo().keyInfo));
+
+       BOOST_REQUIRE(
+               container.getKeyAndInfo().keyInfo.keyLength ==
+                       container2.getKeyAndInfo().keyInfo.keyLength);
+}
+
+BOOST_AUTO_TEST_CASE(moves)
+{
+       CKM::KeyProvider provider;
+
+       try {
+               CKM::KeyProvider provider2(std::move(provider));
+               CKM::KeyProvider provider3 = std::move(provider2);
+       } catch (...) {
+               BOOST_REQUIRE_MESSAGE(false, "Unknown exception on moving KeyProvider");
+       }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_key.cpp b/tests/test_key.cpp
new file mode 100644 (file)
index 0000000..fa80504
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <key-impl.h>
+#include <key-aes-impl.h>
+
+#include <boost/test/unit_test.hpp>
+#include <string>
+
+namespace {
+const std::string PUBKEY_PEM =
+       "-----BEGIN PUBLIC KEY-----\n"
+       "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7Qxv\n"
+       "DKzyFCF3w9vC9IDE/Yr12w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh\n"
+       "7xk8qfEgH3daeDoV59IZ9r543KM+g8jm6KffYGX1bIJVVY5OhBRbO9nY6byYpd5k\n"
+       "bCIUB6dCf7/WrQl1aIdLGFIegAzPGFPXDcU6F192686x54bxt/itMX4agHJ9ZC/r\n"
+       "rTBIZghVsjJo5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY+Cgw1Yoz\n"
+       "+HHv31AllgFsBquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsq\n"
+       "GQIDAQAB\n"
+       "-----END PUBLIC KEY-----\n";
+}
+
+using namespace CKM;
+
+BOOST_AUTO_TEST_SUITE(KEY_TEST)
+
+BOOST_AUTO_TEST_CASE(constructors)
+{
+       RawBuffer keybuf(PUBKEY_PEM.begin(), PUBKEY_PEM.end());
+
+       KeyImpl key(keybuf);
+       BOOST_REQUIRE(!key.empty());
+
+       // valid key type case
+       BOOST_REQUIRE(!KeyImpl(key.getEvpShPtr(), KeyType::KEY_RSA_PUBLIC).empty());
+
+       // invalid key type cases
+       BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_DSA_PUBLIC).empty());
+       BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_DSA_PRIVATE).empty());
+       BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_ECDSA_PUBLIC).empty());
+       BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_ECDSA_PRIVATE).empty());
+       BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_AES).empty());
+       BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), static_cast<KeyType>(999999)).empty());
+}
+
+BOOST_AUTO_TEST_CASE(get_size)
+{
+       RawBuffer keybuf(PUBKEY_PEM.begin(), PUBKEY_PEM.end());
+
+       KeyImpl key(keybuf);
+       BOOST_REQUIRE(!key.empty());
+
+       // not ipmlemented yet but test for coverage. It'll just return 0
+       BOOST_REQUIRE_NO_THROW(key.getSize());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(AES_KEY_TEST)
+
+BOOST_AUTO_TEST_CASE(constructors)
+{
+       // invalid key size
+       RawBuffer keybuf({0x01, 0x02, 0x03, 0x04});
+       BOOST_REQUIRE(!Key::createAES(keybuf));
+
+       keybuf.clear();
+       for (size_t i = 0; i < 16; ++i)
+               keybuf.push_back(i);
+       BOOST_REQUIRE(Key::createAES(keybuf));
+
+       keybuf.clear();
+       for (size_t i = 0; i < 24; ++i)
+               keybuf.push_back(i);
+       BOOST_REQUIRE(Key::createAES(keybuf));
+
+       keybuf.clear();
+       for (size_t i = 0; i < 32; ++i)
+               keybuf.push_back(i);
+       BOOST_REQUIRE(Key::createAES(keybuf));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_log-provider.cpp b/tests/test_log-provider.cpp
new file mode 100644 (file)
index 0000000..5d13104
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <boost/test/unit_test.hpp>
+
+#include <dpl/log/old_style_log_provider.h>
+#include <dpl/log/journal_log_provider.h>
+#include <dpl/log/dlog_log_provider.h>
+#include <dpl/log/log.h>
+
+using namespace CKM;
+using namespace CKM::Log;
+
+namespace {
+
+std::vector<AbstractLogProvider::LogLevel> levels({
+       AbstractLogProvider::LogLevel::Error,
+       AbstractLogProvider::LogLevel::Warning,
+       AbstractLogProvider::LogLevel::Info,
+       AbstractLogProvider::LogLevel::Debug,
+       AbstractLogProvider::LogLevel::Pedantic,
+       static_cast<AbstractLogProvider::LogLevel>(999)
+});
+
+void testProvider(AbstractLogProvider &provider)
+{
+       for (auto level : levels)
+               BOOST_REQUIRE_NO_THROW(provider.Log(
+                       level, "message", __FILE__, __LINE__, __func__));
+
+       BOOST_REQUIRE_NO_THROW(provider.SetTag("tag"));
+}
+
+} // namespace anonymous
+
+BOOST_AUTO_TEST_SUITE(LOG_PROVIDER_TEST)
+
+BOOST_AUTO_TEST_CASE(oldstyle_backend)
+{
+       OldStyleLogProvider provider;
+
+       testProvider(provider);
+}
+
+BOOST_AUTO_TEST_CASE(journal_backend)
+{
+       JournalLogProvider provider;
+
+       testProvider(provider);
+}
+
+BOOST_AUTO_TEST_CASE(dlog_backend)
+{
+       DLOGLogProvider provider;
+
+       testProvider(provider);
+}
+
+BOOST_AUTO_TEST_CASE(log_system)
+{
+       LogSystem system;
+
+       system.AddProvider(new OldStyleLogProvider);
+       system.AddProvider(new JournalLogProvider);
+       system.AddProvider(new DLOGLogProvider);
+
+       for (auto level : levels)
+               BOOST_REQUIRE_NO_THROW(system.Log(
+                       level, "message", __FILE__, __LINE__, __func__));
+
+       BOOST_REQUIRE_NO_THROW(system.SetTag("Test"));
+
+       BOOST_REQUIRE_NO_THROW(system.SetLogLevel("5"));
+       BOOST_REQUIRE_NO_THROW(system.SetLogLevel("4"));
+       BOOST_REQUIRE_NO_THROW(system.SetLogLevel("3"));
+       BOOST_REQUIRE_NO_THROW(system.SetLogLevel("2"));
+       BOOST_REQUIRE_NO_THROW(system.SetLogLevel("1"));
+       BOOST_REQUIRE_NO_THROW(system.SetLogLevel("0"));
+       BOOST_REQUIRE(system.GetLogLevel() == AbstractLogProvider::LogLevel::None);
+
+       BOOST_REQUIRE_NO_THROW(system.SelectProvider("DLOG"));
+       BOOST_REQUIRE_NO_THROW(system.SelectProvider("JOURNALD"));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_ss-crypto.cpp b/tests/test_ss-crypto.cpp
new file mode 100644 (file)
index 0000000..c009207
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <ss-crypto.h>
+
+#include <boost/test/unit_test.hpp>
+
+#include <fstream>
+#include <string>
+
+using namespace CKM;
+
+namespace {
+
+RawBuffer readFile(const std::string &path)
+{
+       std::ifstream f(path.c_str(), std::ios::binary);
+       BOOST_REQUIRE_MESSAGE(f.is_open(), "Failed to open file: " << path);
+
+       f.seekg(0, f.end);
+       auto len = f.tellg();
+       BOOST_REQUIRE_MESSAGE(len > 0, "Failed to get file length: " << path);
+
+       f.seekg(0, f.beg);
+
+       RawBuffer buf(len, 0x00);
+       f.read(reinterpret_cast<char *>(buf.data()), buf.size());
+       BOOST_REQUIRE_MESSAGE(!!f, "Failed to read file: " << path);
+
+       return buf;
+}
+
+} // namespace anonymous
+
+BOOST_AUTO_TEST_SUITE(SS_CRYPTO_TEST)
+
+BOOST_AUTO_TEST_CASE(decrypt)
+{
+       const std::string seed = "secure-storage::test1";
+       const std::string path = std::string(SS_TEST_DIR) + "/" + seed + "/test-data-1";
+       BOOST_REQUIRE(!SsMigration::decrypt(seed, readFile(path)).empty());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_stringify.cpp b/tests/test_stringify.cpp
new file mode 100644 (file)
index 0000000..f4c5c7a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <stringify.h>
+
+#include <boost/test/unit_test.hpp>
+#include <string>
+
+BOOST_AUTO_TEST_SUITE(STRINGIFY_TEST)
+
+BOOST_AUTO_TEST_CASE(stringify_default)
+{
+       BOOST_REQUIRE(Stringify("a", "b", "c") == "abc");
+       BOOST_REQUIRE(Stringify(std::string("a"), "b", "c") == "abc");
+       BOOST_REQUIRE(Stringify().empty());
+}
+
+BOOST_AUTO_TEST_CASE(stringify_avoid)
+{
+       BOOST_REQUIRE(StringifyAvoid("a", "b", "c").empty());
+       BOOST_REQUIRE(StringifyAvoid(std::string("a"), "b", "c").empty());
+       BOOST_REQUIRE(StringifyAvoid().empty());
+}
+
+BOOST_AUTO_TEST_CASE(stringify_error)
+{
+       BOOST_REQUIRE(StringifyError("a", "b", "c") == "abc");
+       BOOST_REQUIRE(StringifyError(std::string("a"), "b", "c") == "abc");
+       BOOST_REQUIRE(StringifyError().empty());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_sw-backend.cpp b/tests/test_sw-backend.cpp
new file mode 100644 (file)
index 0000000..603a1bf
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <sw-backend/crypto.h>
+
+#include <boost/test/unit_test.hpp>
+
+#include "test_common.h"
+
+using namespace CKM;
+using namespace CKM::Crypto::SW::Cipher;
+
+BOOST_AUTO_TEST_SUITE(SW_BACKEND_TEST)
+
+BOOST_AUTO_TEST_SUITE(CRYPTO)
+
+BOOST_AUTO_TEST_CASE(constructs)
+{
+       BOOST_REQUIRE_NO_THROW(AesCbcEncryption128(createRandom(16), createRandom(16)));
+
+       BOOST_REQUIRE_THROW(AesCbcEncryption128(createRandom(16), createRandom(5)),
+                                               Exc::Crypto::InternalError);
+       BOOST_REQUIRE_THROW(AesCbcEncryption128(createRandom(17), createRandom(16)),
+                                               Exc::Crypto::InternalError);
+}
+
+BOOST_AUTO_TEST_CASE(encryption_cbc)
+{
+       AesCbcEncryption128 cipher(createRandom(16), createRandom(16));
+
+       BOOST_REQUIRE_NO_THROW(cipher.Append(createRandom(10)));
+       BOOST_REQUIRE_NO_THROW(cipher.Finalize());
+}
+
+BOOST_AUTO_TEST_CASE(encryption_gcm)
+{
+       AesGcmEncryption128 cipher(createRandom(16), createRandom(16));
+
+       BOOST_REQUIRE_NO_THROW(cipher.AppendAAD(createRandom(10)));
+       BOOST_REQUIRE_NO_THROW(cipher.Append(createRandom(10)));
+       BOOST_REQUIRE_NO_THROW(cipher.Finalize());
+}
+
+BOOST_AUTO_TEST_SUITE_END() // CRYPTO
+
+BOOST_AUTO_TEST_SUITE_END() // SW_BACKEND_TEST
diff --git a/tests/test_tz-backend.cpp b/tests/test_tz-backend.cpp
new file mode 100644 (file)
index 0000000..745d3f8
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+#include <tz-backend/store.h>
+
+#include <boost/test/unit_test.hpp>
+
+using namespace CKM;
+using namespace CKM::Crypto;
+
+BOOST_AUTO_TEST_SUITE(TZ_BACKEND_TEST)
+
+BOOST_AUTO_TEST_CASE(store)
+{
+       TZ::Store store(static_cast<CryptoBackend>(0));
+
+       BOOST_REQUIRE_THROW(store.getObject(Token(), Password()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(store.generateAKey(CryptoAlgorithm(), Password(), Password()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(store.import(Data(), Password()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_THROW(store.importEncrypted(Data(), Password(), DataEncryption()),
+                                               Exc::Crypto::OperationNotSupported);
+       BOOST_REQUIRE_NO_THROW(store.destroy(Token()));
+}
+
+BOOST_AUTO_TEST_SUITE_END()