Remove boost dependency
[platform/core/appfw/app-installers.git] / test / smoke_tests / signature_smoketest.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include <gtest/gtest.h>
6
7 #include <memory>
8
9 #include "common/certificate_validation.h"
10
11 namespace fs = std::filesystem;
12
13 namespace common_installer {
14 namespace security {
15
16 class SignatureValidatorTest : public testing::Test {
17  protected:
18   std::unique_ptr<fs::path> signature_file;
19 };
20
21 // Tests signature verifier with proper signatures
22 TEST_F(SignatureValidatorTest, HandlesInitializedSignatureDir) {
23   signature_file.reset(new fs::path(
24       "/usr/share/app-installers-ut/test_samples/good_signatures"));
25   PrivilegeLevel level = PrivilegeLevel::UNTRUSTED;
26   common_installer::CertificateInfo cert_info;
27   std::string error;
28   EXPECT_TRUE(ValidateSignatures(*signature_file, &level, &cert_info, true,
29                                  &error));
30 }
31
32 // Tests signature verifier with signature directory containing bad signatures
33 TEST_F(SignatureValidatorTest, HandlesBadSignatureDir) {
34   signature_file.reset(new fs::path(
35       "/usr/share/app-installers-ut/test_samples/bad_signatures"));
36   PrivilegeLevel level = PrivilegeLevel::UNTRUSTED;
37   common_installer::CertificateInfo cert_info;
38   std::string error;
39   EXPECT_FALSE(ValidateSignatures(*signature_file, &level, &cert_info, true,
40                                   &error));
41 }
42
43 }  // namespace security
44 }  // namespace common_installer
45
46 int main(int argc, char** argv) {
47   int ret = -1;
48   try {
49     testing::InitGoogleTest(&argc, argv);
50   } catch(...) {
51     std::cout << "Exception occurred" << std::endl;
52   }
53
54   try {
55     ret = RUN_ALL_TESTS();
56   } catch (const ::testing::internal::GoogleTestFailureException& e) {
57     ret = -1;
58     std::cout << "GoogleTestFailureException was thrown:" << e.what()
59               << std::endl;
60   }
61
62   return ret;
63 }