Fix internal tests
[platform/core/security/cert-svc.git] / tests / capi / test_suite_02.cpp
1 /*
2  * Copyright (c) 2011 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 <string>
17
18 #include <openssl/x509.h>
19
20 #include <dpl/test/test_runner.h>
21 #include <memory>
22
23 #include <api_tests.h>
24
25 #include <cert-service.h>
26
27 RUNNER_TEST_GROUP_INIT(DEPRECATED_API)
28
29 typedef std::unique_ptr<CERT_CONTEXT, std::function<int(CERT_CONTEXT*)>> ScopedCertCtx;
30
31 /*
32  * author:      ---
33  * test:        PEM positive.
34  * description: Loading *.pem file.
35  * expect:      *.pem should load with no error.
36  */
37 RUNNER_TEST(deprecated_api_test01_pem_positive)
38 {
39     ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final);
40     RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR ==
41         cert_svc_load_file_to_context(ctx.get(), "/usr/share/cert-svc/cert-type/cert0.pem"));
42 }
43
44 /*
45  * author:      ---
46  * test:        DER positive.
47  * description: Loading *.der file.
48  * expect:      *.der file should load with no error.
49  */
50 RUNNER_TEST(deprecated_api_test02_der_positive)
51 {
52     ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final);
53     RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR ==
54         cert_svc_load_file_to_context(ctx.get(), "/usr/share/cert-svc/cert-type/cert1.der"));
55 }
56
57 /*
58  * author:      ---
59  * test:        PEM negative.
60  * description: Loading *.pem file.
61  * expect:      *.pom file should not load and return error.
62  */
63 RUNNER_TEST(deprecated_api_test03_pem_negative)
64 {
65     ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final);
66     RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR !=
67         cert_svc_load_file_to_context(ctx.get(), "/usr/share/cert-svc/cert-type/cert2fake.pem"));
68 }
69
70 /*
71  * author:      ---
72  * test:        DER negative.
73  * description: Loading *.der file.
74  * expect:      *.der file should not load and return error.
75  */
76 RUNNER_TEST(deprecated_api_test03_der_negative)
77 {
78     ScopedCertCtx ctx(cert_svc_cert_context_init(), cert_svc_cert_context_final);
79     RUNNER_ASSERT(CERT_SVC_ERR_NO_ERROR !=
80         cert_svc_load_file_to_context(ctx.get(), "/usr/share/cert-svc/cert-type/cert3fake.der"));
81 }
82